Files

222 lines
9.0 KiB
C#
Raw Permalink Normal View History

C.H.I.M.P handcannon redesign (#19004) * Added basic alternative fire mode system for the CHIMP * Redesign of the CHIMP handcannon - the CHIMP now has an internal rechargable battery (10 shots at 100% charge) - it has three alternative fire modes, one for each particle type, that its user can easily switch between - syndicate scientists have access to an experimental version which can also fire omega particles (4 TC) - each particle type now has a distinct color and damage type: delta (red): heat, epsilon (green): radiation, zeta (yellow): shock, omega (purple): heat + radiation. This affects A.P.E.s as well - CHIMP particles now do 10 damage (up from 5) - all CHIMP particle cartridges have been removed from the game (including the syndicate omega particle ammo pack) * Code revisions * Code revisions - Removed changes to particle damage and damage types - The experimental CHIMP was removed from the syndicate uplink and replaced with an upgrade kit, which when used on a standard CHIMP will convert it to an experimental one * Code revisions - Added a 2 second DoAfter for applying the upgrade kit * Fixed spelling mistake * Update projectiles.yml Removed commented code * Update Content.Server/Weapons/Ranged/Systems/AlternativeFireModesSystem.cs Co-authored-by: Nemanja <98561806+EmoGarbage404@users.noreply.github.com> * Code revisions - Implemented changes requested by EmoGarbage - Removed UpgradeKitComponent in favor of using a construction graph - Renamed AlternativeFireModesComponent.cs to BatteryWeaponFireModesComponent.cs Textures - Reverted omega particle to being a green color - Epsilon particles are now a cyan color * Added comments * Revisions - Moved BatteryWeaponFireModesComponent from Shared to Server - Restricted access to this component to BatteryWeaponFireModesSystem - Changed the CHIMP upgrade kit to a chip - Updated the localization files to reflect this change * Delete interaction-upgrade-kit-component.ftl This file is no longer needed * Update battery_guns.yml Added new description for the experimental CHIMP * Update battery_guns.yml Updated experimental CHIMP description again... * Fixed issue with ItemComponent --------- Co-authored-by: Nemanja <98561806+EmoGarbage404@users.noreply.github.com>
2023-08-19 17:54:52 -05:00
using Content.Server.Anomaly.Components;
2023-01-17 00:05:20 -05:00
using Content.Server.Atmos.EntitySystems;
using Content.Server.Audio;
using Content.Server.Explosion.EntitySystems;
using Content.Server.Materials;
using Content.Server.Radiation.Systems;
2023-02-06 14:53:59 -05:00
using Content.Server.Radio.EntitySystems;
using Content.Server.Station.Systems;
2023-01-17 00:05:20 -05:00
using Content.Shared.Anomaly;
using Content.Shared.Anomaly.Components;
using Content.Shared.Anomaly.Prototypes;
using Content.Shared.DoAfter;
using Content.Shared.Random;
using Content.Shared.Random.Helpers;
2023-01-17 00:05:20 -05:00
using Robust.Server.GameObjects;
using Robust.Shared.Audio.Systems;
using Robust.Shared.Configuration;
2023-01-17 00:05:20 -05:00
using Robust.Shared.Physics.Events;
2023-02-06 14:53:59 -05:00
using Robust.Shared.Prototypes;
2023-01-17 00:05:20 -05:00
using Robust.Shared.Random;
using Robust.Shared.Serialization.Manager;
using System.Linq;
2023-02-06 14:53:59 -05:00
2023-01-17 00:05:20 -05:00
namespace Content.Server.Anomaly;
/// <summary>
/// This handles logic and interactions relating to <see cref="AnomalyComponent"/>
/// </summary>
public sealed partial class AnomalySystem : SharedAnomalySystem
{
[Dependency] private readonly IConfigurationManager _configuration = default!;
2023-02-06 14:53:59 -05:00
[Dependency] private readonly IPrototypeManager _prototype = default!;
2023-01-17 00:05:20 -05:00
[Dependency] private readonly AmbientSoundSystem _ambient = default!;
[Dependency] private readonly AtmosphereSystem _atmosphere = default!;
[Dependency] private readonly SharedDoAfterSystem _doAfter = default!;
2023-01-17 00:05:20 -05:00
[Dependency] private readonly ExplosionSystem _explosion = default!;
[Dependency] private readonly MaterialStorageSystem _material = default!;
2023-05-24 23:28:40 -04:00
[Dependency] private readonly SharedPointLightSystem _pointLight = default!;
[Dependency] private readonly StationSystem _station = default!;
2023-02-06 14:53:59 -05:00
[Dependency] private readonly RadioSystem _radio = default!;
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly RadiationSystem _radiation = default!;
[Dependency] private readonly SharedAudioSystem _audio = default!;
2023-01-17 00:05:20 -05:00
[Dependency] private readonly UserInterfaceSystem _ui = default!;
public const float MinParticleVariation = 0.8f;
public const float MaxParticleVariation = 1.2f;
[ValidatePrototypeId<WeightedRandomPrototype>]
const string WeightListProto = "AnomalyBehaviorList";
2023-01-17 00:05:20 -05:00
/// <inheritdoc/>
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<AnomalyComponent, MapInitEvent>(OnMapInit);
SubscribeLocalEvent<AnomalyComponent, ComponentShutdown>(OnShutdown);
SubscribeLocalEvent<AnomalyComponent, StartCollideEvent>(OnStartCollide);
InitializeGenerator();
InitializeScanner();
InitializeVessel();
2023-05-06 13:56:02 -04:00
InitializeCommands();
2023-01-17 00:05:20 -05:00
}
private void OnMapInit(Entity<AnomalyComponent> anomaly, ref MapInitEvent args)
2023-01-17 00:05:20 -05:00
{
anomaly.Comp.NextPulseTime = Timing.CurTime + GetPulseLength(anomaly.Comp) * 3; // longer the first time
ChangeAnomalyStability(anomaly, Random.NextFloat(anomaly.Comp.InitialStabilityRange.Item1 , anomaly.Comp.InitialStabilityRange.Item2), anomaly.Comp);
ChangeAnomalySeverity(anomaly, Random.NextFloat(anomaly.Comp.InitialSeverityRange.Item1, anomaly.Comp.InitialSeverityRange.Item2), anomaly.Comp);
ShuffleParticlesEffect(anomaly.Comp);
anomaly.Comp.Continuity = _random.NextFloat(anomaly.Comp.MinContituty, anomaly.Comp.MaxContituty);
SetBehavior(anomaly, GetRandomBehavior());
}
2023-01-17 00:05:20 -05:00
public void ShuffleParticlesEffect(AnomalyComponent anomaly)
{
2023-01-17 00:05:20 -05:00
var particles = new List<AnomalousParticleType>
{ AnomalousParticleType.Delta, AnomalousParticleType.Epsilon, AnomalousParticleType.Zeta, AnomalousParticleType.Sigma };
anomaly.SeverityParticleType = Random.PickAndTake(particles);
anomaly.DestabilizingParticleType = Random.PickAndTake(particles);
anomaly.WeakeningParticleType = Random.PickAndTake(particles);
anomaly.TransformationParticleType = Random.PickAndTake(particles);
2023-01-17 00:05:20 -05:00
}
private void OnShutdown(Entity<AnomalyComponent> anomaly, ref ComponentShutdown args)
2023-01-17 00:05:20 -05:00
{
EndAnomaly(anomaly);
2023-01-17 00:05:20 -05:00
}
private void OnStartCollide(Entity<AnomalyComponent> anomaly, ref StartCollideEvent args)
2023-01-17 00:05:20 -05:00
{
if (!TryComp<AnomalousParticleComponent>(args.OtherEntity, out var particle))
2023-01-17 00:05:20 -05:00
return;
2023-08-23 18:55:58 +10:00
if (args.OtherFixtureId != particle.FixtureId)
2023-01-17 00:05:20 -05:00
return;
var behaviorMod = 1f;
if (anomaly.Comp.CurrentBehavior != null)
{
var b = _prototype.Index(anomaly.Comp.CurrentBehavior.Value);
behaviorMod = b.ParticleSensivity;
}
2023-01-17 00:05:20 -05:00
// small function to randomize because it's easier to read like this
float VaryValue(float v) => v * behaviorMod * Random.NextFloat(MinParticleVariation, MaxParticleVariation);
2023-01-17 00:05:20 -05:00
if (particle.ParticleType == anomaly.Comp.DestabilizingParticleType || particle.DestabilzingOverride)
2023-01-17 00:05:20 -05:00
{
ChangeAnomalyStability(anomaly, VaryValue(particle.StabilityPerDestabilizingHit), anomaly.Comp);
2023-01-17 00:05:20 -05:00
}
if (particle.ParticleType == anomaly.Comp.SeverityParticleType || particle.SeverityOverride)
2023-01-17 00:05:20 -05:00
{
ChangeAnomalySeverity(anomaly, VaryValue(particle.SeverityPerSeverityHit), anomaly.Comp);
2023-01-17 00:05:20 -05:00
}
if (particle.ParticleType == anomaly.Comp.WeakeningParticleType || particle.WeakeningOverride)
2023-01-17 00:05:20 -05:00
{
ChangeAnomalyHealth(anomaly, VaryValue(particle.HealthPerWeakeningeHit), anomaly.Comp);
ChangeAnomalyStability(anomaly, VaryValue(particle.StabilityPerWeakeningeHit), anomaly.Comp);
}
if (particle.ParticleType == anomaly.Comp.TransformationParticleType || particle.TransmutationOverride)
{
ChangeAnomalySeverity(anomaly, VaryValue(particle.SeverityPerSeverityHit), anomaly.Comp);
if (_random.Prob(anomaly.Comp.Continuity))
SetBehavior(anomaly, GetRandomBehavior());
2023-01-17 00:05:20 -05:00
}
}
/// <summary>
/// Gets the amount of research points generated per second for an anomaly.
/// </summary>
/// <param name="anomaly"></param>
/// <param name="component"></param>
/// <returns>The amount of points</returns>
public int GetAnomalyPointValue(EntityUid anomaly, AnomalyComponent? component = null)
{
if (!Resolve(anomaly, ref component, false))
return 0;
var multiplier = 1f;
if (component.Stability > component.GrowthThreshold)
multiplier = component.GrowingPointMultiplier; //more points for unstable
2023-01-17 00:05:20 -05:00
//penalty of up to 50% based on health
multiplier *= MathF.Pow(1.5f, component.Health) - 0.5f;
//Apply behavior modifier
if (component.CurrentBehavior != null)
{
var behavior = _prototype.Index(component.CurrentBehavior.Value);
multiplier *= behavior.EarnPointModifier;
}
2023-02-06 00:03:53 -05:00
var severityValue = 1 / (1 + MathF.Pow(MathF.E, -7 * (component.Severity - 0.5f)));
return (int) ((component.MaxPointsPerSecond - component.MinPointsPerSecond) * severityValue * multiplier) + component.MinPointsPerSecond;
2023-01-17 00:05:20 -05:00
}
/// <summary>
/// Gets the localized name of a particle.
/// </summary>
/// <param name="type"></param>
/// <returns></returns>
public string GetParticleLocale(AnomalousParticleType type)
{
return type switch
{
AnomalousParticleType.Delta => Loc.GetString("anomaly-particles-delta"),
AnomalousParticleType.Epsilon => Loc.GetString("anomaly-particles-epsilon"),
AnomalousParticleType.Zeta => Loc.GetString("anomaly-particles-zeta"),
AnomalousParticleType.Sigma => Loc.GetString("anomaly-particles-sigma"),
2023-01-17 00:05:20 -05:00
_ => throw new ArgumentOutOfRangeException()
};
}
public override void Update(float frameTime)
{
base.Update(frameTime);
2023-02-06 14:53:59 -05:00
UpdateGenerator();
UpdateVessels();
}
#region Behavior
private string GetRandomBehavior()
{
var weightList = _prototype.Index<WeightedRandomPrototype>(WeightListProto);
return weightList.Pick(_random);
}
private void SetBehavior(Entity<AnomalyComponent> anomaly, ProtoId<AnomalyBehaviorPrototype> behaviorProto)
{
if (anomaly.Comp.CurrentBehavior == behaviorProto)
return;
if (anomaly.Comp.CurrentBehavior != null)
RemoveBehavior(anomaly, anomaly.Comp.CurrentBehavior.Value);
//event broadcast
var ev = new AnomalyBehaviorChangedEvent(anomaly, anomaly.Comp.CurrentBehavior, behaviorProto);
anomaly.Comp.CurrentBehavior = behaviorProto;
RaiseLocalEvent(anomaly, ref ev, true);
var behavior = _prototype.Index(behaviorProto);
EntityManager.AddComponents(anomaly, behavior.Components);
}
private void RemoveBehavior(Entity<AnomalyComponent> anomaly, ProtoId<AnomalyBehaviorPrototype> behaviorProto)
{
if (anomaly.Comp.CurrentBehavior == null)
return;
var behavior = _prototype.Index(anomaly.Comp.CurrentBehavior.Value);
EntityManager.RemoveComponents(anomaly, behavior.Components);
}
#endregion
2023-01-17 00:05:20 -05:00
}