Skip to content

Commit

Permalink
refactor: Modify Item::Create(ItemType) (#355)
Browse files Browse the repository at this point in the history
* Modify Item::Create(ItemType)

* Same for Pickup
  • Loading branch information
louis1706 authored Dec 30, 2024
1 parent 5b9c5b7 commit ff302f9
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 37 deletions.
48 changes: 27 additions & 21 deletions EXILED/Exiled.API/Features/Items/Item.cs
Original file line number Diff line number Diff line change
Expand Up @@ -293,28 +293,34 @@ public static T Get<T>(ushort serial)
/// <param name="type">The <see cref="ItemType"/> of the item to create.</param>
/// <param name="owner">The <see cref="Player"/> who owns the item by default.</param>
/// <returns>The <see cref="Item"/> created. This can be cast as a subclass.</returns>
public static Item Create(ItemType type, Player owner = null) => type switch
public static Item Create(ItemType type, Player owner = null) => type.GetTemplate() switch
{
ItemType.SCP268 => new Usable(type),
ItemType.Adrenaline or ItemType.Medkit or ItemType.Painkillers or ItemType.SCP500 or ItemType.SCP207 or ItemType.SCP1853 or ItemType.AntiSCP207 => new Consumable(type),
ItemType.SCP244a or ItemType.SCP244b => new Scp244(type),
ItemType.Ammo9x19 or ItemType.Ammo12gauge or ItemType.Ammo44cal or ItemType.Ammo556x45 or ItemType.Ammo762x39 => new Ammo(type),
ItemType.Flashlight or ItemType.Lantern => new Flashlight(type),
ItemType.Radio => new Radio(),
ItemType.MicroHID => new MicroHid(),
ItemType.GrenadeFlash => new FlashGrenade(owner),
ItemType.GrenadeHE => new ExplosiveGrenade(type, owner),
ItemType.SCP018 => new Scp018(type, owner),
ItemType.GunCrossvec or ItemType.GunLogicer or ItemType.GunRevolver or ItemType.GunShotgun or ItemType.GunAK or ItemType.GunCOM15 or ItemType.GunCOM18 or ItemType.GunCom45 or ItemType.GunE11SR or ItemType.GunFSP9 or ItemType.ParticleDisruptor or ItemType.GunA7 or ItemType.GunFRMG0 => new Firearm(type),
ItemType.KeycardGuard or ItemType.KeycardJanitor or ItemType.KeycardO5 or ItemType.KeycardScientist or ItemType.KeycardChaosInsurgency or ItemType.KeycardContainmentEngineer or ItemType.KeycardFacilityManager or ItemType.KeycardResearchCoordinator or ItemType.KeycardZoneManager or ItemType.KeycardMTFPrivate or ItemType.KeycardMTFOperative or
ItemType.KeycardMTFCaptain => new Keycard(type),
ItemType.ArmorLight or ItemType.ArmorCombat or ItemType.ArmorHeavy => new Armor(type),
ItemType.SCP330 => new Scp330(),
ItemType.SCP2176 => new Scp2176(owner),
ItemType.SCP1576 => new Scp1576(),
ItemType.SCP1344 => new Scp1344(),
ItemType.Jailbird => new Jailbird(),
_ => new Item(type),
InventorySystem.Items.Firearms.Firearm => new Firearm(type),
KeycardItem => new Keycard(type),
UsableItem usable => usable switch
{
Scp330Bag => new Scp330(),
Scp244Item => new Scp244(type),
Scp1576Item => new Scp1576(),
Scp1344Item => new Scp1344(),
BaseConsumable => new Consumable(type),
_ => new Usable(type),
},
RadioItem => new Radio(),
MicroHIDItem => new MicroHid(),
BodyArmor => new Armor(type),
AmmoItem => new Ammo(type),
ToggleableLightItemBase => new Flashlight(type),
JailbirdItem jailbird => new Jailbird(jailbird),
ThrowableItem throwable => throwable.Projectile switch
{
FlashbangGrenade => new FlashGrenade(owner),
ExplosionGrenade => new ExplosiveGrenade(type, owner),
Scp2176Projectile => new Scp2176(owner),
Scp018Projectile => new Scp018(type, owner),
_ => new Throwable(type, owner),
},
_ => new(type),
};

/// <summary>
Expand Down
43 changes: 27 additions & 16 deletions EXILED/Exiled.API/Features/Pickups/Pickup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -474,23 +474,34 @@ public static IEnumerable<T> Get<T>(IEnumerable<GameObject> gameObjects)
/// <param name="type">The <see cref="ItemType"/> of the pickup.</param>
/// <returns>The created <see cref="Pickup"/>.</returns>
/// <seealso cref="Projectile.Create(Enums.ProjectileType)"/>
public static Pickup Create(ItemType type) => type switch
public static Pickup Create(ItemType type) => type.GetTemplate().PickupDropModel switch
{
ItemType.SCP244a or ItemType.SCP244b => new Scp244Pickup(type),
ItemType.Ammo9x19 or ItemType.Ammo12gauge or ItemType.Ammo44cal or ItemType.Ammo556x45 or ItemType.Ammo762x39 => new AmmoPickup(type),
ItemType.Radio => new RadioPickup(),
ItemType.MicroHID => new MicroHIDPickup(),
ItemType.GrenadeFlash => new FlashGrenadePickup(),
ItemType.GrenadeHE => new ExplosiveGrenadePickup(),
ItemType.GunCrossvec or ItemType.GunLogicer or ItemType.GunRevolver or ItemType.GunShotgun or ItemType.GunAK or ItemType.GunCOM15 or ItemType.GunCOM18 or ItemType.GunE11SR or ItemType.GunFSP9 or ItemType.ParticleDisruptor or ItemType.GunA7 or ItemType.GunFRMG0 => new FirearmPickup(type),
ItemType.KeycardGuard or ItemType.KeycardJanitor or ItemType.KeycardO5 or ItemType.KeycardScientist or ItemType.KeycardContainmentEngineer or ItemType.KeycardFacilityManager or ItemType.KeycardResearchCoordinator or ItemType.KeycardZoneManager or ItemType.KeycardMTFCaptain or ItemType.KeycardMTFOperative or ItemType.KeycardMTFPrivate => new KeycardPickup(type),
ItemType.ArmorLight or ItemType.ArmorCombat or ItemType.ArmorHeavy => new BodyArmorPickup(type),
ItemType.SCP330 => new Scp330Pickup(),
ItemType.SCP500 or ItemType.SCP268 or ItemType.SCP207 or ItemType.SCP1853 or ItemType.Painkillers or ItemType.Medkit or ItemType.Adrenaline or ItemType.AntiSCP207 => new UsablePickup(type),
ItemType.Jailbird => new JailbirdPickup(),
ItemType.SCP1576 => new Scp1576Pickup(),
ItemType.SCP2176 => new Projectiles.Scp2176Projectile(),
ItemType.SCP018 => new Projectiles.Scp018Projectile(),
Scp244DeployablePickup => new Scp244Pickup(type),
BaseAmmoPickup => new AmmoPickup(type),
BaseRadioPickup => new RadioPickup(),
BaseMicroHIDPickup => new MicroHIDPickup(),
TimedGrenadePickup timeGrenade => timeGrenade.NetworkInfo.ItemId switch
{
ItemType.GrenadeHE => new ExplosiveGrenadePickup(),
ItemType.GrenadeFlash => new FlashGrenadePickup(),
_ => new GrenadePickup(type),
},
BaseFirearmPickup => new FirearmPickup(type),
BaseKeycardPickup => new KeycardPickup(type),
BaseBodyArmorPickup => new BodyArmorPickup(type),
BaseScp330Pickup => new Scp330Pickup(),
BaseScp1576Pickup => new Scp1576Pickup(),
BaseJailbirdPickup => new JailbirdPickup(),
ThrownProjectile thrownProjectile => thrownProjectile switch
{
BaseScp018Projectile => new Projectiles.Scp018Projectile(),
ExplosionGrenade explosionGrenade => new ExplosionGrenadeProjectile(explosionGrenade),
FlashbangGrenade => new FlashbangProjectile(),
BaseScp2176Projectile => new Projectiles.Scp2176Projectile(),
EffectGrenade => new EffectGrenadeProjectile(type),
TimeGrenade => new TimeGrenadeProjectile(type),
_ => new Projectile(thrownProjectile),
},
_ => new Pickup(type),
};

Expand Down

0 comments on commit ff302f9

Please sign in to comment.