Exemplo n.º 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);
            }
        }
Exemplo n.º 2
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);
            }
        }
Exemplo n.º 3
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);
            }
        }
Exemplo n.º 4
0
        public override ReGoapState GetPreconditions(ReGoapState goalState)
        {
            ReGoapState reGoapState = reGoapAgent.GetWorldState();

            preconditions.Set("isAtPosition", reGoapState.Get("nearestWorkstationPosition") as Vector3?);
            return(preconditions);
        }
Exemplo n.º 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());
     }
 }
Exemplo n.º 6
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);

            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);
            }
        }
Exemplo n.º 8
0
 private void OnDrawGizmos()
 {
     if (worldState != null)
     {
         Gizmos.color = ((bool)worldState.Get("foodInRange")) ? Color.green : Color.white;
     }
     Gizmos.DrawWireSphere(transform.position, SensorRange);
 }
Exemplo n.º 9
0
        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);
        }
Exemplo n.º 10
0
 public override void Precalculations(IReGoapAgent goapAgent, ReGoapState goalState)
 {
     objectivePosition = goalState.Get <Vector3>("isAtPosition");
     settings          = new GenericGoToSettings
     {
         ObjectivePosition = objectivePosition
     };
     base.Precalculations(goapAgent, goalState);
 }
Exemplo n.º 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));
    }
Exemplo n.º 12
0
        Vector3?GetWantedPositionFromState(ReGoapState <string, object> state)
        {
            Vector3?result = null;

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

            if (state != null)
            {
                result = state.Get("At Position") as Vector3?;
            }
            return(result);
        }
Exemplo n.º 14
0
        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);
        }
Exemplo n.º 15
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);
            }
        }
Exemplo n.º 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);
            }
        }
Exemplo n.º 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);
            }
        }
Exemplo n.º 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);
            }
        }
Exemplo n.º 19
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);

            behavior.ExternalBehavior = external;

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

            if (role != null)
            {
                StartCoroutine(ActionCheckCoroutine(role));
            }
            else
            {
                fail(this);
            }
        }
Exemplo n.º 20
0
        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);
        }
Exemplo n.º 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);
            }
        }
Exemplo n.º 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);
        }
Exemplo n.º 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();
        }
    }
Exemplo n.º 24
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);
            }
        }