Esempio n. 1
0
// TODO move to creature
bool Monster::target(const CreatureP& creature) {
	LOGt(this << "::target(" << creature.get() << ")");

	if (creature == this || creature == _master) {
		if (attackedCreature == nullptr) {
			return true;
		}

		return setAttackedCreature(nullptr);
	}

	if (creature == attackedCreature) {
		return true;
	}

	if (creature == nullptr) {
		return setAttackedCreature(nullptr);
	}
	else {
		if (!setAttackedCreature(creature.get())) {
			return false;
		}

		setRetargetDelay(_type->retargetInterval);
		server.dispatcher().addTask(Task::create(std::bind(&Game::checkCreatureAttack, &server.game(), getId())));
	}

	return true;
}
Esempio n. 2
0
bool Actor::selectTarget(Creature* creature)
{
#ifdef __DEBUG__
  std::cout << "Selecting target... " << std::endl;
#endif

  if(!isTarget(creature)){
    return false;
  }

  CreatureList::iterator it = std::find(targetList.begin(), targetList.end(), creature);
  if(it == targetList.end()){
    //Target not found in our target list.
#ifdef __DEBUG__
    std::cout << "Target not found in targetList." << std::endl;
#endif
    return false;
  }

  if(isHostile() || isSummon()){
    if(setAttackedCreature(creature) && !isSummon()){
      g_dispatcher.addTask(createTask(
        boost::bind(&Game::checkCreatureAttack, &g_game, getID())));
    }
  }

  return setFollowCreature(creature, true);
}
Esempio n. 3
0
void Actor::canTarget(bool b)
{
  canTarget_ = b;
  if(!canTarget()){
    setAttackedCreature(0);
    setFollowCreature(0);
  }
}
void Monster::die()
{
	setAttackedCreature(NULL);
	destroySummons();
	clearTargetList();
	clearFriendList();
	Creature::die();
}
Esempio n. 5
0
void Actor::die()
{
  setAttackedCreature(NULL);
  destroySummons();

  clearTargetList();
  clearFriendList();
  onIdleStatus();
  Creature::die();
}
Esempio n. 6
0
void Creature::onCreatureDisappear(const Creature* creature, bool isLogout)
{
	if (attackedCreature == creature) {
		setAttackedCreature(NULL);
		onAttackedCreatureDisappear(isLogout);
	}

	if (followCreature == creature) {
		setFollowCreature(NULL);
		onFollowCreatureDisappear(isLogout);
	}
}
Esempio n. 7
0
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;
}
Esempio n. 8
0
void Monster::death(Creature*)
{
	setAttackedCreature(nullptr);

	for (Creature* summon : summons) {
		summon->changeHealth(-summon->getHealth());
		summon->removeMaster();
	}
	summons.clear();

	clearTargetList();
	clearFriendList();
	onIdleStatus();
}
Esempio n. 9
0
void Monster::death()
{
	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();

	clearTargetList();
	clearFriendList();
	onIdleStatus();
}
Esempio n. 10
0
bool Monster::selectTarget(Creature* creature)
{
	if (!isTarget(creature)) {
		return false;
	}

	auto it = std::find(targetList.begin(), targetList.end(), creature);
	if (it == targetList.end()) {
		//Target not found in our target list.
		return false;
	}

	if (isHostile() || isSummon()) {
		if (setAttackedCreature(creature) && !isSummon()) {
			g_dispatcher.addTask(createTask(std::bind(&Game::checkCreatureAttack, &g_game, getID())));
		}
	}
	return setFollowCreature(creature);
}
Esempio n. 11
0
bool Monster::onDeath()
{
	if(!Creature::onDeath())
		return false;

	destroySummons();
	clearTargetList();
	clearFriendList();

	setAttackedCreature(NULL);
	onIdleStatus();
	if(raid)
	{
		raid->unRef();
		raid = NULL;
	}

	g_game.removeCreature(this, false);
	return true;
}
Esempio n. 12
0
void Creature::onAttacking(uint32_t interval)
{
	if(!attackedCreature || attackedCreature->getHealth() < 1 || interval < 100)
		return;

	bool deny = false;
	CreatureEventList attackEvents = getCreatureEvents(CREATURE_EVENT_ATTACK);
	for(CreatureEventList::iterator it = attackEvents.begin(); it != attackEvents.end(); ++it)
	{
		if(!(*it)->executeAction(this, attackedCreature) && !deny)
			deny = true;
	}

	if(deny)
		setAttackedCreature(NULL);

	if(!attackedCreature)
		return;

	onAttacked();
	attackedCreature->onAttacked();
	if(g_game.isSightClear(getPosition(), attackedCreature->getPosition(), true))
		doAttacking(interval);
}
Esempio n. 13
0
bool Monster::selectTarget(Creature* creature)
{
#ifdef __DEBUG__
	std::cout << "Selecting target... " << std::endl;
#endif
	if(!isTarget(creature))
		return false;
		
	if(!isHostile())
        return false;
        
     std::string value;
     if(getStorage(505, value) && value != "-1") {
       if(creature->isSummon()){
          if(value != creature->getMaster()->getName())
              return false;                     
       }else if(value != creature->getName()) //&& value != "0"){ -- se bugar  
           return false;    
     }   

	CreatureList::iterator it = std::find(targetList.begin(), targetList.end(), creature);
	if(it == targetList.end())
	{
		//Target not found in our target list.
#ifdef __DEBUG__
		std::cout << "Target not found in targetList." << std::endl;
#endif
		return false;
	}

	if((isHostile() || isSummon()) && setAttackedCreature(creature) && !isSummon())
		Dispatcher::getInstance().addTask(createTask(
			boost::bind(&Game::checkCreatureAttack, &g_game, getID())));

	return setFollowCreature(creature, true);
}
Esempio n. 14
0
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;
}
Esempio n. 15
0
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;
}