Adoranda/src/capacite.c

100 lines
2.5 KiB
C
Raw Normal View History

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-02-17 21:26:33 +01:00
for(int i = 0; i < capacities.nbCapacities; i++) {
if(capacities.moves[i]->id == id) return *capacities.moves[i];
}
return *capacities.moves[0];
2022-01-24 21:27:51 +01:00
}
2022-02-16 19:40:41 +01:00
struct Move *get_move_id_pointer(int id) {
2022-02-17 21:26:33 +01:00
for(int i = 0; i < capacities.nbCapacities; i++) {
if(capacities.moves[i]->id == id) return capacities.moves[i];
}
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;
2022-02-17 01:04:45 +01:00
copyMove->init_pp = move.init_pp;
2022-02-17 21:26:33 +01:00
copyMove->id = move.id;
2022-02-17 01:04:45 +01:00
2022-02-15 21:46:53 +01:00
copyMove->pp = move.pp;
copyMove->atk = move.atk;
2022-02-17 19:05:21 +01:00
copyMove->precision = move.precision;
2022-02-15 21:46:53 +01:00
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);
2022-02-17 19:05:21 +01:00
dprint(x+15, y2-17, C_BLACK, "ATK : %d", move->atk);
dprint(x+70, y2-17, C_BLACK, "PRE : %d", move->precision);
2022-02-15 21:46:53 +01:00
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) {
draw_move(x, y, x+125, y+60, move);
2022-01-25 22:20:10 +01:00
}
2022-02-17 19:05:21 +01:00
int execute_move(struct Stats *player_stats, struct Stats *monster_stats, struct Move *move, int ismonster) {
srand(rtc_ticks());
if(is_miss(move)) {
move->pp--;
return MISS;
}
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-17 19:05:21 +01:00
if(is_crit()) return CRIT;
return SUCCESS;
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;
2022-02-17 19:05:21 +01:00
return rand_range(0,proba_crit)==0;
2022-02-16 19:40:41 +01:00
}
float crit(struct Stats *attacker) {
float taux = 1.0f;
if(is_crit()) {
taux = (float)(2 * attacker->level + 5)/(attacker->level+5);
}
return taux;
2022-02-17 19:05:21 +01:00
}
/*1 if miss, else 0*/
int is_miss(struct Move *move) {
return rand_range(0, 101) > move->precision;
2022-01-24 15:15:12 +01:00
}