2018-02-24 07:13:28 +01:00
|
|
|
/*
|
|
|
|
* BreakHack - A dungeone crawler RPG
|
|
|
|
* Copyright (C) 2018 Linus Probert <linus.probert@gmail.com>
|
|
|
|
*
|
|
|
|
* 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 <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2018-02-24 21:24:19 +01:00
|
|
|
#include <stdlib.h>
|
2018-02-24 07:13:28 +01:00
|
|
|
#include <string.h>
|
|
|
|
#include "texturecache.h"
|
|
|
|
#include "skill.h"
|
|
|
|
#include "util.h"
|
2018-02-28 22:31:38 +01:00
|
|
|
#include "player.h"
|
|
|
|
#include "roommatrix.h"
|
|
|
|
#include "stats.h"
|
|
|
|
#include "monster.h"
|
|
|
|
#include "mixer.h"
|
|
|
|
#include "gui.h"
|
|
|
|
#include "random.h"
|
2018-03-01 19:37:57 +01:00
|
|
|
#include "particle_engine.h"
|
2018-03-10 22:04:03 +01:00
|
|
|
#include "projectile.h"
|
|
|
|
#include "linkedlist.h"
|
2018-03-12 09:09:03 +01:00
|
|
|
#include "item.h"
|
2018-07-31 21:23:01 +02:00
|
|
|
#include "animation.h"
|
2018-08-08 00:14:24 +02:00
|
|
|
#include "artifact.h"
|
2018-08-09 13:58:16 +02:00
|
|
|
#include "trap.h"
|
2018-08-20 14:30:31 +02:00
|
|
|
#include "tooltip.h"
|
2019-05-14 15:20:45 +02:00
|
|
|
#include "actiontextbuilder.h"
|
2019-05-16 07:43:19 +02:00
|
|
|
#include "effect_util.h"
|
2018-08-20 14:30:31 +02:00
|
|
|
|
|
|
|
static char *flurry_tooltip[] = {
|
2018-10-09 14:19:59 +02:00
|
|
|
"FLURRY", "",
|
2018-08-20 14:30:31 +02:00
|
|
|
"",
|
2018-10-09 14:19:59 +02:00
|
|
|
" Hits an adjecant enemy with a flurry of three strikes.", "",
|
|
|
|
" Each strike has the same odds of hitting as a regular attack", "",
|
2018-08-20 14:30:31 +02:00
|
|
|
"",
|
2018-10-09 14:19:59 +02:00
|
|
|
"COOLDOWN:", "",
|
|
|
|
" 5 turns", "",
|
2018-08-20 14:30:31 +02:00
|
|
|
"",
|
2018-10-09 14:19:59 +02:00
|
|
|
"USAGE:", "",
|
|
|
|
" activate the skill (press ", "1", ")", "",
|
|
|
|
" followed by a direction (left, right, up or down)", "",
|
2018-08-20 14:30:31 +02:00
|
|
|
"",
|
|
|
|
"",
|
2018-10-09 14:19:59 +02:00
|
|
|
"Press ", "ESC", " to close", "", "",
|
2018-08-20 14:30:31 +02:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2019-05-14 15:20:45 +02:00
|
|
|
static char *vampiric_blow_tooltip[] = {
|
|
|
|
"VAMPIRIC BLOW", "",
|
|
|
|
"",
|
|
|
|
" Hits an adjecant enemy with a vampiric blow.", "",
|
|
|
|
" Upon hitting you will siphon life from the target", "",
|
|
|
|
" and cause the target to bleed.", "",
|
|
|
|
"",
|
|
|
|
"COOLDOWN:", "",
|
|
|
|
" 5 turns", "",
|
|
|
|
"",
|
|
|
|
"USAGE:", "",
|
|
|
|
" activate the skill (press ", "1", ")", "",
|
|
|
|
" followed by a direction (left, right, up or down)", "",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"Press ", "ESC", " to close", "", "",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2018-08-20 14:30:31 +02:00
|
|
|
static char *bash_tooltip[] = {
|
2018-10-09 14:19:59 +02:00
|
|
|
"BASH", "",
|
2018-08-20 14:30:31 +02:00
|
|
|
"",
|
2018-10-09 14:19:59 +02:00
|
|
|
" Bashes an adjecant enemy with your shield", "",
|
|
|
|
" On a successful hit the target will be stunned for 2 turns", "",
|
2018-08-20 14:30:31 +02:00
|
|
|
"",
|
2018-10-09 14:19:59 +02:00
|
|
|
"COOLDOWN:", "",
|
|
|
|
" 3 turns", "",
|
2018-08-20 14:30:31 +02:00
|
|
|
"",
|
2018-10-09 14:19:59 +02:00
|
|
|
"USAGE:", "",
|
|
|
|
" activate the skill (press ", "2", ")", "",
|
|
|
|
" followed by a direction (left, right, up or down)", "",
|
2018-08-20 14:30:31 +02:00
|
|
|
"",
|
|
|
|
"",
|
2018-10-09 14:19:59 +02:00
|
|
|
"Press ", "ESC", " to close", "",
|
2018-08-20 14:30:31 +02:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2018-09-13 15:28:03 +02:00
|
|
|
static char *trip_tooltip[] = {
|
2018-10-09 14:19:59 +02:00
|
|
|
"TRIP", "",
|
2018-09-13 15:28:03 +02:00
|
|
|
"",
|
2018-10-09 14:19:59 +02:00
|
|
|
" Trips an adjecant enemy causing him to fall (move), in", "",
|
|
|
|
" the direction you tripped it in.", "",
|
|
|
|
" On a successful hit the enemy will also be stunned." "",
|
2018-09-13 15:28:03 +02:00
|
|
|
"",
|
2018-10-09 14:19:59 +02:00
|
|
|
" This can be combined with traps and pits to great effect.", "",
|
2018-09-13 15:28:03 +02:00
|
|
|
"",
|
2018-10-09 14:19:59 +02:00
|
|
|
"COOLDOWN:", "",
|
|
|
|
" 3 turns", "",
|
2018-09-13 15:28:03 +02:00
|
|
|
"",
|
2018-10-09 14:19:59 +02:00
|
|
|
"USAGE:", "",
|
|
|
|
" activate the skill (press ", "2", ")", "",
|
|
|
|
" followed by a direction (left, right, up or down)", "",
|
2018-09-13 15:28:03 +02:00
|
|
|
"",
|
|
|
|
"",
|
2018-10-09 14:19:59 +02:00
|
|
|
"Press ", "ESC", " to close", "",
|
2018-09-13 15:28:03 +02:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2018-09-15 11:01:35 +02:00
|
|
|
static char *backstab_tooltip[] = {
|
2018-10-09 14:19:59 +02:00
|
|
|
"BACKSTAB", "",
|
2018-09-15 11:01:35 +02:00
|
|
|
"",
|
2018-10-09 14:19:59 +02:00
|
|
|
" You flip over an adjecant enemy taking it's place and", "",
|
|
|
|
" it taking yours, finnishing off with a stab in the back", "",
|
|
|
|
" of your foe.", "",
|
2018-10-18 22:34:48 +02:00
|
|
|
" A successful attack will also leave the enemy stunned.", "",
|
2018-09-15 11:01:35 +02:00
|
|
|
"",
|
2018-10-09 14:19:59 +02:00
|
|
|
"COOLDOWN:", "",
|
|
|
|
" 5 turns", "",
|
2018-09-15 11:01:35 +02:00
|
|
|
"",
|
2018-10-09 14:19:59 +02:00
|
|
|
"USAGE:", "",
|
|
|
|
" activate the skill (press ", "1", ")", "",
|
|
|
|
" followed by a direction (left, right, up or down)", "",
|
2018-09-15 11:01:35 +02:00
|
|
|
"",
|
|
|
|
"",
|
2018-10-09 14:19:59 +02:00
|
|
|
"Press ", "ESC", " to close", "",
|
2018-09-15 11:01:35 +02:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2018-09-29 06:44:33 +02:00
|
|
|
static char *phase_tooltip[] = {
|
2018-10-09 14:19:59 +02:00
|
|
|
"PHASE", "",
|
2018-09-29 06:44:33 +02:00
|
|
|
"",
|
2018-10-09 14:19:59 +02:00
|
|
|
" You phase out of existence for a time. While you are phased you", "",
|
|
|
|
" are unaffected by gravity, traps and enemies won't see you.", "",
|
|
|
|
" You can also pass through enemies.", "",
|
2018-09-29 06:44:33 +02:00
|
|
|
"",
|
2018-10-09 14:19:59 +02:00
|
|
|
" The effect lasts for 3 turns", "",
|
2018-09-29 06:44:33 +02:00
|
|
|
"",
|
2018-10-09 14:19:59 +02:00
|
|
|
"COOLDOWN:", "",
|
|
|
|
" 8 turns", "",
|
2018-09-29 06:44:33 +02:00
|
|
|
"",
|
|
|
|
"USAGE:",
|
2018-10-09 14:19:59 +02:00
|
|
|
" activate the skill (press ", "3", ")", "",
|
|
|
|
" then move as normal", "",
|
2018-09-29 06:44:33 +02:00
|
|
|
"",
|
|
|
|
"",
|
2018-10-09 14:19:59 +02:00
|
|
|
"Press ", "ESC", " to close", "",
|
2018-09-29 06:44:33 +02:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2018-08-20 14:30:31 +02:00
|
|
|
static char *charge_tooltip[] = {
|
2018-10-09 14:19:59 +02:00
|
|
|
"CHARGE", "",
|
2018-08-20 14:30:31 +02:00
|
|
|
"",
|
2018-10-09 14:19:59 +02:00
|
|
|
" You charge in a chosen direction into the first obstructing", "",
|
|
|
|
" object. Charging into an enemy can deliver massive damage.", "",
|
2018-08-20 14:30:31 +02:00
|
|
|
"",
|
2018-10-09 14:19:59 +02:00
|
|
|
" Damage is affected by charge distance.", "",
|
|
|
|
" Longer distance, more damage.", "",
|
2018-08-20 14:30:31 +02:00
|
|
|
"",
|
2018-10-09 14:19:59 +02:00
|
|
|
"COOLDOWN:", "",
|
|
|
|
" 5 turns", "",
|
2018-08-20 14:30:31 +02:00
|
|
|
"",
|
|
|
|
"USAGE:",
|
2018-10-09 14:19:59 +02:00
|
|
|
" activate the skill (press ", "3", ")", "",
|
|
|
|
" followed by a direction (left, right, up or down)", "",
|
2018-08-20 14:30:31 +02:00
|
|
|
"",
|
|
|
|
"",
|
2018-10-09 14:19:59 +02:00
|
|
|
"Press ", "ESC", " to close", "",
|
2018-08-20 14:30:31 +02:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2019-05-09 10:16:38 +02:00
|
|
|
static char *blink_tooltip[] = {
|
|
|
|
"BLINK", "",
|
|
|
|
"",
|
|
|
|
" You blink in a chosen direction into the first obstructing", "",
|
|
|
|
" object. Monsters will not obstruct your blink.", "",
|
|
|
|
"",
|
|
|
|
"COOLDOWN:", "",
|
2019-05-09 16:02:33 +02:00
|
|
|
" 4 turns", "",
|
2019-05-09 10:16:38 +02:00
|
|
|
"",
|
|
|
|
"USAGE:",
|
|
|
|
" activate the skill (press ", "3", ")", "",
|
|
|
|
" followed by a direction (left, right, up or down)", "",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"Press ", "ESC", " to close", "",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2019-05-09 16:02:33 +02:00
|
|
|
static char *erupt_tooltip[] = {
|
|
|
|
"ERUPT", "",
|
|
|
|
"",
|
|
|
|
" You erupt in a magical explosion damaging monsters", "",
|
2019-05-14 16:10:28 +02:00
|
|
|
" around you pushing them back and causing fear", "",
|
|
|
|
" for 3 turns.", "",
|
2019-05-09 16:02:33 +02:00
|
|
|
"",
|
|
|
|
"COOLDOWN:", "",
|
|
|
|
" 3 turns", "",
|
|
|
|
"",
|
|
|
|
"USAGE:",
|
|
|
|
" Erupt (press ", "2", ")", "",
|
|
|
|
"",
|
|
|
|
"",
|
|
|
|
"Press ", "ESC", " to close", "",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2018-08-20 14:30:31 +02:00
|
|
|
static char *dagger_tooltip[] = {
|
2018-10-09 14:19:59 +02:00
|
|
|
"THROW DAGGER", "",
|
2018-08-20 14:30:31 +02:00
|
|
|
"",
|
2018-10-09 14:19:59 +02:00
|
|
|
" You throw a dagger in the chosen direction.", "",
|
2018-08-20 14:30:31 +02:00
|
|
|
"",
|
2018-10-09 14:19:59 +02:00
|
|
|
" Damage is affected by throwing distance.", "",
|
|
|
|
" Longer distance, more damage.", "",
|
2018-08-20 14:30:31 +02:00
|
|
|
"",
|
2018-10-09 14:19:59 +02:00
|
|
|
" Dagger supply is not infinite, your current dagger", "",
|
|
|
|
" inventory is displayed in the panel to the right.", "",
|
2018-08-20 14:30:31 +02:00
|
|
|
"",
|
2018-10-09 14:19:59 +02:00
|
|
|
"COOLDOWN:", "",
|
|
|
|
" 0 turns", "",
|
2018-08-20 14:30:31 +02:00
|
|
|
"",
|
2018-10-09 14:19:59 +02:00
|
|
|
"USAGE:", "",
|
|
|
|
" activate the skill (press ", "4", ")", "",
|
|
|
|
" followed by a direction (left, right, up or down)", "",
|
2018-08-20 14:30:31 +02:00
|
|
|
"",
|
|
|
|
"",
|
2018-10-09 14:19:59 +02:00
|
|
|
"Press ", "ESC", " to close", "",
|
2018-08-20 14:30:31 +02:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
static char *health_tooltip[] = {
|
2018-10-09 14:19:59 +02:00
|
|
|
"DRINK HEALTH", "",
|
2018-08-20 14:30:31 +02:00
|
|
|
"",
|
2018-10-09 14:19:59 +02:00
|
|
|
" You take a sip from your health vial", "",
|
2018-08-20 14:30:31 +02:00
|
|
|
"",
|
2018-10-09 14:19:59 +02:00
|
|
|
" The current amount of sips in your vials is", "",
|
2018-10-10 22:38:54 +02:00
|
|
|
" displayed in the panel to the right.", "",
|
2018-08-20 14:30:31 +02:00
|
|
|
"",
|
2018-10-09 14:19:59 +02:00
|
|
|
"COOLDOWN:", "",
|
|
|
|
" 0 turns", "",
|
2018-08-20 14:30:31 +02:00
|
|
|
"",
|
2018-10-09 14:19:59 +02:00
|
|
|
"USAGE:", "",
|
|
|
|
" Sip health (press ", "5", ")", "",
|
2018-08-20 14:30:31 +02:00
|
|
|
"",
|
|
|
|
"",
|
2018-10-09 14:19:59 +02:00
|
|
|
"Press ", "ESC", " to close", "",
|
2018-08-20 14:30:31 +02:00
|
|
|
NULL
|
|
|
|
};
|
2018-02-24 07:13:28 +01:00
|
|
|
|
2019-02-24 23:33:08 +01:00
|
|
|
static void
|
|
|
|
perform_pickups_for_space(RoomSpace *space, Player *player)
|
|
|
|
{
|
|
|
|
// Pick up items in the path
|
|
|
|
LinkedList *items = space->items;
|
|
|
|
while (items != NULL) {
|
|
|
|
Item *item = items->data;
|
|
|
|
items = items->next;
|
|
|
|
item_collected(item, player);
|
|
|
|
}
|
|
|
|
LinkedList *artifacts = space->artifacts;
|
|
|
|
while (artifacts != NULL) {
|
|
|
|
Artifact *artifact = artifacts->data;
|
|
|
|
artifacts = artifacts->next;
|
|
|
|
player_add_artifact(player, artifact);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
handle_space_effects(RoomSpace *space,
|
|
|
|
Player *player)
|
|
|
|
{
|
|
|
|
if (space->lethal)
|
|
|
|
player_set_falling(player);
|
|
|
|
else if (space->trap)
|
|
|
|
trap_activate(space->trap, player);
|
|
|
|
|
|
|
|
LinkedList *objects = space->objects;
|
|
|
|
while (objects) {
|
|
|
|
object_damage(objects->data, player);
|
|
|
|
objects = objects->next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-24 07:13:28 +01:00
|
|
|
static Skill *
|
|
|
|
create_default(const char *s_label, Sprite *s)
|
|
|
|
{
|
|
|
|
Skill *skill = ec_malloc(sizeof(Skill));
|
|
|
|
m_strcpy(skill->label, 20, s_label);
|
2018-02-28 15:28:45 +01:00
|
|
|
skill->resetTime = 5;
|
|
|
|
skill->resetCountdown = 0;
|
2018-02-24 07:13:28 +01:00
|
|
|
skill->icon = s;
|
2018-02-28 22:31:38 +01:00
|
|
|
skill->actionRequired = true;
|
|
|
|
skill->instantUse = false;
|
|
|
|
skill->active = false;
|
2018-03-13 16:13:54 +01:00
|
|
|
skill->available = NULL;
|
2018-02-24 07:13:28 +01:00
|
|
|
skill->use = NULL;
|
2018-03-23 22:03:34 +01:00
|
|
|
skill->levelcap = 1;
|
2018-08-20 14:30:31 +02:00
|
|
|
skill->tooltip = NULL;
|
2018-02-24 07:13:28 +01:00
|
|
|
return skill;
|
|
|
|
}
|
|
|
|
|
2018-02-28 15:28:45 +01:00
|
|
|
static bool
|
2018-09-13 13:46:29 +02:00
|
|
|
check_skill_validity(Position *playerPos, Position *targetPos, SkillData *data)
|
2018-02-28 15:28:45 +01:00
|
|
|
{
|
2018-09-13 13:46:29 +02:00
|
|
|
*playerPos = position_to_matrix_coords(&data->player->sprite->pos);
|
|
|
|
*targetPos = *playerPos;
|
|
|
|
targetPos->x += (int) data->direction.x;
|
|
|
|
targetPos->y += (int) data->direction.y;
|
2018-02-28 22:31:38 +01:00
|
|
|
|
2018-07-31 23:45:09 +02:00
|
|
|
player_turn(data->player, &data->direction);
|
2018-03-01 13:48:03 +01:00
|
|
|
|
2018-09-13 13:46:29 +02:00
|
|
|
if (!position_in_roommatrix(targetPos)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-05-14 15:20:45 +02:00
|
|
|
static bool
|
|
|
|
vampiric_blow_skill(Skill *skill, SkillData *data)
|
|
|
|
{
|
|
|
|
UNUSED (skill);
|
|
|
|
|
|
|
|
Position playerPos, targetPos;
|
|
|
|
Player *player = data->player;
|
|
|
|
if (!check_skill_validity(&playerPos, &targetPos, data)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
animation_run(player->swordAnimation);
|
|
|
|
Monster *monster = data->matrix->spaces[targetPos.x][targetPos.y].monster;
|
|
|
|
mixer_play_effect(SWING0);
|
|
|
|
if (monster) {
|
|
|
|
gui_log("You attack %s with a vampiric blow", monster->lclabel);
|
|
|
|
player->stats.advantage = true;
|
|
|
|
CombatResult result = stats_fight(&player->stats, &monster->stats);
|
|
|
|
player->stats.advantage = false;
|
|
|
|
if (result.dmg) {
|
|
|
|
mixer_play_effect(SWORD_HIT);
|
|
|
|
monster_hit(monster, result.dmg, result.critical);
|
|
|
|
monster_set_bleeding(monster);
|
|
|
|
|
|
|
|
unsigned int gain = player->stats.lvl * 3;
|
|
|
|
gain = min(gain, (unsigned int) player->stats.maxhp - player->stats.hp);
|
|
|
|
if (gain > 0) {
|
|
|
|
gui_log("You gain %u health", gain);
|
|
|
|
char msg[4];
|
|
|
|
m_sprintf(msg, 4, "+%u", gain);
|
|
|
|
actiontextbuilder_create_text(msg,
|
|
|
|
C_GREEN,
|
|
|
|
&player->sprite->pos);
|
|
|
|
player->stats.hp += gain;
|
|
|
|
player->stats.hp = min(player->stats.maxhp,
|
|
|
|
player->stats.hp);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
gui_log("You missed %s", monster->lclabel);
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
gui_log("You swing at thin air with a vampiric blow");
|
|
|
|
}
|
|
|
|
player_monster_kill_check(data->player, monster);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Skill *
|
|
|
|
create_vampiric_blow(void)
|
|
|
|
{
|
|
|
|
Texture *t = texturecache_add("Extras/Skills.png");
|
|
|
|
Sprite *s = sprite_create();
|
|
|
|
sprite_set_texture(s, t, 0);
|
|
|
|
s->dim = GAME_DIMENSION;
|
2019-05-14 22:47:35 +02:00
|
|
|
s->clip = CLIP32(0, 64);
|
2019-05-14 15:20:45 +02:00
|
|
|
s->fixed = true;
|
|
|
|
Skill *skill = create_default("Vampiric blow", s);
|
|
|
|
skill->levelcap = 2;
|
|
|
|
skill->use = vampiric_blow_skill;
|
|
|
|
skill->resetTime = 5;
|
|
|
|
return skill;
|
|
|
|
}
|
|
|
|
|
2018-09-13 13:46:29 +02:00
|
|
|
static bool
|
|
|
|
skill_use_flurry(Skill *skill, SkillData *data)
|
|
|
|
{
|
|
|
|
UNUSED (skill);
|
|
|
|
|
|
|
|
Position playerPos, targetPos;
|
|
|
|
if (!check_skill_validity(&playerPos, &targetPos, data)) {
|
2018-03-01 19:37:57 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-07-31 23:45:09 +02:00
|
|
|
animation_run(data->player->swordAnimation);
|
2018-02-28 22:31:38 +01:00
|
|
|
Monster *monster = data->matrix->spaces[targetPos.x][targetPos.y].monster;
|
2018-03-01 06:47:16 +01:00
|
|
|
mixer_play_effect(TRIPPLE_SWING);
|
2018-02-28 22:31:38 +01:00
|
|
|
if (monster) {
|
|
|
|
gui_log("You attack %s with a flurry of strikes", monster->lclabel);
|
2018-03-01 06:47:16 +01:00
|
|
|
unsigned int hitCount = 0;
|
2018-02-28 22:31:38 +01:00
|
|
|
for (size_t i = 0; i < 3; ++i) {
|
2018-03-01 06:47:16 +01:00
|
|
|
unsigned int originalHp = monster->stats.hp;
|
2019-05-14 10:26:28 +02:00
|
|
|
CombatResult result = stats_fight(&data->player->stats, &monster->stats);
|
|
|
|
if (result.dmg > 0 && originalHp > 0) {
|
|
|
|
gui_log("You hit for %u damage", result.dmg);
|
2018-03-01 06:47:16 +01:00
|
|
|
hitCount++;
|
2018-02-28 22:31:38 +01:00
|
|
|
}
|
2019-05-14 10:26:28 +02:00
|
|
|
monster_hit(monster, result.dmg, result.critical);
|
2018-02-28 22:31:38 +01:00
|
|
|
}
|
2018-03-01 06:47:16 +01:00
|
|
|
if (hitCount == 1) {
|
|
|
|
mixer_play_effect(SWORD_HIT);
|
|
|
|
} else if (hitCount == 2) {
|
|
|
|
mixer_play_effect(DOUBLE_SWORD_HIT);
|
|
|
|
} else if (hitCount == 3) {
|
|
|
|
mixer_play_effect(TRIPPLE_SWORD_HIT);
|
|
|
|
}
|
2018-02-28 22:31:38 +01:00
|
|
|
} else {
|
|
|
|
gui_log("You swing at thin air with a flurry of strikes");
|
|
|
|
}
|
|
|
|
player_monster_kill_check(data->player, monster);
|
|
|
|
|
2018-02-28 15:28:45 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-02-24 07:13:28 +01:00
|
|
|
static Skill *
|
|
|
|
create_flurry(void)
|
|
|
|
{
|
2018-03-11 21:06:46 +01:00
|
|
|
Texture *t = texturecache_add("Extras/Skills.png");
|
2018-02-24 07:13:28 +01:00
|
|
|
Sprite *s = sprite_create();
|
|
|
|
sprite_set_texture(s, t, 0);
|
2018-03-11 21:06:46 +01:00
|
|
|
s->dim = GAME_DIMENSION;
|
|
|
|
s->clip = CLIP32(0, 0);
|
2018-02-24 07:13:28 +01:00
|
|
|
s->fixed = true;
|
|
|
|
Skill *skill = create_default("Flurry", s);
|
2018-03-23 22:03:34 +01:00
|
|
|
skill->levelcap = 2;
|
2018-02-28 15:28:45 +01:00
|
|
|
skill->use = skill_use_flurry;
|
2018-02-24 07:13:28 +01:00
|
|
|
return skill;
|
|
|
|
}
|
|
|
|
|
2018-03-13 16:13:54 +01:00
|
|
|
static bool
|
|
|
|
skill_throw_dagger_available(Player *player)
|
|
|
|
{
|
|
|
|
return player->daggers > 0;
|
|
|
|
}
|
|
|
|
|
2018-03-10 22:04:03 +01:00
|
|
|
static bool
|
|
|
|
skill_throw_dagger(Skill *skill, SkillData *data)
|
|
|
|
{
|
|
|
|
UNUSED(skill);
|
|
|
|
|
2018-03-13 16:13:54 +01:00
|
|
|
if (data->player->daggers == 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
data->player->daggers--;
|
|
|
|
|
2018-03-10 22:04:03 +01:00
|
|
|
Projectile *p = projectile_dagger_create();
|
2018-05-05 21:29:08 +02:00
|
|
|
if (vector2d_equals(VECTOR2D_UP, data->direction)) {
|
2018-03-12 09:09:03 +01:00
|
|
|
p->velocity = (Vector2d) { 0, -DAGGER_VELOCITY };
|
2018-05-05 21:29:08 +02:00
|
|
|
p->sprite->flip = SDL_FLIP_VERTICAL;
|
|
|
|
}
|
|
|
|
else if (vector2d_equals(VECTOR2D_DOWN, data->direction)) {
|
2018-03-12 09:09:03 +01:00
|
|
|
p->velocity = (Vector2d) { 0, DAGGER_VELOCITY };
|
2018-05-05 21:29:08 +02:00
|
|
|
p->sprite->flip = SDL_FLIP_HORIZONTAL;
|
|
|
|
}
|
|
|
|
else if (vector2d_equals(VECTOR2D_RIGHT, data->direction)) {
|
2018-03-12 09:09:03 +01:00
|
|
|
p->velocity = (Vector2d) { DAGGER_VELOCITY, 0 };
|
2018-05-05 21:29:08 +02:00
|
|
|
p->sprite->flip = SDL_FLIP_HORIZONTAL;
|
|
|
|
}
|
|
|
|
else {
|
2018-03-12 09:09:03 +01:00
|
|
|
p->velocity = (Vector2d) { -DAGGER_VELOCITY, 0 };
|
2018-05-05 21:29:08 +02:00
|
|
|
p->sprite->angle = -270;
|
|
|
|
}
|
2018-03-10 22:04:03 +01:00
|
|
|
|
2018-07-31 23:45:09 +02:00
|
|
|
player_turn(data->player, &data->direction);
|
2018-03-12 12:35:28 +01:00
|
|
|
|
2018-03-12 09:09:03 +01:00
|
|
|
mixer_play_effect(SWOOSH);
|
2018-03-10 22:04:03 +01:00
|
|
|
p->sprite->pos = data->player->sprite->pos;
|
|
|
|
linkedlist_append(&data->player->projectiles, p);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Skill *
|
|
|
|
create_throw_dagger(void)
|
|
|
|
{
|
2018-03-11 21:06:46 +01:00
|
|
|
Texture *t = texturecache_add("Extras/Skills.png");
|
2018-03-10 22:04:03 +01:00
|
|
|
Sprite *s = sprite_create();
|
|
|
|
sprite_set_texture(s, t, 0);
|
2018-03-11 21:06:46 +01:00
|
|
|
s->dim = GAME_DIMENSION;
|
|
|
|
s->clip = CLIP32(64, 0);
|
2018-03-10 22:04:03 +01:00
|
|
|
s->fixed = true;
|
|
|
|
Skill *skill = create_default("Throw dagger", s);
|
2018-03-23 22:03:34 +01:00
|
|
|
skill->levelcap = 1;
|
2018-03-10 22:04:03 +01:00
|
|
|
skill->instantUse = false;
|
2018-03-13 16:13:54 +01:00
|
|
|
skill->resetTime = 1;
|
|
|
|
skill->available = skill_throw_dagger_available;
|
2018-03-10 22:04:03 +01:00
|
|
|
skill->use = skill_throw_dagger;
|
|
|
|
skill->actionRequired = false;
|
|
|
|
return skill;
|
|
|
|
}
|
|
|
|
|
2018-08-04 23:52:52 +02:00
|
|
|
static bool
|
|
|
|
skill_bash(Skill *skill, SkillData *data)
|
|
|
|
{
|
|
|
|
UNUSED (skill);
|
|
|
|
|
2018-09-13 13:46:29 +02:00
|
|
|
Position playerPos, targetPos;
|
|
|
|
if (!check_skill_validity(&playerPos, &targetPos, data)) {
|
2018-08-04 23:52:52 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
animation_run(data->player->swordAnimation);
|
|
|
|
Monster *monster = data->matrix->spaces[targetPos.x][targetPos.y].monster;
|
2018-08-05 15:47:56 +02:00
|
|
|
mixer_play_effect(SWING0);
|
2018-08-04 23:52:52 +02:00
|
|
|
if (monster) {
|
|
|
|
gui_log("You bash %s with your shield", monster->lclabel);
|
2019-05-14 10:26:28 +02:00
|
|
|
CombatResult result = stats_fight(&data->player->stats, &monster->stats);
|
|
|
|
if (result.dmg > 0) {
|
|
|
|
gui_log("You hit for %u damage", result.dmg);
|
2018-08-04 23:52:52 +02:00
|
|
|
if (monster->stats.hp > 0) {
|
|
|
|
gui_log("%s seems dazed and confused", monster->label);
|
2018-08-09 16:18:34 +02:00
|
|
|
monster_set_state(monster, STUNNED,
|
|
|
|
(Uint8) (3 + player_has_artifact(data->player, INCREASED_STUN)));
|
2018-08-04 23:52:52 +02:00
|
|
|
}
|
2018-08-05 15:47:56 +02:00
|
|
|
mixer_play_effect(SLAM);
|
2018-08-04 23:52:52 +02:00
|
|
|
} else {
|
|
|
|
gui_log("You missed %s", monster->lclabel);
|
|
|
|
}
|
2019-05-14 10:26:28 +02:00
|
|
|
monster_hit(monster, result.dmg, result.critical);
|
2018-08-04 23:52:52 +02:00
|
|
|
} else {
|
|
|
|
gui_log("You bash your shield at nothing");
|
|
|
|
}
|
|
|
|
player_monster_kill_check(data->player, monster);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Skill *
|
|
|
|
create_bash(void)
|
|
|
|
{
|
|
|
|
Texture *t = texturecache_add("Extras/Skills.png");
|
|
|
|
Sprite *s = sprite_create();
|
|
|
|
sprite_set_texture(s, t, 0);
|
|
|
|
s->dim = GAME_DIMENSION;
|
|
|
|
s->clip = CLIP32(96, 0);
|
|
|
|
s->fixed = true;
|
|
|
|
Skill *skill = create_default("Bash", s);
|
|
|
|
skill->levelcap = 3;
|
|
|
|
skill->instantUse = false;
|
2018-09-09 12:43:17 +02:00
|
|
|
skill->resetTime = 3;
|
2018-08-04 23:52:52 +02:00
|
|
|
skill->available = NULL;
|
|
|
|
skill->use = skill_bash;
|
|
|
|
skill->actionRequired = true;
|
|
|
|
return skill;
|
|
|
|
}
|
|
|
|
|
2018-09-13 15:28:03 +02:00
|
|
|
static bool
|
|
|
|
skill_trip(Skill *skill, SkillData *data)
|
|
|
|
{
|
|
|
|
UNUSED (skill);
|
|
|
|
|
|
|
|
Position playerPos, targetPos;
|
|
|
|
if (!check_skill_validity(&playerPos, &targetPos, data)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
RoomSpace *space = &data->matrix->spaces[targetPos.x][targetPos.y];
|
|
|
|
mixer_play_effect(SWING0 + get_random(2));
|
2018-09-14 13:07:20 +02:00
|
|
|
animation_run(data->player->swordAnimation);
|
2018-09-13 15:28:03 +02:00
|
|
|
if (space->monster) {
|
2019-05-14 10:26:28 +02:00
|
|
|
CombatResult result = stats_fight(&data->player->stats, &space->monster->stats);
|
|
|
|
if (result.dmg)
|
2018-10-18 22:34:48 +02:00
|
|
|
mixer_play_effect(SWORD_HIT);
|
2018-09-13 15:28:03 +02:00
|
|
|
gui_log("You trip %s causing it to fall away from you", space->monster->lclabel);
|
2019-05-14 10:26:28 +02:00
|
|
|
monster_hit(space->monster, result.dmg, result.critical);
|
2018-09-13 15:28:03 +02:00
|
|
|
player_monster_kill_check(data->player, space->monster);
|
2019-05-14 10:26:28 +02:00
|
|
|
if (result.dmg && space->monster->stats.hp > 0) {
|
2018-09-17 10:10:25 +02:00
|
|
|
Uint32 pushCount = 1 + player_has_artifact(data->player, PUSH_BACK);
|
|
|
|
for (Uint32 i = 0; i < pushCount; ++i) {
|
|
|
|
monster_push(space->monster, data->player, data->matrix, data->direction);
|
|
|
|
if (space->monster->stats.hp <= 0 || space->monster->sprite->state == SPRITE_STATE_FALLING) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2018-10-24 22:18:56 +02:00
|
|
|
monster_set_state(space->monster, STUNNED, (Uint8)(2 + player_has_artifact(data->player, INCREASED_STUN)));
|
2018-09-17 10:10:25 +02:00
|
|
|
}
|
|
|
|
|
2018-09-13 15:28:03 +02:00
|
|
|
|
|
|
|
} else {
|
|
|
|
gui_log("You flail at the air");
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Skill *
|
|
|
|
create_trip(void)
|
|
|
|
{
|
|
|
|
Texture *t = texturecache_add("Extras/Skills.png");
|
|
|
|
Sprite *s = sprite_create();
|
|
|
|
sprite_set_texture(s, t, 0);
|
|
|
|
s->dim = GAME_DIMENSION;
|
2018-10-18 22:34:48 +02:00
|
|
|
s->clip = CLIP32(32, 32);
|
2018-09-13 15:28:03 +02:00
|
|
|
s->fixed = true;
|
|
|
|
Skill *skill = create_default("Trip", s);
|
|
|
|
skill->levelcap = 3;
|
|
|
|
skill->instantUse = false;
|
2018-10-24 22:18:56 +02:00
|
|
|
skill->resetTime = 2;
|
2018-09-13 15:28:03 +02:00
|
|
|
skill->available = NULL;
|
|
|
|
skill->use = skill_trip;
|
|
|
|
skill->actionRequired = true;
|
|
|
|
return skill;
|
|
|
|
}
|
|
|
|
|
2018-09-15 11:01:35 +02:00
|
|
|
static bool
|
|
|
|
skill_backstab(Skill *skill, SkillData *data)
|
|
|
|
{
|
|
|
|
UNUSED(skill);
|
|
|
|
|
|
|
|
Position playerPos, targetPos;
|
|
|
|
if (!check_skill_validity(&playerPos, &targetPos, data)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
RoomSpace *targetSpace = &data->matrix->spaces[targetPos.x][targetPos.y];
|
|
|
|
if (targetSpace->occupied) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
Vector2d reverseDirection = data->direction;
|
|
|
|
reverseDirection.x *= -1;
|
|
|
|
reverseDirection.y *= -1;
|
|
|
|
|
|
|
|
mixer_play_effect(SWING0 + get_random(2));
|
|
|
|
|
|
|
|
data->player->sprite->pos.x += (int) data->direction.x * TILE_DIMENSION;
|
|
|
|
data->player->sprite->pos.y += (int) data->direction.y * TILE_DIMENSION;
|
|
|
|
player_turn(data->player, &reverseDirection);
|
|
|
|
animation_run(data->player->swordAnimation);
|
|
|
|
|
|
|
|
if (targetSpace->monster) {
|
2018-09-15 15:53:02 +02:00
|
|
|
Monster *m = targetSpace->monster;
|
|
|
|
monster_push(m, data->player, data->matrix, reverseDirection);
|
|
|
|
|
|
|
|
m->stats.disadvantage = true;
|
2019-05-14 10:26:28 +02:00
|
|
|
CombatResult result = stats_fight(&data->player->stats, &m->stats);
|
2018-09-15 15:53:02 +02:00
|
|
|
m->stats.disadvantage = false;
|
2019-05-14 10:26:28 +02:00
|
|
|
monster_hit(m, result.dmg, result.critical);
|
2018-09-15 15:53:02 +02:00
|
|
|
player_monster_kill_check(data->player, m);
|
2019-05-14 10:26:28 +02:00
|
|
|
if (result.dmg) {
|
2018-09-15 11:01:35 +02:00
|
|
|
mixer_play_effect(SWORD_HIT);
|
2019-05-09 16:13:25 +02:00
|
|
|
monster_set_bleeding(m);
|
2018-09-15 11:01:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-24 23:33:08 +01:00
|
|
|
perform_pickups_for_space(targetSpace, data->player);
|
|
|
|
handle_space_effects(targetSpace, data->player);
|
|
|
|
|
2018-09-15 11:01:35 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Skill *
|
|
|
|
create_backstab(void)
|
|
|
|
{
|
|
|
|
Texture *t = texturecache_add("Extras/Skills.png");
|
|
|
|
Sprite *s = sprite_create();
|
|
|
|
sprite_set_texture(s, t, 0);
|
|
|
|
s->dim = GAME_DIMENSION;
|
2018-10-13 00:35:51 +02:00
|
|
|
s->clip = CLIP32(0, 32);
|
2018-09-15 11:01:35 +02:00
|
|
|
s->fixed = true;
|
|
|
|
Skill *skill = create_default("Backstab", s);
|
|
|
|
skill->levelcap = 2;
|
|
|
|
skill->instantUse = false;
|
2018-10-24 22:18:56 +02:00
|
|
|
skill->resetTime = 2;
|
2018-09-15 11:01:35 +02:00
|
|
|
skill->available = NULL;
|
|
|
|
skill->use = skill_backstab;
|
|
|
|
skill->actionRequired = true;
|
|
|
|
return skill;
|
|
|
|
}
|
|
|
|
|
2018-10-02 10:29:32 +02:00
|
|
|
static bool
|
|
|
|
skill_phase(Skill *skill, SkillData *data)
|
|
|
|
{
|
|
|
|
UNUSED(skill);
|
2018-10-18 22:34:48 +02:00
|
|
|
mixer_play_effect(FADE_OUT);
|
2018-10-02 10:29:32 +02:00
|
|
|
data->player->phase_count = 3;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Skill *
|
|
|
|
create_phase(void)
|
|
|
|
{
|
|
|
|
Texture *t = texturecache_add("Extras/Skills.png");
|
|
|
|
Sprite *s = sprite_create();
|
|
|
|
sprite_set_texture(s, t, 0);
|
|
|
|
s->dim = GAME_DIMENSION;
|
2018-10-12 11:56:35 +02:00
|
|
|
s->clip = CLIP32(96, 32);
|
2018-10-02 10:29:32 +02:00
|
|
|
s->fixed = true;
|
|
|
|
Skill *skill = create_default("Phase", s);
|
|
|
|
skill->levelcap = 4;
|
|
|
|
skill->instantUse = true;
|
2018-10-24 22:18:56 +02:00
|
|
|
skill->resetTime = 6;
|
2018-10-02 10:29:32 +02:00
|
|
|
skill->available = NULL;
|
|
|
|
skill->use = skill_phase;
|
|
|
|
skill->actionRequired = false;
|
|
|
|
return skill;
|
|
|
|
}
|
|
|
|
|
2018-03-13 16:13:54 +01:00
|
|
|
static bool
|
|
|
|
skill_sip_health_available(Player *player)
|
|
|
|
{
|
2019-05-14 15:20:45 +02:00
|
|
|
bool hasSips = player->class == MAGE ?
|
|
|
|
player->potion_sips > 1 : player->potion_sips > 0;
|
|
|
|
return hasSips > 0 && player->stats.hp != player->stats.maxhp;
|
2018-03-13 16:13:54 +01:00
|
|
|
}
|
|
|
|
|
2018-02-28 22:31:38 +01:00
|
|
|
static bool
|
|
|
|
skill_sip_health(Skill *skill, SkillData *data)
|
|
|
|
{
|
2018-03-01 06:04:12 +01:00
|
|
|
UNUSED (skill);
|
2018-02-28 22:31:38 +01:00
|
|
|
player_sip_health(data->player);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Skill *
|
2018-03-01 06:04:12 +01:00
|
|
|
create_sip_health(void)
|
2018-02-28 22:31:38 +01:00
|
|
|
{
|
|
|
|
Texture *t = texturecache_add("Items/Potion.png");
|
|
|
|
Sprite *s = sprite_create();
|
|
|
|
sprite_set_texture(s, t, 0);
|
|
|
|
s->dim = DEFAULT_DIMENSION;
|
|
|
|
s->clip = CLIP16(0, 0);
|
|
|
|
s->fixed = true;
|
|
|
|
Skill *skill = create_default("Sip health", s);
|
2018-03-23 22:03:34 +01:00
|
|
|
skill->levelcap = 1;
|
2018-02-28 22:31:38 +01:00
|
|
|
skill->instantUse = true;
|
2018-03-13 16:13:54 +01:00
|
|
|
skill->available = skill_sip_health_available;
|
2018-02-28 22:31:38 +01:00
|
|
|
skill->use = skill_sip_health;
|
|
|
|
skill->resetTime = 0;
|
|
|
|
return skill;
|
|
|
|
}
|
|
|
|
|
2018-08-09 13:58:16 +02:00
|
|
|
static void
|
|
|
|
skill_charge_check_path(SkillData *data,
|
|
|
|
Position origin,
|
|
|
|
Position dest)
|
|
|
|
{
|
|
|
|
RoomMatrix *matrix = data->matrix;
|
|
|
|
Player *player = data->player;
|
|
|
|
|
|
|
|
Position itPos = origin;
|
|
|
|
Position lastPos = dest;
|
|
|
|
lastPos.x += (int) data->direction.x * 2;
|
|
|
|
lastPos.y += (int) data->direction.y * 2;
|
|
|
|
Uint8 steps = 1;
|
|
|
|
while (position_in_roommatrix(&itPos) && !position_equals(&itPos, &lastPos)) {
|
|
|
|
RoomSpace *space = &matrix->spaces[itPos.x][itPos.y];
|
|
|
|
if (space->monster) {
|
|
|
|
Monster *monster = matrix->spaces[itPos.x][itPos.y].monster;
|
|
|
|
Stats tmpStats = player->stats;
|
|
|
|
tmpStats.dmg *= steps > 0 ? steps : 1;
|
2018-08-30 11:13:50 +02:00
|
|
|
mixer_play_effect(SWING0 + get_random(2));
|
2019-05-14 10:26:28 +02:00
|
|
|
CombatResult result = stats_fight(&tmpStats, &monster->stats);
|
|
|
|
if (result.dmg > 0) {
|
|
|
|
gui_log("You charged %s for %u damage", monster->lclabel, result.dmg);
|
2018-08-09 13:58:16 +02:00
|
|
|
mixer_play_effect(SWORD_HIT);
|
|
|
|
}
|
2019-05-14 10:26:28 +02:00
|
|
|
monster_hit(monster, result.dmg, result.critical);
|
2018-08-09 13:58:16 +02:00
|
|
|
player_monster_kill_check(data->player, monster);
|
|
|
|
}
|
|
|
|
|
2019-02-24 23:33:08 +01:00
|
|
|
perform_pickups_for_space(space, player);
|
2018-08-09 13:58:16 +02:00
|
|
|
|
|
|
|
if (space->trap)
|
|
|
|
space->trap->sprite->animate = true;
|
|
|
|
|
|
|
|
itPos.x += (int) data->direction.x;
|
|
|
|
itPos.y += (int) data->direction.y;
|
|
|
|
|
|
|
|
steps++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-01 13:48:03 +01:00
|
|
|
static bool
|
|
|
|
skill_charge(Skill *skill, SkillData *data)
|
|
|
|
{
|
2018-03-02 17:05:13 +01:00
|
|
|
UNUSED(skill);
|
|
|
|
|
2018-03-01 13:48:03 +01:00
|
|
|
Player *player = data->player;
|
|
|
|
RoomMatrix *matrix = data->matrix;
|
|
|
|
|
2018-08-09 13:58:16 +02:00
|
|
|
Position playerStartPos = position_to_matrix_coords(&player->sprite->pos);
|
|
|
|
Position destination = playerStartPos;
|
2018-03-01 13:48:03 +01:00
|
|
|
|
|
|
|
// Find collider
|
2018-03-01 19:37:57 +01:00
|
|
|
destination.x += (int) data->direction.x;
|
|
|
|
destination.y += (int) data->direction.y;
|
2018-03-12 09:09:03 +01:00
|
|
|
RoomSpace *space = &matrix->spaces[destination.x][destination.y];
|
2018-08-09 13:58:16 +02:00
|
|
|
Uint32 passThroughCount = 0;
|
|
|
|
Uint32 chargeThroughLvl = player_has_artifact(data->player, CHARGE_THROUGH);
|
|
|
|
Position lastAvailableDest = playerStartPos;
|
|
|
|
while (position_in_roommatrix(&destination))
|
2018-03-01 19:37:57 +01:00
|
|
|
{
|
2018-10-11 18:54:02 +02:00
|
|
|
if (space->occupied || space->monster) {
|
2018-08-09 13:58:16 +02:00
|
|
|
if (!space->monster || passThroughCount >= chargeThroughLvl)
|
|
|
|
break;
|
|
|
|
else
|
|
|
|
passThroughCount++;
|
|
|
|
} else {
|
|
|
|
lastAvailableDest = destination;
|
|
|
|
}
|
|
|
|
|
2018-03-01 13:48:03 +01:00
|
|
|
destination.x += (int) data->direction.x;
|
|
|
|
destination.y += (int) data->direction.y;
|
2018-03-12 09:09:03 +01:00
|
|
|
space = &matrix->spaces[destination.x][destination.y];
|
2018-03-01 19:37:57 +01:00
|
|
|
}
|
|
|
|
|
2018-08-09 13:58:16 +02:00
|
|
|
destination = lastAvailableDest;
|
2018-03-01 13:48:03 +01:00
|
|
|
|
|
|
|
// Move player
|
2018-03-01 19:37:57 +01:00
|
|
|
Position playerOriginPos = player->sprite->pos;
|
2018-08-09 13:58:16 +02:00
|
|
|
Sint32 xdiff = destination.x - playerStartPos.x;
|
|
|
|
Sint32 ydiff = destination.y - playerStartPos.y;
|
|
|
|
player->sprite->pos.x += xdiff * TILE_DIMENSION;
|
|
|
|
player->sprite->pos.y += ydiff * TILE_DIMENSION;
|
2018-03-01 19:37:57 +01:00
|
|
|
Position playerDestinationPos = player->sprite->pos;
|
2018-07-31 23:45:09 +02:00
|
|
|
player_turn(data->player, &data->direction);
|
2018-03-01 13:48:03 +01:00
|
|
|
|
2018-03-01 19:37:57 +01:00
|
|
|
// Add motion particles
|
|
|
|
bool horizontal = data->direction.x != 0;
|
|
|
|
Dimension particleArea;
|
|
|
|
if (horizontal)
|
2018-08-09 13:58:16 +02:00
|
|
|
particleArea = (Dimension) { abs(xdiff) * TILE_DIMENSION, TILE_DIMENSION };
|
2018-03-01 19:37:57 +01:00
|
|
|
else
|
2018-08-09 13:58:16 +02:00
|
|
|
particleArea = (Dimension) { TILE_DIMENSION, abs(ydiff) * TILE_DIMENSION };
|
2018-03-01 19:37:57 +01:00
|
|
|
|
|
|
|
Position speedLinePos;
|
|
|
|
if (playerOriginPos.x < playerDestinationPos.x || playerOriginPos.y < playerDestinationPos.y)
|
|
|
|
speedLinePos = playerOriginPos;
|
|
|
|
else
|
|
|
|
speedLinePos = playerDestinationPos;
|
|
|
|
|
|
|
|
particle_engine_speed_lines(speedLinePos, particleArea, horizontal);
|
2018-03-01 19:46:23 +01:00
|
|
|
mixer_play_effect(SWOOSH);
|
2018-03-01 19:37:57 +01:00
|
|
|
|
2018-08-09 13:58:16 +02:00
|
|
|
skill_charge_check_path(data, playerStartPos, destination);
|
2018-03-01 13:48:03 +01:00
|
|
|
|
2018-08-30 11:13:50 +02:00
|
|
|
Position lastTilePos = position_to_matrix_coords(&playerDestinationPos);
|
|
|
|
RoomSpace *destSpace = &matrix->spaces[lastTilePos.x][lastTilePos.y];
|
2019-02-24 23:33:08 +01:00
|
|
|
handle_space_effects(destSpace, player);
|
2018-09-11 15:47:14 +02:00
|
|
|
|
2018-03-01 13:48:03 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Skill *
|
|
|
|
create_charge(void)
|
|
|
|
{
|
2018-03-11 21:06:46 +01:00
|
|
|
Texture *t = texturecache_add("Extras/Skills.png");
|
2018-03-01 13:48:03 +01:00
|
|
|
Sprite *s = sprite_create();
|
|
|
|
sprite_set_texture(s, t, 0);
|
2018-03-11 21:06:46 +01:00
|
|
|
s->dim = GAME_DIMENSION;
|
|
|
|
s->clip = CLIP32(32, 0);
|
2018-03-01 13:48:03 +01:00
|
|
|
s->fixed = true;
|
|
|
|
Skill *skill = create_default("Charge", s);
|
2018-03-23 22:03:34 +01:00
|
|
|
skill->levelcap = 4;
|
2018-03-01 13:48:03 +01:00
|
|
|
skill->use = skill_charge;
|
|
|
|
return skill;
|
|
|
|
}
|
|
|
|
|
2019-05-09 10:16:38 +02:00
|
|
|
static bool
|
|
|
|
skill_blink(Skill *skill, SkillData *data)
|
|
|
|
{
|
|
|
|
UNUSED(skill);
|
|
|
|
|
|
|
|
Player *player = data->player;
|
|
|
|
RoomMatrix *matrix = data->matrix;
|
|
|
|
|
|
|
|
Position playerStartPos = position_to_matrix_coords(&player->sprite->pos);
|
|
|
|
Position destination = playerStartPos;
|
|
|
|
|
|
|
|
// Find collider
|
|
|
|
destination.x += (int) data->direction.x;
|
|
|
|
destination.y += (int) data->direction.y;
|
|
|
|
RoomSpace *space = &matrix->spaces[destination.x][destination.y];
|
|
|
|
Position lastAvailableDest = playerStartPos;
|
|
|
|
while (position_in_roommatrix(&destination))
|
|
|
|
{
|
|
|
|
if (space->occupied) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!space->monster) {
|
|
|
|
lastAvailableDest = destination;
|
|
|
|
}
|
|
|
|
|
|
|
|
destination.x += (int) data->direction.x;
|
|
|
|
destination.y += (int) data->direction.y;
|
|
|
|
space = &matrix->spaces[destination.x][destination.y];
|
|
|
|
}
|
|
|
|
|
|
|
|
destination = lastAvailableDest;
|
|
|
|
|
|
|
|
// Move player
|
|
|
|
Position playerOriginPos = player->sprite->pos;
|
|
|
|
Sint32 xdiff = destination.x - playerStartPos.x;
|
|
|
|
Sint32 ydiff = destination.y - playerStartPos.y;
|
|
|
|
player->sprite->pos.x += xdiff * TILE_DIMENSION;
|
|
|
|
player->sprite->pos.y += ydiff * TILE_DIMENSION;
|
|
|
|
Position playerDestinationPos = player->sprite->pos;
|
|
|
|
player_turn(data->player, &data->direction);
|
|
|
|
|
|
|
|
particle_engine_blink(playerOriginPos, DIM(32, 32));
|
|
|
|
particle_engine_blink(playerDestinationPos, DIM(32, 32));
|
|
|
|
mixer_play_effect(BLINK_EFFECT);
|
|
|
|
|
|
|
|
Position lastTilePos = position_to_matrix_coords(&playerDestinationPos);
|
|
|
|
RoomSpace *destSpace = &matrix->spaces[lastTilePos.x][lastTilePos.y];
|
|
|
|
|
|
|
|
perform_pickups_for_space(destSpace, player);
|
|
|
|
handle_space_effects(destSpace, player);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Skill *
|
|
|
|
create_blink(void)
|
|
|
|
{
|
|
|
|
Texture *t = texturecache_add("Extras/Skills.png");
|
|
|
|
Sprite *s = sprite_create();
|
|
|
|
sprite_set_texture(s, t, 0);
|
|
|
|
s->dim = GAME_DIMENSION;
|
2019-05-09 21:06:06 +02:00
|
|
|
s->clip = CLIP32(64, 64);
|
2019-05-09 10:16:38 +02:00
|
|
|
s->fixed = true;
|
|
|
|
Skill *skill = create_default("Blink", s);
|
2019-05-09 16:02:33 +02:00
|
|
|
skill->levelcap = 3;
|
2019-05-09 10:16:38 +02:00
|
|
|
skill->use = skill_blink;
|
2019-05-09 16:02:33 +02:00
|
|
|
skill->resetTime = 4;
|
|
|
|
return skill;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
skill_erupt(Skill *skill, SkillData *data)
|
|
|
|
{
|
|
|
|
UNUSED(skill);
|
|
|
|
|
|
|
|
Player *player = data->player;
|
|
|
|
RoomMatrix *rm = data->matrix;
|
|
|
|
|
|
|
|
gui_log("You erupt in a magical explosion");
|
|
|
|
particle_engine_eldritch_explosion(player->sprite->pos, DIM(32, 32));
|
|
|
|
mixer_play_effect(BLAST_EFFECT);
|
|
|
|
|
2019-05-20 15:37:25 +02:00
|
|
|
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) {
|
|
|
|
if (r->monster->stats.hp > 0)
|
|
|
|
monster_push(r->monster,
|
|
|
|
player,
|
|
|
|
rm,
|
|
|
|
dir);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-05-09 16:02:33 +02:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Skill *
|
|
|
|
create_erupt(void)
|
|
|
|
{
|
|
|
|
Texture *t = texturecache_add("Extras/Skills.png");
|
|
|
|
Sprite *s = sprite_create();
|
|
|
|
sprite_set_texture(s, t, 0);
|
|
|
|
s->dim = GAME_DIMENSION;
|
2019-05-09 21:06:06 +02:00
|
|
|
s->clip = CLIP32(32, 64);
|
2019-05-09 16:02:33 +02:00
|
|
|
s->fixed = true;
|
|
|
|
Skill *skill = create_default("Erupt", s);
|
|
|
|
skill->levelcap = 3;
|
|
|
|
skill->use = skill_erupt;
|
|
|
|
skill->instantUse = true;
|
|
|
|
skill->resetTime = 3;
|
2019-05-09 10:16:38 +02:00
|
|
|
return skill;
|
|
|
|
}
|
|
|
|
|
2018-02-24 07:13:28 +01:00
|
|
|
Skill*
|
2018-08-20 14:30:31 +02:00
|
|
|
skill_create(enum SkillType t, Camera *cam)
|
2018-02-24 07:13:28 +01:00
|
|
|
{
|
2018-08-05 15:47:56 +02:00
|
|
|
Skill *skill;
|
2018-02-24 07:13:28 +01:00
|
|
|
switch (t) {
|
|
|
|
case FLURRY:
|
2018-08-05 15:47:56 +02:00
|
|
|
skill = create_flurry();
|
2018-08-20 14:30:31 +02:00
|
|
|
skill->tooltip = tooltip_create(flurry_tooltip, cam);
|
2018-08-05 15:47:56 +02:00
|
|
|
break;
|
2019-05-14 15:20:45 +02:00
|
|
|
case VAMPIRIC_BLOW:
|
|
|
|
skill = create_vampiric_blow();
|
|
|
|
skill->tooltip = tooltip_create(vampiric_blow_tooltip, cam);
|
|
|
|
break;
|
2018-02-28 22:31:38 +01:00
|
|
|
case SIP_HEALTH:
|
2018-08-05 15:47:56 +02:00
|
|
|
skill = create_sip_health();
|
2018-08-20 14:30:31 +02:00
|
|
|
skill->tooltip = tooltip_create(health_tooltip, cam);
|
2018-08-05 15:47:56 +02:00
|
|
|
break;
|
2018-03-01 13:48:03 +01:00
|
|
|
case CHARGE:
|
2018-08-05 15:47:56 +02:00
|
|
|
skill = create_charge();
|
2018-08-20 14:30:31 +02:00
|
|
|
skill->tooltip = tooltip_create(charge_tooltip, cam);
|
2018-08-05 15:47:56 +02:00
|
|
|
break;
|
2019-05-09 10:16:38 +02:00
|
|
|
case BLINK:
|
|
|
|
skill = create_blink();
|
|
|
|
skill->tooltip = tooltip_create(blink_tooltip, cam);
|
|
|
|
break;
|
2019-05-09 16:02:33 +02:00
|
|
|
case ERUPT:
|
|
|
|
skill = create_erupt();
|
|
|
|
skill->tooltip = tooltip_create(erupt_tooltip, cam);
|
|
|
|
break;
|
2018-03-10 22:04:03 +01:00
|
|
|
case DAGGER_THROW:
|
2018-08-05 15:47:56 +02:00
|
|
|
skill = create_throw_dagger();
|
2018-08-20 14:30:31 +02:00
|
|
|
skill->tooltip = tooltip_create(dagger_tooltip, cam);
|
2018-08-05 15:47:56 +02:00
|
|
|
break;
|
2018-08-04 23:52:52 +02:00
|
|
|
case BASH:
|
2018-08-05 15:47:56 +02:00
|
|
|
skill = create_bash();
|
2018-08-20 14:30:31 +02:00
|
|
|
skill->tooltip = tooltip_create(bash_tooltip, cam);
|
2018-08-05 15:47:56 +02:00
|
|
|
break;
|
2018-09-13 15:28:03 +02:00
|
|
|
case TRIP:
|
|
|
|
skill = create_trip();
|
|
|
|
skill->tooltip = tooltip_create(trip_tooltip, cam);
|
|
|
|
break;
|
|
|
|
case BACKSTAB:
|
2018-09-15 11:01:35 +02:00
|
|
|
skill = create_backstab();
|
|
|
|
skill->tooltip = tooltip_create(backstab_tooltip, cam);
|
|
|
|
break;
|
2018-09-28 14:57:43 +02:00
|
|
|
case PHASE:
|
2018-10-02 10:29:32 +02:00
|
|
|
skill = create_phase();
|
|
|
|
skill->tooltip = tooltip_create(phase_tooltip, cam);
|
|
|
|
break;
|
2018-02-24 07:13:28 +01:00
|
|
|
default:
|
|
|
|
fatal("Unknown SkillType %u", (unsigned int) t);
|
|
|
|
return NULL;
|
|
|
|
}
|
2018-08-05 15:47:56 +02:00
|
|
|
|
2018-09-14 18:54:48 +02:00
|
|
|
#ifdef DEBUG
|
2018-08-05 15:47:56 +02:00
|
|
|
skill->levelcap = 1;
|
|
|
|
#endif
|
|
|
|
return skill;
|
2018-02-24 07:13:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
skill_destroy(Skill *skill)
|
|
|
|
{
|
|
|
|
sprite_destroy(skill->icon);
|
2018-08-20 14:30:31 +02:00
|
|
|
if (skill->tooltip)
|
|
|
|
sprite_destroy(skill->tooltip);
|
2018-02-24 07:13:28 +01:00
|
|
|
free(skill);
|
|
|
|
}
|