Inventory slot enumerator rejig (#21788)
This commit is contained in:
@@ -40,6 +40,16 @@ namespace Content.Server.Zombies
|
||||
[Dependency] private readonly MobStateSystem _mobState = default!;
|
||||
[Dependency] private readonly SharedPopupSystem _popup = default!;
|
||||
|
||||
public const SlotFlags ProtectiveSlots =
|
||||
SlotFlags.FEET |
|
||||
SlotFlags.HEAD |
|
||||
SlotFlags.EYES |
|
||||
SlotFlags.GLOVES |
|
||||
SlotFlags.MASK |
|
||||
SlotFlags.NECK |
|
||||
SlotFlags.INNERCLOTHING |
|
||||
SlotFlags.OUTERCLOTHING;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
@@ -164,33 +174,27 @@ namespace Content.Server.Zombies
|
||||
|
||||
private float GetZombieInfectionChance(EntityUid uid, ZombieComponent component)
|
||||
{
|
||||
var baseChance = component.MaxZombieInfectionChance;
|
||||
var max = component.MaxZombieInfectionChance;
|
||||
|
||||
if (!TryComp<InventoryComponent>(uid, out var inventoryComponent))
|
||||
return baseChance;
|
||||
|
||||
var enumerator =
|
||||
new InventorySystem.ContainerSlotEnumerator(uid, inventoryComponent.TemplateId, _protoManager, _inv,
|
||||
SlotFlags.FEET |
|
||||
SlotFlags.HEAD |
|
||||
SlotFlags.EYES |
|
||||
SlotFlags.GLOVES |
|
||||
SlotFlags.MASK |
|
||||
SlotFlags.NECK |
|
||||
SlotFlags.INNERCLOTHING |
|
||||
SlotFlags.OUTERCLOTHING);
|
||||
if (!_inventory.TryGetContainerSlotEnumerator(uid, out var enumerator, ProtectiveSlots))
|
||||
return max;
|
||||
|
||||
var items = 0f;
|
||||
var total = 0f;
|
||||
while (enumerator.MoveNext(out var con))
|
||||
{
|
||||
total++;
|
||||
|
||||
if (con.ContainedEntity != null)
|
||||
items++;
|
||||
}
|
||||
|
||||
var max = component.MaxZombieInfectionChance;
|
||||
if (total == 0)
|
||||
return max;
|
||||
|
||||
// Everyone knows that when it comes to zombies, socks & sandals provide just as much protection as an
|
||||
// armored vest. Maybe these should be weighted per-item. I.e. some kind of coverage/protection component.
|
||||
// Or at the very least different weights per slot.
|
||||
|
||||
var min = component.MinZombieInfectionChance;
|
||||
//gets a value between the max and min based on how many items the entity is wearing
|
||||
var chance = (max-min) * ((total - items)/total) + min;
|
||||
|
||||
Reference in New Issue
Block a user