public override List <GOAPState> getWorldState(GOAPAgent agent) { List <GOAPState> worldData = new List <GOAPState>(); worldData.Add(new GOAPState("Patrol", false)); return(worldData); }
public override bool CheckProceduralPrecondition(GOAPAgent agent) { List <Building> buildings = EntityManager.GetBuildings(); Building nearest = null; float distance = 0; foreach (Building b in buildings.Where(x => x.BuildingType == BuildingType.Stockpile)) { if (b.Inventory.Items.ContainsKey(Food.ItemType)) { if (nearest == null) { nearest = b; distance = (agent.PlannedLocation.Distance(b.Position)); } else { float tempDistance = agent.PlannedLocation.Distance(b.Position); if (tempDistance < distance) { nearest = b; distance = tempDistance; } } } } Target = nearest; if (Target != null) { agent.PlannedLocation = Target.Position; } return(nearest != null); }
public ChopWood(GOAPAgent agent, Game game, Movement movement) : base(agent, game, movement) { Preconditions.Add(Effect.HAS_THING, TypeOfThing.Axe); Effects.Add(Effect.HAS_THING, TypeOfThing.Wood); _inventory = agent.GetComponent <Inventory>(); }
void Start() { goal = new HashSet <KeyValuePair <ActionKey, object> >(); goapAgent = GetComponent <GOAPAgent>(); navAgent = GetComponent <NavMeshAgent>(); }
//Checks to see if the axe has been picked up public override bool checkComplete(GOAPAgent agent) { var anim = agent.GetComponentInChildren <Animator>(); if (agent.Target != null) { if (anim.GetBool("hasPickedUp")) { var controller = agent.GetComponentInParent <PlayerController>(); if (controller != null) { controller.SetHandObject(agent.Target); } anim.SetBool("hasPickedUp", false); return(true); } else { return(false); } } else { return(false); } }
public override bool CheckProceduralPrecondition(GOAPAgent agent) { List <Building> buildings = EntityManager.GetBuildings().Where(x => x.BuildingType == Recipe.Type).ToList(); Building nearest = null; float distance = 0; foreach (Building b in buildings) { if (nearest == null) { nearest = b; distance = (agent.PlannedLocation.Distance(b.Position)); } else { float tempDistance = (agent.PlannedLocation.Distance(b.Position)); if (tempDistance < distance) { nearest = b; distance = tempDistance; } } } Target = nearest; if (Target != null) { agent.PlannedLocation = Target.Position; } return(nearest != null); }
protected override float CalculateCost(GOAPAgent agent, GroundEntity entity) { var targetPos = entity.EntityState.GetValue(StateVariables.TargetLocation); //Since we are not doing pathfinding, this is merely an estimative. return(Vector3.Distance(targetPos, entity.Position)); }
public override bool CheckProceduralPrecondition(GOAPAgent agent) { List <ResourceNode> resourceNodes = EntityManager.GetResourceNodes(); ResourceNode nearest = null; float distance = 0; foreach (ResourceNode rn in resourceNodes.Where(x => x.ResourceNodeType == Gather.Type)) { if (nearest == null) { nearest = rn; distance = (agent.PlannedLocation.Distance(rn.Position)); } else { float tempDistance = (agent.PlannedLocation.Distance(rn.Position)); if (tempDistance < distance) { nearest = rn; distance = tempDistance; } } } Target = nearest; if (Target != null) { agent.PlannedLocation = Target.Position; } return(nearest != null); }
public override bool IsPossible(GOAPAgent agent, EntityState state) { // Although this action requires two entities to be within the hearing range of one another, which requires // entities to move themselves (if they are not already), this "location required" condition cannot // negate the "talk to" action itself, an entity can talk to whichever entity it wants to (in most countries), // however, it does negate the "walk to" action, which is a depency of the "talk to" one (because we have // the "nearPrecondition"). I'm not good with words so I hope you can understand this :D return(true); }
// Use this for initialization void Start() { thoughts = new List <string>(); agent = GetComponent <GOAPAgent>(); _foodKey = GameManager.main.addCounter(foodSpendTime); _energyKey = GameManager.main.addCounter(energySpendTime); _lifeKey = GameManager.main.addCounter(lifeSpendTime); _ageKey = GameManager.main.addCounter(ageSpendTime); }
public override void OnUpdate(GOAPAgent agent) { var p = NearPrecondition.Precondition; if (!p.IsMet(agent)) { agent.CurrentPlan.ForceEnqueue(agent, p); } }
public GOAPAction(GOAPAgent agent, Game game) { _game = game; _agent = agent; Cost = 1f; Preconditions = new Dictionary <string, object>(); Effects = new Dictionary <string, object>(); }
public override bool IsMet(GOAPAgent agent) { var e = agent.EntityStateProvider as Examples.Entity; if (!e) { return(false); } return(Vector3.Distance(GetTargetPosition(), e.Position) <= DistanceThreshold); }
public Idle(GOAPAgent agent, Game game, Movement movement) : base(agent, game) { _movement = movement; Goal = GOAPGoal.Goal.IS_IDLING; Preconditions.Add(Effect.HAS_THING, TypeOfThing.None); //Effects.Add(GOAPAction.Effect.IS_WORKING, true); }
public GetThing(GOAPAgent agent, Game game, Thing thing, Movement movement, TypeOfThing resource) : base(agent, game, movement) { _thing = thing; _movement = movement; _resource = resource; _inventory = _thing.Inventory; Preconditions.Add(Effect.HAS_THING, TypeOfThing.None); Effects.Add(Effect.HAS_THING, resource); }
public Construct(GOAPAgent agent, Game game, Movement movement, TypeOfThing resource, Thing thing) : base(agent, game, movement) { Goal = GOAPGoal.Goal.IS_WORKING; _movement = movement; _resource = resource; _thing = thing; _inventory = _thing.Inventory; Preconditions.Add(GOAPAction.Effect.HAS_THING, resource); }
//Uses its onActivation function on the agent public void activate(GOAPAgent agent) { if (onActivation != null) { onActivation.onActivation(agent); } else { Debug.Log("ERROR! Action: " + actionName + " does not contain an onActivate behaviour"); } }
public EastSomething(GOAPAgent agent, Game game, Thing thing) : base(agent, game) { _inventory = thing.Inventory; Goal = GOAPGoal.Goal.IS_NOT_HUNGRY; //Preconditions.Add(GOAPAction.Effect.IS_HUNGRY, true); Preconditions.Add(GOAPAction.Effect.HAS_EDIBLE_THING, true); //Effects.Add(GOAPAction.Effect.IS_HUNGRY, false); }
//Checks if the current agent has completed this action using its checkComplete public bool isDone(GOAPAgent agent) { if (checkComplete != null) { return(checkComplete.checkComplete(agent)); } else { Debug.Log("ERROR! Action: " + actionName + " has no checkComplete behaviour."); return(true); } }
public override void onActivation(GOAPAgent agent) { var anim = agent.GetComponentInChildren <Animator>(); if (anim == null) { Debug.Log("Animator doesn't exist"); } else { anim.SetTrigger("tr_pickup"); } }
public FillStorage(GOAPAgent agent, Game game, Movement movement, Inventory inventory, TypeOfThing type) : base(agent, game, movement) { _movement = movement; _inventory = inventory; _type = type; var thingConfig = Assets.GetThingConfig(type); // Preconditions.Add(GOAPAction.Effect.HAS_THING + thingConfig.InventorySlot, type); // Preconditions.Add(GOAPAction.Effect.HAS_THING_FOR_STORAGE, true); // Effects.Add(GOAPAction.Effect.HAS_THING_FOR_STORAGE, false); // Effects.Add(GOAPAction.Effect.IS_WORKING, true); }
public List <GameObject> StartSpecific(GameObject target, GOAPAgent thisAgent) { Reset(); Hashtable backupStats = thisAgent.playerValues; agentPlanningFor = thisAgent; print("SEARCHING"); planData.Add(new PlanData(target, null, 0)); if (target.GetComponent <GOAPObject>().singleUse) { ignore.Add(target); } if (target.GetComponent <GOAPObject>().preconditions.Length > 0) { for (int condition = 0; condition < target.GetComponent <GOAPObject>().preconditions.Length; condition++) { if (backupStats.ContainsKey(target.GetComponent <GOAPObject>().preconditions[condition].precondition)) { if ((float)backupStats[target.GetComponent <GOAPObject>().preconditions[condition].precondition] >= target.GetComponent <GOAPObject>().preconditions[condition].requiredAmount) { float newVal = (float)backupStats[target.GetComponent <GOAPObject>().preconditions[condition].precondition]; newVal -= target.GetComponent <GOAPObject>().preconditions[condition].requiredAmount; backupStats[target.GetComponent <GOAPObject>().preconditions[condition].precondition] = newVal; } else { float remainingVal = (float)backupStats[target.GetComponent <GOAPObject>().preconditions[condition].precondition]; remainingVal -= target.GetComponent <GOAPObject>().preconditions[condition].requiredAmount; backupStats[target.GetComponent <GOAPObject>().preconditions[condition].precondition] = 0; precondQueue.Add(new Precondition(target.GetComponent <GOAPObject>().preconditions[condition].precondition, remainingVal)); } } else { return(null); } } if (precondQueue.Count > 0) { ActionSearch(precondQueue[precondQueue.Count - 1].precondition, precondQueue[precondQueue.Count - 1].requiredAmount, planData[planData.Count - 1], precondQueue, 0, backupStats); } } else { finalTiles.Add(planData[planData.Count - 1]); } path = new List <GameObject>(); BuildPath(CheapestPath()); return(path); }
public Sleep(GOAPAgent agent, Game game, Thing thing, Movement movement, Villager villager, Needs needs) : base(agent, game) { _thing = thing; _movement = movement; _villager = villager; _needs = needs; Goal = GOAPGoal.Goal.IS_RESTED; Preconditions.Add(GOAPAction.Effect.IS_RESTED, false); Preconditions.Add(GOAPAction.Effect.HAS_THING, TypeOfThing.None); Effects.Add(GOAPAction.Effect.IS_RESTED, true); }
//A simple way to set goals. Shoul be replaced with an actual method of getting the highest priority goalSet and setting it's goals public override List <GOAPState> getWorldState(GOAPAgent agent) { List <GOAPState> worldData = new List <GOAPState>(); var controller = agent.GetComponentInParent <PlayerController>(); bool hasAxe = false; if ((controller != null) && (controller.hand.GetComponentInChildren <InteractableItemBase>() != null)) { hasAxe = (controller.hand.GetComponentInChildren <InteractableItemBase>().tag != null); } worldData.Add(new GOAPState("FirewoodCollected", false)); worldData.Add(new GOAPState("HasAxe", hasAxe)); worldData.Add(new GOAPState("FirewoodAvailable", GameObject.FindGameObjectsWithTag("Firewood").Length > 0)); return(worldData); }
protected override void Start() { base.Start(); SMActive = false; GOAP = new GOAPAgent(); GOAP.AvailableActions.AddRange(GetComponents <GOAPAction>()); GOAP.util.Actions.Add(attackGoal.UtilAction); GOAP.util.Actions.Add(buildingAttack.UtilAction); GOAP.util.Actions.Add(explore.UtilAction); foreach (UtilityAction <GOAPGoal> goal in GOAP.util.Actions) { goal.ObjectReference.Initialise(this); } }
public void OnInit(GOAPAgent agent) { var entity = agent.EntityStateProvider as GroundEntity; if (entity == null) { //Since this is only an example and the only known provider is Entity, this is "safe" //If you can to use this as a base, you can easily modify throw new WTFException(); } var targetPos = entity.EntityState.GetValue(StateVariables.TargetLocation); //We are not doing pathfinding, let's just teleport the entity to the target location //Here is where you would set the pathfinding target on a real example tho :D entity.Teleport(targetPos); }
protected override void OnEnable() { base.OnEnable(); agent = target as GOAPAgent; goalsProperty = serializedObject.FindProperty("goals"); goalsReorderableList = new ReorderableList(serializedObject, goalsProperty, true, false, true, true); goalsReorderableList.headerHeight = 3; goalsReorderableList.elementHeight = 20; goalsReorderableList.drawElementCallback += (a, b, c, d) => DrawElement(a, b, c, d, goalsProperty); preStateProperty = serializedObject.FindProperty("preState"); preStateReorderableList = new ReorderableList(serializedObject, preStateProperty, true, false, true, true); preStateReorderableList.headerHeight = 3; preStateReorderableList.elementHeight = 20; preStateReorderableList.drawElementCallback += (a, b, c, d) => DrawElement(a, b, c, d, preStateProperty); }
public override bool RunAction(GOAPAgent agent) { agent.transform.LookAt(meleeItem); agent.transform.position += agent.transform.forward * 2; if (Vector3.Distance(agent.transform.position, meleeItem.transform.position) < 0.25f) { bool one = false; if (one == false) { meleeItem.transform.position = agent.transform.position + agent.transform.right * 1; meleeItem.transform.SetParent(agent.transform); one = true; return(true); } } return(true); }
private void Awake() { GOAP = new GOAPAgent(); SMActive = false; //GOAP.AvailableActions.AddRange(GetComponents<GOAPAction>()); foreach (GOAPAction action in GOAP.AvailableActions) { action.Agent = GOAP; } deposit.Initialise(this); pickup.Initialise(this); GOAP.util.Actions = new List <UtilityAction <GOAPGoal> > { deposit.UtilAction, pickup.UtilAction }; }
public SubmitFactoryJob(GOAPAgent agent, Game game, Thing thing, Movement movement, TypeOfThing factoryType, TypeOfThing input, TypeOfThing output, bool requiresAgentToMake) : base(agent, game, movement) { _thing = thing; _movement = movement; _factoryType = factoryType; _inventory = _thing.Inventory; _output = output; _input = input; _requiresAgentToMake = requiresAgentToMake; var inputConfig = Assets.GetThingConfig(input); var outputConfig = Assets.GetThingConfig(output); // Preconditions.Add(GOAPAction.Effect.HAS_THING + inputConfig.InventorySlot, _input); // Effects.Add(GOAPAction.Effect.HAS_THING + outputConfig.InventorySlot, _output); // Effects.Add(GOAPAction.Effect.IS_WORKING, true); }