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); }
public bool HoldItem(IGrabbableItem item) { if (HeldItem != null) { return(false); } HeldItem = item; return(true); }
protected override bool Begin(IStateMachine <AIAttributes, object> stateMachine) { item = (IGrabbableItem)Agent.Memory.Get(AIAttributes.ItemToGather); if (item == null) { return(false); } isGathering = false; moveState = new MoveState(Agent, movement, item.Transform); stateMachine.Enqueue(moveState); stateMachine.OnComplete += OnTargetReached; return(true); }
public void SetGrabbingItem(IGrabbableItem item) { if (item == null) { gameObject.SetActive(false); } else { gameObject.SetActive(true); var itemName = item.Item.ItemName; if (string.IsNullOrEmpty(itemName)) { itemName = "アイテム"; } itemLabelText.text = itemName; useTooltip.SetActive(item.Item.gameObject.GetComponent <IUseItemTrigger>() != null); } }
public bool AddMaterial(IGrabbableItem item) { if (!(item is ResourceBase resource)) { return(false); } switch (resource.resourceType) { case ResourceTypes.None: return(false); case ResourceTypes.Iron: if (!NeedsIron) { return(false); } numIron++; break; case ResourceTypes.Coal: if (!NeedsCoal) { return(false); } numCoal++; break; case ResourceTypes.Copper: if (!NeedsCopper) { return(false); } numCopper++; break; default: Debug.LogError("invalid resource type: " + resource.resourceType); return(false); } Materials.Add(item); 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 bool RemoveMaterial(IGrabbableItem item) { if (!Materials.Contains(item)) { return(false); } if (!(item is ResourceBase resource)) { return(false); } switch (resource.resourceType) { case ResourceTypes.None: return(false); case ResourceTypes.Iron: numIron--; break; case ResourceTypes.Coal: numCoal--; break; case ResourceTypes.Copper: numCopper--; break; default: Debug.LogError("invalid resource type: " + resource.resourceType); return(false); } Materials.Remove(item); return(true); }
public bool TakeItem(IGrabbableItem item) { if (!(item is ResourceBase resource)) { return(false); } if (!resourceTypes.Contains(resource.resourceType)) { return(false); } Destroy(resource.gameObject); if (!resourceDict.ContainsKey(resource.resourceType)) { resourceDict.Add(resource.resourceType, 1); } else { resourceDict[resource.resourceType]++; } return(true); }
private void Hold(IGrabbableItem item) { HeldItem = item; item.Transform.gameObject.SetActive(false); }