2022-02-16 17:42:05 +01:00
|
|
|
#include "item.h"
|
|
|
|
#include "aoe.h"
|
|
|
|
#include "comp/fighter.h"
|
|
|
|
#include "comp/physical.h"
|
|
|
|
#include "comp/visible.h"
|
|
|
|
#include <gint/defs/util.h>
|
|
|
|
|
2022-03-16 20:00:22 +01:00
|
|
|
anim_t const *item_anim(int item)
|
|
|
|
{
|
|
|
|
if(item == ITEM_LIFE)
|
|
|
|
return &anims_item_life;
|
|
|
|
else if(item == ITEM_POTION_ATK)
|
|
|
|
return &anims_item_potion_atk;
|
|
|
|
else if(item == ITEM_POTION_COOLDOWN)
|
|
|
|
return &anims_item_potion_cooldown;
|
|
|
|
else if(item == ITEM_POTION_DEF)
|
|
|
|
return &anims_item_potion_def;
|
|
|
|
else if(item == ITEM_POTION_FRZ)
|
|
|
|
return &anims_item_potion_frz;
|
|
|
|
else if(item == ITEM_POTION_HP)
|
|
|
|
return &anims_item_potion_hp;
|
|
|
|
else if(item == ITEM_POTION_SPD)
|
|
|
|
return &anims_item_potion_spd;
|
|
|
|
else if(item == ITEM_SCEPTER1)
|
|
|
|
return &anims_item_stick1;
|
|
|
|
else if(item == ITEM_SCEPTER2)
|
|
|
|
return &anims_item_stick2;
|
|
|
|
else if(item == ITEM_SWORD1)
|
|
|
|
return &anims_item_sword1;
|
|
|
|
else if(item == ITEM_SWORD2)
|
|
|
|
return &anims_item_sword2;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2022-03-10 19:34:32 +01:00
|
|
|
entity_t *item_make(int type, vec2 position)
|
2022-02-16 17:42:05 +01:00
|
|
|
{
|
|
|
|
entity_t *e = aoe_make(AOE_ITEM, position, fix(9999.0));
|
|
|
|
|
|
|
|
visible_t *v = getcomp(e, visible);
|
|
|
|
v->sprite_plane = VERTICAL;
|
|
|
|
v->shadow_size = 3;
|
|
|
|
v->z = fix(0.35);
|
|
|
|
|
|
|
|
physical_t *p = getcomp(e, physical);
|
|
|
|
p->hitbox = (rect){ -fix(4)/16, fix(3)/16, -fix(2)/16, fix(1)/16 };
|
|
|
|
|
|
|
|
aoe_t *aoe = getcomp(e, aoe);
|
|
|
|
aoe->origin = NULL;
|
|
|
|
aoe->repeat_delay = 0;
|
2022-03-10 19:34:32 +01:00
|
|
|
aoe->data.item.type = type;
|
2022-02-16 17:42:05 +01:00
|
|
|
|
2022-03-16 20:00:22 +01:00
|
|
|
anim_t const *anim = item_anim(type);
|
|
|
|
if(anim)
|
|
|
|
visible_set_anim(e, anim, 1);
|
2022-02-16 17:42:05 +01:00
|
|
|
return e;
|
|
|
|
}
|
|
|
|
|
2022-03-10 19:34:32 +01:00
|
|
|
void item_pick_up(int type, entity_t *player)
|
2022-02-16 17:42:05 +01:00
|
|
|
{
|
|
|
|
fighter_t *f = getcomp(player, fighter);
|
|
|
|
|
2022-03-10 19:34:32 +01:00
|
|
|
if(type == ITEM_LIFE && f) {
|
|
|
|
int added = max(f->HP_max / 2, 8);
|
|
|
|
f->HP_max += added;
|
|
|
|
f->HP += added;
|
|
|
|
}
|
|
|
|
else if(type == ITEM_POTION_ATK && f) {
|
|
|
|
/* TODO: Double attack for 10 seconds */
|
|
|
|
}
|
|
|
|
else if(type == ITEM_POTION_COOLDOWN && f) {
|
|
|
|
/* TODO: Restore all cooldowns */
|
|
|
|
}
|
|
|
|
else if(type == ITEM_POTION_DEF && f) {
|
|
|
|
/* TODO: Defense +50% for 10 seconds */
|
|
|
|
}
|
|
|
|
else if(type == ITEM_POTION_FRZ && f) {
|
|
|
|
/* TODO: Freeze all monsters for 5 seconds */
|
|
|
|
}
|
|
|
|
else if(type == ITEM_POTION_HP && f) {
|
|
|
|
int restored = max(f->HP_max / 2, 8);
|
|
|
|
f->HP = min(f->HP + restored, f->HP_max);
|
|
|
|
}
|
|
|
|
else if(type == ITEM_POTION_SPD && f) {
|
|
|
|
/* TODO: Speed +50% for 10 seconds */
|
|
|
|
}
|
|
|
|
|
|
|
|
else if(type >= ITEM_EQUIPMENT_START && type < ITEM_EQUIPMENT_END
|
|
|
|
&& f->player) {
|
|
|
|
/* TODO: Give item to player */
|
2022-02-16 17:42:05 +01:00
|
|
|
}
|
|
|
|
}
|