| 74 | } |
| 75 | |
| 76 | void SpellCreatureDefense::checkSpellCast(GameMap* gameMap, const InputManager& inputManager, InputCommand& inputCommand) |
| 77 | { |
| 78 | Player* player = gameMap->getLocalPlayer(); |
| 79 | int32_t pricePerTarget = ConfigManager::getSingleton().getSpellConfigInt32("CreatureDefensePrice"); |
| 80 | int32_t playerMana = static_cast<int32_t>(player->getSeat()->getMana()); |
| 81 | if(inputManager.mCommandState == InputCommandState::infoOnly) |
| 82 | { |
| 83 | if(playerMana < pricePerTarget) |
| 84 | { |
| 85 | std::string txt = formatCastSpell(SpellType::creatureDefense, pricePerTarget); |
| 86 | inputCommand.displayText(Ogre::ColourValue::Red, txt); |
| 87 | } |
| 88 | else |
| 89 | { |
| 90 | std::string txt = formatCastSpell(SpellType::creatureDefense, pricePerTarget); |
| 91 | inputCommand.displayText(Ogre::ColourValue::White, txt); |
| 92 | } |
| 93 | inputCommand.selectSquaredTiles(inputManager.mXPos, inputManager.mYPos, inputManager.mXPos, |
| 94 | inputManager.mYPos); |
| 95 | return; |
| 96 | } |
| 97 | |
| 98 | Tile* tileSelected = gameMap->getTile(inputManager.mXPos, inputManager.mYPos); |
| 99 | if(tileSelected == nullptr) |
| 100 | return; |
| 101 | |
| 102 | if(inputManager.mCommandState == InputCommandState::building) |
| 103 | { |
| 104 | inputCommand.selectSquaredTiles(inputManager.mXPos, inputManager.mYPos, inputManager.mXPos, |
| 105 | inputManager.mYPos); |
| 106 | } |
| 107 | |
| 108 | std::vector<GameEntity*> entities; |
| 109 | // We search the closest creature alive |
| 110 | tileSelected->fillWithEntities(entities, SelectionEntityWanted::creatureAliveAllied, player); |
| 111 | Creature* closestCreature = nullptr; |
| 112 | double closestDist = 0; |
| 113 | for(GameEntity* entity : entities) |
| 114 | { |
| 115 | if(entity->getObjectType() != GameEntityType::creature) |
| 116 | { |
| 117 | OD_LOG_ERR("entityName=" + entity->getName() + ", entityType=" + Helper::toString(static_cast<uint32_t>(entity->getObjectType()))); |
| 118 | continue; |
| 119 | } |
| 120 | |
| 121 | const Ogre::Vector3& entityPos = entity->getPosition(); |
| 122 | double dist = Pathfinding::squaredDistance(entityPos.x, inputManager.mKeeperHandPos.x, entityPos.y, inputManager.mKeeperHandPos.y); |
| 123 | if(closestCreature == nullptr) |
| 124 | { |
| 125 | closestDist = dist; |
| 126 | closestCreature = static_cast<Creature*>(entity); |
| 127 | continue; |
| 128 | } |
| 129 | |
| 130 | if(dist >= closestDist) |
| 131 | continue; |
| 132 | |
| 133 | closestDist = dist; |
nothing calls this directly
no test coverage detected