Exemplo n.º 1
0
        private void UpdateLootContainer(Dictionary <string, LootContainerData> containerData, LootContainer container, Dictionary <string, LootSpawn> lootSpawns)
        {
            if (container == null)
            {
                return;
            }
            LootContainerData containerConfig;

            if (containerData == null || !containerData.TryGetValue(container.PrefabName, out containerConfig))
            {
                Puts("No container data found: {0}", container.PrefabName);
                return;
            }
            container.maxDefinitionsToSpawn    = containerConfig.MaxDefinitionsToSpawn;
            container.minSecondsBetweenRefresh = containerConfig.MinSecondsBetweenRefresh;
            container.maxSecondsBetweenRefresh = containerConfig.MaxSecondsBetweenRefresh;
            container.destroyOnEmpty           = containerConfig.DestroyOnEmpty;
            container.distributeFragments      = containerConfig.DistributeFragments;
            container.lootDefinition           = GetLootSpawn(containerConfig.LootDefinition, lootSpawns);
            container.inventorySlots           = containerConfig.InventorySlots;
            container.SpawnType = containerConfig.SpawnType;
            if (!container.gameObject.activeInHierarchy || container.inventory == null)
            {
                return;
            }
            container.inventory.capacity = containerConfig.InventorySlots;
            container.CancelInvoke("SpawnLoot");
            container.SpawnLoot();
        }
        private void ClearContainer(BaseEntity container)
        {
            if (container is LootContainer)
            {
                LootContainer lootContainer = container as LootContainer;
                lootContainer.minSecondsBetweenRefresh = -1;
                lootContainer.maxSecondsBetweenRefresh = 0;
                lootContainer.CancelInvoke(lootContainer.SpawnLoot);

                while (lootContainer.inventory.itemList.Count > 0)
                {
                    Item item = lootContainer.inventory.itemList[0];
                    item.RemoveFromContainer();
                    item.Remove(0f);
                }
            }
            else
            {
                StorageContainer storageContainer = container as StorageContainer;
                while (storageContainer.inventory.itemList.Count > 0)
                {
                    Item item = storageContainer.inventory.itemList[0];
                    item.RemoveFromContainer();
                    item.Remove(0f);
                }
            }
        }
Exemplo n.º 3
0
        private void UpdateLootContainer(Dictionary <string, LootContainerData> containerData, LootContainer container, Dictionary <string, LootSpawn> lootSpawns)
        {
            if (container == null)
            {
                return;
            }
            LootContainerData containerConfig;

            if (containerData == null || !containerData.TryGetValue(container.PrefabName, out containerConfig))
            {
                Puts("No container data found: {0}", container.PrefabName);
                return;
            }
            container.maxDefinitionsToSpawn    = containerConfig.MaxDefinitionsToSpawn;
            container.minSecondsBetweenRefresh = containerConfig.MinSecondsBetweenRefresh;
            container.maxSecondsBetweenRefresh = containerConfig.MaxSecondsBetweenRefresh;
            container.destroyOnEmpty           = containerConfig.DestroyOnEmpty;
            container.lootDefinition           = GetLootSpawn(containerConfig.LootDefinition, lootSpawns);
            container.inventorySlots           = containerConfig.InventorySlots;
            container.initialLootSpawn         = containerConfig.InitialLootSpawn;
            container.BlockPlayerItemInput     = containerConfig.BlockPlayerItemInput;
            container.scrapAmount    = containerConfig.ScrapAmount;
            container.SpawnType      = containerConfig.SpawnType;
            container.LootSpawnSlots = new LootContainer.LootSpawnSlot[containerConfig.LootSpawnSlots.Length];
            for (var i = 0; i < containerConfig.LootSpawnSlots.Length; i++)
            {
                var lootSpawnSlot = containerConfig.LootSpawnSlots[i];
                container.LootSpawnSlots[i] = new LootContainer.LootSpawnSlot
                {
                    definition    = GetLootSpawn(lootSpawnSlot.Definition, lootSpawns),
                    numberToSpawn = lootSpawnSlot.NumberToSpawn,
                    probability   = lootSpawnSlot.Probability
                };
            }
            if (container.inventory == null)
            {
                return;
            }
            container.CancelInvoke(new Action(container.SpawnLoot));
            container.inventory.capacity = containerConfig.InventorySlots;
            container.inventory.SetFlag(ItemContainer.Flag.NoItemInput, container.BlockPlayerItemInput);
            container.inventory.Clear();
            if (container.gameObject.activeInHierarchy && container.initialLootSpawn)
            {
                container.SpawnLoot();
            }
        }
Exemplo n.º 4
0
 // Suppresses automatic refreshes of a container
 private void SuppressRefresh(LootContainer container)
 {
     container.minSecondsBetweenRefresh = -1;
     container.maxSecondsBetweenRefresh = 0;
     container.CancelInvoke("SpawnLoot");
 }