示例#1
0
Direction Monster::getWanderingDirection() const {
	if (!isAlive()) {
		return Direction::NONE;
	}

	Direction direction = Direction::NONE;
	if (attackedCreature != nullptr) {
		//target dancing
		if(isFleeing())
			direction = getDanceStep(false, false);
		else if(_type->staticAttackChance < (uint32_t)random_range(1, 100))
			direction = getDanceStep();
	}
	else {
		direction = getRandomStepDirection();
	}

	if(direction != Direction::NONE && (canPushItems() || canPushCreatures()))
	{
		if(Tile* tile = server.game().getTile(Spells::getCasterPosition(this, direction)))
		{
			// TODO refactor!

			if(canPushItems())
				const_cast<Monster*>(this)->pushItems(tile);
		}
	}

	return direction;
}
示例#2
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;
}
示例#3
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;
}
示例#4
0
bool Monster::getNextStep(Direction& direction, 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() || !isMasterInRange)) {
		if (followCreature || getTimeSinceLastMove() > 1000) {
			//choose a random direction
			result = getRandomStep(getPosition(), direction);
		}
	} else if ((isSummon() && isMasterInRange) || followCreature) {
		result = Creature::getNextStep(direction, flags);
		if (result) {
			flags |= FLAG_PATHFINDING;
		} else {
			//target dancing
			if (attackedCreature && attackedCreature == followCreature) {
				if (isFleeing()) {
					result = getDanceStep(getPosition(), direction, false, false);
				} else if (mType->info.staticAttackChance < static_cast<uint32_t>(uniform_random(1, 100))) {
					result = getDanceStep(getPosition(), direction);
				}
			}
		}
	}

	if (result && (canPushItems() || canPushCreatures())) {
		const Position& pos = Spells::getCasterPosition(this, direction);
		Tile* tile = g_game.map.getTile(pos);
		if (tile) {
			if (canPushItems()) {
				Monster::pushItems(tile);
			}

			if (canPushCreatures()) {
				Monster::pushCreatures(tile);
			}
		}
	}

	return result;
}