public BuildingBase FindClosestBuilding <T>(BuildingTypes type, Vector3 pos, Predicate <T> predicate) where T : BuildingBase { var distance = float.MaxValue; BuildingBase building = null; foreach (var b in GameManager.Objects.Buildings) { if (b.buildingType != type) { continue; } if (!predicate.Invoke((T)b)) { continue; } var dist = Vector3.Distance(pos, b.Transform.position); if (!(dist < distance)) { continue; } distance = dist; building = b; } return(building); }
protected override bool Begin(IStateMachine <AIAttributes, object> stateMachine) { item = (IGrabbableItem)Agent.Memory.Get(AIAttributes.HeldItem); if (item == null) { return(false); } if (!(item is ResourceBase resource)) { return(false); } building = GetCraftingPad(resource); if (building == null || !(building is ICraftingStation s)) { return(false); } station = s; var moveState = new MoveState(Agent, movement, building.Transform); stateMachine.Enqueue(moveState); stateMachine.OnComplete += OnTargetReached; return(true); }
protected override bool Begin(IStateMachine <AIAttributes, object> stateMachine) { pad = (CraftingPad)Agent.Memory.Get(AIAttributes.TargetBuilding); if (pad == null || !(pad is BuildingBase b)) { return(false); } building = b; var moveState = new MoveState(Agent, movement, building.Transform); stateMachine.Enqueue(moveState); stateMachine.OnComplete += OnTargetReached; return(true); }
protected override bool Begin(IStateMachine <AIAttributes, object> stateMachine) { item = (IGrabbableItem)Agent.Memory.Get(AIAttributes.HeldItem); if (item == null) { return(false); } var type = BuildingTypes.None; if (item is ResourceBase) { type = BuildingTypes.ResourceDepot; } if (type == BuildingTypes.None) { return(false); } var buildingSensor = Agent.Sensors.Get <BuildingSensor>(); if (buildingSensor == null) { return(false); } building = buildingSensor.FindClosestBuilding(type, Agent.Owner.transform.position); if (building == null || !(building is IStorage s)) { return(false); } storage = s; var target = building.pathingPoint == null ? building.Transform : building.pathingPoint; var moveState = new MoveState(Agent, movement, target); stateMachine.Enqueue(moveState); stateMachine.OnComplete += OnTargetReached; return(true); }
public BuildingBase FindClosestBuilding(BuildingTypes type, Vector3 pos) { var distance = float.MaxValue; BuildingBase building = null; foreach (var b in GameManager.Objects.Buildings) { if (b.buildingType != type) { continue; } var dist = Vector3.Distance(pos, b.Transform.position); if (!(dist < distance)) { continue; } distance = dist; building = b; } return(building); }
public void RemoveBuilding(BuildingBase building) { Buildings.Remove(building); }
public void AddBuilding(BuildingBase building) { Buildings.Add(building); }