Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Multiphase energy gun #1581

Merged
merged 28 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
56a7576
Add Multifaze gun
Kirus59 Aug 13, 2024
dc4f18e
Add opportunity to change SoundGunshoot
Kirus59 Aug 13, 2024
c890a34
some fixes
Kirus59 Aug 13, 2024
9063a7b
Fix comp init
Kirus59 Aug 13, 2024
9645418
Delete needless using
Kirus59 Aug 13, 2024
0d2bf1a
Add opportunity to change MagazineVisuals by mode
Kirus59 Aug 14, 2024
d4b4f22
format fixes
Kirus59 Aug 14, 2024
84fab77
Move BatteryWeaponFireModesSystem to SS220
Kirus59 Aug 14, 2024
c767cda
Add summary and some fixes
Kirus59 Aug 14, 2024
1210457
Add Updateshots and some fixes
Kirus59 Aug 15, 2024
eba1fb0
Add comments
Kirus59 Aug 15, 2024
ba2e14f
Add sprites and some changes
Kirus59 Aug 15, 2024
d5d680f
Fix localization
Kirus59 Aug 15, 2024
883e8c8
Add EMP mode and sprite changes
Kirus59 Aug 15, 2024
f7be5fe
Add weapon to locker and add localization
Kirus59 Aug 15, 2024
8583ea6
Add steal objective
Kirus59 Aug 15, 2024
a7e1792
Fix objective name
Kirus59 Aug 15, 2024
1e25bda
Merge branch 'master' into AddMultifazeGun
Kirus59 Aug 15, 2024
2b14c98
Try fix checks
Kirus59 Aug 15, 2024
4dc6996
Merge branch 'AddMultifazeGun' of https://github.com/Kirus59/space-st…
Kirus59 Aug 15, 2024
387c6fc
Try fix checks 2
Kirus59 Aug 15, 2024
8cdd111
Add UpdateAmmoCount
Kirus59 Aug 15, 2024
b5da58d
Add sprite to BulletEMP
Kirus59 Aug 15, 2024
40d2047
Subscribe fixes
Kirus59 Aug 16, 2024
1a19b80
Fix SoundGunshotModifiers and checks fix
Kirus59 Aug 16, 2024
0174e61
Change sprites name from "disarm" to "disabler"
Kirus59 Aug 16, 2024
96a34c1
Fix YAML Linter
Kirus59 Aug 16, 2024
18a020c
Merge branch 'master' into AddMultifazeGun
Kirus59 Aug 18, 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// © SS220, An EULA/CLA with a hosting restriction, full text: https://raw.githubusercontent.com/SerbiaStrong-220/space-station-14/master/CLA.txt
using Content.Client.Weapons.Ranged.Systems;
using Content.Shared.Weapons.Ranged.Components;
using Content.Shared.Weapons.Ranged.Systems;

namespace Content.Client.SS220.Weapons.Ranged.Systems;

public sealed partial class BatteryWeaponFireModesSystem : EntitySystem
{
[Dependency] private readonly GunSystem _gunSystem = default!;

public override void Initialize()
{
base.Initialize();

SubscribeLocalEvent<BatteryWeaponFireModesComponent, ChangeFireModeEvent>(OnFireModeChange);
}

private void OnFireModeChange(Entity<BatteryWeaponFireModesComponent> ent, ref ChangeFireModeEvent args)
{
var fireMode = ent.Comp.FireModes[args.Index];

if (fireMode.MagState is not null)
_gunSystem.SetMagState(ent, fireMode.MagState);
}
}
15 changes: 15 additions & 0 deletions Content.Client/Weapons/Ranged/Systems/GunSystem.Battery.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Content.Shared.Weapons.Ranged.Components;
using Robust.Client.GameObjects;

namespace Content.Client.Weapons.Ranged.Systems;

Expand All @@ -10,10 +11,12 @@ protected override void InitializeBattery()
// Hitscan
SubscribeLocalEvent<HitscanBatteryAmmoProviderComponent, AmmoCounterControlEvent>(OnControl);
SubscribeLocalEvent<HitscanBatteryAmmoProviderComponent, UpdateAmmoCounterEvent>(OnAmmoCountUpdate);
SubscribeLocalEvent<HitscanBatteryAmmoProviderComponent, AppearanceChangeEvent>(OnHitscanAppearanceChange); //SS220 Add Multifaze gun

