Example #1
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);
            this.settings = settings;
            var bank = settings.Get("bank") as Bank;

            if (bank != null && bank.AddResource(resourcesBag, (string)settings.Get("resourceName")))
            {
                done(this);
            }
            else
            {
                fail(this);
            }
        }
        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);
            }
        }
        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);
            }
        }
Example #4
0
        public override ReGoapState GetPreconditions(ReGoapState goalState)
        {
            ReGoapState reGoapState = reGoapAgent.GetWorldState();

            preconditions.Set("isAtPosition", reGoapState.Get("nearestWorkstationPosition") as Vector3?);
            return(preconditions);
        }
Example #5
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, Action <IReGoapAction <string, object> > done, Action <IReGoapAction <string, object> > fail)
        {
            base.Run(previous, next, settings, goalState, done, fail);

            behavior.ExternalBehavior = external;

            var carryable = settings.Get("Objective Carryable") as Carryable;

            if (carryable != null)
            {
                var distance = Vector3.Distance(transform.position, carryable.transform.position);
                if (distance > range)
                {
                    fail(this);
                }
                else
                {
                    if (carryable.Carry(holder))
                    {
                        agent.GetMemory().GetWorldState().Set("Carrying", carryable);
                        StartCoroutine(ActionCheckCoroutine());
                    }
                    else
                    {
                        fail(this);
                    }
                }
            }
            else
            {
                fail(this);
            }
        }
        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);
            }
        }
Example #8
0
 private void OnDrawGizmos()
 {
     if (worldState != null)
     {
         Gizmos.color = ((bool)worldState.Get("foodInRange")) ? Color.green : Color.white;
     }
     Gizmos.DrawWireSphere(transform.position, SensorRange);
 }
        public override ReGoapState GetPreconditions(ReGoapState goalState)
        {
            var newNeededResourceName = GetNeededResourceFromGoal(goalState);

            preconditions.Clear();
            if (newNeededResourceName != null)
            {
                ReGoapState reGoapState = reGoapAgent.GetWorldState();

                Resource wantedResource = reGoapState.Get("nearest" + newNeededResourceName) as Resource;
                if (wantedResource != null)
                {
                    Vector3 resourcePosition = (Vector3)reGoapState.Get(string.Format("nearest{0}Position", newNeededResourceName));
                    preconditions.Set("isAtPosition", resourcePosition);
                }
            }
            return(preconditions);
        }
Example #10
0
 public override void Precalculations(IReGoapAgent goapAgent, ReGoapState goalState)
 {
     objectivePosition = goalState.Get <Vector3>("isAtPosition");
     settings          = new GenericGoToSettings
     {
         ObjectivePosition = objectivePosition
     };
     base.Precalculations(goapAgent, goalState);
 }
Example #11
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));
    }
Example #12
0
        Vector3?GetWantedPositionFromState(ReGoapState <string, object> state)
        {
            Vector3?result = null;

            if (state != null)
            {
                result = state.Get("isAtPosition") as Vector3?;
            }
            return(result);
        }
        Vector3?GetGoalPosition(ReGoapState <string, object> state)
        {
            Vector3?result = null;

            if (state != null)
            {
                result = state.Get("At Position") as Vector3?;
            }
            return(result);
        }
        public override IReGoapActionSettings GetSettings(ReGoapState goalState)
        {
            var newNeededResourceName             = GetNeededResourceFromGoal(goalState);
            GatherResourceSettings wantedSettings = null;

            if (newNeededResourceName != null)
            {
                ReGoapState reGoapState = reGoapAgent.GetWorldState();

                Resource wantedResource = reGoapState.Get("nearest" + newNeededResourceName) as Resource;
                if (wantedResource != null)
                {
                    wantedSettings = new GatherResourceSettings
                    {
                        ResourcePosition = (Vector3)reGoapState.Get(string.Format("nearest{0}Position", newNeededResourceName)),
                        Resource         = wantedResource
                    };
                }
            }
            return(wantedSettings);
        }
        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);
            }
        }
Example #16
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);
            var workstation = settings.Get("workstation") as Workstation;

            if (workstation != null && workstation.CraftResource(resourcesBag, recipe))
            {
                ReGoapLogger.Log("[CraftRecipeAction] crafted recipe " + recipe.GetCraftedResource());
                done(this);
            }
            else
            {
                fail(this);
            }
        }
Example #17
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);

            var bed = (Bed)settings.Get("bed");

            if (bed == null)
            {
                failCallback(this);
            }
            else
            {
                bed.Sleep(stamina);
            }
        }
Example #18
0
        public override void Run(IReGoapActionSettings settings, Action <ReGoapAction> done, Action <ReGoapAction> fail)
        {
            base.Run(settings, done, fail);

            ReGoapState reGoapState = reGoapAgent.GetWorldState();

            var workstation = reGoapState.Get("nearestWorkstation") as Workstation;

            if (workstation != null && workstation.CraftResource(resourcesBag, recipe))
            {
                done(this);
            }
            else
            {
                fail(this);
            }
        }
        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);

            behavior.ExternalBehavior = external;

            var role = settings.Get($"Objective {type}") as CarryRole;

            if (role != null)
            {
                StartCoroutine(ActionCheckCoroutine(role));
            }
            else
            {
                fail(this);
            }
        }
        public override ReGoapState GetEffects(ReGoapState goalState)
        {
            var newNeededResourceName = GetNeededResourceFromGoal(goalState);

            effects.Clear();
            if (newNeededResourceName != null)
            {
                ReGoapState reGoapState = reGoapAgent.GetWorldState();

                var wantedResource = reGoapState.Get("nearest" + newNeededResourceName) as Resource;
                if (wantedResource != null)
                {
                    effects.Set("hasResource" + newNeededResourceName, true);
                }
            }
            return(effects);
        }
Example #21
0
        public override void Run(IReGoapActionSettings settings, Action <ReGoapAction> done, Action <ReGoapAction> fail)
        {
            base.Run(settings, done, fail);
            this.settings = (AddResourceToBankSettings)settings;

            ReGoapState reGoapState = reGoapAgent.GetWorldState();

            Bank bank = reGoapState.Get("nearestBank") as Bank;

            if (bank != null && bank.AddResource(resourcesBag, ((AddResourceToBankSettings)settings).ResourceName))
            {
                done(this);
            }
            else
            {
                fail(this);
            }
        }
Example #22
0
        public override ReGoapState GetPreconditions(ReGoapState goalState)
        {
            ReGoapState reGoapState  = reGoapAgent.GetWorldState();
            Vector3?    bankPosition = reGoapState.Get("nearestBankPosition") as Vector3?;

            preconditions.Clear();
            preconditions.Set("isAtPosition", bankPosition);

            foreach (var pair in goalState.GetValues())
            {
                if (pair.Key.StartsWith("collectedResource"))
                {
                    var resourceName = pair.Key.Substring(17);
                    preconditions.Set("hasResource" + resourceName, true);
                    break;
                }
            }

            return(preconditions);
        }
Example #23
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();
        }
    }
        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);
            }
        }