forked from NotAShelf/rogged
combat: add hit chance & damage variance to make combat more engaging
Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: Ia1e0a503dba03e5df7b863b97db962e36a6a6964
This commit is contained in:
parent
fdc0657237
commit
9cbbb9636f
5 changed files with 140 additions and 28 deletions
41
src/player.c
41
src/player.c
|
|
@ -25,6 +25,8 @@ void player_init(Player *p, int x, int y) {
|
|||
p->equipped_weapon.picked_up = 1;
|
||||
p->equipped_armor.picked_up = 1; // mark as invalid
|
||||
p->inventory_count = 0;
|
||||
p->dmg_variance_min = 80;
|
||||
p->dmg_variance_max = 120;
|
||||
|
||||
// Initialize inventory to empty
|
||||
for (int i = 0; i < MAX_INVENTORY; i++) {
|
||||
|
|
@ -186,6 +188,16 @@ int player_equip_item(Player *p, int inv_index) {
|
|||
p->equipped_weapon = *item;
|
||||
p->has_weapon = 1;
|
||||
p->attack += item->power;
|
||||
// Adjust damage variance based on weapon power
|
||||
// Higher power = wider range (more swingy but higher potential)
|
||||
int min_var = 100 - (item->power * 3);
|
||||
int max_var = 100 + (item->power * 5);
|
||||
if (min_var < 60)
|
||||
min_var = 60;
|
||||
if (max_var > 150)
|
||||
max_var = 150;
|
||||
p->dmg_variance_min = min_var;
|
||||
p->dmg_variance_max = max_var;
|
||||
// Remove from inventory
|
||||
player_remove_inventory_item(p, inv_index);
|
||||
return 1;
|
||||
|
|
@ -205,5 +217,32 @@ int player_equip_item(Player *p, int inv_index) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
return 0; // Not equippable (potion)
|
||||
return 0; // not equippable (potion)
|
||||
}
|
||||
|
||||
int player_drop_item(Player *p, int inv_index, Item *items, int item_count) {
|
||||
if (p == NULL)
|
||||
return 0;
|
||||
if (inv_index < 0 || inv_index >= MAX_INVENTORY)
|
||||
return 0;
|
||||
|
||||
Item *item = player_get_inventory_item(p, inv_index);
|
||||
if (item == NULL)
|
||||
return 0;
|
||||
|
||||
// Find an empty slot in items array to place the dropped item
|
||||
for (int i = 0; i < item_count; i++) {
|
||||
if (items[i].picked_up) {
|
||||
// Place dropped item at this position
|
||||
items[i] = *item;
|
||||
items[i].x = p->x;
|
||||
items[i].y = p->y;
|
||||
items[i].picked_up = 0;
|
||||
// Remove from inventory
|
||||
player_remove_inventory_item(p, inv_index);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0; // no room to drop
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue