2022-01-24 15:15:12 +01:00
|
|
|
#include <gint/display.h>
|
|
|
|
#include <gint/keyboard.h>
|
2022-01-24 21:27:51 +01:00
|
|
|
#include <string.h>
|
2022-02-15 21:46:53 +01:00
|
|
|
#include <stdlib.h>
|
2022-02-13 21:46:52 +01:00
|
|
|
#include <math.h>
|
2022-02-16 19:40:41 +01:00
|
|
|
#include <gint/rtc.h>
|
2022-01-24 15:15:12 +01:00
|
|
|
|
|
|
|
#include "capacite.h"
|
2022-02-16 19:40:41 +01:00
|
|
|
#include "util.h"
|
2022-01-24 15:15:12 +01:00
|
|
|
|
2022-01-24 21:27:51 +01:00
|
|
|
extern struct Capacities capacities;
|
2022-01-24 15:15:12 +01:00
|
|
|
|
|
|
|
struct Move default_move() {
|
2022-01-24 21:27:51 +01:00
|
|
|
return *capacities.moves[0];
|
2022-01-24 15:15:12 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
struct Move get_move_id(int id) {
|
2022-01-24 21:27:51 +01:00
|
|
|
return *capacities.moves[id];
|
|
|
|
}
|
|
|
|
|
2022-02-16 19:40:41 +01:00
|
|
|
struct Move *get_move_id_pointer(int id) {
|
2022-02-15 21:46:53 +01:00
|
|
|
return capacities.moves[id];
|
|
|
|
}
|
|
|
|
|
|
|
|
struct Move *copy_move(struct Move move) {
|
|
|
|
struct Move *copyMove = malloc(sizeof(struct Move));
|
|
|
|
copyMove->name = move.name;
|
|
|
|
copyMove->pp = move.pp;
|
|
|
|
copyMove->atk = move.atk;
|
|
|
|
|
|
|
|
return copyMove;
|
|
|
|
}
|
|
|
|
|
|
|
|
void draw_move(int x, int y, int x2, int y2, struct Move *move) {
|
2022-02-15 02:15:08 +01:00
|
|
|
extern bopti_image_t img_capacite;
|
2022-01-24 21:27:51 +01:00
|
|
|
const int font_size = 8;
|
2022-02-15 02:15:08 +01:00
|
|
|
dimage(x, y, &img_capacite);
|
2022-02-15 21:46:53 +01:00
|
|
|
int color = move->pp > 0 ? C_BLACK : C_RED;
|
|
|
|
dprint(x+15, y+5, color, "PP : %d", move->pp);
|
|
|
|
dprint(x+15, y2-20, C_BLACK, "ATK : %d", move->atk);
|
|
|
|
dprint((int)((x+x2)/2)-(int)(strlen(move->name)/2*font_size),
|
2022-01-24 21:27:51 +01:00
|
|
|
(int)((y+y2)/2)-font_size/2,
|
2022-02-15 21:46:53 +01:00
|
|
|
C_BLACK, "%s", move->name);
|
2022-01-24 21:27:51 +01:00
|
|
|
}
|
|
|
|
|
2022-02-15 21:46:53 +01:00
|
|
|
void draw_classic_move(int x, int y, struct Move *move) {
|
2022-01-27 23:53:10 +01:00
|
|
|
draw_move(x, y, x+125, y+60, move);
|
2022-01-25 22:20:10 +01:00
|
|
|
}
|
|
|
|
|
2022-02-15 21:46:53 +01:00
|
|
|
void execute_move(struct Stats *player_stats, struct Stats *monster_stats, struct Move *move, int ismonster) {
|
2022-02-11 19:00:44 +01:00
|
|
|
if(ismonster) {
|
2022-02-13 21:46:52 +01:00
|
|
|
player_stats->pv-=calc_damage(monster_stats, player_stats, move);
|
2022-02-11 19:00:44 +01:00
|
|
|
} else {
|
2022-02-15 21:46:53 +01:00
|
|
|
move->pp--;
|
2022-02-13 21:46:52 +01:00
|
|
|
monster_stats->pv-=calc_damage(player_stats, monster_stats, move);
|
2022-02-11 19:00:44 +01:00
|
|
|
}
|
2022-02-13 21:46:52 +01:00
|
|
|
}
|
|
|
|
|
2022-02-15 21:46:53 +01:00
|
|
|
int calc_damage(struct Stats *attacker, struct Stats *target, struct Move *move) {
|
2022-02-16 19:40:41 +01:00
|
|
|
return (floor(((2*attacker->level / 5 + 2) * attacker->atk * move->atk / target->def) / 50) + 2)*crit(attacker);
|
|
|
|
}
|
|
|
|
|
|
|
|
int is_crit() {
|
|
|
|
//une chance sur 16 d'avoir un coup critique
|
|
|
|
const int proba_crit = 16;
|
|
|
|
return rand_range(0,proba_crit)==0 ? 1 : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
float crit(struct Stats *attacker) {
|
|
|
|
srand(rtc_ticks());
|
|
|
|
float taux = 1.0f;
|
|
|
|
//une chance sur 16 d'avoir un coup critique
|
|
|
|
if(is_crit()) {
|
|
|
|
taux = (float)(2 * attacker->level + 5)/(attacker->level+5);
|
|
|
|
}
|
|
|
|
return taux;
|
2022-01-24 15:15:12 +01:00
|
|
|
}
|