-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathctmbattlesystem.c
321 lines (267 loc) · 9.08 KB
/
ctmbattlesystem.c
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <stdbool.h>
#include <string.h>
#include <unistd.h>
#include "character.h"
#include "ctmcharlist.h"
#include "ctmbattlequeue.h"
#include "ctmbattlesystem.h"
void delay(int MS){
clock_t start = clock();
// Calcular o número de pulsos de clock correspondentes aos milissegundos desejados
clock_t pulses = (MS * CLOCKS_PER_SEC) / 1000;
while ((clock() - start) < pulses){
}
}
bool probability(int success){
srand(time(NULL));
int result = rand() % 100;
if (result < success){
//porcentagem de sucesso foi correspondida
return true;
}
else{
//nao foi correspondida
return false;
}
}
int hitOrMiss(int DMG, float CRIT_DMG, int agility){
int true_DMG;
if(probability(agility)){
true_DMG = DMG;
}
else{
printf("miss\n");
return 0;
}
int critical_agility = agility/2;
if(probability(critical_agility)){
printf("dano critico\n");
true_DMG += (true_DMG * CRIT_DMG);
}
return true_DMG;
}
void attack(struct character *char_attacked, int atk, struct equipment_weapon weapon, float crit, int agility, char author_name[20], int control){
float def = char_attacked->DEF;
if(weapon.equipment_action != -1){ // sistema de arma deve ser aprimorado assim que o inventário for implementado
atk = atk + weapon.equipment_action;
}
int local;
do{
if(control == 1){
printf("\nescolha a parte do corpo que deseja atacar:\n\n1. cabeça\n2. tronco\n3. braço direito\n4. braço esquerdo\n5. perna direita\n6. perna esquerda\n");
setbuf(stdin, NULL);
scanf("%i",&local);
}
else{
srand(time(NULL));
local = rand() % 6 + 1; //bot para testes, implementar um bot inteligente em cython
}
switch (local){
case 1:
if(char_attacked->members.head > 0){
atk = hitOrMiss(atk, crit, agility);
printf("%s infligiu %i de dano na cabeça do(a) %s.\n", author_name, atk, char_attacked->name);
printf("%i ->", char_attacked->members.head);
char_attacked->members.head -= atk-(atk*def);
printf(" %i\n", char_attacked->members.head);
if(char_attacked->members.head <= 0){
printf("a cabeça do(a) %s foi arrancada.\n", char_attacked->name);
char_attacked->HP = 0;
}
printf("vida total: %i ->", char_attacked->HP);
char_attacked->HP -= atk-(atk*def);
printf(" %i\n", char_attacked->HP);
}
break;
case 2:
if(char_attacked->members.torso > 0){
atk = hitOrMiss(atk, crit, agility);
printf("%s infligiu %i de dano no tronco do(a) %s.\n", author_name, atk, char_attacked->name);
printf("%i ->", char_attacked->members.torso);
char_attacked->members.torso -= atk-(atk*def);
printf(" %i\n", char_attacked->members.torso);
if(char_attacked->members.torso <= 0){
printf("BULLSEYA FOR %s\n", char_attacked->name);
char_attacked->HP = 0;
}
printf("vida total: %i ->", char_attacked->HP);
char_attacked->HP -= atk-(atk*def);
printf(" %i\n", char_attacked->HP);
}
break;
case 3:
if(char_attacked->members.arm_right > 0){
atk = hitOrMiss(atk, crit, agility);
printf("%s infligiu %i de dano no braço direito do(a) %s.\n", author_name, atk, char_attacked->name);
printf("%i ->", char_attacked->members.arm_right);
char_attacked->members.arm_right -= atk-(atk*def);
printf(" %i\n", char_attacked->members.arm_right);
if(char_attacked->members.arm_right <= 0){
printf("o braço direito do(a) %s foi arrancado.\n", char_attacked->name);
printf("%s não pode mais empunhar a arma %s\n", char_attacked->name, char_attacked->equipment.weapon.name);
char_attacked->equipment.weapon.equipment_action = -1; //aqui também
}
printf("vida total: %i ->", char_attacked->HP);
char_attacked->HP -= atk-(atk*def);
printf(" %i\n", char_attacked->HP);
}
else{
printf("o braço direito do(a) %s já foi arrancado.\n", char_attacked->name);
local = 666;
}
break;
case 4:
if(char_attacked->members.arm_left > 0){
atk = hitOrMiss(atk, crit, agility);
printf("%s infligiu %i de dano no braço esquerdo do(a) %s.\n", author_name, atk, char_attacked->name);
printf("%i ->", char_attacked->members.arm_left);
char_attacked->members.arm_left -= atk-(atk*def);
printf(" %i\n", char_attacked->members.arm_left);
if(char_attacked->members.arm_left <= 0)
printf("o braço esquerdo do(a) %s foi arrancado.\n", char_attacked->name);
printf("vida total: %i ->", char_attacked->HP);
char_attacked->HP -= atk-(atk*def);
printf(" %i\n", char_attacked->HP);
}
else{
printf("o braço esquerdo do(a) %s já foi arrancado.\n", char_attacked->name);
local = 666;
}
break;
case 5:
if(char_attacked->members.leg_right > 0){
atk = hitOrMiss(atk, crit, agility);
printf("%s infligiu %i de dano na perna direita do(a) %s.\n", author_name, atk, char_attacked->name);
printf("%i ->", char_attacked->members.leg_right);
char_attacked->members.leg_right -= atk-(atk*def);
printf(" %i\n", char_attacked->members.leg_right);
if(char_attacked->members.leg_right <= 0){
printf("a perna direita do(a) %s foi arrancado. (-10 de agilidade)\n", char_attacked->name);
char_attacked->agility = agility - 10;
}
printf("vida total: %i ->", char_attacked->HP);
char_attacked->HP -= atk-(atk*def);
printf(" %i\n", char_attacked->HP);
}
else{
printf("a perna direita do(a) %s já foi arrancada.\n", char_attacked->name);
local = 666;
}
break;
case 6:
if(char_attacked->members.leg_left > 0){
atk = hitOrMiss(atk, crit, agility);
printf("%s infligiu %i de dano na perna esquerda do(a) %s.\n", author_name, atk, char_attacked->name);
printf("%i ->", char_attacked->members.leg_left);
char_attacked->members.leg_left -= atk-(atk*def);
printf(" %i\n", char_attacked->members.leg_left);
if(char_attacked->members.leg_left <= 0){
printf("a perna esquerda do(a) %s foi arrancado. (-10 de agilidade)\n", char_attacked->name);
char_attacked->agility = agility - 10;
}
printf("vida total: %i ->", char_attacked->HP);
char_attacked->HP -= atk-(atk*def);
printf(" %i\n", char_attacked->HP);
}
else{
printf("a perna esquerda do(a) %s já foi arrancada.\n", char_attacked->name);
local = 666;
}
break;
default:
printf("escolha invalida.\n");
break;
}
}while((local > 6) || (local < 1));
return;
}
void battle(struct desc_LSE *list, struct character *player, struct character *oponent){
bool victory = false;
bool defeat = false;
struct desc_queue *queue = newQueue();
struct queue_node *new_queue_node = NULL;
while((victory == false) && (defeat == false)){
new_queue_node = queueNode(player);
enqueue(queue, new_queue_node);
new_queue_node = queueNode(oponent);
enqueue(queue, new_queue_node);
new_queue_node = head(queue);
if(strcmp(new_queue_node->info->name, player->name) == 0){
printf("\n\n===================================================================\n\t\t\tS E U T U R N O\n");
int op;
do{
printf("\n\n1. a t t a c k\t\t2. r e s t\t\t3. s k i l l s\n\n4. t a l k\t\t5. i t e m\t\t6. r u n\n");
setbuf(stdin, NULL);
scanf("%i",&op);
switch(op){
case 1:
if(player->SP >= 12){
attack(oponent, player->DMG, player->equipment.weapon, player->CRIT_DMG, player->agility, player->name, 1);
player->SP -= 12;
}
else{
printf("estamina insuficiente.\n");
op = 666;
}
break;
case 2:
printf("descansando...\n");
player->SP += 9;
break;
case 3:
printf("NAO IMPLEMENTADO\n");
break;
case 4:
printf("NAO IMPLEMENTADO\n");
break;
case 5:
printf("NAO IMPLEMENTADO\n");
break;
case 6:
if(probability(player->agility)){
printf("você escapou com sucesso!\n");
return;
}
printf("você não conseguiu escapar!\n");
break;
default:
printf("escolha inválida na batalha.\n");
break;
}
}while((op > 6) || (op < 1));
printf("===================================================================\n\n");
dequeue(queue);
if(oponent->HP <= 0)
victory = true;
}
new_queue_node = head(queue);
if(strcmp(new_queue_node->info->name, oponent->name) == 0){
printf("\n\n===================================================================\n\t\tT U R N O D O O P O N E N T E\n\n\n");
if(oponent->SP >= 12){
delay(1000);
attack(player, oponent->DMG, oponent->equipment.weapon, oponent->CRIT_DMG, oponent->agility, oponent->name, 2);
oponent->SP -= 12;
}
else{
printf("descansando...\n");
oponent->SP += 9;
}
printf("===================================================================\n\n");
dequeue(queue);
if(player->HP <= 0)
defeat = true;
}
}
if(victory == true){
printf("you win!\n");
removeCharacter(list ,oponent->name);
}
else{
printf("you lose!\n");
removeCharacter(list, player->name);
}
return;
}