]>
Commit | Line | Data |
---|---|---|
1 | #include "player.h" | |
2 | #include "pouch.h" | |
3 | #include "extern.h" | |
4 | #include "flags.h" | |
5 | #include <stdlib.h> | |
6 | #include <stdio.h> | |
7 | ||
8 | void Player::reset() | |
9 | { | |
10 | memset(name, 0, 256); | |
11 | memset(password, 0, 256); | |
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 | forest_fights = forestfights; | |
24 | player_fights = 3; | |
25 | fight = NULL; | |
26 | master = NULL; | |
27 | battle = NULL; | |
28 | flags = 0; | |
29 | setAlive(this); | |
30 | inventory.reset(); | |
31 | } | |
32 | Player::Player() | |
33 | { | |
34 | name = new char[256]; | |
35 | password = new char[256]; | |
36 | setData(NULL); | |
37 | ||
38 | #ifdef DEBUGMODE | |
39 | log("New Player: %s", name); | |
40 | #endif | |
41 | } | |
42 | ||
43 | Player::Player(aClient *user) | |
44 | { | |
45 | ||
46 | name = new char[256]; | |
47 | password = new char[256]; | |
48 | ||
49 | if (user) | |
50 | { | |
51 | setData(user->stats); | |
52 | strcpy(name, user->getNick()); | |
53 | } | |
54 | else | |
55 | setData(NULL); | |
56 | ||
57 | } | |
58 | ||
59 | Player::Player(char *n) | |
60 | { | |
61 | name = new char[256]; | |
62 | password = new char[256]; | |
63 | ||
64 | reset(); // Set defaults | |
65 | ||
66 | strcpy(name, n); | |
67 | ||
68 | #ifdef DEBUGMODE | |
69 | log("New Player: %s", name); | |
70 | #endif | |
71 | } | |
72 | ||
73 | Player::~Player() | |
74 | { | |
75 | #ifdef DEBUGMODE | |
76 | char *output; | |
77 | output = new char[strlen(name) + strlen(password) + 48]; | |
78 | strcpy(output, "Deleting Player"); | |
79 | #endif | |
80 | ||
81 | if (name != NULL) | |
82 | { | |
83 | #ifdef DEBUGMODE | |
84 | sprintf(output, "%s: %s", output, name); | |
85 | #endif | |
86 | ||
87 | delete [] name; | |
88 | } | |
89 | ||
90 | if (password != NULL) | |
91 | { | |
92 | #ifdef DEBUGMODE | |
93 | sprintf(output, "%s Password: %s", output, password); | |
94 | #endif | |
95 | ||
96 | delete [] password; | |
97 | } | |
98 | ||
99 | #ifdef DEBUGMODE | |
100 | log ("%s", output); | |
101 | delete [] output; | |
102 | #endif | |
103 | } | |
104 | ||
105 | void Player::setData(Player *right) | |
106 | { | |
107 | if (right) | |
108 | { | |
109 | strcpy(name, right->name); | |
110 | strcpy(password, right->password); | |
111 | exp = right->exp; | |
112 | gold = right->gold; | |
113 | bank = right->bank; | |
114 | hp = right->hp; | |
115 | maxhp = right->maxhp; | |
116 | strength = right->strength; | |
117 | defense = right->defense; | |
118 | armor = right->armor; | |
119 | weapon = right->weapon; | |
120 | level = right->level; | |
121 | forest_fights = right->forest_fights; | |
122 | player_fights = right->player_fights; | |
123 | flags = right->flags; | |
124 | inventory.setInventory(&right->inventory); | |
125 | client = right->client; | |
126 | } | |
127 | else | |
128 | { | |
129 | reset(); | |
130 | client = NULL; | |
131 | int num = rand() % 32767; | |
132 | sprintf(name, "Player%d", num); | |
133 | } | |
134 | ||
135 | #ifdef DEBUGMODE | |
136 | log("Setting Player data for %s", name); | |
137 | #endif | |
138 | } | |
139 | ||
140 | monster_::~monster_() | |
141 | { | |
142 | delete name; | |
143 | delete weapon; | |
144 | delete death; | |
145 | } | |
146 | ||
147 | monster_::monster_() | |
148 | { | |
149 | name = new char[64]; | |
150 | weapon = new char[64]; | |
151 | death = new char[512]; | |
152 | ||
153 | memset(name, 0, 64); | |
154 | memset(weapon, 0, 64); | |
155 | memset(death, 0, 512); | |
156 | } | |
157 | ||
158 | monster_::monster_(monster_ *m) | |
159 | { | |
160 | name = new char[strlen(m->name) + 1]; | |
161 | weapon = new char[strlen(m->weapon) + 1]; | |
162 | death = new char[strlen(m->death) + 1]; | |
163 | ||
164 | strcpy(name, m->name); | |
165 | strcpy(weapon, m->weapon); | |
166 | strcpy(death, m->death); | |
167 | ||
168 | strength = m->strength; | |
169 | maxhp = m->maxhp; | |
170 | hp = m->hp; | |
171 | gold = m->gold; | |
172 | exp = m->exp; | |
173 | } | |
174 | ||
175 | long int Player::setFlags(long int newflags) | |
176 | { | |
177 | flags = newflags; | |
178 | return getFlags(); | |
179 | } | |
180 | ||
181 | long int Player::addFlag(long int flag) | |
182 | { | |
183 | flags |= flag; | |
184 | return getFlags(); | |
185 | } | |
186 | ||
187 | long int Player::remFlag(long int flag) | |
188 | { | |
189 | flags &= ~flag; | |
190 | return getFlags(); | |
191 | } | |
192 | ||
193 | Pouch::Pouch(int h, int s, int d) | |
194 | { | |
195 | setHealing(h); | |
196 | setStrength(s); | |
197 | setDefense(d); | |
198 | } |