| 51 | } |
| 52 | |
| 53 | void TrapFactory::checkBuildTrapDefault(GameMap* gameMap, TrapType type, const InputManager& inputManager, InputCommand& inputCommand) const |
| 54 | { |
| 55 | Player* player = gameMap->getLocalPlayer(); |
| 56 | int32_t pricePerTarget = TrapManager::costPerTile(type); |
| 57 | int32_t playerGold = static_cast<int32_t>(player->getSeat()->getGold()); |
| 58 | if(inputManager.mCommandState == InputCommandState::infoOnly) |
| 59 | { |
| 60 | if(playerGold < pricePerTarget) |
| 61 | { |
| 62 | std::string txt = formatBuildTrap(type, pricePerTarget); |
| 63 | inputCommand.displayText(Ogre::ColourValue::Red, txt); |
| 64 | } |
| 65 | else |
| 66 | { |
| 67 | std::string txt = formatBuildTrap(type, pricePerTarget); |
| 68 | inputCommand.displayText(Ogre::ColourValue::White, txt); |
| 69 | } |
| 70 | inputCommand.selectSquaredTiles(inputManager.mXPos, inputManager.mYPos, inputManager.mXPos, |
| 71 | inputManager.mYPos); |
| 72 | return; |
| 73 | } |
| 74 | |
| 75 | std::vector<Tile*> buildableTiles = gameMap->getBuildableTilesForPlayerInArea(inputManager.mXPos, |
| 76 | inputManager.mYPos, inputManager.mLStartDragX, inputManager.mLStartDragY, player); |
| 77 | |
| 78 | if(inputManager.mCommandState == InputCommandState::building) |
| 79 | inputCommand.selectTiles(buildableTiles); |
| 80 | |
| 81 | if(buildableTiles.empty()) |
| 82 | { |
| 83 | std::string txt = formatBuildTrap(type, 0); |
| 84 | inputCommand.displayText(Ogre::ColourValue::White, txt); |
| 85 | return; |
| 86 | } |
| 87 | |
| 88 | int32_t priceTotal = static_cast<int32_t>(buildableTiles.size()) * pricePerTarget; |
| 89 | if(playerGold < priceTotal) |
| 90 | { |
| 91 | std::string txt = formatBuildTrap(type, priceTotal); |
| 92 | inputCommand.displayText(Ogre::ColourValue::Red, txt); |
| 93 | return; |
| 94 | } |
| 95 | |
| 96 | std::string txt = formatBuildTrap(type, priceTotal); |
| 97 | inputCommand.displayText(Ogre::ColourValue::White, txt); |
| 98 | |
| 99 | if(inputManager.mCommandState != InputCommandState::validated) |
| 100 | return; |
| 101 | |
| 102 | ClientNotification *clientNotification = TrapManager::createTrapClientNotification(type); |
| 103 | uint32_t nbTiles = buildableTiles.size(); |
| 104 | clientNotification->mPacket << nbTiles; |
| 105 | for(Tile* tile : buildableTiles) |
| 106 | gameMap->tileToPacket(clientNotification->mPacket, tile); |
| 107 | |
| 108 | ODClient::getSingleton().queueClientNotification(clientNotification); |
| 109 | } |
| 110 |
nothing calls this directly
no test coverage detected