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