Example #1
0
    private void PlanAndExecute()
    {
        var actions = new List <GOAPAction> {
            new GOAPAction("Patrol")
            .Effect("isPlayerInSight", true)
            .LinkedState(patrolState),


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

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

        var from = new GOAPState();

        from.values["isPlayerInSight"] = false;
        from.values["isPlayerNear"]    = false;
        from.values["isPlayerAlive"]   = true;

        var to = new GOAPState();

        to.values["isPlayerAlive"] = false;

        var planner = new GoapPlanner();

        var plan = planner.Run(from, to, actions);

        ConfigureFsm(plan);
    }
Example #2
0
    private void PlanAndExecute()
    {
        var actions = new List <GOAPAction> {
            new GOAPAction("Patrol")
            .Effect("isPlayerInSight", true)
            .LinkedState(patrolState),

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

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

        var from = new GOAPState();

        from.values["isPlayerInSight"] = false;
        from.values["isPlayerNear"]    = false;
        from.values["isPlayerAlive"]   = true;

        var to = new GOAPState();

        to.values["isPlayerAlive"] = false;

        var planner = new GoapPlanner();

        planner.OnPlanCompleted += OnPlanCompleted;
        planner.OnCantPlan      += OnCantPlan;

        planner.Run(from, to, actions, StartCoroutine);
    }
Example #3
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);
        }
    }
Example #4
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);
    }
Example #5
0
    private void OnlyPlan()
    {
        var actions = new List <GOAPAction> {
            new GOAPAction("Patrol")
            .Effect("isPlayerInSight", true),

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

            new GOAPAction("Melee Attack")
            .Pre("isPlayerNear", true)
            .Pre("hasMeleeWeapon", true)
            .Effect("isPlayerAlive", false)
            .Cost(2f),

            new GOAPAction("Range Attack")
            .Pre("isPlayerInRange", true)
            .Pre("hasRangeWeapon", true)
            .Effect("isPlayerAlive", false),

            new GOAPAction("Pick Melee Weapon")
            .Effect("hasMeleeWeapon", true)
            .Cost(2f),

            new GOAPAction("Pick Range Weapon")
            .Effect("hasRangeWeapon", true)
        };
        var from = new GOAPState();

        from.values["isPlayerInSight"] = true;
        from.values["isPlayerNear"]    = true;
        from.values["isPlayerInRange"] = true;
        from.values["isPlayerAlive"]   = true;
        from.values["hasRangeWeapon"]  = true;
        from.values["hasMeleeWeapon"]  = false;

        var to = new GOAPState();

        to.values["isPlayerAlive"] = false;

        var planner = new GoapPlanner();

        //planner.OnPlanCompleted += OnPlanCompleted;
        //planner.OnCantPlan      += OnCantPlan;

        planner.Run(from, to, actions, StartCoroutine);
    }
Example #6
0
    private void OnlyPlan()
    {
        //var distanceKnife =

        var actions = new List <GOAPAction> {
            new GOAPAction("Patrol")
            .Effect("isPlayerInSight", true),

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

            new GOAPAction("Melee Attack")
            .Pre("isPlayerNear", true)
            .Pre("hasMeleeWeapon", true)
            .Effect("isPlayerAlive", false)
            .Cost(2f),

            new GOAPAction("Range Attack")
            .Pre("isPlayerInRange", true)
            .Pre("hasRangeWeapon", true)
            .Effect("isPlayerAlive", false),

            new GOAPAction("Pick Melee Weapon")
            .Effect("hasMeleeWeapon", true),

            new GOAPAction("Pick Range Weapon")
            .Effect("hasRangeWeapon", true)
        };
        var from = new GOAPState();

        from.values["isPlayerInSight"] = false;
        from.values["isPlayerNear"]    = false;
        from.values["isPlayerInRange"] = false;
        from.values["isPlayerAlive"]   = true;
        from.values["hasRangeWeapon"]  = false;
        from.values["hasMeleeWeapon"]  = false;

        var to = new GOAPState();

        to.values["isPlayerAlive"] = false;

        var planner = new GoapPlanner();

        planner.Run(from, to, actions);
    }
Example #7
0
    private void OnReplan()
    {
        if (Time.time >= _lastReplanTime + _replanRate)
        {
            _lastReplanTime = Time.time;
        }
        else
        {
            return;
        }

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

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

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

        var from = new GOAPState();

        from.values["isPlayerInSight"] = false;
        from.values["isPlayerNear"]    = false;
        from.values["isPlayerAlive"]   = true;

        var to = new GOAPState();

        to.values["isPlayerAlive"] = false;

        var planner = new GoapPlanner();

        var plan = planner.Run(from, to, actions);

        ConfigureFsm(plan);
    }