Esempio n. 1
0
    private void RePlan(object[] parameters)
    {
        if ((GOAPEnemy)parameters[0] == this)
        {
            //Tendriamos que hacer aca el seteo del estado dependiendo las condiciones????
            StopAllCoroutines();
            //IA2-P3
            var nIEActions = actions.Aggregate(new List <GOAPAction>(), (acum, action) =>
            {
                //Intento de "Costos dinamicos"
                if (action.name == "Charge Mana")
                {
                    acum.Add(action.Cost(2 - mana / maxMana));
                }
                else if (action.name == "Melee Attack")
                {
                    var playerPosAtMyHeight = new Vector3(player.transform.position.x, transform.position.y, player.transform.position.z);
                    var delta = (playerPosAtMyHeight - transform.position);
                    acum.Add(action.Cost(1 + Mathf.Clamp01(delta.magnitude / distanceToChooseMelee)));
                }
                else
                {
                    acum.Add(action);
                }

                return(acum);
            });

            actions = nIEActions;
            planner.Run(from, to, actions, StartCoroutine);
            _fsm = GoapPlanner.ConfigureFSM(actions, StartCoroutine);
        }
    }
Esempio n. 2
0
    private void OnCantPlan()
    {
        Debug.LogWarning("!!! NO PUDO COMPLETAR EL PLAN !!!");

        actions = new List <GOAPAction>
        {
            new GOAPAction("Patrol")
            .Effect("isPlayerInSight", true)
            .LinkedState(patrolState)
            .Cost(2),

            new GOAPAction("Chase")
            .Pre("isPlayerInSight", true)
            .Effect("isPlayerNear", true)
            .Effect("isPlayerInRange", true)
            .LinkedState(chaseState),

            new GOAPAction("Melee Attack")
            .Pre("isPlayerNear", true)
            .Effect("isPlayerAlive", false)
            .LinkedState(meleeAttackState),

            new GOAPAction("Range Attack")
            .Pre("isPlayerInRange", true)
            .Pre("hasMana", true)
            .Effect("isPlayerAlive", false)
            .Effect("hasMana", false)
            .LinkedState(rangeAttackState),

            new GOAPAction("Charge Mana")
            .Effect("hasMana", true)
            .LinkedState(chargeManaState)
        };
        from = new GOAPState();
        from.values["isPlayerInSight"] = false;
        from.values["isPlayerNear"]    = false;
        from.values["isPlayerInRange"] = false;
        from.values["hasMana"]         = false;
        from.values["isPlayerAlive"]   = true;
        to = new GOAPState();
        to.values["isPlayerAlive"] = false;

        planner = new GoapPlanner();
        planner.OnPlanCompleted += OnPlanCompleted;
        planner.OnCantPlan      += OnCantPlan;

        planner.Run(from, to, actions, StartCoroutine);

        _fsm = GoapPlanner.ConfigureFSM(actions, StartCoroutine);
    }
Esempio n. 3
0
 private void OnPlanCompleted(IEnumerable <GOAPAction> plan)
 {
     _fsm        = GoapPlanner.ConfigureFSM(plan, StartCoroutine);
     _fsm.Active = true;
 }
Esempio n. 4
0
 private void ConfigureFsm(IEnumerable <GOAPAction> plan)
 {
     Debug.Log("Completed Plan");
     _fsm        = GoapPlanner.ConfigureFSM(plan, StartCoroutine);
     _fsm.Active = true;
 }