From db53ca7d5c47c48139d483ed567b4ee8cac62062 Mon Sep 17 00:00:00 2001 From: Yamato Date: Thu, 1 Aug 2024 16:09:24 +0200 Subject: [PATCH] More implementation --- EXILED/Exiled.API/Features/Items/Item.cs | 34 +++++++++++++++ EXILED/Exiled.API/Features/Pickups/Pickup.cs | 43 +++++++++++++++++++ .../Pickups/Projectiles/Projectile.cs | 43 ++++++++++++++++--- 3 files changed, 115 insertions(+), 5 deletions(-) diff --git a/EXILED/Exiled.API/Features/Items/Item.cs b/EXILED/Exiled.API/Features/Items/Item.cs index 28e48d2ef..cef0b5017 100644 --- a/EXILED/Exiled.API/Features/Items/Item.cs +++ b/EXILED/Exiled.API/Features/Items/Item.cs @@ -286,6 +286,40 @@ ItemType.KeycardGuard or ItemType.KeycardJanitor or ItemType.KeycardO5 or ItemTy _ => new Item(type), }; + /// + /// Creates a new with the proper inherited subclass. + /// + /// Based on the , the returned can be casted into a subclass to gain more control over the object. + ///
- Usable items (Adrenaline, Medkit, Painkillers, SCP-207, SCP-268, and SCP-500) should be casted to the class. + ///
- All valid ammo should be casted to the class. + ///
- All valid firearms (not including the Micro HID) should be casted to the class. + ///
- All valid keycards should be casted to the class. + ///
- All valid armor should be casted to the class. + ///
- Explosive grenades and SCP-018 should be casted to the class. + ///
- Flash grenades should be casted to the class. + ///
+ /// + ///
The following have their own respective classes: + ///
- Flashlights can be casted to . + ///
- Radios can be casted to . + ///
- The Micro HID can be casted to . + ///
- SCP-244 A and B variants can be casted to . + ///
- SCP-330 can be casted to . + ///
- SCP-2176 can be casted to the class. + ///
- SCP-1576 can be casted to the class. + ///
- Jailbird can be casted to the class. + ///
+ /// + /// Items that are not listed above do not have a subclass, and can only use the base class. + /// + ///
+ /// The of the item to create. + /// The who owns the item by default. + /// The specified type. + /// The created. This can be cast as a subclass. + public static Item Create(ItemType type, Player owner = null) + where T : Item => Create(type, owner) as T; + /// /// Gives this item to a . /// diff --git a/EXILED/Exiled.API/Features/Pickups/Pickup.cs b/EXILED/Exiled.API/Features/Pickups/Pickup.cs index 0f038c1ec..3f7373dee 100644 --- a/EXILED/Exiled.API/Features/Pickups/Pickup.cs +++ b/EXILED/Exiled.API/Features/Pickups/Pickup.cs @@ -496,6 +496,36 @@ public static IEnumerable Get(IEnumerable gameObjects) _ => new Pickup(type), }; + /// + /// Creates and returns a new with the proper inherited subclass. + /// + /// Based on the , the returned can be cast into a subclass to gain more control over the object. + ///
- All valid ammo should be cast to the class. + ///
- All valid firearms (not including the Micro HID) should be cast to the class. + ///
- All valid keycards should be cast to the class. + ///
- All valid armor should be cast to the class. + ///
- All grenades and throwables (not including SCP-018 and SCP-2176) should be cast to the class. + ///
+ /// + ///
The following have their own respective classes: + ///
- Radios can be cast to . + ///
- The Micro HID can be cast to . + ///
- SCP-244 A and B variants can be cast to . + ///
- SCP-330 can be cast to . + ///
- SCP-018 can be cast to . + ///
- SCP-2176 can be cast to . + ///
+ /// + /// Items that are not listed above do not have a subclass, and can only use the base class. + /// + ///
+ /// The of the pickup. + /// The specified type. + /// The created . + /// + public static Pickup Create(ItemType type) + where T : Pickup => Create(type) as T; + /// /// Creates and spawns a . /// @@ -507,6 +537,19 @@ public static IEnumerable Get(IEnumerable gameObjects) /// public static Pickup CreateAndSpawn(ItemType type, Vector3 position, Quaternion rotation, Player previousOwner = null) => Create(type).Spawn(position, rotation, previousOwner); + /// + /// Creates and spawns a . + /// + /// The of the pickup. + /// The position to spawn the at. + /// The rotation to spawn the . + /// An optional previous owner of the item. + /// The specified type. + /// The . See documentation of for more information on casting. + /// + public static Pickup CreateAndSpawn(ItemType type, Vector3 position, Quaternion rotation, Player previousOwner = null) + where T : Pickup => CreateAndSpawn(type, position, rotation, previousOwner) as T; + /// /// Spawns a . /// diff --git a/EXILED/Exiled.API/Features/Pickups/Projectiles/Projectile.cs b/EXILED/Exiled.API/Features/Pickups/Projectiles/Projectile.cs index cd18059bc..5406d6414 100644 --- a/EXILED/Exiled.API/Features/Pickups/Projectiles/Projectile.cs +++ b/EXILED/Exiled.API/Features/Pickups/Projectiles/Projectile.cs @@ -83,17 +83,37 @@ internal Projectile(ItemType type) /// Projectile that are not listed will cause an Exception. /// /// - /// The of the pickup. - /// The created . + /// The of the projectile. + /// The created . public static Projectile Create(ProjectileType projectiletype) => projectiletype switch { ProjectileType.Scp018 => new Scp018Projectile(), ProjectileType.Flashbang => new FlashbangProjectile(), ProjectileType.Scp2176 => new Scp2176Projectile(), ProjectileType.FragGrenade => new ExplosionGrenadeProjectile(ItemType.GrenadeHE), - _ => throw new System.Exception($"ProjectileType does not contain a valid value : {projectiletype}"), + _ => throw new Exception($"ProjectileType does not contain a valid value : {projectiletype}"), }; + /// + /// Creates and returns a new with the proper inherited subclass. + /// + /// Based on the , the returned can be casted into a subclass to gain more control over the object. + ///
The following have their own respective classes: + ///
- FragGrenade can be casted to . + ///
- Flashbang can be casted to . + ///
- Scp018 A and B variants can be casted to . + ///
- Scp2176 can be casted to . + ///
+ /// + /// Projectile that are not listed will cause an Exception. + /// + ///
+ /// The of the projectile. + /// The specified type. + /// The created . + public static Projectile Create(ProjectileType projectiletype) + where T : Projectile => Create(projectiletype) as T; + /// /// Spawns a . /// @@ -110,14 +130,27 @@ public static Projectile Spawn(Projectile pickup, Vector3 position, Quaternion r /// /// Creates and spawns a . /// - /// The of the pickup. + /// The of the projectile. /// The position to spawn the at. /// The rotation to spawn the . /// Whether the should be in active state after spawn. /// An optional previous owner of the item. - /// The . See documentation of for more information on casting. + /// The . See documentation of for more information on casting. public static Projectile CreateAndSpawn(ProjectileType type, Vector3 position, Quaternion rotation, bool shouldBeActive = true, Player previousOwner = null) => Create(type).Spawn(position, rotation, shouldBeActive, previousOwner); + /// + /// Creates and spawns a . + /// + /// The of the projectile. + /// The position to spawn the at. + /// The rotation to spawn the . + /// Whether the should be in active state after spawn. + /// An optional previous owner of the item. + /// The specified type. + /// The . See documentation of for more information on casting. + public static Projectile CreateAndSpawn(ProjectileType type, Vector3 position, Quaternion rotation, bool shouldBeActive = true, Player previousOwner = null) + where T : Projectile => CreateAndSpawn(type, position, rotation, shouldBeActive, previousOwner) as T; + /// /// Activates the current . ///