diff --git a/src/item_builder.c b/src/item_builder.c index f22997c..22f1ccc 100644 --- a/src/item_builder.c +++ b/src/item_builder.c @@ -158,13 +158,13 @@ item_builder_build_item(ItemKey key, int level) Item *item = NULL; switch (key) { case TREASURE: - item = create_treasure(level); + item = create_treasure(level*2); break; case FLESH: item = create_item(path_flesh, - (SDL_Rect) { 0, 0, 16, 16 }, + (SDL_Rect) { get_random(7) * 16, get_random(1) * 16, 16, 16 }, &eat_flesh); - item->value = get_random(level); + item->value = 1 + get_random(level*2); break; case HEALTH: item = create_item(path_potion, diff --git a/src/item_builder.h b/src/item_builder.h index 8c36bbf..4331bb1 100644 --- a/src/item_builder.h +++ b/src/item_builder.h @@ -34,8 +34,8 @@ typedef enum { } Treasure; typedef enum { - FLESH, HEALTH, + FLESH, TREASURE, ITEM_COUNT } ItemKey; diff --git a/src/main.c b/src/main.c index 2771ed8..13f9b2f 100644 --- a/src/main.c +++ b/src/main.c @@ -446,7 +446,7 @@ check_next_level(void) static void run_game(void) { - map_clear_dead_monsters(gMap); + map_clear_dead_monsters(gMap, gPlayer); map_clear_collected_items(gMap); roommatrix_populate_from_map(gRoomMatrix, gMap); roommatrix_add_lightsource(gRoomMatrix, diff --git a/src/map.c b/src/map.c index 04f57ee..11334f5 100644 --- a/src/map.c +++ b/src/map.c @@ -95,7 +95,7 @@ void map_add_decoration(Map *map, Position *tile_pos, MapTile *tile) } void -map_clear_dead_monsters(Map *map) +map_clear_dead_monsters(Map *map, Player *player) { LinkedList *last, *current, *next; @@ -112,7 +112,7 @@ map_clear_dead_monsters(Map *map) Monster *monster = current->data; // Loot drops - monster_drop_loot(monster, map); + monster_drop_loot(monster, map, player); monster_destroy(monster); current->data = NULL; diff --git a/src/map.h b/src/map.h index 8296e9b..3511a7c 100644 --- a/src/map.h +++ b/src/map.h @@ -29,6 +29,7 @@ #include "timer.h" #include "defines.h" #include "monster.h" +#include "player.h" typedef struct MapTile_t { int textureIndex0; @@ -74,7 +75,7 @@ bool map_move_monsters(Map*, RoomMatrix*); void -map_clear_dead_monsters(Map*); +map_clear_dead_monsters(Map*, Player*); void map_clear_collected_items(Map*); diff --git a/src/monster.c b/src/monster.c index 31ec77e..2a700b3 100644 --- a/src/monster.c +++ b/src/monster.c @@ -294,13 +294,19 @@ monster_update_stats_for_level(Monster *m, unsigned int level) } void -monster_drop_loot(Monster *monster, Map *map) +monster_drop_loot(Monster *monster, Map *map, Player *player) { - static unsigned int item_drop_chance = 1; static unsigned int treasure_drop_chance = 1; + + unsigned int item_drop_chance = 1; Item *item; Item *items[2]; unsigned int item_count = 0; + bool player_full_health = false; + + player_full_health = player->stats.hp >= player->stats.maxhp; + if (player->stats.hp < player->stats.maxhp / 2) + item_drop_chance = 0; if (get_random(treasure_drop_chance) == 0) { item = item_builder_build_item(TREASURE, map->level); @@ -308,7 +314,12 @@ monster_drop_loot(Monster *monster, Map *map) items[item_count++] = item; } if (get_random(item_drop_chance) == 0) { - item = item_builder_build_item(get_random(TREASURE - 1), map->level); + ItemKey key; + if (!player_full_health) + key = get_random(TREASURE - 1); + else + key = HEALTH; + item = item_builder_build_item(key, map->level); item->sprite->pos = monster->sprite->pos; items[item_count++] = item; } diff --git a/src/monster.h b/src/monster.h index 1c3a8c9..a765640 100644 --- a/src/monster.h +++ b/src/monster.h @@ -23,6 +23,7 @@ #include "sprite.h" #include "stats.h" #include "actiontext.h" +#include "player.h" typedef enum { PASSIVE, AGRESSIVE, SCARED } StateType; @@ -61,7 +62,7 @@ void monster_update_stats_for_level(Monster*, unsigned int level); void -monster_drop_loot(Monster*, Map*); +monster_drop_loot(Monster*, Map*, Player*); void monster_destroy(Monster*);