Skip to content
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
345f91c
init
IRacle1 Dec 1, 2024
d0482d2
xd
IRacle1 Dec 1, 2024
4fc2ebb
let him cook
IRacle1 Dec 1, 2024
35fe771
uuu
IRacle1 Dec 1, 2024
9dfa8ec
Merge branch 'scpsl14' into firearmhard
Misaka-ZeroTwo Dec 2, 2024
b79cb11
yep
IRacle1 Dec 3, 2024
c384ed9
oh
IRacle1 Dec 3, 2024
6bf5c81
ammo drain
IRacle1 Dec 6, 2024
e43047a
OnAdded fix
IRacle1 Dec 8, 2024
a651eda
Reload
IRacle1 Dec 8, 2024
6c77a89
IsDistributed
IRacle1 Dec 8, 2024
7a660a3
reviewuwu
IRacle1 Dec 9, 2024
e3cf0dc
Merge branch 'scpsl14' into firearmhard
IRacle1 Dec 9, 2024
cd3d4d5
-_-
IRacle1 Dec 9, 2024
76d36c7
build
IRacle1 Dec 9, 2024
ad20e18
reimplement props
IRacle1 Dec 9, 2024
db01c37
😥
IRacle1 Dec 9, 2024
13fe7f5
😊
IRacle1 Dec 9, 2024
8503fc5
ah
IRacle1 Dec 9, 2024
a5da95d
docs
IRacle1 Dec 9, 2024
16eceb7
docs
IRacle1 Dec 9, 2024
89151a8
Merge branch 'scpsl14' into firearmhard
IRacle1 Dec 14, 2024
c8beea0
fix: some server crash
IRacle1 Dec 16, 2024
5431c57
refactor: docs
IRacle1 Dec 16, 2024
95533f6
fix/feat: syncing `MaxAmmo`
IRacle1 Dec 16, 2024
c68eb7e
ammo drain sync
IRacle1 Dec 16, 2024
9c48040
refactor: strange modules interaction
IRacle1 Dec 16, 2024
d50b888
docs: its automatic, trust me
IRacle1 Dec 16, 2024
770d8b3
fix: revolver and maxammo
IRacle1 Dec 16, 2024
9c3bd16
fix: ammodrain for automatic firearms
IRacle1 Dec 16, 2024
2d1b9c5
Update EXILED/Exiled.API/Features/Items/Firearm.cs
IRacle1 Dec 22, 2024
bb1a0d8
Update EXILED/Exiled.API/Features/Items/FirearmModules/Barrel/Automat…
IRacle1 Dec 22, 2024
64fc8e8
Update EXILED/Exiled.API/Features/Items/FirearmModules/Primary/Normal…
IRacle1 Dec 22, 2024
619629f
Update EXILED/Exiled.API/Features/Items/FirearmModules/Primary/Normal…
IRacle1 Dec 22, 2024
10596b6
Update EXILED/Exiled.API/Features/Items/FirearmModules/Primary/Normal…
IRacle1 Dec 22, 2024
7623aa2
all yamato requests
IRacle1 Dec 22, 2024
ad0aaa5
Merge branch 'scpsl14' into firearmhard
IRacle1 Dec 22, 2024
e82b890
fix
IRacle1 Dec 22, 2024
a3263ae
Merge branch 'dev' into firearmhard
BoltonDev Dec 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions EXILED/Exiled.API/Enums/RevolverChamberState.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// -----------------------------------------------------------------------
// <copyright file="RevolverChamberState.cs" company="ExMod Team">
// Copyright (c) ExMod Team. All rights reserved.
// Licensed under the CC BY-SA 3.0 license.
// </copyright>
// -----------------------------------------------------------------------

namespace Exiled.API.Enums
{
using Exiled.API.Features.Items.FirearmModules.Primary;

/// <summary>
/// States for chamber in revolver cylindric magazine.
/// </summary>
/// <seealso cref="CylinderMagazine"/>
public enum RevolverChamberState
{
/// <summary>
/// State for empty chamber.
/// </summary>
Empty,

/// <summary>
/// State for chamber with a bullet.
/// </summary>
Live,

/// <summary>
/// State for discharged chamber.
/// </summary>
Discharged,
}
}
128 changes: 106 additions & 22 deletions EXILED/Exiled.API/Features/Items/Firearm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ namespace Exiled.API.Features.Items

using CameraShaking;
using Enums;

