/// <summary> /// Server-side only. Populate this ItemStorage using the specified populator. Destroys any existing /// items in this storage. /// </summary> /// <param name="populator"></param> /// <param name="context">context of the population</param> public void ServerPopulate(IItemStoragePopulator populator, PopulationContext context) { if (populator == null) { return; } if (!CustomNetworkManager.IsServer) { return; } if (!context.SpawnInfo.SpawnItems) { return; } populator.PopulateItemStorage(this, context); }
public override void PopulateSlot(ItemSlot toPopulate, PopulationContext context) { Logger.LogTraceFormat("Trying to auto-populate magazine for {0}", Category.Inventory, toPopulate); var gun = toPopulate.ItemStorage.GetComponent <Gun>(); if (gun == null) { Logger.LogErrorFormat("Cannot auto-populate magazine, itemstorage containing this slot does not have Gun component", Category.Inventory); return; } var ammoPrefab = Resources.Load("Rifles/Magazine_" + gun.AmmoType) as GameObject; Logger.LogTraceFormat("Populating with ammo prefab {0}", Category.Inventory, ammoPrefab?.name); GameObject m = Spawn.ServerPrefab(ammoPrefab).GameObject; Inventory.ServerAdd(m, toPopulate); }
public void PopulateItemStorage(ItemStorage toPopulate, PopulationContext context) { //if appending, start at first free slot index var start = 0; if (MergeMode == IndexedStoragePopulator.IndexedMergeMode.Append) { var freeSlot = toPopulate.GetNextFreeIndexedSlot(); if (freeSlot == null) { Logger.LogTraceFormat("Can't populate {0}, no more free slots.", Category.Inventory, toPopulate); return; } start = freeSlot.SlotIdentifier.SlotIndex; } for (var i = start; i < Contents.Count; i++) { // General protection against missing items if (Contents[i] == null) { continue; // Will skip the missing item } var slot = toPopulate.GetIndexedItemSlot(i); if (slot == null) { Logger.LogErrorFormat("Storage {0} does not have a slot with index {1}. Please ensure" + " the Contents don't exceed the number of slots in the ItemStorage.", Category.Inventory, toPopulate, i); return; } if (slot.Item != null && MergeMode == IndexedStoragePopulator.IndexedMergeMode.Overwrite) { Inventory.ServerDespawn(slot); } var spawned = Spawn.ServerPrefab(Contents[i]).GameObject; Inventory.ServerAdd(spawned, slot); } }
public override void PopulateItemStorage(ItemStorage ItemStorage, PopulationContext context) { //Uses the old contents for now foreach (var gameObject in DeprecatedContents) { var ItemSlot = ItemStorage.GetNextFreeIndexedSlot(); var spawn = Spawn.ServerPrefab(gameObject, PrePickRandom: true); Inventory.ServerAdd(spawn.GameObject, ItemSlot, IgnoreRestraints: true); } if (SlotContents.Count == 0) { return; } //Look through the specified slots, and tries to find it on the storage and populates if so, //and then attempts recursion foreach (var namedSlotPopulatorEntry in SlotContents) { ItemSlot ItemSlot; if (namedSlotPopulatorEntry.UesIndex) { ItemSlot = ItemStorage.GetIndexedItemSlot(namedSlotPopulatorEntry.IndexSlot); } else { ItemSlot = ItemStorage.GetNamedItemSlot(namedSlotPopulatorEntry.NamedSlot); } if (ItemSlot == null) { continue; } var spawn = Spawn.ServerPrefab(namedSlotPopulatorEntry.Prefab, PrePickRandom: true); Inventory.ServerAdd(spawn.GameObject, ItemSlot, namedSlotPopulatorEntry.ReplacementStrategy, true); Inventory.PopulateSubInventory(spawn.GameObject, namedSlotPopulatorEntry.namedSlotPopulatorEntrys); } }
public override void PopulateItemStorage(ItemStorage toPopulate, PopulationContext context) { Logger.LogTraceFormat("Populating item storage {0}", Category.Inventory, toPopulate.name); foreach (var entry in Entries) { var slot = toPopulate.GetNamedItemSlot(entry.NamedSlot); if (slot == null) { Logger.LogTraceFormat("Skipping populating slot {0} because it doesn't exist in this itemstorage {1}.", Category.Inventory, entry.NamedSlot, toPopulate.name); continue; } if (entry.SlotPopulator == null) { Logger.LogTraceFormat("Skipping populating slot {0} because Slot Populator was empty for this entry.", Category.Inventory, entry.NamedSlot); continue; } entry.SlotPopulator.PopulateSlot(slot, context); } }
public override void PopulateSlot(ItemSlot toPopulate, PopulationContext context) { SlotPopulator.PopulateSlot(toPopulate, context); var storage = toPopulate.Item.GetComponent <ItemStorage>(); if (storage == null) { Logger.LogErrorFormat("Item in slot {0} does not have an ItemStorage to populate, please ensure Item" + " creates an object with ItemStorage", Category.Inventory, toPopulate); return; } if (IndexedStoragePopulator == null) { Logger.LogTraceFormat("Not populating indexed storage in {0} because the indexed storage slot " + "populator is unspecified.", Category.Inventory, toPopulate); return; } IndexedStoragePopulator.PopulateItemStorage(storage, context); }
public override void PopulateItemStorage(ItemStorage toPopulate, PopulationContext context) { var occupation = PopulatorUtils.TryGetOccupation(context); if (occupation == null) { return; } if (context.SpawnInfo.SpawnItems == false) { return; } Logger.LogTraceFormat("Populating item storage using configured populator for occupation {0}", Category.EntitySpawn, occupation.JobType); occupation.InventoryPopulator.PopulateItemStorage(toPopulate, context); if (StandardPopulator != null) { Logger.LogTraceFormat("Populating item storage using standard populator", Category.EntitySpawn); StandardPopulator.PopulateItemStorage(toPopulate, context); } }
public override void PopulateItemStorage(ItemStorage toPopulate, PopulationContext context) { Logger.LogTraceFormat("Populating item storage {0}", Category.Inventory, toPopulate.name); foreach (var entry in Entries) { var slot = toPopulate.GetNamedItemSlot(entry.NamedSlot); if (slot == null) { Logger.LogTraceFormat("Skipping populating slot {0} because it doesn't exist in this itemstorage {1}.", Category.Inventory, entry.NamedSlot, toPopulate.name); continue; } if (entry.Prefab == null) { Logger.LogTraceFormat("Skipping populating slot {0} because Prefab Populator was empty for this entry.", Category.Inventory, entry.NamedSlot); continue; } if (entry.Prefab != null) { // making exception for jumpsuit/jumpskirt if (context.SpawnInfo.CharacterSettings.Clothing == Clothing.JumpSkirt && entry.NamedSlot == NamedSlot.uniform && skirtVariant != null) { var spawnskirt = Spawn.ServerPrefab(skirtVariant); Inventory.ServerAdd(spawnskirt.GameObject, slot); continue; } //exceoptions for backpack preference if (entry.NamedSlot == NamedSlot.back) { ///SpawnResult spawnbackpack; GameObject spawnThing; switch (context.SpawnInfo.CharacterSettings.Backpack) { case Backpack.Duffle: spawnThing = (duffelVariant != null) ? duffelVariant: entry.Prefab; break; case Backpack.Satchel: spawnThing = (satchelVariant != null) ? satchelVariant: entry.Prefab; break; default: spawnThing = entry.Prefab; break; } var spawnbackpack = Spawn.ServerPrefab(spawnThing); Inventory.ServerAdd(spawnbackpack.GameObject, slot); } var spawn = Spawn.ServerPrefab(entry.Prefab); Inventory.ServerAdd(spawn.GameObject, slot); } } }
public override void PopulateItemStorage(ItemStorage toPopulate, PopulationContext context) { Logger.LogError("This shouldn't be used but is required for inheritance", Category.EntitySpawn); }
/// <summary> /// Populate the specified slot. /// </summary> /// <param name="toPopulate">slot to populate</param> /// <param name="context">context the slot is being populated in</param> public abstract void PopulateSlot(ItemSlot toPopulate, PopulationContext context);
public PopulationController() { _populationContext = PopulationContext.SingleInstance; Logger = Program.Logger; }
/// <summary> /// Populate the specified storage. /// </summary> /// <param name="toPopulate">storage to populate</param> public abstract void PopulateItemStorage(ItemStorage toPopulate, PopulationContext context);