| 155 | } |
| 156 | |
| 157 | bool SpellCreatureDefense::castSpell(GameMap* gameMap, Player* player, ODPacket& packet) |
| 158 | { |
| 159 | std::string creatureName; |
| 160 | OD_ASSERT_TRUE(packet >> creatureName); |
| 161 | |
| 162 | // We check that the creature is a valid target |
| 163 | Creature* creature = gameMap->getCreature(creatureName); |
| 164 | if(creature == nullptr) |
| 165 | { |
| 166 | OD_LOG_ERR("creatureName=" + creatureName); |
| 167 | return false; |
| 168 | } |
| 169 | |
| 170 | if(!creature->getSeat()->isAlliedSeat(player->getSeat())) |
| 171 | { |
| 172 | OD_LOG_ERR("creatureName=" + creatureName); |
| 173 | return false; |
| 174 | } |
| 175 | |
| 176 | Tile* pos = creature->getPositionTile(); |
| 177 | if(pos == nullptr) |
| 178 | { |
| 179 | OD_LOG_ERR("creatureName=" + creatureName); |
| 180 | return false; |
| 181 | } |
| 182 | |
| 183 | if(!creature->isAlive()) |
| 184 | { |
| 185 | // This can happen if the creature was alive on client side but is not since we received the message |
| 186 | OD_LOG_WRN("creatureName=" + creatureName); |
| 187 | return false; |
| 188 | } |
| 189 | |
| 190 | // That can happen if the creature is not in perfect synchronization and is not on a claimed tile on the server gamemap |
| 191 | if(!pos->isClaimedForSeat(player->getSeat())) |
| 192 | { |
| 193 | OD_LOG_WRN("Creature=" + creatureName + ", tile=" + Tile::displayAsString(pos)); |
| 194 | return false; |
| 195 | } |
| 196 | |
| 197 | int32_t pricePerTarget = ConfigManager::getSingleton().getSpellConfigInt32("CreatureDefensePrice"); |
| 198 | |
| 199 | if(!player->getSeat()->takeMana(pricePerTarget)) |
| 200 | return false; |
| 201 | |
| 202 | uint32_t duration = ConfigManager::getSingleton().getSpellConfigUInt32("CreatureDefenseDuration"); |
| 203 | double value = ConfigManager::getSingleton().getSpellConfigDouble("CreatureDefenseValue"); |
| 204 | CreatureEffectDefense* effect = new CreatureEffectDefense(duration, value, 0.0, 0.0, "SpellCreatureDefense"); |
| 205 | creature->addCreatureEffect(effect); |
| 206 | |
| 207 | fireSpellSound(*pos, "Defense"); |
| 208 | |
| 209 | return true; |
| 210 | } |
| 211 | |
| 212 | Spell* SpellCreatureDefense::getSpellFromStream(GameMap* gameMap, std::istream &is) |
| 213 | { |
nothing calls this directly
no test coverage detected