using Exiled.API.Features.Items.FirearmModules;
using Exiled.API.Features.Items.FirearmModules.Barrel;
using Exiled.API.Features.Items.FirearmModules.Primary;
using Exiled.API.Features.Pickups;
using Exiled.API.Interfaces;
using Exiled.API.Structs;
Expand Down Expand Up @@ -55,6 +59,20 @@ public Firearm(BaseFirearm itemBase)
: base(itemBase)
{
Base = itemBase;

foreach (ModuleBase module in Base.Modules)
{
if (module is IPrimaryAmmoContainerModule primaryAmmoModule)
{
PrimaryMagazine ??= (PrimaryMagazine)Magazine.Get(primaryAmmoModule);
continue;
}

if (module is IAmmoContainerModule ammoModule)
{
BarrelMagazine ??= (BarrelMagazine)Magazine.Get(ammoModule);
}
}
}

/// <summary>
Expand Down Expand Up @@ -105,24 +123,97 @@ public static IReadOnlyDictionary<Player, Dictionary<FirearmType, AttachmentIden
public new BaseFirearm Base { get; }

/// <summary>
/// Gets or sets the amount of ammo in the firearm.
/// Gets a primaty magazine for current firearm.
/// </summary>
public PrimaryMagazine PrimaryMagazine { get; }

/// <summary>
/// Gets a barrel magazine for current firearm.
/// </summary>
/// <remarks>
/// <see langword="null"/> for Revolver and ParticleDisruptor.
/// </remarks>
public BarrelMagazine BarrelMagazine { get; }

/// <summary>
/// Gets or sets the amount of ammo in the firearm magazine.
/// </summary>
public int MagazineAmmo
{
get => PrimaryMagazine.Ammo;
set => PrimaryMagazine.Ammo = value;
}

/// <summary>
/// Gets or sets the amount of ammo in the firearm barrel.
/// </summary>
public int Ammo
/// <remarks>
/// not working for Revolver and ParticleDisruptor.
/// </remarks>
public int BarrelAmmo
{
get => (Base.Modules[Array.IndexOf(Base.Modules, typeof(MagazineModule))] as MagazineModule).AmmoStored;
set => (Base.Modules[Array.IndexOf(Base.Modules, typeof(MagazineModule))] as MagazineModule).AmmoStored = value;
get
{
return BarrelMagazine?.Ammo ?? 0;
}

set
{
if (BarrelMagazine != null)
BarrelMagazine.Ammo = value;
}
}

/// <summary>
/// Gets the total amount of ammo in the firearm.
/// </summary>
public int TotalAmmo =>
Base.GetTotalStoredAmmo();
Comment thread
IRacle1 marked this conversation as resolved.
Outdated

/// <summary>
/// Gets or sets the max ammo for this firearm.
/// </summary>
/// <remarks>Disruptor can't be used for MaxAmmo.</remarks>
public int MaxAmmo
public int MaxMagazineAmmo
{
get => PrimaryMagazine.MaxAmmo;
set => PrimaryMagazine.MaxAmmo = value;
}

/// <summary>
/// Gets or sets the amount of max ammo in the firearm barrel.
/// </summary>
/// <remarks>
/// not working for Revolver and ParticleDisruptor.
/// </remarks>
public int MaxBarrelAmmo
{
get => (Base.Modules[Array.IndexOf(Base.Modules, typeof(MagazineModule))] as MagazineModule).AmmoMax;
set => (Base.Modules[Array.IndexOf(Base.Modules, typeof(MagazineModule))] as MagazineModule)._defaultCapacity = value; // Synced?
get
{
return BarrelMagazine?.MaxAmmo ?? 0;
}
Comment thread
IRacle1 marked this conversation as resolved.
Outdated

set
{
if (BarrelMagazine != null)
BarrelMagazine.MaxAmmo = value;
}
}

/// <summary>
/// Gets the total amount of ammo in the firearm.
/// </summary>
public int TotalMaxAmmo =>
Base.GetTotalMaxAmmo();
Comment thread
IRacle1 marked this conversation as resolved.
Outdated

/// <summary>
/// Gets or sets a ammo drain per shoot.
/// </summary>
/// <remarks>
/// Always <see langword="1"/> by default.
/// Applied on a high layer nether basegame ammo controllers.
/// </remarks>
public int AmmoDrain { get; set; } = 2;
Comment thread
IRacle1 marked this conversation as resolved.
Outdated

/// <summary>
/// Gets the <see cref="Enums.FirearmType"/> of the firearm.
/// </summary>
Expand Down Expand Up @@ -602,20 +693,10 @@ public void ClearPreferences()
/// <param name="emptyMagazine">Whether empty magazine should be loaded.</param>
public void Reload(bool emptyMagazine = false)
{
MagazineModule magazineModule = Base.Modules.OfType<MagazineModule>().FirstOrDefault();

if (magazineModule == null)
return;

magazineModule.ServerRemoveMagazine();

Timing.CallDelayed(0.1f, () =>
if (Base.TryGetModule(out AnimatorReloaderModuleBase module))
{
if (emptyMagazine)
magazineModule.ServerInsertEmptyMagazine();
else
magazineModule.ServerInsertMagazine();
});
module.StartReloading();
}
}

