]>
Commit | Line | Data |
---|---|---|
1 | #include "player.h" | |
2 | #include <stdlib.h> | |
3 | #include <stdio.h> | |
4 | ||
5 | void Player::reset() | |
6 | { | |
7 | delete this; | |
8 | name = new char[64]; | |
9 | password = new char[256]; | |
10 | name[0] = '\0'; | |
11 | password[0] = '\0'; | |
12 | ||
13 | exp = 1; | |
14 | gold = 0; | |
15 | bank = 500; | |
16 | hp = 10; | |
17 | maxhp = 10; | |
18 | strength = 0; | |
19 | defense = 0; | |
20 | armor = 1; | |
21 | weapon = 1; | |
22 | level = 1; | |
23 | alive = 1; | |
24 | started = 1; // Possibly deprecated | |
25 | forest_fights = 100; | |
26 | player_fights = 3; | |
27 | fight = NULL; | |
28 | master = NULL; | |
29 | battle = NULL; | |
30 | } | |
31 | ||
32 | Player::Player(aClient *user) | |
33 | { | |
34 | ||
35 | if (user) | |
36 | { | |
37 | if (user->stats) | |
38 | setData(user->stats); | |
39 | else | |
40 | reset(); // Set Defaults | |
41 | ||
42 | strcpy(name, user->getNick()); | |
43 | } | |
44 | else | |
45 | { | |
46 | reset(); // Set default properties | |
47 | int num = rand() % 32767; | |
48 | sprintf(name, "Player%d", num); | |
49 | } | |
50 | cout << "New Player: " << name << endl << flush; | |
51 | } | |
52 | Player::Player(char *n) | |
53 | { | |
54 | reset(); // Set defaults | |
55 | ||
56 | strcpy(name, n); | |
57 | ||
58 | cout << "New Player: " << name << endl << flush; | |
59 | } | |
60 | ||
61 | Player::~Player() | |
62 | { | |
63 | if (name) | |
64 | delete name; | |
65 | if (password) | |
66 | delete password; | |
67 | } | |
68 | ||
69 | void Player::setData(Player *right) | |
70 | { | |
71 | if (right) | |
72 | { | |
73 | strcpy(name, right->name); | |
74 | strcpy(password, right->password); | |
75 | ||
76 | exp = right->exp; | |
77 | gold = right->gold; | |
78 | bank = right->bank; | |
79 | hp = right->hp; | |
80 | maxhp = right->maxhp; | |
81 | strength = right->strength; | |
82 | defense = right->defense; | |
83 | armor = right->armor; | |
84 | weapon = right->weapon; | |
85 | level = right->level; | |
86 | alive = right->alive; | |
87 | started = right->started; // Possibly obsoleted | |
88 | forest_fights = right->forest_fights; | |
89 | player_fights = right->player_fights; | |
90 | cout << "Setting Player data for " << right->name << endl; | |
91 | } | |
92 | } | |
93 | ||
94 | const Player &Player::operator=( const Player &right ) | |
95 | { | |
96 | if (&right != this) | |
97 | { | |
98 | strcpy(name, right.name); | |
99 | strcpy(password, right.password); | |
100 | exp = right.exp; | |
101 | gold = right.gold; | |
102 | bank = right.bank; | |
103 | hp = right.hp; | |
104 | maxhp = right.maxhp; | |
105 | strength = right.strength; | |
106 | defense = right.defense; | |
107 | armor = right.armor; | |
108 | weapon = right.weapon; | |
109 | level = right.level; | |
110 | alive = right.alive; | |
111 | started = right.started; // Possibly obsoleted | |
112 | forest_fights = right.forest_fights; | |
113 | player_fights = right.player_fights; | |
114 | } | |
115 | return *this; // Enables Cascading ( x = y = z;) | |
116 | } |