Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mole die execution #163

Merged
merged 5 commits into from
May 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ set(SOURCE
gameLogic/validation/gadget/DiamondCollar.cpp
gameLogic/validation/gadget/Cocktail.cpp
gameLogic/validation/gadget/BowlerBlade.cpp
gameLogic/execution/gadget/MoleDie.cpp
gameLogic/execution/gadget/BowlerBlade.cpp
gameLogic/execution/gadget/TechnicolorPrism.cpp
network/messages/EquipmentChoice.cpp
Expand Down
2 changes: 2 additions & 0 deletions src/gameLogic/execution/gadget/GadgetExecutor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ namespace spy::gameplay {

static bool executeBowlerBlade(State &s, const GadgetAction &a, const MatchConfig &config);

static bool executeMoleDie(State &s, const GadgetAction &a);

};
}

Expand Down
37 changes: 37 additions & 0 deletions src/gameLogic/execution/gadget/MoleDie.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
* @file MoleDie.cpp
* @author Marco Deuscher
* @date 04.05.2020 (creation)
* @brief Implementation of mole die execution
*/

#include "GadgetExecutor.hpp"
#include "util/GameLogicUtils.hpp"

namespace spy::gameplay {

bool GadgetExecutor::executeMoleDie(State &s, const GadgetAction &a) {
using spy::gadget::GadgetEnum;

// character that issues the action and remove mole die from their inventory
auto character = s.getCharacters().getByUUID(a.getCharacterId());
character->removeGadget(GadgetEnum::MOLEDIE);

// check if target field has character
auto person = util::GameLogicUtils::getInCharacterSetByCoordinates(s.getCharacters(), a.getTarget());
if (person != s.getCharacters().end()) {
// mole die goes into the person inventory
person->addGadget(gadget::Gadget(GadgetEnum::MOLEDIE));
return true;
}

// mole die bounces into the inventory of the closest person
auto closestPoint = util::GameLogicUtils::getRandomCharacterNearField(s, a.getTarget());
auto closestPerson = util::GameLogicUtils::getInCharacterSetByCoordinates(s.getCharacters(), closestPoint);

closestPerson->addGadget(gadget::Gadget(GadgetEnum::MOLEDIE));

return true;
}

}
1 change: 1 addition & 0 deletions src/util/GameLogicUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,3 +199,4 @@ namespace spy::util {
return result;
}
}