Beispiel #1
0
	bool MonsterAI::RandomRun()
	{
		CMonster *monster = static_cast<CMonster*>(GetOwner());
		if (monster == NULL)
		{
			LogError(AI_MODULE, "MosterAI has no owner object...");
		}
		assert(monster);
		if(random(10000) < monster->GetMoveRandomValue())
		{
			long dir = 0;
			long curX = monster->GetTileX();
			long curY = monster->GetTileY();
			long dis = monster->Distance(curX, curY, m_BornPos.x, m_BornPos.y);
			if(dis > monster->GetPeaceMoveRange())
			{
				dir = GetLineDir(curX, curY, m_BornPos.x, m_BornPos.y);
				long gdir = (8 - dir) % 8;
				if(gdir >= 2 || gdir <= 6)
				{
					dir = (dir + random(3) - 1 + 8) % 8;
				}
			}
			else
			{
				dir = random(8);
			}

			long maxRunTimes = monster->GetMaxRunTimes();
			long minRunTimes = monster->GetMinRunTimes();

			AI_EVENT_SENDER(this).MoveByStep(dir, random(maxRunTimes - minRunTimes) + minRunTimes);
			// drive the ai
			Resume(0);
		}
		else
		{
			Stand(monster->GetStopFrame());
		}
		return true;
	}
Beispiel #2
0
    void SummonPeaceState::Execute(BaseType::EntityType *entity)
    {
		if (entity == NULL)
		{
			LogError(AI_MODULE, "entity is null.");
			return;
		}
        if(SearchEnemy(entity))
        {
            return;
        }

        /// Stand ... Don't move
        MonsterAI *ai = static_cast<MonsterAI*>(entity);
        CMonster  *monster = static_cast<CMonster*>(entity->GetOwner());
		if (monster == NULL)
		{
			LogError(AI_MODULE, "MonsterAI do not have owner.");
		}
        assert(ai && monster);
        ai->Stand(monster->GetStopFrame());
    }