2018-08-08 00:14:24 +02: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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "artifact.h"
|
|
|
|
#include "util.h"
|
|
|
|
#include "texturecache.h"
|
2018-08-08 14:46:59 +02:00
|
|
|
#include "particle_engine.h"
|
2018-08-10 13:00:23 +02:00
|
|
|
#include "player.h"
|
|
|
|
#include "random.h"
|
2018-08-08 00:14:24 +02:00
|
|
|
|
|
|
|
static void
|
|
|
|
artifact_set_effect(Artifact *a, MagicalEffect effect)
|
|
|
|
{
|
|
|
|
a->effect = effect;
|
|
|
|
switch (effect) {
|
|
|
|
case IMPROVED_HEARING:
|
|
|
|
a->info.name = "Potion of ear juice";
|
|
|
|
a->info.desc = "Your hearing is slightly improved";
|
|
|
|
break;
|
|
|
|
case TRAP_AVOIDANCE:
|
|
|
|
a->info.name = "Boot with nails inside";
|
|
|
|
a->info.desc = "You are lighter on your feet";
|
|
|
|
break;
|
|
|
|
case PIERCING_DAGGERS:
|
|
|
|
a->info.name = "Whetstone";
|
|
|
|
a->info.desc = "Your daggers are sharper";
|
|
|
|
break;
|
|
|
|
case CHARGE_THROUGH:
|
|
|
|
a->info.name = "Greasy shield";
|
|
|
|
a->info.desc = "You glide through obstructions";
|
|
|
|
break;
|
|
|
|
case PUSH_BACK:
|
|
|
|
a->info.name = "Glove of strength";
|
|
|
|
a->info.desc = "Your arm is stronger";
|
|
|
|
break;
|
|
|
|
case DAGGER_RECOVERY:
|
|
|
|
a->info.name = "Forging hammer";
|
|
|
|
a->info.desc = "Your daggers are more durable";
|
|
|
|
break;
|
|
|
|
case INCREASED_STUN:
|
|
|
|
a->info.name = "Solid shield";
|
|
|
|
a->info.desc = "Your shield is harder";
|
|
|
|
break;
|
|
|
|
case FEAR_INDUCING:
|
|
|
|
a->info.name = "Ugly shirt";
|
|
|
|
a->info.desc = "You look disgusting";
|
|
|
|
break;
|
2018-10-02 13:08:32 +02:00
|
|
|
case PHASE_IMPROVEMENT:
|
|
|
|
a->info.name = "Shadow cloak";
|
|
|
|
a->info.desc = "You feel more in phase with the world";
|
|
|
|
break;
|
2018-08-08 00:14:24 +02:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-02 13:08:32 +02:00
|
|
|
static int WarriorArtifacts[] = {
|
|
|
|
IMPROVED_HEARING, // 0
|
|
|
|
TRAP_AVOIDANCE, // 1
|
|
|
|
PIERCING_DAGGERS, // 2
|
|
|
|
DAGGER_RECOVERY, // 3
|
|
|
|
PUSH_BACK, // 4
|
|
|
|
FEAR_INDUCING, // 5
|
|
|
|
INCREASED_STUN, // 6
|
|
|
|
CHARGE_THROUGH // 7
|
|
|
|
};
|
|
|
|
|
|
|
|
static int RogueArtifacts[] = {
|
|
|
|
IMPROVED_HEARING, // 0
|
|
|
|
TRAP_AVOIDANCE, // 1
|
|
|
|
PIERCING_DAGGERS, // 2
|
|
|
|
DAGGER_RECOVERY, // 3
|
|
|
|
PUSH_BACK, // 4
|
|
|
|
FEAR_INDUCING, // 5
|
|
|
|
INCREASED_STUN, // 6
|
|
|
|
PHASE_IMPROVEMENT // 7
|
|
|
|
};
|
|
|
|
|
2018-08-10 13:00:23 +02:00
|
|
|
Artifact *
|
|
|
|
artifact_create_random(Player *p, Uint8 level)
|
|
|
|
{
|
|
|
|
int option = -1;
|
2018-08-10 22:31:06 +02:00
|
|
|
if (p->stats.lvl >= 4)
|
2018-10-02 13:08:32 +02:00
|
|
|
option = get_random(7);
|
2018-08-10 22:31:06 +02:00
|
|
|
else if (p->stats.lvl >= 3)
|
2018-10-02 13:08:32 +02:00
|
|
|
option = get_random(6);
|
|
|
|
else
|
|
|
|
option = get_random(5);
|
|
|
|
|
|
|
|
int * artifactPool = NULL;
|
|
|
|
if (p->class == ROGUE)
|
|
|
|
artifactPool = RogueArtifacts;
|
2018-08-10 22:31:06 +02:00
|
|
|
else
|
2018-10-02 13:08:32 +02:00
|
|
|
artifactPool = WarriorArtifacts;
|
2018-08-10 22:31:06 +02:00
|
|
|
|
2018-10-02 13:08:32 +02:00
|
|
|
Artifact *a = artifact_create(artifactPool[option]);
|
2018-08-10 13:00:23 +02:00
|
|
|
a->level = level;
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
2018-08-21 12:30:44 +02:00
|
|
|
Sprite *
|
|
|
|
artifact_sprite_for(MagicalEffect effect)
|
|
|
|
{
|
|
|
|
Sprite *sprite = sprite_create();
|
|
|
|
Texture *t;
|
|
|
|
switch (effect) {
|
|
|
|
case IMPROVED_HEARING:
|
|
|
|
t = texturecache_add("Items/Potion.png");
|
|
|
|
sprite_set_texture(sprite, t, 0);
|
|
|
|
sprite->clip = CLIP16(7*16, 4*16);
|
|
|
|
break;
|
|
|
|
case TRAP_AVOIDANCE:
|
|
|
|
t = texturecache_add("Items/Boot.png");
|
|
|
|
sprite_set_texture(sprite, t, 0);
|
|
|
|
sprite->clip = CLIP16(5*16, 0);
|
|
|
|
break;
|
|
|
|
case PIERCING_DAGGERS:
|
|
|
|
t = texturecache_add("Items/Rock.png");
|
|
|
|
sprite_set_texture(sprite, t, 0);
|
|
|
|
sprite->clip = CLIP16(0, 0);
|
|
|
|
break;
|
|
|
|
case CHARGE_THROUGH:
|
|
|
|
t = texturecache_add("Items/Shield.png");
|
|
|
|
sprite_set_texture(sprite, t, 0);
|
|
|
|
sprite->clip = CLIP16(16, 0);
|
|
|
|
break;
|
|
|
|
case PUSH_BACK:
|
|
|
|
t = texturecache_add("Items/Glove.png");
|
|
|
|
sprite_set_texture(sprite, t, 0);
|
|
|
|
sprite->clip = CLIP16(0, 0);
|
|
|
|
break;
|
|
|
|
case DAGGER_RECOVERY:
|
|
|
|
t = texturecache_add("Items/LongWep.png");
|
|
|
|
sprite_set_texture(sprite, t, 0);
|
|
|
|
sprite->clip = CLIP16(0, 6*16);
|
|
|
|
break;
|
|
|
|
case INCREASED_STUN:
|
|
|
|
t = texturecache_add("Items/Shield.png");
|
|
|
|
sprite_set_texture(sprite, t, 0);
|
|
|
|
sprite->clip = CLIP16(4*16, 0);
|
|
|
|
break;
|
|
|
|
case FEAR_INDUCING:
|
|
|
|
t = texturecache_add("Items/Armor.png");
|
|
|
|
sprite_set_texture(sprite, t, 0);
|
|
|
|
sprite->clip = CLIP16(6*16, 8*16);
|
|
|
|
break;
|
2018-10-02 13:08:32 +02:00
|
|
|
case PHASE_IMPROVEMENT:
|
|
|
|
t = texturecache_add("Items/Armor.png");
|
|
|
|
sprite_set_texture(sprite, t, 0);
|
|
|
|
sprite->clip = CLIP16(1*16, 5*16);
|
|
|
|
break;
|
2018-08-21 12:30:44 +02:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return sprite;
|
|
|
|
}
|
|
|
|
|
2018-08-08 00:14:24 +02:00
|
|
|
Artifact *
|
|
|
|
artifact_create(MagicalEffect effect)
|
|
|
|
{
|
|
|
|
Artifact *a = ec_malloc(sizeof(Artifact));
|
2018-08-21 12:30:44 +02:00
|
|
|
a->sprite = artifact_sprite_for(effect);
|
2018-08-08 00:14:24 +02:00
|
|
|
a->sprite->dim = GAME_DIMENSION;
|
|
|
|
a->collected = false;
|
|
|
|
a->level = 1;
|
|
|
|
artifact_set_effect(a, effect);
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
|
|
|
Artifact *
|
|
|
|
artifact_copy(Artifact *a)
|
|
|
|
{
|
|
|
|
Artifact *new = ec_malloc(sizeof(Artifact));
|
|
|
|
*new = *a;
|
|
|
|
return new;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
artifact_render(Artifact *a, Camera *cam)
|
|
|
|
{
|
|
|
|
sprite_render(a->sprite, cam);
|
2018-08-08 14:46:59 +02:00
|
|
|
Position pos = a->sprite->pos;
|
|
|
|
pos.x += 4;
|
|
|
|
pos.y += 4;
|
|
|
|
particle_engine_sparkle(pos, (Dimension) { 24, 24 }, C_PURPLE, false);
|
2018-08-08 00:14:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
artifact_destroy(Artifact *a)
|
|
|
|
{
|
|
|
|
sprite_destroy(a->sprite);
|
|
|
|
free(a);
|
|
|
|
}
|