void Actor::onCreatureConvinced(const Creature* convincer, const Creature* creature) { if(convincer != this && (isFriend(creature) || isOpponent(creature))){ updateTargetList(); updateIdleStatus(); } }
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 Monster::onCreatureConvinced(const Creature* convincer, const Creature* creature) { if(convincer == this || (!isFriend(creature) && !isOpponent(creature))) return; updateTargetList(); updateIdleStatus(); }
void Monster::onCreatureConvinced(const Creature* convincer, const Creature* creature) { if(convincer != this && (isFriend(creature) || isOpponent(creature))){ updateTargetList(); updateIdleStatus(); } #ifdef __MIN_PVP_LEVEL_APPLIES_TO_SUMMONS__ g_game.forceClientsToReloadCreature(creature); #endif }
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)); } } } }
bool Monster::convinceCreature(Creature* creature) { Player* player = creature->getPlayer(); if(player && !player->hasFlag(PlayerFlag_CanConvinceAll) && !mType->isConvinceable) return false; Creature* oldMaster = NULL; if(isSummon()) oldMaster = master; if(oldMaster) { if(oldMaster->getPlayer() || oldMaster == creature) return false; oldMaster->removeSummon(this); } setFollowCreature(NULL); setAttackedCreature(NULL); destroySummons(); creature->addSummon(this); updateTargetList(); updateIdleStatus(); //Notify surrounding about the change SpectatorVec list; g_game.getSpectators(list, getPosition(), false, true); g_game.getSpectators(list, creature->getPosition(), true, true); isMasterInRange = true; for(SpectatorVec::iterator it = list.begin(); it != list.end(); ++it) (*it)->onCreatureConvinced(creature, this); if(spawn) { spawn->removeMonster(this); spawn = NULL; masterRadius = -1; } if(raid) { raid->unRef(); raid = NULL; } return true; }
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)); }
bool Actor::convinceCreature(Creature* creature) { Player* player = creature->getPlayer(); if(player && !player->hasFlag(PlayerFlag_CanConvinceAll)){ if(!cType.isConvinceable()){ return false; } } if(isPlayerSummon()){ return false; } else if(isSummon()){ if(getMaster() != creature){ Creature* oldMaster = getMaster(); oldMaster->removeSummon(this); creature->addSummon(this); setFollowCreature(NULL); setAttackedCreature(NULL); //destroy summons destroySummons(); isMasterInRange = true; updateTargetList(); updateIdleStatus(); //Notify surrounding about the change SpectatorVec list; g_game.getSpectators(list, getPosition(), false, true); g_game.getSpectators(list, creature->getPosition(), true, true); for(SpectatorVec::iterator it = list.begin(); it != list.end(); ++it){ (*it)->onCreatureConvinced(creature, this); } if(spawn){ spawn->removeMonster(this); spawn = NULL; masterRadius = -1; } return true; } } else{ creature->addSummon(this); setFollowCreature(NULL); setAttackedCreature(NULL); destroySummons(); isMasterInRange = true; updateTargetList(); updateIdleStatus(); //Notify surrounding about the change SpectatorVec list; g_game.getSpectators(list, getPosition(), false, true); g_game.getSpectators(list, creature->getPosition(), true, true); for(SpectatorVec::iterator it = list.begin(); it != list.end(); ++it){ (*it)->onCreatureConvinced(creature, this); } if(spawn){ spawn->removeMonster(this); spawn = NULL; masterRadius = -1; } return true; } return false; }
bool Monster::convinceCreature(Creature* creature) { Player* player = creature->getPlayer(); if(player && !player->hasFlag(PlayerFlag_CanConvinceAll)) { if(!mType->isConvinceable) return false; } if(isSummon()) { if(getMaster()->getPlayer()) return false; else if(getMaster() != creature) { Creature* oldMaster = getMaster(); oldMaster->removeSummon(this); creature->addSummon(this); setFollowCreature(NULL); setAttackedCreature(NULL); //destroy summons for(std::list<Creature*>::iterator cit = summons.begin(); cit != summons.end(); ++cit) { (*cit)->changeHealth(-(*cit)->getHealth()); (*cit)->setMaster(NULL); (*cit)->releaseThing2(); } summons.clear(); isMasterInRange = true; updateTargetList(); updateIdleStatus(); //Notify surrounding about the change SpectatorVec list; g_game.getSpectators(list, getPosition(), false, true); g_game.getSpectators(list, creature->getPosition(), true, true); for(SpectatorVec::iterator it = list.begin(); it != list.end(); ++it) (*it)->onCreatureConvinced(creature, this); if(spawn) { spawn->removeMonster(this); spawn = NULL; masterRadius = -1; } return true; } } else { creature->addSummon(this); setFollowCreature(NULL); setAttackedCreature(NULL); for(std::list<Creature*>::iterator cit = summons.begin(); cit != summons.end(); ++cit) { (*cit)->changeHealth(-(*cit)->getHealth()); (*cit)->setMaster(NULL); (*cit)->releaseThing2(); } summons.clear(); isMasterInRange = true; updateTargetList(); updateIdleStatus(); //Notify surrounding about the change SpectatorVec list; g_game.getSpectators(list, getPosition(), false, true); g_game.getSpectators(list, creature->getPosition(), true, true); for(SpectatorVec::iterator it = list.begin(); it != list.end(); ++it) (*it)->onCreatureConvinced(creature, this); if(spawn) { spawn->removeMonster(this); spawn = NULL; masterRadius = -1; } return true; } return false; }
void SUnit::proces(uint32_t delta, Processor* processor){ postProces(delta); if(_lastCombat < 1000000) _lastCombat++; if(this->_updateCounter) this->_updateCounter--; for(SSlotNodeI it = this->slots.begin(); it != this->slots.end(); it++){ if (it->second->getSS()) it->second->getSS()->proces(processor); } if(_order){ if(_targetUpdateCounter % 5 == 0){ _order->proces(OrdreEvent::Tick5,this); } if(_targetUpdateCounter % 10 == 0){ _order->proces(OrdreEvent::Tick10,this); } if(_targetUpdateCounter % 25 == 0){ _order->proces(OrdreEvent::Tick25,this); } } _targetUpdateCounter++; this->addRecoil(getUnitType()->getRecoilRecharge()); if (_targetUpdateCounter % 5 == 0){ this->updateTargetsPrio(_processor); this->addEnergy(_recharge/5); } if (_targetUpdateCounter % 25 == 0){ if(_id == 2) setProgram(_processor->getPrograms()["test"]); updateTargetList(_processor); this->updateAutoMove(); sendPosUpdate(SubscriptionLevel::lowFreq); this->_bonuslist.clear(); for(SSlotNodeI it = this->slots.begin(); it != this->slots.end(); it++){ if (it->second->getSS()){ if (it->second->getSS()->isBonus()){ it->second->getSS()->isBonus()->procesBonus(this); } } } this->_recharge = getUnitType()->getRecharge() * 1000; this->_maxEnergy = getUnitType()->getEnergy() * 1000; this->_maxdeflector = getUnitType()->getDeflector()*1000; //this->_deflector = stype.getDeflector()*1000; for (int i = 0; i< 6; i++){ this->_maxshield[i] = getUnitType()->getShield(i) * getUnitType()->getShieldStr() * 10; } this->_maxarmor = getUnitType()->getArmor()*1000; this->_maxhull = getUnitType()->getHull()*1000; this->_scanRange = getUnitType()->getScanRange() * 100; this->_scanPRange = getUnitType()->getScanPRange() * 100; _topSpeed = getUnitType()->getTopSpeed() * 100; _agility = getUnitType()->getAgility(); for (map<BonusTypes::Enum, int32_t>::iterator it = this->_bonuslist.begin(); it != this->_bonuslist.end();it++){ switch(it->first){ case BonusTypes::Armor:{this->_maxarmor+= it->second;break;} case BonusTypes::Deflector:{this->_maxdeflector+= it->second;break;} case BonusTypes::Hull:{this->_maxhull+= it->second;break;} case BonusTypes::ShieldStr:{ for(uint32_t i = 0; i < 6 ; i++){ this->_maxshield[i] += (this->getUnitType()->getShield(i) * it->second)/100; } break; } case BonusTypes::ERecharge:{this->_recharge+= it->second;break;} case BonusTypes::Energy:{this->_maxEnergy+= it->second;break;} case BonusTypes::ScanRange:{this->_scanRange+= (it->second/10);break;} case BonusTypes::ScanPRange:{this->_scanPRange+= (it->second/10);break;} case BonusTypes::SpeedThruster:{this->_topSpeed+= (it->second/(getUnitType()->getMass()/10));break;} case BonusTypes::ManuvereThruster:{this->_agility+= (it->second/(getUnitType()->getMass()*10));break;} } } for(SSlotNodeI it = this->slots.begin(); it != this->slots.end(); it++){ if (it->second->getSS()) it->second->getSS()->reset(); } //cerr<<"this->_topSpeed"<<this->_topSpeed<<endl; } if (_targetUpdateCounter == 100) _targetUpdateCounter = 0; }
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); } } } }