Esempio n. 1
0
        public void OnLoadingColony(Colony colony, JSONNode data)
        {
            if (data.TryGetAs <JSONNode>(nameof(CrateLocations), out var crateJson))
            {
                if (!CrateLocations.ContainsKey(colony))
                {
                    CrateLocations.Add(colony, new Dictionary <Vector3Int, CrateInventory>());
                }

                foreach (var loc in crateJson.LoopObject())
                {
                    CrateLocations[colony][Vector3Int.Parse(loc.Key)] = new CrateInventory(loc.Value, colony);
                }
            }

            if (data.TryGetAs <JSONNode>(nameof(ItemCrateLocations), out var icl))
            {
                if (!ItemCrateLocations.ContainsKey(colony))
                {
                    ItemCrateLocations.Add(colony, new Dictionary <ushort, List <Vector3Int> >());
                }

                foreach (var kvp in icl.LoopObject())
                {
                    List <Vector3Int> locs = new List <Vector3Int>();

                    foreach (var l in kvp.Value.LoopArray())
                    {
                        locs.Add((Vector3Int)l);
                    }

                    ItemCrateLocations[colony][Convert.ToUInt16(kvp.Key)] = locs;
                }
            }
        }
Esempio n. 2
0
        public void AfterWorldLoad()
        {
            _worldLoaded = true;

            foreach (var colony in ServerManager.ColonyTracker.ColoniesByID.Values)
            {
                if (!CrateLocations.ContainsKey(colony))
                {
                    CrateLocations.Add(colony, new Dictionary <Vector3Int, CrateInventory>());
                }

                if (!ItemCrateLocations.ContainsKey(colony))
                {
                    ItemCrateLocations.Add(colony, new Dictionary <ushort, List <Vector3Int> >());
                }

                RecalcMax(colony);
            }
        }
Esempio n. 3
0
        public void OnChangedBlock(ModLoader.OnTryChangeBlockData tryChangeBlockData)
        {
            var colony = tryChangeBlockData?.RequestOrigin.AsPlayer?.ActiveColony;

            if (colony == null)
            {
                colony = tryChangeBlockData.RequestOrigin.AsColony;
            }

            if (colony != null &&
                (StorageBlockTypes.ContainsKey(tryChangeBlockData.TypeNew.Name) ||
                 StorageBlockTypes.ContainsKey(tryChangeBlockData.TypeOld.Name)))
            {
                RecalcStockpileMaxSize(colony);
                return;
            }

            if (colony != null && CrateTypes.TryGetValue(tryChangeBlockData.TypeOld.Name, out var oldCrate))
            {
                /// empty the crate. TODO may want to do something other than magically teleporting.
                if (CrateLocations[colony].TryGetValue(tryChangeBlockData.Position, out var inv))
                {
                    StoreItems(colony, inv.GetAllItems().Values);
                }

                CrateLocations[colony].Remove(tryChangeBlockData.Position);

                foreach (var item in ItemCrateLocations[colony])
                {
                    item.Value.Remove(tryChangeBlockData.Position);
                }
            }
            else if (CrateTypes.TryGetValue(tryChangeBlockData.TypeNew.Name, out var newCrate))
            {
                if (!CrateLocations.ContainsKey(colony))
                {
                    CrateLocations.Add(colony, new Dictionary <Vector3Int, CrateInventory>());
                }

                CrateLocations[colony][tryChangeBlockData.Position] = new CrateInventory(newCrate, tryChangeBlockData.Position, colony);
            }
        }
Esempio n. 4
0
        public void AfterWorldLoad()
        {
            _worldLoaded = true;

            if (ServerManager.BlockEntityCallbacks.TryGetAutoLoadedInstance <CivCrateTracker>(out var crateTracker))
            {
                CrateTracker = crateTracker;
            }

            foreach (var colony in ServerManager.ColonyTracker.ColoniesByID.Values.Where(c => c != null))
            {
                if (!CrateLocations.ContainsKey(colony))
                {
                    CrateLocations.Add(colony, new Dictionary <Vector3Int, CrateInventory>());
                }

                if (!ItemCrateLocations.ContainsKey(colony))
                {
                    ItemCrateLocations.Add(colony, new Dictionary <ushort, List <Vector3Int> >());
                }

                RecalcStockpileMaxSize(colony);
            }
        }