void Creature::onWalk() { if (getWalkDelay() <= 0) { Direction dir; uint32_t flags = FLAG_IGNOREFIELDDAMAGE; if (getNextStep(dir, flags)) { ReturnValue ret = g_game.internalMoveCreature(this, dir, flags); if (ret != RETURNVALUE_NOERROR) { if (Player* player = getPlayer()) { player->sendCancelMessage(ret); player->sendCancelWalk(); } forceUpdateFollowPath = true; } } else { if (listWalkDir.empty()) { onWalkComplete(); } stopEventWalk(); } } if (cancelNextWalk) { listWalkDir.clear(); onWalkAborted(); cancelNextWalk = false; } if (eventWalk != 0) { eventWalk = 0; addEventWalk(); } }
void Creature::onWalk() { if(getWalkDelay() <= 0) { Direction dir; uint32_t flags = FLAG_IGNOREFIELDDAMAGE; if(!getNextStep(dir, flags)) { if(listWalkDir.empty()) onWalkComplete(); stopEventWalk(); } else if(g_game.internalMoveCreature(this, dir, flags) != RET_NOERROR) forceUpdateFollowPath = true; } if(cancelNextWalk) { cancelNextWalk = false; listWalkDir.clear(); onWalkAborted(); } if(eventWalk) { eventWalk = 0; addEventWalk(); } }
void Monster::onThink(uint32_t interval) { Creature::onThink(interval); if(despawn()) { g_game.internalTeleport(this, masterPos); setIdle(true); } else { updateIdleStatus(); if(!isIdle) { addEventWalk(); if(isSummon()) { if(!attackedCreature) { if(getMaster() && getMaster()->getAttackedCreature()) { ///This happens if the monster is summoned during combat selectTarget(getMaster()->getAttackedCreature()); } else if(getMaster() != followCreature) { //Our master has not ordered us to attack anything, lets follow him around instead. setFollowCreature(getMaster()); } } else if(attackedCreature == this) setFollowCreature(NULL); else if(followCreature != attackedCreature) { //This happens just after a master orders an attack, so lets follow it aswell. setFollowCreature(attackedCreature); } } else if(!targetList.empty()) { if(!followCreature || !hasFollowPath) searchTarget(); else if(isFleeing()) { if(attackedCreature && !canUseAttack(getPosition(), attackedCreature)) searchTarget(TARGETSEARCH_ATTACKRANGE); } } onThinkTarget(interval); onThinkYell(interval); onThinkDefense(interval); } } }
void Monster::onThink(uint32_t interval) { Creature::onThink(interval); if(despawn()) { g_game.removeCreature(this, true); setIdle(true); return; } updateIdleStatus(); if(isIdle) return; if(teleportToMaster && doTeleportToMaster()) teleportToMaster = false; addEventWalk(); if(getMaster()){ if(getPosition().z != getMaster()->getPosition().z){ g_game.internalTeleport(this, getMaster()->getPosition(), false); //g_game.addMagicEffect(getPosition(), MAGIC_EFFECT_SOUND_YELLOW); } } if(isSummon()) { if(!attackedCreature) { std::string strValue; if(getMaster() && getMaster()->getAttackedCreature()) //This happens if the monster is summoned during combat selectTarget(getMaster()->getAttackedCreature()); else{ setFollowCreature((getMaster()->getStorage(500, strValue) && strValue != "-1") ? NULL : getMaster()); } } else if(attackedCreature == this) setFollowCreature(NULL); else if(followCreature != attackedCreature) //This happens just after a master orders an attack, so lets follow it aswell. setFollowCreature(attackedCreature); } else if(!targetList.empty()) { if(!followCreature || !hasFollowPath) searchTarget(); else if(isFleeing() && attackedCreature && !canUseAttack(getPosition(), attackedCreature)) searchTarget(TARGETSEARCH_ATTACKRANGE); } onThinkTarget(interval); onThinkYell(interval); onThinkDefense(interval); }
void Creature::startAutoWalk(const std::forward_list<Direction>& listDir) { listWalkDir = listDir; size_t size = 0; for (auto it = listDir.begin(); it != listDir.end() && size <= 1; ++it) { size++; } addEventWalk(size == 1); }
bool Creature::startAutoWalk(const std::list<Direction>& listDir) { const Player* thisPlayer = getPlayer(); if (thisPlayer && thisPlayer->getNoMove()) { thisPlayer->sendCancelWalk(); return false; } listWalkDir = listDir; addEventWalk(listDir.size() == 1); return true; }
bool Creature::startAutoWalk(std::list<Direction>& listDir) { if(getPlayer() && getPlayer()->getNoMove()) { getPlayer()->sendCancelWalk(); return false; } listWalkDir = listDir; addEventWalk(); return true; }
void Npc::onThink(uint32_t interval) { Creature::onThink(interval); if (npcEventHandler) { npcEventHandler->onThink(); } if (getTimeSinceLastMove() >= walkTicks) { addEventWalk(); } }
void Npc::onCreatureAppear(const Creature* creature, bool isLogin) { Creature::onCreatureAppear(creature, isLogin); if(creature == this && autoWalkChance > 0){ addEventWalk(); } //only players for script events if(creature->getPlayer()){ m_npcEventHandler->onCreatureAppear(creature); } }
void Npc::reload() { reset(); load(); // Simulate that the creature is placed on the map again. if (npcEventHandler) { npcEventHandler->onCreatureAppear(this); } if (walkTicks > 0) { addEventWalk(); } }
void Npc::onCreatureAppear(const Creature* creature, bool isLogin) { Creature::onCreatureAppear(creature, isLogin); if (creature == this && walkTicks > 0) { addEventWalk(); } if (creature == this || creature->getPlayer()) { if (m_npcEventHandler) { m_npcEventHandler->onCreatureAppear(creature); } } }
void Npc::onCreatureAppear(Creature* creature, bool isLogin) { Creature::onCreatureAppear(creature, isLogin); if (creature == this) { if (walkTicks > 0) { addEventWalk(); } if (npcEventHandler) { npcEventHandler->onCreatureAppear(creature); } } else if (creature->getPlayer()) { if (npcEventHandler) { npcEventHandler->onCreatureAppear(creature); } } }
void Creature::onWalk() { if(getWalkDelay() <= 0) { Direction dir; uint32_t flags = FLAG_IGNOREFIELDDAMAGE; if(getNextStep(dir, flags) && g_game.internalMoveCreature(this, dir, flags) != RET_NOERROR) forceUpdateFollowPath = true; } if(listWalkDir.empty()) onWalkComplete(); if(eventWalk) { eventWalk = 0; addEventWalk(); } }
void Npc::onCreatureAppear(const Creature* creature, bool isLogin) { Creature::onCreatureAppear(creature, isLogin); if(creature == this && walkTicks > 0){ addEventWalk(); } if(creature == this){ if(m_npcEventHandler){ m_npcEventHandler->onCreatureAppear(creature); } } //only players for script events else if(Player* player = const_cast<Player*>(creature->getPlayer())){ if(m_npcEventHandler){ m_npcEventHandler->onCreatureAppear(creature); } } }
void Npc::onCreatureAppear(Creature* creature, bool isLogin) { Creature::onCreatureAppear(creature, isLogin); if (creature == this) { if (walkTicks > 0) { addEventWalk(); } if (npcEventHandler) { npcEventHandler->onCreatureAppear(creature); } } else if (Player* player = creature->getPlayer()) { if (npcEventHandler) { npcEventHandler->onCreatureAppear(creature); } spectators.insert(player); updateIdleStatus(); } }
void Monster::onThink(uint32_t interval) { Creature::onThink(interval); if (mType->info.thinkEvent != -1) { // onThink(self, interval) LuaScriptInterface* scriptInterface = mType->info.scriptInterface; if (!scriptInterface->reserveScriptEnv()) { std::cout << "[Error - Monster::onThink] Call stack overflow" << std::endl; return; } ScriptEnvironment* env = scriptInterface->getScriptEnv(); env->setScriptId(mType->info.thinkEvent, scriptInterface); lua_State* L = scriptInterface->getLuaState(); scriptInterface->pushFunction(mType->info.thinkEvent); LuaScriptInterface::pushUserdata<Monster>(L, this); LuaScriptInterface::setMetatable(L, -1, "Monster"); lua_pushnumber(L, interval); if (scriptInterface->callFunction(2)) { return; } } if (!isInSpawnRange(position)) { g_game.internalTeleport(this, masterPos); setIdle(true); } else { updateIdleStatus(); if (!isIdle) { addEventWalk(); if (isSummon()) { if (!attackedCreature) { if (getMaster() && getMaster()->getAttackedCreature()) { //This happens if the monster is summoned during combat selectTarget(getMaster()->getAttackedCreature()); } else if (getMaster() != followCreature) { //Our master has not ordered us to attack anything, lets follow him around instead. setFollowCreature(getMaster()); } } else if (attackedCreature == this) { setFollowCreature(nullptr); } else if (followCreature != attackedCreature) { //This happens just after a master orders an attack, so lets follow it aswell. setFollowCreature(attackedCreature); } } else if (!targetList.empty()) { if (!followCreature || !hasFollowPath) { searchTarget(); } else if (isFleeing()) { if (attackedCreature && !canUseAttack(getPosition(), attackedCreature)) { searchTarget(TARGETSEARCH_ATTACKRANGE); } } } onThinkTarget(interval); onThinkYell(interval); onThinkDefense(interval); } } }
bool Creature::startAutoWalk(std::list<Direction>& listDir) { listWalkDir = listDir; addEventWalk(); return true; }
void Creature::startAutoWalk(const std::list<Direction>& listDir) { listWalkDir = listDir; addEventWalk(listDir.size() == 1); }