MCPcopy Create free account
hub / github.com/OpenDungeons/OpenDungeons / checkSpellCast

Method checkSpellCast

source/spells/SpellCreatureExplosion.cpp:74–154  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

72}
73
74void SpellCreatureExplosion::checkSpellCast(GameMap* gameMap, const InputManager& inputManager, InputCommand& inputCommand)
75{
76 Player* player = gameMap->getLocalPlayer();
77 int32_t priceTotal = 0;
78 int32_t pricePerTarget = ConfigManager::getSingleton().getSpellConfigInt32("CreatureExplosionPrice");
79 int32_t playerMana = static_cast<int32_t>(player->getSeat()->getMana());
80 if(inputManager.mCommandState == InputCommandState::infoOnly)
81 {
82 if(playerMana < pricePerTarget)
83 {
84 std::string txt = formatCastSpell(SpellType::creatureExplosion, pricePerTarget);
85 inputCommand.displayText(Ogre::ColourValue::Red, txt);
86 }
87 else
88 {
89 std::string txt = formatCastSpell(SpellType::creatureExplosion, pricePerTarget);
90 inputCommand.displayText(Ogre::ColourValue::White, txt);
91 }
92 inputCommand.selectSquaredTiles(inputManager.mXPos, inputManager.mYPos, inputManager.mXPos,
93 inputManager.mYPos);
94 return;
95 }
96
97 if(inputManager.mCommandState == InputCommandState::building)
98 {
99 inputCommand.selectSquaredTiles(inputManager.mXPos, inputManager.mYPos, inputManager.mLStartDragX,
100 inputManager.mLStartDragY);
101 }
102
103 std::vector<GameEntity*> targets;
104 gameMap->playerSelects(targets, inputManager.mXPos, inputManager.mYPos, inputManager.mLStartDragX, inputManager.mLStartDragY,
105 SelectionTileAllowed::groundClaimedAllied, SelectionEntityWanted::creatureAliveEnemy, player);
106
107 if(targets.empty())
108 {
109 std::string txt = formatCastSpell(SpellType::creatureExplosion, 0);
110 inputCommand.displayText(Ogre::ColourValue::White, txt);
111 return;
112 }
113
114 std::random_shuffle(targets.begin(), targets.end());
115 std::vector<Creature*> creatures;
116 for(GameEntity* target : targets)
117 {
118 if(playerMana < pricePerTarget)
119 break;
120
121 if(target->getObjectType() != GameEntityType::creature)
122 {
123 static bool logMsg = false;
124 if(!logMsg)
125 {
126 logMsg = true;
127 OD_LOG_ERR("Wrong target name=" + target->getName() + ", type=" + Helper::toString(static_cast<int32_t>(target->getObjectType())));
128 }
129 continue;
130 }
131

Callers

nothing calls this directly

Calls 11

getLocalPlayerMethod · 0.80
getSpellConfigInt32Method · 0.80
getManaMethod · 0.80
playerSelectsMethod · 0.80
toStringFunction · 0.50
getSeatMethod · 0.45
displayTextMethod · 0.45
selectSquaredTilesMethod · 0.45
getObjectTypeMethod · 0.45
unselectAllTilesMethod · 0.45

Tested by

no test coverage detected