public Vector3Int GetPosition() { List <Vector3Int> cratesWithItems = new List <Vector3Int>(); foreach (var item in ItemsToGet) { if (StorageFactory.ItemCrateLocations[Job.Owner].TryGetValue(item.Id, out var locations)) { foreach (var loc in locations) { if (!LastCratePosition.Contains(loc)) { cratesWithItems.AddIfUnique(loc); } } } } if (cratesWithItems.Count == 0) { WalkingTo = StorageType.Stockpile; return(StorageFactory.GetStockpilePosition(Job.Owner).Position); } else { WalkingTo = StorageType.Crate; CurrentCratePosition = JobSettings.OriginalPosition[Job].GetClosestPosition(cratesWithItems); return(CurrentCratePosition); } }
public virtual Vector3Int GetPosition() { if (WalkingTo == StorageType.Crate) { var locations = JobSettings.OriginalPosition[Job].SortClosestPositions(StorageFactory.CrateLocations[Job.Owner].Keys.ToList()); foreach (var location in locations) { if (!LastCratePosition.Contains(location)) { CurrentCratePosition = location; break; } } // we have checked every crate, they are all full. // put items in stockpile. if (LastCratePosition.Contains(CurrentCratePosition)) { WalkingTo = StorageType.Stockpile; CurrentCratePosition = StorageFactory.GetStockpilePosition(Job.Owner).Position; } } return(CurrentCratePosition); }
public Vector3Int GetPosition() { if (WalkingTo == StorageType.Crate) { foreach (var location in ClosestLocations) { if (!LastCratePosition.Contains(location) && !InProgress.Contains(location) && StorageFactory.CrateLocations[Job.Owner].TryGetValue(location, out var inv) && inv.IsAlmostFull && inv.StorageTypeLookup[StorageType.Stockpile].Count > 0) { CurrentCratePosition = location; InProgress.Add(location); break; } } // No new goal. go back to job pos. if (CurrentCratePosition == Vector3Int.invalidPos) { return(PorterJob.OriginalPosition); } return(CurrentCratePosition); } else { return(StorageFactory.GetStockpilePosition(Job.Owner).Position); } }
public Vector3Int GetPosition() { if (WalkingTo == StorageType.Crate) { // check for full crates. ensure they get serviced first foreach (var location in ClosestLocations) { if (!LastCratePosition.Contains(location) && !InProgress.Contains(location) && StorageFactory.CrateLocations[Job.Owner].TryGetValue(location, out var inv) && inv.IsAlmostFull && inv.StorageTypeLookup[StorageType.Stockpile].Count > 0) { CurrentCratePosition = location; InProgress.Add(location); break; } } // No new goal. just take anything if (CurrentCratePosition == Vector3Int.invalidPos) { foreach (var location in ClosestLocations) { if (!LastCratePosition.Contains(location) && !InProgress.Contains(location) && StorageFactory.CrateLocations[Job.Owner].TryGetValue(location, out var inv) && inv.StorageTypeLookup[StorageType.Stockpile].Count > 0) { CurrentCratePosition = location; InProgress.Add(location); break; } } } // everything is empty stand at job. if (CurrentCratePosition == Vector3Int.invalidPos) { return(PorterJob.OriginalPosition); } return(CurrentCratePosition); } else { return(StorageFactory.GetStockpilePosition(Job.Owner).Position); } }
public virtual Vector3Int GetPosition() { var stockpileLoc = StorageFactory.GetStockpilePosition(Job.Owner); if (WalkingTo == StorageType.Crate) { if (!StorageFactory.CrateLocations.ContainsKey(Job.Owner)) { StorageFactory.CrateLocations.Add(Job.Owner, new Dictionary <Vector3Int, CrateInventory>()); } if (!LastCratePosition.Contains(GoalStoring.ClosestCrate) && StorageFactory.CrateLocations[Job.Owner].ContainsKey(GoalStoring.ClosestCrate)) { CurrentCratePosition = GoalStoring.ClosestCrate; } else { var locations = GetCrateSearchPosition().SortClosestPositions(StorageFactory.CrateLocations[Job.Owner].Keys.ToList()); foreach (var location in locations) { if (!LastCratePosition.Contains(location)) { CurrentCratePosition = location; break; } } // we have checked every crate, they are all full. // put items in stockpile. if (LastCratePosition.Contains(CurrentCratePosition)) { WalkingTo = StorageType.Stockpile; if (stockpileLoc.Position == Vector3Int.invalidPos || stockpileLoc.Position == default(Vector3Int)) { CurrentCratePosition = Job.Owner.Banners.FirstOrDefault().Position; } else { CurrentCratePosition = stockpileLoc.Position; } } } } if (CurrentCratePosition == Vector3Int.invalidPos || CurrentCratePosition == default(Vector3Int)) { WalkingTo = StorageType.Stockpile; if (stockpileLoc.Position == Vector3Int.invalidPos || stockpileLoc.Position == default(Vector3Int)) { CurrentCratePosition = Job.Owner.Banners.FirstOrDefault().Position; } else { CurrentCratePosition = stockpileLoc.Position; } } return(CurrentCratePosition); }
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)); } } }
public Vector3Int GetPosition() { List <Vector3Int> cratesWithItems = new List <Vector3Int>(); var stockpileLoc = StorageFactory.GetStockpilePosition(Job.Owner); cratesWithItems.Add(stockpileLoc.Position); bool stockpileHasItems = true; foreach (var item in ItemsToGet) { if (!Job.Owner.Stockpile.Contains(item)) { stockpileHasItems = false; } if (StorageFactory.ItemCrateLocations.TryGetValue(Job.Owner, out var itemCrates) && itemCrates.TryGetValue(item.Id, out var locations)) { if (!LastCratePosition.Contains(ItemsForGoal.ClosestCrate) && locations.Contains(ItemsForGoal.ClosestCrate)) { cratesWithItems.Add(ItemsForGoal.ClosestCrate); } else { foreach (var loc in locations) { if (!LastCratePosition.Contains(loc)) { cratesWithItems.AddIfUnique(loc); } } } } } if (cratesWithItems.Count == 0 || cratesWithItems[0] == stockpileLoc.Position) { if (stockpileHasItems) { WalkingTo = StorageType.Stockpile; if (stockpileLoc.Position == Vector3Int.invalidPos || stockpileLoc.Position == default(Vector3Int)) { return(Job.Owner.Banners.FirstOrDefault().Position); } else { return(stockpileLoc.Position); } } else { PandaJobFactory.SetActiveGoal(Job, new StandAtJobGoal(Job, NextGoal, OriginalPosition, ItemsToGet.FirstOrDefault())); return(OriginalPosition); } } else { WalkingTo = StorageType.Crate; if (cratesWithItems.Count == 1) { CurrentCratePosition = cratesWithItems[0]; } else { var pos = OriginalPosition.GetClosestPosition(cratesWithItems); if (pos == stockpileLoc.Position) { WalkingTo = StorageType.Stockpile; return(stockpileLoc.Position); } else { CurrentCratePosition = pos; } } return(CurrentCratePosition); } }