// Projectile
SubscribeLocalEvent<ProjectileBatteryAmmoProviderComponent, AmmoCounterControlEvent>(OnControl);
SubscribeLocalEvent<ProjectileBatteryAmmoProviderComponent, UpdateAmmoCounterEvent>(OnAmmoCountUpdate);
SubscribeLocalEvent<ProjectileBatteryAmmoProviderComponent, AppearanceChangeEvent>(OnProjectileAppearanceChange); //SS220 Add Multifaze gun
}

private void OnAmmoCountUpdate(EntityUid uid, BatteryAmmoProviderComponent component, UpdateAmmoCounterEvent args)
Expand All @@ -27,4 +30,16 @@ private void OnControl(EntityUid uid, BatteryAmmoProviderComponent component, Am
{
args.Control = new BoxesStatusControl();
}

//SS220 Add Multifaze gun begin
private void OnHitscanAppearanceChange(Entity<HitscanBatteryAmmoProviderComponent> ent, ref AppearanceChangeEvent args)
{
UpdateAmmoCount(ent);
}

private void OnProjectileAppearanceChange(Entity<ProjectileBatteryAmmoProviderComponent> ent, ref AppearanceChangeEvent args)
{
UpdateAmmoCount(ent);
}
//SS220 Add Multifaze gun end
}
10 changes: 10 additions & 0 deletions Content.Client/Weapons/Ranged/Systems/GunSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -387,4 +387,14 @@ protected override void CreateEffect(EntityUid gunUid, MuzzleFlashEvent message,
_animPlayer.Stop(gunUid, uidPlayer, "muzzle-flash-light");
_animPlayer.Play((gunUid, uidPlayer), animTwo, "muzzle-flash-light");
}

//SS220 Add Multifaze gun begin
public void SetMagState(EntityUid uid, string magState, MagazineVisualsComponent? component = null)
{
if (!Resolve(uid, ref component))
return;

component.MagState = magState;
}
//SS220 Add Multifaze gun end
}
17 changes: 17 additions & 0 deletions Content.Server/Weapons/Ranged/Systems/GunSystem.Battery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Content.Shared.Projectiles;
using Content.Shared.Weapons.Ranged;
using Content.Shared.Weapons.Ranged.Components;
using Content.Shared.Weapons.Ranged.Systems;
using Robust.Shared.Prototypes;

namespace Content.Server.Weapons.Ranged.Systems;
Expand All @@ -19,11 +20,13 @@ protected override void InitializeBattery()
SubscribeLocalEvent<HitscanBatteryAmmoProviderComponent, ComponentStartup>(OnBatteryStartup);
SubscribeLocalEvent<HitscanBatteryAmmoProviderComponent, ChargeChangedEvent>(OnBatteryChargeChange);
SubscribeLocalEvent<HitscanBatteryAmmoProviderComponent, DamageExamineEvent>(OnBatteryDamageExamine);
SubscribeLocalEvent<HitscanBatteryAmmoProviderComponent, ChangeFireModeEvent>(OnHitscanFireModeChange); //SS220 Add Multifaze gun

// Projectile
SubscribeLocalEvent<ProjectileBatteryAmmoProviderComponent, ComponentStartup>(OnBatteryStartup);
SubscribeLocalEvent<ProjectileBatteryAmmoProviderComponent, ChargeChangedEvent>(OnBatteryChargeChange);
SubscribeLocalEvent<ProjectileBatteryAmmoProviderComponent, DamageExamineEvent>(OnBatteryDamageExamine);
SubscribeLocalEvent<ProjectileBatteryAmmoProviderComponent, ChangeFireModeEvent>(OnProjectileFireModeChange); //SS220 Add Multifaze gun
}

