Exemplo n.º 1
0
    public override void Write(Data data)
    {
        if (!(data is DataObstacle))
        {
            return;
        }
        DataObstacle dataObstacle = data as DataObstacle;

        bool exist = false;
        int  index = 0;

        foreach (DataObstacle d in obstacles)
        {
            if (d.collider == dataObstacle.collider)
            {
                exist = true;
                break;
            }
            ++index;
        }

        if (exist)
        {
            if (dataObstacle.RegistrationDate >= obstacles[index].RegistrationDate)
            {
                Replace(new DataObstacle(dataObstacle), index);
            }
        }
        else
        {
            obstacles.Add(new DataObstacle(dataObstacle));
        }
    }
Exemplo n.º 2
0
    public void RemoveByKey(Collider key)
    {
        DataObstacle element = obstacles.Find(data => data.collider == key);

        if (element != null)
        {
            obstacles.Remove(element);
        }
    }
Exemplo n.º 3
0
    public override void Process()
    {
        Goal child = GetActiveGoal();

        if (child.IsInactive)
        {
            child.Activate();
        }

        bool enemyClose    = false;
        bool obstacleClose = false;

        IReadOnlyCollection <DataCreature> creatures = owner.Memory.Creatures.Read();

        foreach (DataCreature data in creatures)
        {
            Agent agent = data.creature?.agentCreature;
            if (!agent || !agent.gameObject.activeSelf || data.RegistrationDate < Time.time - 5f)
            {
                continue;
            }

            bool isHostil = CreatureIsHostil(owner, agent.Creature);
            if (isHostil && Vector3.Distance(owner.transform.position, agent.transform.position) < owner.PerceptionConfig.viewRadius / 4)
            {
                enemyClose = true;
                break;
            }
        }

        DataObstacle obstacle = owner.Memory.Obstacles.Read().FirstOrDefault(data => MaxColliderSize(data.collider) >= 2f);

        obstacleClose = obstacle != null;

        switch (evadeState)
        {
        case EvadeState.Flee:
            if (!enemyClose && obstacleClose)
            {
                child.Abort();
                AddSubgoal(new GoalHide(owner));
                evadeState = EvadeState.Hide;
            }
            break;

        case EvadeState.Hide:
            if (enemyClose)
            {
                child.Abort();
                AddSubgoal(new GoalFlee(owner));
                evadeState = EvadeState.Flee;
            }
            break;
        }

        base.ProcessSubgoals();
    }
Exemplo n.º 4
0
    public override void Process()
    {
        Goal child = GetActiveGoal();

        if (child.IsInactive)
        {
            child.Activate();
        }

        bool playerClose = owner.Memory.Player.lastSeeTime > Time.time - 5f &&
                           Vector3.Distance(owner.transform.position, Player.Instance.transform.position) < owner.PerceptionConfig.viewRadius / 4;

        DataObstacle obstacle      = owner.Memory.Obstacles.Read().FirstOrDefault(data => MaxColliderSize(data.collider) >= 2f);
        bool         obstacleClose = obstacle != null;

        switch (evadeState)
        {
        case EvadeState.Flee:
            if (!playerClose && obstacleClose)
            {
                child.Abort();
                AddSubgoal(new GoalHidePlayer(owner));
                evadeState = EvadeState.Hide;
            }
            break;

        case EvadeState.Hide:
            if (playerClose)
            {
                child.Abort();
                AddSubgoal(new GoalFleePlayer(owner));
                evadeState = EvadeState.Flee;
            }
            break;
        }

        base.ProcessSubgoals();
    }
Exemplo n.º 5
0
 public DataObstacle(DataObstacle dataObstacle) : base(expirationTime - (Time.time - dataObstacle.RegistrationDate))
 {
     this.collider = dataObstacle.collider;
 }