bool Combat::CombatNullFunc(Creature* caster, Creature* target, const CombatParams& params, void* data) { CombatConditionFunc(caster, target, params, NULL); CombatDispelFunc(caster, target, params, NULL); onCreatureDoCombat(caster, target, params.isAggressive); return true; }
void Combat::doCombatCondition(Creature* caster, Creature* target, const CombatParams& params) { if(!params.isAggressive || (caster != target && Combat::canDoCombat(caster, target) == RET_NOERROR)){ CombatConditionFunc(caster, target, params, NULL); if(params.targetCallback){ params.targetCallback->onTargetCombat(caster, target); } if(params.impactEffect != NM_ME_NONE){ g_game.addMagicEffect(target->getPosition(), params.impactEffect); } if(caster && params.distanceEffect != NM_ME_NONE){ addDistanceEffect(caster, caster->getPosition(), target->getPosition(), params.distanceEffect); } onCreatureDoCombat(caster, target, params.isAggressive); } }
void Combat::CombatFunc(Creature* caster, const Position& pos, const AreaCombat* area, const CombatParams& params, COMBATFUNC func, void* data) { std::list<Tile*> tileList; if(caster){ getCombatArea(caster->getPosition(), pos, area, tileList); } else{ getCombatArea(pos, pos, area, tileList); } SpectatorVec list; uint32_t maxX = 0; uint32_t maxY = 0; uint32_t diff; //calculate the max viewable range for(std::list<Tile*>::iterator it = tileList.begin(); it != tileList.end(); ++it){ diff = std::abs((*it)->getPosition().x - pos.x); if(diff > maxX){ maxX = diff; } diff = std::abs((*it)->getPosition().y - pos.y); if(diff > maxY){ maxY = diff; } } g_game.getSpectators(list, pos, false, true, maxX + Map::maxViewportX, maxX + Map::maxViewportX, maxY + Map::maxViewportY, maxY + Map::maxViewportY); for(std::list<Tile*>::iterator it = tileList.begin(); it != tileList.end(); ++it){ Tile* iter_tile = *it; bool bContinue = true; if(canDoCombat(caster, iter_tile, params.isAggressive) == RET_NOERROR){ if(iter_tile->getCreatures()){ for(CreatureVector::iterator cit = iter_tile->getCreatures()->begin(), cend = iter_tile->getCreatures()->end(); bContinue && cit != cend; ++cit) { if(params.targetCasterOrTopMost){ if(caster && caster->getTile() == iter_tile){ if(*cit == caster){ bContinue = false; } } else if(*cit == iter_tile->getTopCreature()){ bContinue = false; } if(bContinue){ continue; } } if(!params.isAggressive || (caster != *cit && Combat::canDoCombat(caster, *cit) == RET_NOERROR)){ func(caster, *cit, params, data); if(params.targetCallback){ params.targetCallback->onTargetCombat(caster, *cit); } if(func == CombatDispelFunc || func == CombatConditionFunc){ onCreatureDoCombat(caster, *cit, params.isAggressive); } } } } combatTileEffects(list, caster, iter_tile, params); } } postCombatEffects(caster, pos, params); }