private void OnBatteryStartup(EntityUid uid, BatteryAmmoProviderComponent component, ComponentStartup args)
Expand Down Expand Up @@ -107,4 +110,18 @@ protected override void TakeCharge(EntityUid uid, BatteryAmmoProviderComponent c
// Will raise ChargeChangedEvent
_battery.UseCharge(uid, component.FireCost);
}

//SS220 Add Multifaze gun begin
private void OnHitscanFireModeChange(Entity<HitscanBatteryAmmoProviderComponent> ent, ref ChangeFireModeEvent args)
{
UpdateShots(ent, ent.Comp);
Dirty(ent, ent.Comp);
}

private void OnProjectileFireModeChange(Entity<ProjectileBatteryAmmoProviderComponent> ent, ref ChangeFireModeEvent args)
{
UpdateShots(ent, ent.Comp);
Dirty(ent, ent.Comp);
}
//SS220 Add Multifaze gun end
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,27 @@ public sealed partial class BatteryWeaponFireMode
/// The projectile prototype associated with this firing mode
/// </summary>
[DataField("proto", required: true)]
public EntProtoId Prototype = default!;
public string Prototype = default!; //SS220 Add Multifaze gun

//SS220 Add Multifaze gun begin
/// <summary>
/// Name of the fire mode
/// </summary>
[DataField("name")]
public string? FireModeName;
DexlerXD marked this conversation as resolved.
Show resolved Hide resolved

/// <summary>
/// Sound of a gunshot that is used in the selected fire mode
/// </summary>
[DataField]
public string? SoundGunshot;

/// <summary>
/// Sprite of the remaining charge that is used in the selected fire mode
/// </summary>
[DataField]
public string? MagState;
DexlerXD marked this conversation as resolved.
Show resolved Hide resolved
//SS220 Add Multifaze gun end

/// <summary>
/// The battery cost to fire the projectile associated with this firing mode
Expand Down
140 changes: 128 additions & 12 deletions Content.Shared/Weapons/Ranged/Systems/BatteryWeaponFireModesSystem.cs
DexlerXD marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,19 @@
using Content.Shared.Popups;
using Content.Shared.Verbs;
using Content.Shared.Weapons.Ranged.Components;
using Content.Shared.Weapons.Ranged.Events;
using Robust.Shared.Audio;
using Robust.Shared.Prototypes;
using Robust.Shared.Timing;

namespace Content.Shared.Weapons.Ranged.Systems;

