public void PerformGoal(ref NPC.NPCBase.NPCState state) { StoredItem[] remaining = new StoredItem[0]; state.JobIsDone = true; state.SetCooldown(_waitTime); if (remaining != null && remaining.Length != 0) { state.SetIndicator(new Shared.IndicatorState(_waitTime, remaining.FirstOrDefault().Id.Name, true, false)); } if (WalkingTo == StorageType.Crate) { if (StorageFactory.CrateLocations[Job.Owner].TryGetValue(CurrentCratePosition, out CrateInventory ci)) { remaining = ci.TryTake(ItemsToGet).Values.ToArray(); } } else { remaining = StorageFactory.TryTakeItemsReturnRemaining(Job.Owner, ItemsToGet); LastCratePosition.Clear(); WalkingTo = StorageType.Crate; } if (remaining.Length != 0) { ItemsToGet = remaining; LastCratePosition.Add(CurrentCratePosition); } else { JobSettings.SetGoal(Job, NextGoal, ref state); } }
public void PerformGoal(ref NPCBase.NPCState state) { state.JobIsDone = true; state.SetCooldown(1); if (WalkingTo == StorageType.Crate) { if (StorageFactory.CrateLocations.TryGetValue(Job.Owner, out var locs)) { if (locs.TryGetValue(CurrentCratePosition, out var crate)) { ToStockpike = crate.GetAllItems(StorageType.Stockpile).Values.ToArray(); ShowIndicator(ref state); crate.TryTake(ToStockpike); WalkingTo = StorageType.Stockpile; } else { LastCratePosition.Clear(); } } else { CivLogger.Log(ChatColor.red, "Crate locations does not contain colony id {0}", Job.Owner.ColonyID); } } else { ShowIndicator(ref state); StorageFactory.StoreItems(Job.Owner, ToStockpike); ToStockpike = null; WalkingTo = StorageType.Crate; InProgress.Remove(CurrentCratePosition); CurrentCratePosition = Vector3Int.invalidPos; GetPosition(); } }
public void PerformGoal(ref NPCBase.NPCState state) { state.JobIsDone = true; if (WalkingTo == StorageType.Stockpile) { if (CrateFull) { Job.NPC.Inventory.Dump(Job.Owner.Stockpile); CrateFull = false; } WalkingTo = StorageType.Crate; var nexPos = Vector3Int.invalidPos; foreach (var location in ClosestLocations) { if (!LastCratePosition.Contains(location) && !InProgress.Contains(location) && StorageFactory.CrateLocations[Job.Owner].TryGetValue(location, out var inv) && !inv.IsAlmostFull && ItemsNeeded.TryGetValue(location, out var itemsNeeded)) { nexPos = location; InProgress.Add(location); var addToInv = StorageFactory.TryTakeItems(Job.Owner, itemsNeeded.Values); var leftovers = new List <StoredItem>(); foreach (var item in addToInv) { if (Job.NPC.Inventory.Full) { leftovers.Add(item); } else { Job.NPC.Inventory.Add(item); } } StorageFactory.StoreItems(Job.Owner, leftovers); break; } } CurrentCratePosition = nexPos; if (nexPos == Vector3Int.invalidPos) { LastCratePosition.Clear(); state.SetCooldown(5); } else { state.SetCooldown(1); state.SetIndicator(new Shared.IndicatorState(5, ItemId.GetItemId(StockpileBlock.Name).Id)); } } else { if (StorageFactory.CrateLocations[Job.Owner].TryGetValue(CurrentCratePosition, out var crateInventory)) { WalkingTo = StorageType.Stockpile; var leftovers = crateInventory.TryAdd(Job.NPC.Inventory.Inventory.Select(ii => new StoredItem(ii, int.MaxValue, StorageType.Crate)).ToArray()); state.SetCooldown(1); state.SetIndicator(new Shared.IndicatorState(5, ColonyBuiltIn.ItemTypes.CRATE.Id)); if (leftovers.Count > 0) { Job.NPC.Inventory.Inventory.Clear(); foreach (var item in leftovers) { Job.NPC.Inventory.Add(item); } CrateFull = true; } } else { CrateFull = true; state.SetCooldown(1); state.SetIndicator(new Shared.IndicatorState(5, ColonyBuiltIn.ItemTypes.CRATE.Id, false, false)); } } }