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

Method castSpell

source/spells/SpellCreatureDefense.cpp:157–210  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

155}
156
157bool 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
212Spell* SpellCreatureDefense::getSpellFromStream(GameMap* gameMap, std::istream &is)
213{

Callers

nothing calls this directly

Calls 11

isAlliedSeatMethod · 0.80
getPositionTileMethod · 0.80
isAliveMethod · 0.80
isClaimedForSeatMethod · 0.80
getSpellConfigInt32Method · 0.80
takeManaMethod · 0.80
getSpellConfigUInt32Method · 0.80
getSpellConfigDoubleMethod · 0.80
addCreatureEffectMethod · 0.80
getCreatureMethod · 0.45
getSeatMethod · 0.45

Tested by

no test coverage detected