diff --git a/src/artifact.c b/src/artifact.c index 6f4555e..0a614c4 100644 --- a/src/artifact.c +++ b/src/artifact.c @@ -20,6 +20,8 @@ #include "util.h" #include "texturecache.h" #include "particle_engine.h" +#include "player.h" +#include "random.h" static void artifact_set_effect(Artifact *a, MagicalEffect effect) @@ -89,6 +91,29 @@ artifact_set_effect(Artifact *a, MagicalEffect effect) } } +Artifact * +artifact_create_random(Player *p, Uint8 level) +{ + int option = -1; + switch (p->stats.lvl) { + case 4: + option = get_random(CHARGE_THROUGH); + break; + case 3: + option = get_random(INCREASED_STUN); + break; + case 1: + option = get_random(FEAR_INDUCING); + break; + default: + option = get_random(LAST_ARTIFACT_EFFECT) - 1; + break; + } + Artifact *a = artifact_create(option); + a->level = level; + return a; +} + Artifact * artifact_create(MagicalEffect effect) { diff --git a/src/artifact.h b/src/artifact.h index ece86e9..eeb2471 100644 --- a/src/artifact.h +++ b/src/artifact.h @@ -24,11 +24,11 @@ typedef enum MagicalEffect { IMPROVED_HEARING, TRAP_AVOIDANCE, PIERCING_DAGGERS, - CHARGE_THROUGH, - PUSH_BACK, DAGGER_RECOVERY, - INCREASED_STUN, + PUSH_BACK, FEAR_INDUCING, + INCREASED_STUN, + CHARGE_THROUGH, LAST_ARTIFACT_EFFECT // Sentinel } MagicalEffect; @@ -45,6 +45,9 @@ typedef struct Artifact { int level; } Artifact; +Artifact * +artifact_create_random(Player*, Uint8 level); + Artifact * artifact_create(MagicalEffect); diff --git a/src/monster.c b/src/monster.c index a92e89b..db4d1b2 100644 --- a/src/monster.c +++ b/src/monster.c @@ -519,6 +519,12 @@ monster_drop_loot(Monster *monster, Map *map, Player *player) unsigned int item_count = 0; bool player_full_health = player->stats.hp >= player->stats.maxhp; + if (get_random(19) == 0) { + Artifact *a = artifact_create_random(player, 1); + a->sprite->pos = monster->sprite->pos; + linkedlist_append(&map->artifacts, a); + } + if (player->stats.hp < player->stats.maxhp / 2) item_drop_chance = 0; @@ -556,12 +562,6 @@ monster_drop_loot(Monster *monster, Map *map, Player *player) } linkedlist_append(&map->items, container); } - - // TODO: This should not occur every time - // Debug code. - Artifact *a = artifact_create(DAGGER_RECOVERY); - a->sprite->pos = monster->sprite->pos; - linkedlist_append(&map->artifacts, a); } void diff --git a/src/trap.c b/src/trap.c index 03eca20..126221f 100644 --- a/src/trap.c +++ b/src/trap.c @@ -47,6 +47,7 @@ trap_activate(Trap *trap, Player *player) if (get_random(10) > 2 * player_has_artifact(player, TRAP_AVOIDANCE)) { player->stats.hp -= trap->damage; player_hit(player, trap->damage); + gui_log("The trap damages you for %d damage", trap->damage); } else { actiontextbuilder_create_text("Dodged", C_YELLOW, &player->sprite->pos); gui_log("You nimbly avoid getting hurt by the trap");