Skip to content

Commit

Permalink
potentially fix mirror
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyler-Lentz committed Jun 7, 2024
1 parent 82f5204 commit d09095e
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 2 deletions.
4 changes: 2 additions & 2 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"game": {
"maze": {
"directory": "maps",
"procedural": true,
"maze_file": "demo/candidate5"
"procedural": false,
"maze_file": "test/itemRoom.maze"
},
"disable_enemies": false
},
Expand Down
64 changes: 64 additions & 0 deletions src/server/game/weaponcollider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include "server/game/creature.hpp"
#include "server/game/weaponcollider.hpp"
#include "server/game/servergamestate.hpp"
#include "server/game/item.hpp"
#include "server/game/mirror.hpp"
#include "shared/audio/constants.hpp"
#include <chrono>

Expand Down Expand Up @@ -30,8 +32,70 @@ void WeaponCollider::doCollision(Object* other, ServerGameState& state) {

// don't dmg yourself
if (this->usedPlayer != nullptr) {

if (creature->globalID == this->usedPlayer->globalID) return;
}

// If this weapon collider is a lightning bolt and it collides with
// a Player whose currently using a Mirror, then don't do any damage
// to the player and destroy the player's mirror.
// Also, paralyze the DM for some amount of time.
if (this->info.lightning && creature->type == ObjectType::Player) {
std::cout << "Applying lightning damage!" << std::endl;
Player* player = dynamic_cast<Player*>(creature);

// Return early if this player is currently invulnerable to lightning
if (player->isInvulnerableToLightning()) {
std::cout << "Player is invulnerable to lightning - applying no damage." << std::endl;
return;
}

for (int i = 0; i < player->inventory.size(); i++) {
if (player->inventory[i] == -1)
continue;

// Get item
Item* item = state.objects.getItem(player->inventory[i]);

// If the item is a mirror and is used, then apply special
// behavior
if (item->type == ObjectType::Mirror && item->iteminfo.used) {
std::cout << "Player using a mirror got hit by a lightning bolt!" << std::endl;
std::cout << "Deleting mirror!" << std::endl;

Mirror* mirror = dynamic_cast<Mirror*>(item);

// Add mirror shatter sound effect
state.soundTable().addNewSoundSource(SoundSource(
ServerSFX::MirrorShatter,
player->physics.shared.corner,
FULL_VOLUME,
FAR_DIST,
FAR_ATTEN
));

// Mark player as invulnerable to lightning for 1 second
player->setInvulnerableToLightning(true, 1);

// Inform player they successfully relfected a lightning bolt
// using a mirror
player->info.used_mirror_to_reflect_lightning = true;

// Destroy the mirror that the player is holding
mirror->dropItem(player, state, i, 0.0f);
state.markForDeletion(item->globalID);

// Remove mirror from player's list of used items
player->sharedInventory.usedItems.erase(item->typeID);

// Paralyze the DM for 5 seconds
state.objects.getDM()->setParalysis(true, 5);

// Don't apply damage to the player
return;
}
}
}

// do damage if creature
creature->stats.health.decrease(this->opt.damage);
Expand Down

0 comments on commit d09095e

Please sign in to comment.