Completes #2 artifacts

This commit is contained in:
Linus Probert 2018-08-10 13:00:23 +02:00
parent 8dd774b308
commit 71c1279ef7
4 changed files with 38 additions and 9 deletions

View File

@ -20,6 +20,8 @@
#include "util.h" #include "util.h"
#include "texturecache.h" #include "texturecache.h"
#include "particle_engine.h" #include "particle_engine.h"
#include "player.h"
#include "random.h"
static void static void
artifact_set_effect(Artifact *a, MagicalEffect effect) 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 *
artifact_create(MagicalEffect effect) artifact_create(MagicalEffect effect)
{ {

View File

@ -24,11 +24,11 @@ typedef enum MagicalEffect {
IMPROVED_HEARING, IMPROVED_HEARING,
TRAP_AVOIDANCE, TRAP_AVOIDANCE,
PIERCING_DAGGERS, PIERCING_DAGGERS,
CHARGE_THROUGH,
PUSH_BACK,
DAGGER_RECOVERY, DAGGER_RECOVERY,
INCREASED_STUN, PUSH_BACK,
FEAR_INDUCING, FEAR_INDUCING,
INCREASED_STUN,
CHARGE_THROUGH,
LAST_ARTIFACT_EFFECT // Sentinel LAST_ARTIFACT_EFFECT // Sentinel
} MagicalEffect; } MagicalEffect;
@ -45,6 +45,9 @@ typedef struct Artifact {
int level; int level;
} Artifact; } Artifact;
Artifact *
artifact_create_random(Player*, Uint8 level);
Artifact * Artifact *
artifact_create(MagicalEffect); artifact_create(MagicalEffect);

View File

@ -519,6 +519,12 @@ monster_drop_loot(Monster *monster, Map *map, Player *player)
unsigned int item_count = 0; unsigned int item_count = 0;
bool player_full_health = player->stats.hp >= player->stats.maxhp; 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) if (player->stats.hp < player->stats.maxhp / 2)
item_drop_chance = 0; item_drop_chance = 0;
@ -556,12 +562,6 @@ monster_drop_loot(Monster *monster, Map *map, Player *player)
} }
linkedlist_append(&map->items, container); 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 void

View File

@ -47,6 +47,7 @@ trap_activate(Trap *trap, Player *player)
if (get_random(10) > 2 * player_has_artifact(player, TRAP_AVOIDANCE)) { if (get_random(10) > 2 * player_has_artifact(player, TRAP_AVOIDANCE)) {
player->stats.hp -= trap->damage; player->stats.hp -= trap->damage;
player_hit(player, trap->damage); player_hit(player, trap->damage);
gui_log("The trap damages you for %d damage", trap->damage);
} else { } else {
actiontextbuilder_create_text("Dodged", C_YELLOW, &player->sprite->pos); actiontextbuilder_create_text("Dodged", C_YELLOW, &player->sprite->pos);
gui_log("You nimbly avoid getting hurt by the trap"); gui_log("You nimbly avoid getting hurt by the trap");