예제 #1
0
 public override void PlanExit(IReGoapAction <string, object> previousAction, IReGoapAction <string, object> nextAction, ReGoapState <string, object> settings, ReGoapState <string, object> goalState)
 {
     if (settings.HasKey("resource"))
     {
         ((IResource)settings.Get("resource")).Unreserve(GetHashCode());
     }
 }
        public override void Run(IReGoapAction <string, object> previous, IReGoapAction <string, object> next, ReGoapState <string, object> settings, ReGoapState <string, object> goalState, System.Action <IReGoapAction <string, object> > done, System.Action <IReGoapAction <string, object> > fail)
        {
            base.Run(previous, next, settings, goalState, done, fail);

            if (settings.HasKey("Objective Role"))
            {
                var role = settings.Get("Objective Role") as Role;
                if (role && role.Reserve(gameObject))
                {
                    var state = agent.GetMemory().GetWorldState();
                    var prev  = state.Get("Reserved Role") as Role;
                    if (prev != role)
                    {
                        prev?.Release(gameObject);
                        state.Set("Reserved Role", role);
                    }

                    done(this);
                }
                else
                {
                    fail(this);
                }
            }
            else
            {
                fail(this);
            }
        }
예제 #3
0
        public override void Run(IReGoapAction <string, object> previous, IReGoapAction <string, object> next, ReGoapState <string, object> settings, ReGoapState <string, object> goalState, System.Action <IReGoapAction <string, object> > done, System.Action <IReGoapAction <string, object> > fail)
        {
            base.Run(previous, next, settings, goalState, done, fail);

            if (settings.HasKey("Objective Position"))
            {
                destination = settings.Get("Objective Position") as Vector3?;
                if (destination.HasValue)
                {
                    behavior.ExternalBehavior = external;

                    behavior.SetVariableValue("Destination", destination.Value);
                    behavior.SetVariableValue("Speed", speed);

                    StartCoroutine(TimeOutCoroutine());
                }
                else
                {
                    fail(this);
                }
            }
            else
            {
                fail(this);
            }
        }
예제 #4
0
        public override void Run(IReGoapAction <string, object> previous, IReGoapAction <string, object> next, ReGoapState <string, object> settings, ReGoapState <string, object> goalState, Action <IReGoapAction <string, object> > done, Action <IReGoapAction <string, object> > fail)
        {
            base.Run(previous, next, settings, goalState, done, fail);

            if (settings.HasKey($"Objective {type}"))
            {
                var role = settings.Get($"Objective {type}") as RepairRole;
                if (role)
                {
                    _light.enabled = false;

                    behavior.ExternalBehavior = external;
                    behavior.SetVariableValue("Target", role.breakable.gameObject);

                    StartCoroutine(ActionCheckCoroutine(role));
                }
                else
                {
                    fail(this);
                }
            }
            else
            {
                fail(this);
            }
        }
예제 #5
0
        public override void Run(IReGoapAction <string, object> previous, IReGoapAction <string, object> next, ReGoapState <string, object> settings, ReGoapState <string, object> goalState, Action <IReGoapAction <string, object> > done, Action <IReGoapAction <string, object> > fail)
        {
            base.Run(previous, next, settings, goalState, done, fail);

            if (settings.HasKey("ObjectivePosition"))
            {
                smsGoto.GoTo((Vector3)settings.Get("ObjectivePosition"), OnDoneMovement, OnFailureMovement);
            }
            else
            {
                failCallback(this);
            }
        }
예제 #6
0
    public void TestReGoapStateMissingDifference()
    {
        var state = new ReGoapState();

        state.Set("var0", true);
        state.Set("var1", "string");
        state.Set("var2", 1);
        var otherState = new ReGoapState();

        otherState.Set("var1", "stringDifferent");
        otherState.Set("var2", 1);
        var differences = new ReGoapState();
        var count       = state.MissingDifference(otherState, ref differences);

        Assert.That(count, Is.EqualTo(2));
        Assert.That(differences.Get <bool>("var0"), Is.EqualTo(true));
        Assert.That(differences.Get <string>("var1"), Is.EqualTo("string"));
        Assert.That(differences.HasKey("var2"), Is.EqualTo(false));
    }
예제 #7
0
    public override void Run(IReGoapAction <string, object> previous, IReGoapAction <string, object> next, ReGoapState <string, object> settings, ReGoapState <string, object> goalState, Action <IReGoapAction <string, object> > done, Action <IReGoapAction <string, object> > fail)
    {
        base.Run(previous, next, settings, goalState, done, fail);
        List <Transform> patrolDestinations = (List <Transform>)settings.Get("patrolDestination");

        if (settings.HasKey("patrolDestination"))
        {
            blackboard.onDoneMovement    = OnDoneMovement;
            blackboard.onFailureMovement = OnFailureMovement;

            blackboard.currentTarget = patrolDestinations[_waypointIndex].position;

            //Debug.Log("Setting currentTarget to: " + blackboard.currentTarget.position);

            if (blackboard.targetReachedStatus && _setOncePerUpdate)
            {
                //Debug.Log("Reached waypoint, time to plot another");
                if (_waypointIndex < (patrolDestinations.Count - 1))
                {
                    _waypointIndex++;
                }
                else
                {
                    _waypointIndex = 0;
                }
                _setOncePerUpdate = false;
            }
            else
            {
                fail(this);
                _setOncePerUpdate = true;
            }
            // done(this);
        }
        else
        {
            OnFailureMovement();
        }
    }
예제 #8
0
        public override void Run(IReGoapAction <string, object> previous, IReGoapAction <string, object> next, ReGoapState <string, object> settings, ReGoapState <string, object> goalState, Action <IReGoapAction <string, object> > done, Action <IReGoapAction <string, object> > fail)
        {
            base.Run(previous, next, settings, goalState, done, fail);

            if (settings.HasKey($"Objective {type}"))
            {
                var role = settings.Get($"Objective {type}") as StandRole;
                if (role)
                {
                    behavior.ExternalBehavior = external;
                    behavior.SetVariableValue("Points", role.points);

                    StartCoroutine(ActionCheckCoroutine(role));
                }
                else
                {
                    fail(this);
                }
            }
            else
            {
                fail(this);
            }
        }