void Monster::onCreatureMove(const Creature* creature, const Tile* newTile, const Position& newPos, const Tile* oldTile, const Position& oldPos, bool teleport) { Creature::onCreatureMove(creature, newTile, newPos, oldTile, oldPos, teleport); if(creature == this) { if(isSummon()) isMasterInRange = canSee(master->getPosition()); updateTargetList(); updateIdleStatus(); } else { bool canSeeNewPos = canSee(newPos), canSeeOldPos = canSee(oldPos); if(canSeeNewPos && !canSeeOldPos) onCreatureEnter(const_cast<Creature*>(creature)); else if(!canSeeNewPos && canSeeOldPos) onCreatureLeave(const_cast<Creature*>(creature)); if(isSummon() && master == creature && canSeeNewPos) //Turn the summon on again isMasterInRange = true; updateIdleStatus(); if(!followCreature && !isSummon() && isOpponent(creature)) //we have no target lets try pick this one selectTarget(const_cast<Creature*>(creature)); } }
void Actor::onCreatureMove(const Creature* creature, const Tile* newTile, const Position& newPos, const Tile* oldTile, const Position& oldPos, bool teleport) { Creature::onCreatureMove(creature, newTile, newPos, oldTile, oldPos, teleport); if(creature == this){ if(isSummon()){ isMasterInRange = canSee(getMaster()->getPosition()); } updateTargetList(); updateIdleStatus(); /* TODO: Optimizations here if(teleport){ //do a full update of the friend/target list } else{ //partial update of the friend/target list } */ } else{ bool canSeeNewPos = canSee(newPos); bool canSeeOldPos = canSee(oldPos); if(canSeeNewPos && !canSeeOldPos){ onCreatureEnter(const_cast<Creature*>(creature)); } else if(!canSeeNewPos && canSeeOldPos){ onCreatureLeave(const_cast<Creature*>(creature)); } if(isSummon() && getMaster() == creature){ if(canSeeNewPos){ //Turn the summon on again isMasterInRange = true; } } updateIdleStatus(); if(!followCreature && !isSummon()){ //we have no target lets try pick this one if(isOpponent(creature)){ selectTarget(const_cast<Creature*>(creature)); } } } }
void Monster::onCreatureAppear(const Creature* creature) { Creature::onCreatureAppear(creature); if(creature == this) { //We just spawned lets look around to see who is there. if(isSummon()) isMasterInRange = canSee(master->getPosition()); updateTargetList(); updateIdleStatus(); } else onCreatureEnter(const_cast<Creature*>(creature)); }
void Actor::onCreatureAppear(const Creature* creature, bool isLogin) { Creature::onCreatureAppear(creature, isLogin); if(creature == this){ //We just spawned lets look around to see who is there. if(isSummon()){ isMasterInRange = canSee(getMaster()->getPosition()); } updateTargetList(); updateIdleStatus(); } else{ onCreatureEnter(const_cast<Creature*>(creature)); } }
void Monster::onCreatureAppear(Creature* creature, bool isLogin) { Creature::onCreatureAppear(creature, isLogin); if (mType->info.creatureAppearEvent != -1) { // onCreatureAppear(self, creature) LuaScriptInterface* scriptInterface = mType->info.scriptInterface; if (!scriptInterface->reserveScriptEnv()) { std::cout << "[Error - Monster::onCreatureAppear] Call stack overflow" << std::endl; return; } ScriptEnvironment* env = scriptInterface->getScriptEnv(); env->setScriptId(mType->info.creatureAppearEvent, scriptInterface); lua_State* L = scriptInterface->getLuaState(); scriptInterface->pushFunction(mType->info.creatureAppearEvent); LuaScriptInterface::pushUserdata<Monster>(L, this); LuaScriptInterface::setMetatable(L, -1, "Monster"); LuaScriptInterface::pushUserdata<Creature>(L, creature); LuaScriptInterface::setCreatureMetatable(L, -1, creature); if (scriptInterface->callFunction(2)) { return; } } if (creature == this) { //We just spawned lets look around to see who is there. if (isSummon()) { isMasterInRange = canSee(getMaster()->getPosition()); } updateTargetList(); updateIdleStatus(); } else { onCreatureEnter(creature); } }
void Monster::onCreatureAppear(const Creature* creature) { Creature::onCreatureAppear(creature); if(creature == this) { //We just spawned lets look around to see who is there. if(isSummon()) isMasterInRange = canSee(getMaster()->getPosition()); setStorage(510, mType->realName); // sistema de shiny nomes 2.0 CreatureEventList spawn = getCreatureEvents(CREATURE_EVENT_SPAWN); for(CreatureEventList::iterator it = spawn.begin(); it != spawn.end(); ++it) (*it)->executeOnSpawn(this); updateTargetList(); updateIdleStatus(); } else onCreatureEnter(const_cast<Creature*>(creature)); }
void Monster::onCreatureMove(Creature* creature, const Tile* newTile, const Position& newPos, const Tile* oldTile, const Position& oldPos, bool teleport) { Creature::onCreatureMove(creature, newTile, newPos, oldTile, oldPos, teleport); if (mType->info.creatureMoveEvent != -1) { // onCreatureMove(self, creature, oldPosition, newPosition) LuaScriptInterface* scriptInterface = mType->info.scriptInterface; if (!scriptInterface->reserveScriptEnv()) { std::cout << "[Error - Monster::onCreatureMove] Call stack overflow" << std::endl; return; } ScriptEnvironment* env = scriptInterface->getScriptEnv(); env->setScriptId(mType->info.creatureMoveEvent, scriptInterface); lua_State* L = scriptInterface->getLuaState(); scriptInterface->pushFunction(mType->info.creatureMoveEvent); LuaScriptInterface::pushUserdata<Monster>(L, this); LuaScriptInterface::setMetatable(L, -1, "Monster"); LuaScriptInterface::pushUserdata<Creature>(L, creature); LuaScriptInterface::setCreatureMetatable(L, -1, creature); LuaScriptInterface::pushPosition(L, oldPos); LuaScriptInterface::pushPosition(L, newPos); if (scriptInterface->callFunction(4)) { return; } } if (creature == this) { if (isSummon()) { isMasterInRange = canSee(getMaster()->getPosition()); } updateTargetList(); updateIdleStatus(); } else { bool canSeeNewPos = canSee(newPos); bool canSeeOldPos = canSee(oldPos); if (canSeeNewPos && !canSeeOldPos) { onCreatureEnter(creature); } else if (!canSeeNewPos && canSeeOldPos) { onCreatureLeave(creature); } if (canSeeNewPos && isSummon() && getMaster() == creature) { isMasterInRange = true; //Follow master again } updateIdleStatus(); if (!isSummon()) { if (followCreature) { const Position& followPosition = followCreature->getPosition(); const Position& position = getPosition(); int32_t offset_x = Position::getDistanceX(followPosition, position); int32_t offset_y = Position::getDistanceY(followPosition, position); if ((offset_x > 1 || offset_y > 1) && mType->info.changeTargetChance > 0) { Direction dir = getDirectionTo(position, followPosition); const Position& checkPosition = getNextPosition(dir, position); Tile* tile = g_game.map.getTile(checkPosition); if (tile) { Creature* topCreature = tile->getTopCreature(); if (topCreature && followCreature != topCreature && isOpponent(topCreature)) { selectTarget(topCreature); } } } } else if (isOpponent(creature)) { //we have no target lets try pick this one selectTarget(creature); } } } }