Exemple #1
0
        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 virtual void PerformGoal(ref NPC.NPCBase.NPCState state)
        {
            StoredItem[] remaining = new StoredItem[0];
            state.SetCooldown(1);

            if (ItemsToStore != null && ItemsToStore.Length != 0)
            {
                state.SetIndicator(new Shared.IndicatorState(1, ItemsToStore.FirstOrDefault().Id.Name));
            }

            if (WalkingTo == StorageType.Crate)
            {
                if (StorageFactory.CrateLocations[Job.Owner].TryGetValue(CurrentCratePosition, out CrateInventory ci))
                {
                    remaining = ci.TryAdd(ItemsToStore).ToArray();
                }
            }
            else
            {
                StorageFactory.StoreItems(Job.Owner, ItemsToStore);
            }

            if (remaining.Length > 0)
            {
                ItemsToStore = remaining;
                LastCratePosition.Add(CurrentCratePosition);
            }
            else
            {
                PandaJobFactory.SetActiveGoal(Job, NextGoal, ref state);
            }
        }
Exemple #3
0
        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);
            }
        }
Exemple #4
0
        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 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 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));
                }
            }
        }
Exemple #10
0
        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);
            }
        }