Пример #1
0
bool Actor::getNextStep(Direction& dir, uint32_t& flags)
{
  if(isIdle || getHealth() <= 0){
    //we dont have anyone watching might aswell stop walking
    eventWalk = 0;
    return false;
  }

  bool result = false;
  if((!followCreature || !hasFollowPath) && !isSummon()){
    if(followCreature){
      result = getRandomStep(getPosition(), dir);
    }else{
      if(getTimeSinceLastMove() > 1000){
        //choose a random direction
        result = getRandomStep(getPosition(), dir);
      }
    }
  }
  else if(isSummon() || followCreature){
    result = Creature::getNextStep(dir, flags);
    if(result){
      flags |= FLAG_PATHFINDING;
    }
    else{
      //target dancing
      if(attackedCreature && attackedCreature == followCreature){
        if(isFleeing()){
          result = getDanceStep(getPosition(), dir, false, false);
        }
        else if(cType.staticAttackChance() < (uint32_t)random_range(1, 100)){
          result = getDanceStep(getPosition(), dir);
        }
      }
    }
  }

  if(result && (canPushItems() || canPushCreatures()) ){
    const Position& pos = Combat::getCasterPosition(this, dir);
    Tile* tile = g_game.getParentTile(pos.x, pos.y, pos.z);
    if(tile){
      if(canPushItems()){
        pushItems(tile);
      }

      if(canPushCreatures()){
        pushCreatures(tile);
      }
    }
#ifdef __DEBUG__
    else{
      std::cout << "getNextStep - no tile." << std::endl;
    }
#endif
  }

  return result;
}
Пример #2
0
bool Monster::getNextStep(Direction& dir, uint32_t& flags)
{
	if(isIdle || getHealth() <= 0)
	{
		//we dont have anyone watching might aswell stop walking
		eventWalk = 0;
		return false;
	}

	bool result = false;
	if((!followCreature || !hasFollowPath) && !isSummon())
	{
		if(followCreature || getTimeSinceLastMove() > 1000) //choose a random direction
			result = getRandomStep(getPosition(), dir);
	}
	else if(isSummon() || followCreature)
	{
		result = Creature::getNextStep(dir, flags);
		if(!result)
		{
			//target dancing
			if(attackedCreature && attackedCreature == followCreature)
			{
				if(isFleeing())
					result = getDanceStep(getPosition(), dir, false, false);
				else if(mType->staticAttackChance < (uint32_t)random_range(1, 100))
					result = getDanceStep(getPosition(), dir);
			}
		}
		else
			flags |= FLAG_PATHFINDING;
	}

	if(result && (canPushItems() || canPushCreatures()))
	{
		if(Tile* tile = g_game.getTile(Spells::getCasterPosition(this, dir)))
		{
			if(canPushItems())
				pushItems(tile);

			if(canPushCreatures())
				pushCreatures(tile);
		}
#ifdef __DEBUG__
		else
			std::clog << "[Warning - Monster::getNextStep] no tile found." << std::endl;
#endif
	}

	return result;
}