SourceForge has been redesigned. Learn more.
Close

[c5a3d1]: / Classes / Player.cs  Maximize  Restore  History

Download this file

91 lines (77 with data), 2.8 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net.Sockets;
using System.Text;
using System.Windows;
using MySql.Data.MySqlClient;
using System.Net;
namespace YuGiOh_Ultra {
public sealed class Player {
public Deck MainDeck;
public Hand Hand;
public Field MonsterField, StField;
public CardStack ExtraDeck, Graveyard, Banished;
private uint _lifepoints;
/// <summary>
/// Player Id
/// </summary>
public uint Id { get; private set; }
public string Name { get; private set; }
public uint LifePoints {
get { return _lifepoints; }
set {
if( _lifepoints + value <= 0 ) {
_lifepoints = 0;
//call lose event
} else _lifepoints += value;
}
}
private Player( uint id ) { //loads player
Id = id;
}
public Player( MySqlDataReader reader ) : this( reader.GetUInt32( "id" ) ) {
uint eqdeck = reader.GetUInt32( "eqdeck" );
if( eqdeck != 0 ) EquipDeck( eqdeck );
Name = reader.GetString( "name" );
}
public void UpdateDbLastAction() {
var con = new MySqlConnection( Com.connStr );
con.Open();
try {
new MySqlCommand( "UPDATE users SET `lastlog` = NOW( ) WHERE `id` = " + Id, con ).ExecuteNonQuery();
}
catch {
//MessageBox.Show( "Failure!" );
}
con.Close();
}
public void EquipDeck( uint deck ) { EquipDeck( new Deck( deck ) ); }
public void InitBattle( uint startlp = 8000 ) {
LifePoints = startlp;
MainDeck.Reset();
ExtraDeck = new CardStack();
Graveyard = new CardStack();
Banished = new CardStack();
MonsterField = new Field();
StField = new Field();
Hand = new Hand( MainDeck.Draw( 7 ) );
}
public string GetIP(){
string localIP = "127.0.0.1";
var host = Dns.GetHostEntry( Dns.GetHostName() );
foreach( IPAddress ip in host.AddressList )
if( ip.AddressFamily == AddressFamily.InterNetwork ) localIP = ip.ToString();
return localIP;
}
public void EquipDeck( Deck deck ) {
MainDeck = deck;
var con = new MySqlConnection( Com.connStr );
con.Open();
new MySqlCommand( "UPDATE `users` SET `eqdeck` = '" + deck.Id + "' WHERE `id` =" + Id, con ).ExecuteNonQuery();
con.Close();
UpdateDbLastAction();
}
}
}