public sealed class BatteryWeaponFireModesSystem : EntitySystem
{
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly SharedPopupSystem _popupSystem = default!;
[Dependency] private readonly IGameTiming _gameTiming = default!; //SS220 Add Multifaze gun
[Dependency] private readonly SharedGunSystem _gunSystem = default!; //SS220 Add Multifaze gun

public override void Initialize()
{
Expand All @@ -21,6 +26,8 @@ public override void Initialize()
SubscribeLocalEvent<BatteryWeaponFireModesComponent, ActivateInWorldEvent>(OnInteractHandEvent);
SubscribeLocalEvent<BatteryWeaponFireModesComponent, GetVerbsEvent<Verb>>(OnGetVerb);
SubscribeLocalEvent<BatteryWeaponFireModesComponent, ExaminedEvent>(OnExamined);
SubscribeLocalEvent<BatteryWeaponFireModesComponent, ComponentInit>(OnInit); //SS220 Add Multifaze gun
SubscribeLocalEvent<BatteryWeaponFireModesComponent, GunRefreshModifiersEvent>(OnRefreshModifiers); //SS220 Add Multifaze gun
}

private void OnExamined(EntityUid uid, BatteryWeaponFireModesComponent component, ExaminedEvent args)
Expand All @@ -29,11 +36,19 @@ private void OnExamined(EntityUid uid, BatteryWeaponFireModesComponent component
return;

var fireMode = GetMode(component);
var name = string.Empty; //SS220 Add Multifaze gun

if (!_prototypeManager.TryIndex<EntityPrototype>(fireMode.Prototype, out var proto))
return;
//SS220 Add Multifaze gun begin
//if (!_prototypeManager.TryIndex<EntityPrototype>(fireMode.Prototype, out var proto))
// return;

if (fireMode.FireModeName != null)
name = fireMode.FireModeName;
else if (_prototypeManager.TryIndex<EntityPrototype>(fireMode.Prototype, out var entProto))
name = entProto.Name;
//SS220 Add Multifaze gun end

args.PushMarkup(Loc.GetString("gun-set-fire-mode", ("mode", proto.Name)));
args.PushMarkup(Loc.GetString("gun-set-fire-mode", ("mode", Loc.GetString(name)))); //SS220 Add Multifaze gun
}

private BatteryWeaponFireMode GetMode(BatteryWeaponFireModesComponent component)
Expand All @@ -52,14 +67,30 @@ private void OnGetVerb(EntityUid uid, BatteryWeaponFireModesComponent component,
for (var i = 0; i < component.FireModes.Count; i++)
{
var fireMode = component.FireModes[i];
var entProto = _prototypeManager.Index<EntityPrototype>(fireMode.Prototype);
// var entProto = _prototypeManager.Index<EntityPrototype>(fireMode.Prototype); //SS220 Add Multifaze gun
var index = i;

//SS220 Add Multifaze gun begin
var text = string.Empty;

if (_prototypeManager.TryIndex<EntityPrototype>(fireMode.Prototype, out var entProto))
{
if (fireMode.FireModeName is not null)
text = fireMode.FireModeName;
else
text = entProto.Name;
}
else if (_prototypeManager.TryIndex<HitscanPrototype>(fireMode.Prototype, out _))
{
text += fireMode.FireModeName;
}
//SS220 Add Multifaze gun end

var v = new Verb
{
Priority = 1,
Category = VerbCategory.SelectType,
Text = entProto.Name,
Text = Loc.GetString(text), //SS220 Add Multifaze gun
Disabled = i == component.CurrentFireMode,
Impact = LogImpact.Low,
DoContactInteraction = true,
Expand Down Expand Up @@ -99,18 +130,103 @@ private void SetFireMode(EntityUid uid, BatteryWeaponFireModesComponent componen
component.CurrentFireMode = index;
Dirty(uid, component);

if (TryComp(uid, out ProjectileBatteryAmmoProviderComponent? projectileBatteryAmmoProvider))
//SS220 Add Multifaze gun begin
var name = string.Empty;

//if (TryComp(uid, out ProjectileBatteryAmmoProviderComponent? projectileBatteryAmmoProvider))
//{
// if (!_prototypeManager.TryIndex<EntityPrototype>(fireMode.Prototype, out var prototype))
// return;

// projectileBatteryAmmoProvider.Prototype = fireMode.Prototype;
// projectileBatteryAmmoProvider.FireCost = fireMode.FireCost;
//}

if (_prototypeManager.TryIndex<EntityPrototype>(fireMode.Prototype, out var entProto))
{
if (HasComp<HitscanBatteryAmmoProviderComponent>(uid))
RemComp<HitscanBatteryAmmoProviderComponent>(uid);

if (!_gameTiming.ApplyingState)
EnsureComp<ProjectileBatteryAmmoProviderComponent>(uid);

if (TryComp(uid, out ProjectileBatteryAmmoProviderComponent? projectileBatteryAmmoProvider))
{

if (fireMode.FireModeName is not null)
name = fireMode.FireModeName;
else
name = entProto.Name;

projectileBatteryAmmoProvider.Prototype = fireMode.Prototype;
projectileBatteryAmmoProvider.FireCost = fireMode.FireCost;

Dirty(uid, projectileBatteryAmmoProvider);
}
}
else if (_prototypeManager.TryIndex<HitscanPrototype>(fireMode.Prototype, out _))
{
if (!_prototypeManager.TryIndex<EntityPrototype>(fireMode.Prototype, out var prototype))
return;
if (HasComp<ProjectileBatteryAmmoProviderComponent>(uid))
RemComp<ProjectileBatteryAmmoProviderComponent>(uid);

projectileBatteryAmmoProvider.Prototype = fireMode.Prototype;
projectileBatteryAmmoProvider.FireCost = fireMode.FireCost;
if (!_gameTiming.ApplyingState)
EnsureComp<HitscanBatteryAmmoProviderComponent>(uid);

if (user != null)
if (TryComp(uid, out HitscanBatteryAmmoProviderComponent? hitscanBatteryAmmoProvider))
{
_popupSystem.PopupClient(Loc.GetString("gun-set-fire-mode", ("mode", prototype.Name)), uid, user.Value);
name += fireMode.FireModeName;

hitscanBatteryAmmoProvider.Prototype = fireMode.Prototype;
hitscanBatteryAmmoProvider.FireCost = fireMode.FireCost;

Dirty(uid, hitscanBatteryAmmoProvider);
}
}
else
{
Log.Error($"{fireMode.Prototype} is not Entity or Hitscan prototype");
return;
}

_gunSystem.RefreshModifiers(uid);
//SS220 Add Multifaze gun end

if (user != null)
{
_popupSystem.PopupClient(Loc.GetString("gun-set-fire-mode", ("mode", Loc.GetString(name))), uid, user.Value); //SS220 Add Multifaze gun
}

//SS220 Add Multifaze gun begin
var ev = new ChangeFireModeEvent(index);
RaiseLocalEvent(uid, ref ev);
//SS220 Add Multifaze gun end
}

//SS220 Add Multifaze gun begin
private void OnInit(Entity<BatteryWeaponFireModesComponent> ent, ref ComponentInit args)
{
if (ent.Comp.FireModes.Count <= 0)
return;

var index = ent.Comp.CurrentFireMode % ent.Comp.FireModes.Count;
SetFireMode(ent, ent.Comp, index);
}

private void OnRefreshModifiers(Entity<BatteryWeaponFireModesComponent> ent, ref GunRefreshModifiersEvent args)
{
var firemode = GetMode(ent.Comp);

if (firemode.SoundGunshot is not null)
args.SoundGunshot = new SoundPathSpecifier(firemode.SoundGunshot);
}
//SS220 Add Multifaze gun end
}

//SS220 Add Multifaze gun begin
/// <summary>
/// The event that rises when the fire mode is selected
/// </summary>
/// <param name="Index"></param>
[ByRefEvent]
public record struct ChangeFireModeEvent(int Index);
//SS220 Add Multifaze gun end
18 changes: 18 additions & 0 deletions Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.Battery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,32 @@ private void OnBatteryHandleState(EntityUid uid, BatteryAmmoProviderComponent co
component.Shots = state.Shots;
component.Capacity = state.MaxShots;
component.FireCost = state.FireCost;

//SS220 Add Multifaze gun begin
if (component is ProjectileBatteryAmmoProviderComponent projectileComp)
projectileComp.Prototype = state.Prototype;
else if (component is HitscanBatteryAmmoProviderComponent hitscanComp)
hitscanComp.Prototype = state.Prototype;
//SS220 Add Multifaze gun end
}

private void OnBatteryGetState(EntityUid uid, BatteryAmmoProviderComponent component, ref ComponentGetState args)
{
//SS220 Add Multifaze gun begin
string prototype = string.Empty;

if (component is ProjectileBatteryAmmoProviderComponent projectileComp)
prototype = projectileComp.Prototype;
else if (component is HitscanBatteryAmmoProviderComponent hitscanComp)
prototype = hitscanComp.Prototype;
//SS220 Add Multifaze gun end

args.State = new BatteryAmmoProviderComponentState()
{
Shots = component.Shots,
MaxShots = component.Capacity,
FireCost = component.FireCost,
Prototype = prototype, //SS220 Add Multifaze gun
};
}

Expand Down Expand Up @@ -112,5 +129,6 @@ private sealed class BatteryAmmoProviderComponentState : ComponentState
public int Shots;
public int MaxShots;
public float FireCost;
public string Prototype = string.Empty; //SS220 Add Multifaze gun
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
firemode-name-disabler = Станнер
firemode-name-laser = Лазер
firemode-name-emp = ЭМИ

ent-WeaponMultiPhaseEnergyGun = мультифазовый энергетический пистолет
.desc = Это дорогая, современная версия антикварного лазерного пистолета. У этого оружия есть несколько уникальных режимов огня, но нет возможности самостоятельно перезаряжаться с течением времени.
Loading
Loading