# Conflicts: # Content.Server/Antag/AntagSelectionSystem.cs # Content.Server/Changeling/ChangelingRuleSystem.cs # Content.Server/Changeling/ChangelingSystem.Abilities.cs # Content.Server/Doors/Systems/DoorSystem.cs # Content.Server/GameTicking/Rules/NukeopsRuleSystem.cs # Content.Server/GameTicking/Rules/RevolutionaryRuleSystem.cs # Content.Server/GameTicking/Rules/TraitorRuleSystem.cs # Content.Server/GameTicking/Rules/ZombieRuleSystem.cs # Content.Server/Holosign/HolosignSystem.cs # Content.Server/Revenant/EntitySystems/RevenantSystem.Abilities.cs # Content.Server/_White/Cult/GameRule/CultRuleComponent.cs # Content.Server/_White/Cult/GameRule/CultRuleSystem.cs # Content.Server/_White/Cult/Runes/Systems/CultSystem.Rune.cs # Content.Server/_White/Keyhole/KeyholeSystem.cs # Content.Server/_White/MeatyOre/MeatyOreStoreSystem.cs # Content.Shared/Projectiles/SharedProjectileSystem.cs # Content.Shared/Weapons/Melee/SharedMeleeWeaponSystem.cs # Content.Shared/_White/Keyhole/Components/KeyBaseComponent.cs # Resources/Locale/ru-RU/White/stuff.ftl/runes-entities.ftl # Resources/Locale/ru-RU/_white/cult/blood-spear.ftl # Resources/Locale/ru-RU/_white/cult/bolt-barrage.ftl # Resources/Locale/ru-RU/_white/cult/cult.ftl # Resources/Locale/ru-RU/_white/cult/gui.ftl # Resources/Locale/ru-RU/cult/cult-structure.ftl # Resources/Locale/ru-RU/cult/pylon.ftl # Resources/Maps/White/Scoupidia.yml # Resources/Maps/White/Void.yml # Resources/Maps/White/WonderBox.yml # Resources/Prototypes/Actions/types.yml # Resources/Prototypes/Atmospherics/gases.yml # Resources/Prototypes/Catalog/Cargo/cargo_atmospherics.yml # Resources/Prototypes/Catalog/Cargo/cargo_vending.yml # Resources/Prototypes/Catalog/Fills/Lockers/dressers.yml # Resources/Prototypes/Catalog/Fills/Lockers/heads.yml # Resources/Prototypes/Catalog/Fills/Lockers/misc.yml # Resources/Prototypes/Catalog/uplink_catalog.yml # Resources/Prototypes/Entities/Clothing/OuterClothing/armor.yml # Resources/Prototypes/Entities/Objects/Misc/subdermal_implants.yml # Resources/Prototypes/Entities/Objects/Tools/jaws_of_life.yml # Resources/Prototypes/Entities/Objects/Weapons/Melee/sledgehammer.yml # Resources/Prototypes/Entities/Objects/Weapons/Melee/sword.yml # Resources/Prototypes/Entities/Structures/Doors/Airlocks/base_assembly.yml # Resources/Prototypes/Entities/Structures/Doors/Airlocks/base_structureairlocks.yml # Resources/Prototypes/Entities/Structures/Doors/Firelocks/firelock.yml # Resources/Prototypes/Entities/Structures/Doors/Firelocks/frame.yml # Resources/Prototypes/Entities/Structures/Doors/SecretDoor/secret_door.yml # Resources/Prototypes/Entities/Structures/Doors/Windoors/assembly.yml # Resources/Prototypes/Entities/Structures/Doors/Windoors/base_structurewindoors.yml # Resources/Prototypes/Entities/Structures/Furniture/dresser.yml # Resources/Prototypes/Entities/Structures/Lighting/base_lighting.yml # Resources/Prototypes/Entities/Structures/Power/cable_terminal.yml # Resources/Prototypes/Entities/Structures/Walls/grille.yml # Resources/Prototypes/Entities/Structures/Walls/walls.yml # Resources/Prototypes/Entities/Structures/stairs.yml # Resources/Prototypes/_White/Entities/Objects/Misc/books.yml
170 lines
5.5 KiB
C#
170 lines
5.5 KiB
C#
using System.Linq;
|
|
using Content.Shared._White.WeaponModules;
|
|
using Content.Shared.Actions;
|
|
using Content.Shared.Examine;
|
|
using Content.Shared.Hands;
|
|
using Content.Shared.Verbs;
|
|
using Content.Shared.Weapons.Ranged.Components;
|
|
using Robust.Shared.Utility;
|
|
|
|
namespace Content.Shared.Weapons.Ranged.Systems;
|
|
|
|
public abstract partial class SharedGunSystem
|
|
{
|
|
private void OnExamine(EntityUid uid, GunComponent component, ExaminedEvent args)
|
|
{
|
|
if (!args.IsInDetailsRange || !component.ShowExamineText)
|
|
return;
|
|
|
|
using (args.PushGroup(nameof(GunComponent)))
|
|
{
|
|
args.PushMarkup(Loc.GetString("gun-selected-mode-examine", ("color", ModeExamineColor),
|
|
("mode", GetLocSelector(component.SelectedMode))));
|
|
args.PushMarkup(Loc.GetString("gun-fire-rate-examine", ("color", FireRateExamineColor),
|
|
("fireRate", $"{component.FireRateModified:0.0}")));
|
|
|
|
if (TryComp<WeaponModulesComponent>(uid, out var weaponModulesComponent))
|
|
{
|
|
if (weaponModulesComponent.Modules.Count == 0)
|
|
{
|
|
args.PushMarkup(Loc.GetString("gun-modules", ("modules", "Пусто")));
|
|
return;
|
|
}
|
|
|
|
var moduleNames = weaponModulesComponent.Modules.Select(module => Name(module)).ToArray();
|
|
|
|
args.PushMarkup(Loc.GetString("gun-modules", ("modules", string.Join(", ", moduleNames))));
|
|
}
|
|
|
|
if (!TryComp<TwoModeEnergyAmmoProviderComponent>(uid, out var comp))
|
|
return;
|
|
|
|
args.PushMarkup(Loc.GetString("gun-twomode-mode-examine", ("color", TwoModeExamineColor),
|
|
("mode", GetLocMode(comp))));
|
|
}
|
|
}
|
|
|
|
private object GetLocMode(TwoModeEnergyAmmoProviderComponent comp)
|
|
{
|
|
return Loc.GetString($"gun-twomode-{comp.ModeNames[comp.CurrentMode]}");
|
|
}
|
|
|
|
private string GetLocSelector(SelectiveFire mode)
|
|
{
|
|
return Loc.GetString($"gun-{mode.ToString()}");
|
|
}
|
|
|
|
private void OnAltVerb(EntityUid uid, GunComponent component, GetVerbsEvent<AlternativeVerb> args)
|
|
{
|
|
if (!args.CanAccess || !args.CanInteract || component.SelectedMode == component.AvailableModes)
|
|
return;
|
|
|
|
var nextMode = GetNextMode(component);
|
|
|
|
AlternativeVerb verb = new()
|
|
{
|
|
Act = () => SelectFire(uid, component, nextMode, args.User),
|
|
Text = Loc.GetString("gun-selector-verb", ("mode", GetLocSelector(nextMode))),
|
|
Icon = new SpriteSpecifier.Texture(new("/Textures/Interface/VerbIcons/fold.svg.192dpi.png")),
|
|
};
|
|
|
|
args.Verbs.Add(verb);
|
|
}
|
|
|
|
private SelectiveFire GetNextMode(GunComponent component)
|
|
{
|
|
var modes = new List<SelectiveFire>();
|
|
|
|
foreach (var mode in Enum.GetValues<SelectiveFire>())
|
|
{
|
|
if ((mode & component.AvailableModes) == 0x0)
|
|
continue;
|
|
|
|
modes.Add(mode);
|
|
}
|
|
|
|
var index = modes.IndexOf(component.SelectedMode);
|
|
return modes[(index + 1) % modes.Count];
|
|
}
|
|
|
|
private void SelectFire(EntityUid uid, GunComponent component, SelectiveFire fire, EntityUid? user = null)
|
|
{
|
|
if (component.SelectedMode == fire)
|
|
return;
|
|
|
|
DebugTools.Assert((component.AvailableModes & fire) != 0x0);
|
|
component.SelectedMode = fire;
|
|
|
|
if (!Paused(uid))
|
|
{
|
|
var curTime = Timing.CurTime;
|
|
var cooldown = TimeSpan.FromSeconds(InteractNextFire);
|
|
|
|
if (component.NextFire < curTime)
|
|
component.NextFire = curTime + cooldown;
|
|
else
|
|
component.NextFire += cooldown;
|
|
}
|
|
|
|
Audio.PlayPredicted(component.SoundMode, uid, user);
|
|
Popup(Loc.GetString("gun-selected-mode", ("mode", GetLocSelector(fire))), uid, user);
|
|
Dirty(uid, component);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Cycles the gun's <see cref="SelectiveFire"/> to the next available one.
|
|
/// </summary>
|
|
public void CycleFire(EntityUid uid, GunComponent component, EntityUid? user = null)
|
|
{
|
|
// Noop
|
|
if (component.SelectedMode == component.AvailableModes)
|
|
return;
|
|
|
|
DebugTools.Assert((component.AvailableModes & component.SelectedMode) == component.SelectedMode);
|
|
var nextMode = GetNextMode(component);
|
|
SelectFire(uid, component, nextMode, user);
|
|
}
|
|
|
|
// TODO: Actions need doing for guns anyway.
|
|
private sealed partial class CycleModeEvent : InstantActionEvent
|
|
{
|
|
public SelectiveFire Mode = default;
|
|
}
|
|
|
|
private void OnCycleMode(EntityUid uid, GunComponent component, CycleModeEvent args)
|
|
{
|
|
SelectFire(uid, component, args.Mode, args.Performer);
|
|
}
|
|
|
|
private void OnGunSelected(EntityUid uid, GunComponent component, HandSelectedEvent args)
|
|
{
|
|
// WD EDIT START
|
|
if (component.FireRateModified <= 0f)
|
|
component.FireRateModified = component.FireRate;
|
|
|
|
if (component.FireRateModified <= 0f)
|
|
return;
|
|
// WD EDIT END
|
|
|
|
var fireDelay = 1f / component.FireRateModified;
|
|
if (fireDelay.Equals(0f))
|
|
return;
|
|
|
|
if (!component.ResetOnHandSelected)
|
|
return;
|
|
|
|
if (Paused(uid))
|
|
return;
|
|
|
|
// If someone swaps to this weapon then reset its cd.
|
|
var curTime = Timing.CurTime;
|
|
var minimum = curTime + TimeSpan.FromSeconds(fireDelay);
|
|
|
|
if (minimum < component.NextFire)
|
|
return;
|
|
|
|
component.NextFire = minimum;
|
|
Dirty(uid, component);
|
|
}
|
|
}
|