Merge branch 'final-version' into upupup
This commit is contained in:
@@ -1,130 +0,0 @@
|
||||
using Content.Server.Popups;
|
||||
using Content.Server.Weapons.Ranged.Components;
|
||||
using Content.Shared.Database;
|
||||
using Content.Shared.Examine;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Verbs;
|
||||
using Content.Shared.Weapons.Ranged.Components;
|
||||
using Robust.Shared.Prototypes;
|
||||
using System.Linq;
|
||||
|
||||
namespace Content.Server.Weapons.Ranged.Systems;
|
||||
|
||||
public sealed class BatteryWeaponFireModesSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
||||
[Dependency] private readonly PopupSystem _popupSystem = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<BatteryWeaponFireModesComponent, ActivateInWorldEvent>(OnInteractHandEvent);
|
||||
SubscribeLocalEvent<BatteryWeaponFireModesComponent, GetVerbsEvent<Verb>>(OnGetVerb);
|
||||
SubscribeLocalEvent<BatteryWeaponFireModesComponent, ExaminedEvent>(OnExamined);
|
||||
}
|
||||
|
||||
private void OnExamined(EntityUid uid, BatteryWeaponFireModesComponent component, ExaminedEvent args)
|
||||
{
|
||||
if (component.FireModes == null || component.FireModes.Count < 2)
|
||||
return;
|
||||
|
||||
if (component.CurrentFireMode == null)
|
||||
{
|
||||
SetFireMode(uid, component, component.FireModes.First());
|
||||
}
|
||||
|
||||
if (component.CurrentFireMode?.Prototype == null)
|
||||
return;
|
||||
|
||||
if (!_prototypeManager.TryIndex<EntityPrototype>(component.CurrentFireMode.Prototype, out var proto))
|
||||
return;
|
||||
|
||||
args.PushMarkup(Loc.GetString("gun-set-fire-mode", ("mode", proto.Name)));
|
||||
}
|
||||
|
||||
private void OnGetVerb(EntityUid uid, BatteryWeaponFireModesComponent component, GetVerbsEvent<Verb> args)
|
||||
{
|
||||
if (!args.CanAccess || !args.CanInteract || args.Hands == null)
|
||||
return;
|
||||
|
||||
if (component.FireModes == null || component.FireModes.Count < 2)
|
||||
return;
|
||||
|
||||
if (component.CurrentFireMode == null)
|
||||
{
|
||||
SetFireMode(uid, component, component.FireModes.First());
|
||||
}
|
||||
|
||||
foreach (var fireMode in component.FireModes)
|
||||
{
|
||||
var entProto = _prototypeManager.Index<EntityPrototype>(fireMode.Prototype);
|
||||
|
||||
var v = new Verb
|
||||
{
|
||||
Priority = 1,
|
||||
Category = VerbCategory.SelectType,
|
||||
Text = entProto.Name,
|
||||
Disabled = fireMode == component.CurrentFireMode,
|
||||
Impact = LogImpact.Low,
|
||||
DoContactInteraction = true,
|
||||
Act = () =>
|
||||
{
|
||||
SetFireMode(uid, component, fireMode, args.User);
|
||||
}
|
||||
};
|
||||
|
||||
args.Verbs.Add(v);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnInteractHandEvent(EntityUid uid, BatteryWeaponFireModesComponent component, ActivateInWorldEvent args)
|
||||
{
|
||||
if (component.FireModes == null || component.FireModes.Count < 2)
|
||||
return;
|
||||
|
||||
CycleFireMode(uid, component, args.User);
|
||||
}
|
||||
|
||||
private void CycleFireMode(EntityUid uid, BatteryWeaponFireModesComponent component, EntityUid user)
|
||||
{
|
||||
int index = (component.CurrentFireMode != null) ?
|
||||
Math.Max(component.FireModes.IndexOf(component.CurrentFireMode), 0) + 1 : 1;
|
||||
|
||||
BatteryWeaponFireMode? fireMode;
|
||||
|
||||
if (index >= component.FireModes.Count)
|
||||
{
|
||||
fireMode = component.FireModes.FirstOrDefault();
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
fireMode = component.FireModes[index];
|
||||
}
|
||||
|
||||
SetFireMode(uid, component, fireMode, user);
|
||||
}
|
||||
|
||||
private void SetFireMode(EntityUid uid, BatteryWeaponFireModesComponent component, BatteryWeaponFireMode? fireMode, EntityUid? user = null)
|
||||
{
|
||||
if (fireMode?.Prototype == null)
|
||||
return;
|
||||
|
||||
component.CurrentFireMode = fireMode;
|
||||
|
||||
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 (user != null)
|
||||
{
|
||||
_popupSystem.PopupEntity(Loc.GetString("gun-set-fire-mode", ("mode", prototype.Name)), uid, user.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,6 @@ using Content.Shared.Damage;
|
||||
using Content.Shared.Damage.Systems;
|
||||
using Content.Shared.Database;
|
||||
using Content.Shared.Effects;
|
||||
using Content.Shared.FixedPoint;
|
||||
using Content.Shared.Interaction.Components;
|
||||
using Content.Shared.Projectiles;
|
||||
using Content.Shared.Throwing;
|
||||
@@ -21,7 +20,6 @@ using Content.Shared.Weapons.Ranged.Components;
|
||||
using Content.Shared.Weapons.Ranged.Events;
|
||||
using Content.Shared.Weapons.Ranged.Systems;
|
||||
using Content.Shared.Weapons.Reflect;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Physics;
|
||||
@@ -143,31 +141,13 @@ public sealed partial class GunSystem : SharedGunSystem
|
||||
case CartridgeAmmoComponent cartridge:
|
||||
if (!cartridge.Spent)
|
||||
{
|
||||
if (gun.CompatibleAmmo != null &&
|
||||
!gun.CompatibleAmmo.Exists(ammoAllowed => ammoAllowed.Equals(cartridge.Prototype))
|
||||
&& user != null)
|
||||
{
|
||||
if (gun.DamageOnWrongAmmo != null)
|
||||
Damageable.TryChangeDamage(user, gun.DamageOnWrongAmmo, origin: user);
|
||||
_stun.TryParalyze(user.Value, TimeSpan.FromSeconds(3f), true);
|
||||
|
||||
Audio.PlayPvs(new SoundPathSpecifier("/Audio/Weapons/Guns/Gunshots/bang.ogg"), gunUid);
|
||||
|
||||
PopupSystem.PopupEntity(Loc.GetString("gun-component-wrong-ammo"), user.Value);
|
||||
_adminLogger.Add(LogType.EntityDelete, LogImpact.Medium, $"Shot wrong ammo by {ToPrettyString(user.Value)} deleted {ToPrettyString(gunUid)}");
|
||||
userImpulse = false;
|
||||
|
||||
SetCartridgeSpent(ent!.Value, cartridge, true);
|
||||
MuzzleFlash(gunUid, cartridge, user);
|
||||
Del(gunUid);
|
||||
if (cartridge.DeleteOnSpawn)
|
||||
Del(ent.Value);
|
||||
return;
|
||||
}
|
||||
if (cartridge.Count > 1)
|
||||
{
|
||||
var angles = LinearSpread(mapAngle - cartridge.Spread / 2,
|
||||
mapAngle + cartridge.Spread / 2, cartridge.Count);
|
||||
var ev = new GunGetAmmoSpreadEvent(cartridge.Spread);
|
||||
RaiseLocalEvent(gunUid, ref ev);
|
||||
|
||||
var angles = LinearSpread(mapAngle - ev.Spread / 2,
|
||||
mapAngle + ev.Spread / 2, cartridge.Count);
|
||||
|
||||
for (var i = 0; i < cartridge.Count; i++)
|
||||
{
|
||||
@@ -190,7 +170,7 @@ public sealed partial class GunSystem : SharedGunSystem
|
||||
|
||||
SetCartridgeSpent(ent.Value, cartridge, true);
|
||||
MuzzleFlash(gunUid, cartridge, user);
|
||||
Audio.PlayPredicted(gun.SoundGunshot, gunUid, user);
|
||||
Audio.PlayPredicted(gun.SoundGunshotModified, gunUid, user);
|
||||
|
||||
if (cartridge.DeleteOnSpawn)
|
||||
Del(ent.Value);
|
||||
@@ -211,7 +191,7 @@ public sealed partial class GunSystem : SharedGunSystem
|
||||
case AmmoComponent newAmmo:
|
||||
shotProjectiles.Add(ent!.Value);
|
||||
MuzzleFlash(gunUid, newAmmo, user);
|
||||
Audio.PlayPredicted(gun.SoundGunshot, gunUid, user);
|
||||
Audio.PlayPredicted(gun.SoundGunshotModified, gunUid, user);
|
||||
ShootOrThrow(ent.Value, mapDirection, gunVelocity, gun, gunUid, user);
|
||||
break;
|
||||
case HitscanPrototype hitscan:
|
||||
@@ -298,7 +278,7 @@ public sealed partial class GunSystem : SharedGunSystem
|
||||
FireEffects(fromEffect, hitscan.MaxLength, dir.ToAngle(), hitscan);
|
||||
}
|
||||
|
||||
Audio.PlayPredicted(gun.SoundGunshot, gunUid, user);
|
||||
Audio.PlayPredicted(gun.SoundGunshotModified, gunUid, user);
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
@@ -325,14 +305,14 @@ public sealed partial class GunSystem : SharedGunSystem
|
||||
var angle = EnsureComp<ThrowingAngleComponent>(uid);
|
||||
angle.Angle = gun.Angle;
|
||||
}
|
||||
ThrowingSystem.TryThrow(uid, mapDirection.Normalized() * 7f * coefficient, gun.ProjectileSpeed, user);
|
||||
ThrowingSystem.TryThrow(uid, mapDirection.Normalized() * 7f * coefficient, gun.ProjectileSpeedModified, user);
|
||||
if (gun.ForceThrowingAngle)
|
||||
RemComp<ThrowingAngleComponent>(uid);
|
||||
// WD EDIT END
|
||||
return;
|
||||
}
|
||||
|
||||
ShootProjectile(uid, mapDirection, gunVelocity, gunUid, user, gun.ProjectileSpeed);
|
||||
ShootProjectile(uid, mapDirection, gunVelocity, gunUid, user, gun.ProjectileSpeedModified);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -357,7 +337,7 @@ public sealed partial class GunSystem : SharedGunSystem
|
||||
private Angle GetRecoilAngle(TimeSpan curTime, GunComponent component, Angle direction)
|
||||
{
|
||||
var timeSinceLastFire = (curTime - component.LastFire).TotalSeconds;
|
||||
var newTheta = MathHelper.Clamp(component.CurrentAngle.Theta + component.AngleIncrease.Theta - component.AngleDecay.Theta * timeSinceLastFire, component.MinAngle.Theta, component.MaxAngle.Theta);
|
||||
var newTheta = MathHelper.Clamp(component.CurrentAngle.Theta + component.AngleIncreaseModified.Theta - component.AngleDecayModified.Theta * timeSinceLastFire, component.MinAngleModified.Theta, component.MaxAngleModified.Theta);
|
||||
component.CurrentAngle = new Angle(newTheta);
|
||||
component.LastFire = component.NextFire;
|
||||
|
||||
@@ -365,7 +345,7 @@ public sealed partial class GunSystem : SharedGunSystem
|
||||
var random = Random.NextFloat(-0.5f, 0.5f);
|
||||
var spread = component.CurrentAngle.Theta * random;
|
||||
var angle = new Angle(direction.Theta + component.CurrentAngle.Theta * random);
|
||||
DebugTools.Assert(spread <= component.MaxAngle.Theta);
|
||||
DebugTools.Assert(spread <= component.MaxAngleModified.Theta);
|
||||
return angle;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user