From 7f232beb32b23fce9d4a020d9aabf1b04c072acf Mon Sep 17 00:00:00 2001 From: Linus Probert Date: Thu, 16 May 2019 07:43:19 +0200 Subject: [PATCH] A beginning to the new exploding artifacts --- CMakeLists.txt | 1 + src/artifact.c | 26 ++++++++++++++----- src/artifact.h | 1 + src/effect_util.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++ src/effect_util.h | 30 ++++++++++++++++++++++ src/skill.c | 41 ++++++------------------------ 6 files changed, 123 insertions(+), 39 deletions(-) create mode 100644 src/effect_util.c create mode 100644 src/effect_util.h diff --git a/CMakeLists.txt b/CMakeLists.txt index afe617d..7bdf17b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -238,6 +238,7 @@ add_executable(breakhack src/gui_util src/tooltip src/gamecontroller + src/effect_util ${STEAM_SOURCES} ) diff --git a/src/artifact.c b/src/artifact.c index 083c6d7..5735e4d 100644 --- a/src/artifact.c +++ b/src/artifact.c @@ -73,6 +73,10 @@ artifact_set_effect(Artifact *a, MagicalEffect effect) a->info.name = "Magnet"; a->info.desc = "You are attractive to daggers"; break; + case EXPLOSIVE_KILLS: + a->info.name = "Stick of dynamite"; + a->info.desc = "You are an explosive slayer"; + break; default: break; } @@ -87,7 +91,8 @@ static int WarriorArtifacts[] = { FEAR_INDUCING, // 5 INCREASED_STUN, // 6 DAGGER_BOUNCE, // 7 - CHARGE_THROUGH // 8 + EXPLOSIVE_KILLS, // 8 + CHARGE_THROUGH // 9 }; static int RogueArtifacts[] = { @@ -99,7 +104,8 @@ static int RogueArtifacts[] = { FEAR_INDUCING, // 5 INCREASED_STUN, // 6 DAGGER_BOUNCE, // 7 - PHASE_IMPROVEMENT // 8 + EXPLOSIVE_KILLS, // 8 + PHASE_IMPROVEMENT // 9 }; static int MageArtifacts[] = { @@ -111,7 +117,8 @@ static int MageArtifacts[] = { FEAR_INDUCING, // 5 INCREASED_STUN, // 6 DAGGER_BOUNCE, // 7 - SKILL_RADIUS // 8 + EXPLOSIVE_KILLS, // 8 + SKILL_RADIUS // 9 }; /* Not in play yet */ @@ -124,7 +131,8 @@ static int PaladinArtifacts[] = { FEAR_INDUCING, // 5 INCREASED_STUN, // 6 DAGGER_BOUNCE, // 7 - SKILL_RADIUS // 8 + EXPLOSIVE_KILLS, // 8 + SKILL_RADIUS // 9 }; /* Not in play yet */ @@ -137,7 +145,8 @@ static int EngineerArtifacts[] = { FEAR_INDUCING, // 5 INCREASED_STUN, // 6 DAGGER_BOUNCE, // 7 - PHASE_IMPROVEMENT // 8 + EXPLOSIVE_KILLS, // 8 + PHASE_IMPROVEMENT // 9 }; static void @@ -157,7 +166,7 @@ add_level_sprite(Artifact *a) Artifact * artifact_create_random(Player *p, Uint8 level) { - int option = get_random(8); + int option = get_random(9); int * artifactPool = NULL; if (p->class == ROGUE) @@ -254,6 +263,11 @@ artifact_sprite_for(MagicalEffect effect) sprite_set_texture(sprite, t, 0); sprite->clip = CLIP16(0, 0); break; + case EXPLOSIVE_KILLS: + t = texturecache_add("Extras/Artifacts.png"); + sprite_set_texture(sprite, t, 0); + sprite->clip = CLIP16(32, 0); + break; default: break; } diff --git a/src/artifact.h b/src/artifact.h index b51b1cf..ca7271f 100644 --- a/src/artifact.h +++ b/src/artifact.h @@ -32,6 +32,7 @@ typedef enum MagicalEffect { PHASE_IMPROVEMENT, SKILL_RADIUS, DAGGER_BOUNCE, + EXPLOSIVE_KILLS, LAST_ARTIFACT_EFFECT // Sentinel } MagicalEffect; diff --git a/src/effect_util.c b/src/effect_util.c new file mode 100644 index 0000000..916bfc6 --- /dev/null +++ b/src/effect_util.c @@ -0,0 +1,63 @@ +/* + * BreakHack - A dungeone crawler RPG + * Copyright (C) 2018 Linus Probert + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "gui.h" +#include "monster.h" +#include "roommatrix.h" +#include "effect_util.h" + +void +effect_damage_surroundings(Position *pos, + RoomMatrix *rm, + Stats *attackerStats, + unsigned int radius, + unsigned int pushRadius, + bool damagePlayer) +{ + Position roomPos = position_to_matrix_coords(pos); + for (Sint32 i = -radius; i <= (Sint32) radius; ++i) { + for (Sint32 j = -radius; j <= (Sint32) radius; ++j) { + if (i == 0 && j == 0) + continue; + + Position matrixPos = POS(roomPos.x + i, roomPos.y + j); + if (!position_in_roommatrix(&matrixPos)) + continue; + + RoomSpace *r = &rm->spaces[matrixPos.x][matrixPos.y]; + if (r->monster) { + CombatResult result = stats_fight(attackerStats, &r->monster->stats); + monster_hit(r->monster, result.dmg, result.critical); + gui_log("%s takes %d damage from the explosion", r->monster->label, result.dmg); + + Vector2d dir = vector2d_to_direction(&VEC2D((float) i, (float) j)); + for (unsigned int k = 0; k < pushRadius; ++k) { + monster_push(r->monster, + roommatrix_get_player(rm), + rm, + dir + ); + } + } else if (r->player && damagePlayer) { + CombatResult result = stats_fight(attackerStats, &r->player->stats); + player_hit(r->player, result.dmg); + gui_log("You take %d damage from the explosion", result.dmg); + } + } + } +} diff --git a/src/effect_util.h b/src/effect_util.h new file mode 100644 index 0000000..1dcc1d5 --- /dev/null +++ b/src/effect_util.h @@ -0,0 +1,30 @@ +/* + * BreakHack - A dungeone crawler RPG + * Copyright (C) 2018 Linus Probert + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#include + +#include "roommatrix.h" +#include "position.h" +#include "stats.h" + +void +effect_damage_surroundings(Position *pos, + RoomMatrix *rm, + Stats *attackerStats, + unsigned int radius, + unsigned int pushRadius, + bool damagePlayer); diff --git a/src/skill.c b/src/skill.c index 84b7296..e49c311 100644 --- a/src/skill.c +++ b/src/skill.c @@ -37,6 +37,7 @@ #include "trap.h" #include "tooltip.h" #include "actiontextbuilder.h" +#include "effect_util.h" static char *flurry_tooltip[] = { "FLURRY", "", @@ -953,39 +954,13 @@ skill_erupt(Skill *skill, SkillData *data) particle_engine_eldritch_explosion(player->sprite->pos, DIM(32, 32)); mixer_play_effect(BLAST_EFFECT); - Position playerMPos = position_to_matrix_coords(&player->sprite->pos); - int range = player_has_artifact(player, SKILL_RADIUS); - for (Sint32 i = -1 - range; i <= 1 + range; ++i) { - for (Sint32 j = -1 - range; j <= 1 + range; ++j) { - - if (i == 0 && j == 0) - continue; - - Position matrixPos = POS(playerMPos.x + i, playerMPos.y + j); - if (!position_in_roommatrix(&matrixPos)) - continue; - - RoomSpace *r = &rm->spaces[matrixPos.x][matrixPos.y]; - if (r->monster) { - player->stats.advantage = true; - CombatResult result = stats_fight(&player->stats, &r->monster->stats); - player->stats.advantage = false; - monster_hit(r->monster, result.dmg, result.critical); - gui_log("%s takes %d damage from the explosion", r->monster->label, result.dmg); - monster_set_state(r->monster, SCARED, 3); - - int lvl = 1 + player_has_artifact(player, PUSH_BACK); - Vector2d dir = vector2d_to_direction(&VEC2D((float) i, (float) j)); - for (int k = 0; k < lvl; ++k) { - monster_push(r->monster, - player, - rm, - dir - ); - } - } - } - } + int range = 1 + player_has_artifact(player, SKILL_RADIUS); + effect_damage_surroundings(&player->sprite->pos, + rm, + &player->stats, + range, + 1 + player_has_artifact(player, PUSH_BACK), + false); return true; }