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