Skip to content

Commit

Permalink
damage system refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
VMSolidus committed Feb 17, 2024
1 parent 3a59fb4 commit 88ceff8
Show file tree
Hide file tree
Showing 43 changed files with 114 additions and 20 deletions.
6 changes: 6 additions & 0 deletions Content.Client/Nyanotrasen/Lamiae/ClientLamiaVisuals.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Robust.Client.GameObjects;
using System.Numerics;
using Content.Shared.Nyanotrasen.Lamiae;

namespace Content.Client.Nyanotrasen.Lamiae;
Expand All @@ -16,6 +17,11 @@ private void OnAppearanceChange(EntityUid uid, LamiaSegmentComponent component,
{
if (args.Sprite == null) return;

if (AppearanceSystem.TryGetData<float>(uid, ScaleVisuals.Scale, out var scale) && TryComp<SpriteComponent>(uid, out var sprite))
{
sprite.Scale = (new Vector2(scale, scale));
}

if (AppearanceSystem.TryGetData<bool>(uid, LamiaSegmentVisualLayers.Armor, out var worn)
&& AppearanceSystem.TryGetData<string>(uid, LamiaSegmentVisualLayers.ArmorRsi, out var path))
{
Expand Down
35 changes: 30 additions & 5 deletions Content.Server/Nyanotrasen/Lamiae/LamiaSystem.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Robust.Shared.Physics;
using Content.Shared.Damage;
using Content.Shared.Explosion;
using Content.Shared.Clothing.Components;
using Content.Shared.Humanoid;
using Content.Shared.Humanoid.Markings;
Expand All @@ -8,7 +9,6 @@
using Content.Shared.Tag;
using Content.Shared.Standing;
using Content.Shared.Storage.Components;
using Robust.Shared.Prototypes;
using Robust.Shared.Containers;
using Robust.Shared.Map;
using Robust.Shared.Physics.Systems;
Expand Down Expand Up @@ -58,9 +58,9 @@ public override void Update(float frameTime)
revoluteJoint.CollideConnected = false;
}
if (segment.segment.SegmentNumber < segment.segment.MaxSegments)
Transform(segmentUid).Coordinates = Transform(attachedUid).Coordinates.Offset(new Vector2(0f, 0.15f));
Transform(segmentUid).Coordinates = Transform(attachedUid).Coordinates.Offset(new Vector2(0, segment.segment.OffsetSwitching));
else
Transform(segmentUid).Coordinates = Transform(attachedUid).Coordinates.Offset(new Vector2(0, 0.1f));
Transform(segmentUid).Coordinates = Transform(attachedUid).Coordinates.Offset(new Vector2(0, segment.segment.OffsetSwitching));

var joint = _jointSystem.CreateDistanceJoint(attachedUid, segmentUid, id: ("Segment" + segment.segment.SegmentNumber + segment.segment.Lamia));
joint.CollideConnected = false;
Expand All @@ -84,6 +84,7 @@ public override void Initialize()
SubscribeLocalEvent<LamiaComponent, DidUnequipEvent>(OnDidUnequipEvent);
SubscribeLocalEvent<LamiaSegmentComponent, BeforeDamageChangedEvent>(OnHitSelf);
SubscribeLocalEvent<LamiaSegmentComponent, StandAttemptEvent>(TailCantStand);
SubscribeLocalEvent<LamiaSegmentComponent, GetExplosionResistanceEvent>(OnSnekBoom);
}

/// <summary>
Expand All @@ -101,6 +102,9 @@ private void OnSegmentSpawned(EntityUid uid, LamiaSegmentComponent component, Se

if (!TryComp<HumanoidAppearanceComponent>(uid, out var species)) return;
if (!TryComp<HumanoidAppearanceComponent>(args.Lamia, out var humanoid)) return;
if (!TryComp<AppearanceComponent>(uid, out var appearance)) return;

_appearance.SetData(uid, ScaleVisuals.Scale, component.ScaleFactor, appearance);

if (humanoid.MarkingSet.TryGetCategory(MarkingCategories.Tail, out var tailMarkings))
{
Expand All @@ -116,6 +120,7 @@ private void OnSegmentSpawned(EntityUid uid, LamiaSegmentComponent component, Se

private void OnInit(EntityUid uid, LamiaComponent component, ComponentInit args)
{
component.DamageModifierConstant = Math.Clamp(component.DamageModifierConstant, 1, component.NumberOfSegments);
SpawnSegments(uid, component);
}

Expand Down Expand Up @@ -154,7 +159,7 @@ private void OnRemovedFromContainer(EntityUid uid, LamiaComponent component, Ent

private void HandleSegmentDamage(EntityUid uid, LamiaSegmentComponent component, DamageModifyEvent args)
{
args.Damage = args.Damage / component.DamageModifyFactor / 5;
args.Damage = args.Damage / component.DamageModifyFactor;
}
private void HandleDamageTransfer(EntityUid uid, LamiaSegmentComponent component, DamageChangedEvent args)
{
Expand Down Expand Up @@ -190,18 +195,33 @@ private void SpawnSegments(EntityUid uid, LamiaComponent component)
private EntityUid AddSegment(EntityUid uid, EntityUid lamia, LamiaComponent lamiaComponent, int segmentNumber)
{
LamiaSegmentComponent segmentComponent = new();
segmentComponent.Lamia = lamia;
segmentComponent.AttachedToUid = uid;
segmentComponent.MaxSegments = lamiaComponent.NumberOfSegments;
segmentComponent.DamageModifyFactor = lamiaComponent.NumberOfSegments;
float taperConstant = segmentComponent.MaxSegments / 2;
float damageModifyCoefficient = lamiaComponent.DamageModifierConstant / lamiaComponent.NumberOfSegments;
segmentComponent.DamageModifyFactor = lamiaComponent.DamageModifierConstant * damageModifyCoefficient;
segmentComponent.ExplosiveModifyFactor = 1 / segmentComponent.DamageModifyFactor / (segmentComponent.MaxSegments / 10);

EntityUid segment;
if (segmentNumber == 1)
segment = EntityManager.SpawnEntity("LamiaInitialSegment", Transform(uid).Coordinates);
else
segment = EntityManager.SpawnEntity("LamiaSegment", Transform(uid).Coordinates);
if (segmentNumber >= taperConstant)
{
segmentComponent.OffsetSwitching = 0.15f * MathF.Pow(1.02f, segmentNumber);
segmentComponent.ScaleFactor = MathF.Pow(0.99f, segmentNumber);
}
if (segmentNumber % 2 != 0)
{
segmentComponent.OffsetSwitching *= -1;
}

segmentComponent.Owner = segment;
segmentComponent.SegmentNumber = segmentNumber;
EntityManager.AddComponent(segment, segmentComponent, true);

_segments.Enqueue((segmentComponent, lamia));
lamiaComponent.Segments.Add(segmentComponent.Owner);
return segment;
Expand Down Expand Up @@ -232,6 +252,11 @@ private void OnDidEquipEvent(EntityUid equipee, LamiaComponent component, DidEqu
}
}

private void OnSnekBoom(EntityUid uid, LamiaSegmentComponent component, ref GetExplosionResistanceEvent args)
{
args.DamageCoefficient = component.ExplosiveModifyFactor;
}

private void OnDidUnequipEvent(EntityUid equipee, LamiaComponent component, DidUnequipEvent args)
{
if (args.Slot == "outerClothing" && _tagSystem.HasTag(args.Equipment, LamiaHardsuitTag))
Expand Down
7 changes: 7 additions & 0 deletions Content.Shared/Nyanotrasen/Lamiae/LamiaComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,12 @@ public sealed partial class LamiaComponent : Component

[DataField("numberOfSegments")]
public int NumberOfSegments = 30;

/// <summary>
/// Used to derive how much damage should transfer from segments to body. Higher = less damage transfered.
/// Clamped to NumberOfSegments as a maximum value
/// </summary>
[DataField("damageModifierConstant")]
public float DamageModifierConstant = 8f;
}
}
7 changes: 5 additions & 2 deletions Content.Shared/Nyanotrasen/Lamiae/LamiaSegmentComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ namespace Content.Shared.Nyanotrasen.Lamiae
public sealed partial class LamiaSegmentComponent : Component
{
public EntityUid AttachedToUid = default!;
public int DamageModifyFactor = default!;
public bool SexChanged = false;
public float DamageModifyFactor = default!;
public float OffsetSwitching = 0.15f;
public float ScaleFactor = 1f;
public float DamageModifierCoefficient = default!;
public float ExplosiveModifyFactor = default!;
public EntityUid Lamia = default!;
public int SegmentNumber = default!;
public int MaxSegments = default!;
Expand Down
27 changes: 14 additions & 13 deletions Resources/Prototypes/Nyanotrasen/Entities/Mobs/Species/lamia.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,19 @@
- type: NoSlip
- type: Internals
- type: MobState
- type: DamageVisuals
thresholds: [ 60, 120, 200 ] #these values aren't final, adjust accordingly with thresholds above'
targetLayers:
- "enum.HumanoidVisualLayers.Chest"
- "enum.HumanoidVisualLayers.Head"
- "enum.HumanoidVisualLayers.LArm"
- "enum.HumanoidVisualLayers.RArm"
damageOverlayGroups:
Brute:
sprite: Nyanotrasen/Mobs/Effects/Lamia/brute_damage.rsi
color: "#FF0000"
Burn:
sprite: Nyanotrasen/Mobs/Effects/Lamia/burn_damage.rsi
- type: MobThresholds
thresholds:
0: Alive
Expand All @@ -137,19 +150,6 @@
- type: BuckleVisualizer
- type: CreamPiedVisualizer
state: creampie_human
- type: DamageVisuals
thresholds: [ 60, 120, 200 ] #these values aren't final, adjust accordingly with thresholds above'
targetLayers:
- "enum.HumanoidVisualLayers.Chest"
- "enum.HumanoidVisualLayers.Head"
- "enum.HumanoidVisualLayers.LArm"
- "enum.HumanoidVisualLayers.RArm"
damageOverlayGroups:
Brute:
sprite: Mobs/Effects/brute_damage.rsi
color: "#FF0000"
Burn:
sprite: Mobs/Effects/burn_damage.rsi
- type: FireVisuals
sprite: Mobs/Effects/onfire.rsi
normalState: Generic_mob_burning
Expand Down Expand Up @@ -202,6 +202,7 @@
layer:
- MobLayer
- type: Lamia
damageModifierConstant: 12
- type: Speech
speechSounds: Alto
- type: Vocal
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"version": 1,
"license": "CC-BY-SA-3.0",
"copyright": "Taken from https://github.com/Citadel-Station-13/Citadel-Station-13/blob/971ddef989f7f4f365a714ef3d4df5dea2d53d9a/icons/mob/dam_mob.dmi",
"size": {"x": 32, "y": 32},
"states": [
{"name": "Head_Brute_60", "directions": 4},
{"name": "LArm_Brute_60", "directions": 4},
{"name": "LLeg_Brute_60", "directions": 4},
{"name": "RArm_Brute_60", "directions": 4},
{"name": "RLeg_Brute_60", "directions": 4},
{"name": "Chest_Brute_60", "directions": 4},
{"name": "Head_Brute_120", "directions": 4},
{"name": "LArm_Brute_120", "directions": 4},
{"name": "LLeg_Brute_120", "directions": 4},
{"name": "RArm_Brute_120", "directions": 4},
{"name": "RLeg_Brute_120", "directions": 4},
{"name": "Chest_Brute_120", "directions": 4},
{"name": "Head_Brute_200", "directions": 4},
{"name": "LArm_Brute_200", "directions": 4},
{"name": "LLeg_Brute_200", "directions": 4},
{"name": "RArm_Brute_200", "directions": 4},
{"name": "RLeg_Brute_200", "directions": 4},
{"name": "Chest_Brute_200", "directions": 4}
]
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"version": 1,
"license": "CC-BY-SA-3.0",
"copyright": "Taken from https://github.com/Citadel-Station-13/Citadel-Station-13/blob/971ddef989f7f4f365a714ef3d4df5dea2d53d9a/icons/mob/dam_mob.dmi",
"size": {"x": 32, "y": 32},
"states": [
{"name": "Head_Burn_60", "directions": 4},
{"name": "LArm_Burn_60", "directions": 4},
{"name": "LLeg_Burn_60", "directions": 4},
{"name": "RArm_Burn_60", "directions": 4},
{"name": "RLeg_Burn_60", "directions": 4},
{"name": "Chest_Burn_60", "directions": 4},
{"name": "Head_Burn_120", "directions": 4},
{"name": "LArm_Burn_120", "directions": 4},
{"name": "LLeg_Burn_120", "directions": 4},
{"name": "RArm_Burn_120", "directions": 4},
{"name": "RLeg_Burn_120", "directions": 4},
{"name": "Chest_Burn_120", "directions": 4},
{"name": "Head_Burn_200", "directions": 4},
{"name": "LArm_Burn_200", "directions": 4},
{"name": "LLeg_Burn_200", "directions": 4},
{"name": "RArm_Burn_200", "directions": 4},
{"name": "RLeg_Burn_200", "directions": 4},
{"name": "Chest_Burn_200", "directions": 4}
]
}

0 comments on commit 88ceff8

Please sign in to comment.