/// <summary>
Expand All @@ -626,7 +707,6 @@ public override Item Clone()
{
Firearm cloneableItem = new(Type)
{
Ammo = Ammo,
};

// TODO Not finish
Expand All @@ -651,6 +731,10 @@ internal override void ChangeOwner(Player oldOwner, Player newOwner)
{
Base.Owner = newOwner.ReferenceHub;
Base._footprintCacheSet = false;
foreach (ModuleBase module in Base.Modules)
{
module.OnAdded();
}
}

/// <inheritdoc/>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
// -----------------------------------------------------------------------
// <copyright file="AutomaticBarrelMagazine.cs" company="ExMod Team">
// Copyright (c) ExMod Team. All rights reserved.
// Licensed under the CC BY-SA 3.0 license.
// </copyright>
// -----------------------------------------------------------------------

namespace Exiled.API.Features.Items.FirearmModules.Barrel
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using InventorySystem.Items.Firearms.Modules;

using UnityEngine;

/// <summary>
/// Basic realization of <see cref="AutomaticActionModule"/> barrel.
/// </summary>
public class AutomaticBarrelMagazine : BarrelMagazine
{
/// <summary>
/// Initializes a new instance of the <see cref="AutomaticBarrelMagazine"/> class.
/// </summary>
/// <param name="automaticModule">Target <see cref="AutomaticActionModule"/>.</param>
public AutomaticBarrelMagazine(AutomaticActionModule automaticModule)
: base(automaticModule)
{
AutomaticBarrel = automaticModule;
Firearm = (Firearm)Item.Get(AutomaticBarrel.Firearm);
}

/// <summary>
/// Gets an original <see cref="IAmmoContainerModule"/>.
/// </summary>
public AutomaticActionModule AutomaticBarrel { get; }

/// <inheritdoc/>
public override Firearm Firearm { get; }

/// <inheritdoc/>
public override int Ammo
{
get
{
return AutomaticBarrel.AmmoStored;
}

set
{
AutomaticBarrel.AmmoStored = Mathf.Max(value, 0);

Resync();
}
}

/// <inheritdoc/>
/// <remarks>
/// Will be ranged between <see langword="0"/> and <see langword="16"/> due basegame logic.
/// </remarks>
public override int MaxAmmo
{
get
{
return AutomaticBarrel.ChamberSize;
}

set
{
AutomaticBarrel.ChamberSize = Mathf.Clamp(value, 0, 16);
}
Comment thread
IRacle1 marked this conversation as resolved.
Outdated
}

/// <inheritdoc/>
public override bool IsCocked
{
get
{
return AutomaticBarrel.Cocked;
}

set
{
AutomaticBarrel.Cocked = value;
Resync();
}
}

/// <summary>
/// Gets a value indicating whether barrel magazine has open bolt or not.
/// </summary>
public bool IsOpenBolted =>
AutomaticBarrel.OpenBolt;

/// <summary>
/// Gets or sets a value indicating whether barrel bolt is currently locked.
/// </summary>
public bool BoltLocked
{
get
{
return AutomaticBarrel.BoltLocked;
}

set
{
AutomaticBarrel.BoltLocked = value;
Resync();
}
}

/// <inheritdoc/>
public override void Resync()
{
AutomaticBarrel.ServerResync();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// -----------------------------------------------------------------------
// <copyright file="BarrelMagazine.cs" company="ExMod Team">
// Copyright (c) ExMod Team. All rights reserved.
// Licensed under the CC BY-SA 3.0 license.
// </copyright>
// -----------------------------------------------------------------------

namespace Exiled.API.Features.Items.FirearmModules.Barrel
{
using InventorySystem.Items.Firearms.Modules;

/// <summary>
/// Basic abstraction of <see cref="IAmmoContainerModule"/> whose are logically used to be a barrels magazines.
/// </summary>
public abstract class BarrelMagazine : Magazine
{
/// <summary>
/// Initializes a new instance of the <see cref="BarrelMagazine"/> class.
/// </summary>
/// <param name="module">target <see cref="IAmmoContainerModule"/>.</param>
public BarrelMagazine(IAmmoContainerModule module)
: base(module)
{
}

/// <summary>
/// Gets or sets a value indicating whether barrel is cocked.
/// </summary>
public abstract bool IsCocked { get; set; }
}
}
Loading