make legs affect movement speed with body (#12928)
Co-authored-by: DrSmugleaf <DrSmugleaf@users.noreply.github.com>
This commit is contained in:
@@ -21,6 +21,13 @@ public sealed class BodyComponent : Component, IDraggable
|
|||||||
[DataField("gibSound")]
|
[DataField("gibSound")]
|
||||||
public SoundSpecifier GibSound = new SoundCollectionSpecifier("gib");
|
public SoundSpecifier GibSound = new SoundCollectionSpecifier("gib");
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The amount of legs required to move at full speed.
|
||||||
|
/// If 0, then legs do not impact speed.
|
||||||
|
/// </summary>
|
||||||
|
[DataField("requiredLegs")]
|
||||||
|
public int RequiredLegs;
|
||||||
|
|
||||||
bool IDraggable.CanStartDrag(StartDragDropEvent args)
|
bool IDraggable.CanStartDrag(StartDragDropEvent args)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -164,6 +164,32 @@ public partial class SharedBodySystem
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns all body part slots in the graph, including ones connected by
|
||||||
|
/// body parts which are null.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="partId"></param>
|
||||||
|
/// <param name="part"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public IEnumerable<BodyPartSlot> GetAllBodyPartSlots(EntityUid partId, BodyPartComponent? part = null)
|
||||||
|
{
|
||||||
|
if (!Resolve(partId, ref part, false))
|
||||||
|
yield break;
|
||||||
|
|
||||||
|
foreach (var slot in part.Children.Values)
|
||||||
|
{
|
||||||
|
if (!TryComp<BodyPartComponent>(slot.Child, out var childPart))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
yield return slot;
|
||||||
|
|
||||||
|
foreach (var child in GetAllBodyPartSlots(slot.Child.Value, childPart))
|
||||||
|
{
|
||||||
|
yield return child;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public virtual HashSet<EntityUid> GibBody(EntityUid? partId, bool gibOrgans = false,
|
public virtual HashSet<EntityUid> GibBody(EntityUid? partId, bool gibOrgans = false,
|
||||||
BodyComponent? body = null, bool deleteItems = false)
|
BodyComponent? body = null, bool deleteItems = false)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ using Content.Shared.Body.Organ;
|
|||||||
using Content.Shared.Body.Part;
|
using Content.Shared.Body.Part;
|
||||||
using Content.Shared.Damage;
|
using Content.Shared.Damage;
|
||||||
using Content.Shared.Damage.Prototypes;
|
using Content.Shared.Damage.Prototypes;
|
||||||
|
using Content.Shared.Movement.Components;
|
||||||
using Content.Shared.Random.Helpers;
|
using Content.Shared.Random.Helpers;
|
||||||
using Robust.Shared.Containers;
|
using Robust.Shared.Containers;
|
||||||
using Robust.Shared.GameStates;
|
using Robust.Shared.GameStates;
|
||||||
@@ -211,6 +212,9 @@ public partial class SharedBodySystem
|
|||||||
|
|
||||||
if (part.Body is { } newBody)
|
if (part.Body is { } newBody)
|
||||||
{
|
{
|
||||||
|
if (part.PartType == BodyPartType.Leg)
|
||||||
|
UpdateMovementSpeed(newBody);
|
||||||
|
|
||||||
var partAddedEvent = new BodyPartAddedEvent(slot.Id, part);
|
var partAddedEvent = new BodyPartAddedEvent(slot.Id, part);
|
||||||
RaiseLocalEvent(newBody, ref partAddedEvent);
|
RaiseLocalEvent(newBody, ref partAddedEvent);
|
||||||
|
|
||||||
@@ -254,9 +258,10 @@ public partial class SharedBodySystem
|
|||||||
var args = new BodyPartRemovedEvent(slot.Id, part);
|
var args = new BodyPartRemovedEvent(slot.Id, part);
|
||||||
RaiseLocalEvent(oldBody, ref args);
|
RaiseLocalEvent(oldBody, ref args);
|
||||||
|
|
||||||
if (part.PartType == BodyPartType.Leg &&
|
if (part.PartType == BodyPartType.Leg)
|
||||||
!GetBodyChildrenOfType(oldBody, BodyPartType.Leg).Any())
|
|
||||||
{
|
{
|
||||||
|
UpdateMovementSpeed(oldBody);
|
||||||
|
if(!GetBodyChildrenOfType(oldBody, BodyPartType.Leg).Any())
|
||||||
Standing.Down(oldBody);
|
Standing.Down(oldBody);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -282,6 +287,44 @@ public partial class SharedBodySystem
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void UpdateMovementSpeed(EntityUid body, BodyComponent? component = null, MovementSpeedModifierComponent? movement = null)
|
||||||
|
{
|
||||||
|
if (!Resolve(body, ref component, ref movement, false))
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (component.RequiredLegs <= 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (component.Root?.Child is not { } root)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var allSlots = GetAllBodyPartSlots(root).ToHashSet();
|
||||||
|
var allLegs = new HashSet<EntityUid>();
|
||||||
|
foreach (var slot in allSlots)
|
||||||
|
{
|
||||||
|
if (slot.Type == BodyPartType.Leg && slot.Child is { } child)
|
||||||
|
allLegs.Add(child);
|
||||||
|
}
|
||||||
|
|
||||||
|
var walkSpeed = 0f;
|
||||||
|
var sprintSpeed = 0f;
|
||||||
|
var acceleration = 0f;
|
||||||
|
foreach (var leg in allLegs)
|
||||||
|
{
|
||||||
|
if (!TryComp<MovementSpeedModifierComponent>(leg, out var legModifier))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
walkSpeed += legModifier.BaseWalkSpeed;
|
||||||
|
sprintSpeed += legModifier.BaseSprintSpeed;
|
||||||
|
acceleration += legModifier.Acceleration;
|
||||||
|
}
|
||||||
|
|
||||||
|
walkSpeed /= component.RequiredLegs;
|
||||||
|
sprintSpeed /= component.RequiredLegs;
|
||||||
|
acceleration /= component.RequiredLegs;
|
||||||
|
Movement.ChangeBaseSpeed(body, walkSpeed, sprintSpeed, acceleration, movement);
|
||||||
|
}
|
||||||
|
|
||||||
public bool DropPartAt(EntityUid? partId, EntityCoordinates dropAt, BodyPartComponent? part = null)
|
public bool DropPartAt(EntityUid? partId, EntityCoordinates dropAt, BodyPartComponent? part = null)
|
||||||
{
|
{
|
||||||
if (partId == null || !DropPart(partId, part))
|
if (partId == null || !DropPart(partId, part))
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using Content.Shared.Damage;
|
using Content.Shared.Damage;
|
||||||
|
using Content.Shared.Movement.Systems;
|
||||||
using Content.Shared.Standing;
|
using Content.Shared.Standing;
|
||||||
using Robust.Shared.Containers;
|
using Robust.Shared.Containers;
|
||||||
using Robust.Shared.Prototypes;
|
using Robust.Shared.Prototypes;
|
||||||
@@ -14,6 +15,7 @@ public abstract partial class SharedBodySystem : EntitySystem
|
|||||||
[Dependency] protected readonly SharedContainerSystem Containers = default!;
|
[Dependency] protected readonly SharedContainerSystem Containers = default!;
|
||||||
[Dependency] protected readonly DamageableSystem Damageable = default!;
|
[Dependency] protected readonly DamageableSystem Damageable = default!;
|
||||||
[Dependency] protected readonly StandingStateSystem Standing = default!;
|
[Dependency] protected readonly StandingStateSystem Standing = default!;
|
||||||
|
[Dependency] protected readonly MovementSpeedModifierSystem Movement = default!;
|
||||||
|
|
||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -37,6 +37,7 @@
|
|||||||
components:
|
components:
|
||||||
- type: BodyPart
|
- type: BodyPart
|
||||||
partType: Leg
|
partType: Leg
|
||||||
|
- type: MovementSpeedModifier
|
||||||
|
|
||||||
- type: entity
|
- type: entity
|
||||||
id: FeetAnimal
|
id: FeetAnimal
|
||||||
|
|||||||
@@ -118,6 +118,9 @@
|
|||||||
- type: BodyPart
|
- type: BodyPart
|
||||||
partType: Leg
|
partType: Leg
|
||||||
symmetry: Left
|
symmetry: Left
|
||||||
|
- type: MovementSpeedModifier
|
||||||
|
baseWalkSpeed : 1.5
|
||||||
|
baseSprintSpeed : 3.5
|
||||||
|
|
||||||
- type: entity
|
- type: entity
|
||||||
id: RightLegDiona
|
id: RightLegDiona
|
||||||
@@ -131,6 +134,9 @@
|
|||||||
- type: BodyPart
|
- type: BodyPart
|
||||||
partType: Leg
|
partType: Leg
|
||||||
symmetry: Right
|
symmetry: Right
|
||||||
|
- type: MovementSpeedModifier
|
||||||
|
baseWalkSpeed : 1.5
|
||||||
|
baseSprintSpeed : 3.5
|
||||||
|
|
||||||
- type: entity
|
- type: entity
|
||||||
id: LeftFootDiona
|
id: LeftFootDiona
|
||||||
|
|||||||
@@ -136,6 +136,7 @@
|
|||||||
- type: BodyPart
|
- type: BodyPart
|
||||||
partType: Leg
|
partType: Leg
|
||||||
symmetry: Left
|
symmetry: Left
|
||||||
|
- type: MovementSpeedModifier
|
||||||
|
|
||||||
- type: entity
|
- type: entity
|
||||||
id: RightLegHuman
|
id: RightLegHuman
|
||||||
@@ -152,6 +153,7 @@
|
|||||||
- type: BodyPart
|
- type: BodyPart
|
||||||
partType: Leg
|
partType: Leg
|
||||||
symmetry: Right
|
symmetry: Right
|
||||||
|
- type: MovementSpeedModifier
|
||||||
|
|
||||||
- type: entity
|
- type: entity
|
||||||
id: LeftFootHuman
|
id: LeftFootHuman
|
||||||
|
|||||||
@@ -134,6 +134,9 @@
|
|||||||
- type: BodyPart
|
- type: BodyPart
|
||||||
partType: Leg
|
partType: Leg
|
||||||
symmetry: Left
|
symmetry: Left
|
||||||
|
- type: MovementSpeedModifier
|
||||||
|
baseWalkSpeed : 2.7
|
||||||
|
baseSprintSpeed : 4.5
|
||||||
|
|
||||||
- type: entity
|
- type: entity
|
||||||
id: RightLegReptilian
|
id: RightLegReptilian
|
||||||
@@ -150,6 +153,9 @@
|
|||||||
- type: BodyPart
|
- type: BodyPart
|
||||||
partType: Leg
|
partType: Leg
|
||||||
symmetry: Right
|
symmetry: Right
|
||||||
|
- type: MovementSpeedModifier
|
||||||
|
baseWalkSpeed : 2.7
|
||||||
|
baseSprintSpeed : 4.5
|
||||||
|
|
||||||
- type: entity
|
- type: entity
|
||||||
id: LeftFootReptilian
|
id: LeftFootReptilian
|
||||||
|
|||||||
@@ -149,6 +149,7 @@
|
|||||||
- type: BodyPart
|
- type: BodyPart
|
||||||
partType: Leg
|
partType: Leg
|
||||||
symmetry: Left
|
symmetry: Left
|
||||||
|
- type: MovementSpeedModifier
|
||||||
|
|
||||||
- type: entity
|
- type: entity
|
||||||
id: RightLegSkeleton
|
id: RightLegSkeleton
|
||||||
@@ -165,6 +166,7 @@
|
|||||||
- type: BodyPart
|
- type: BodyPart
|
||||||
partType: Leg
|
partType: Leg
|
||||||
symmetry: Right
|
symmetry: Right
|
||||||
|
- type: MovementSpeedModifier
|
||||||
|
|
||||||
- type: entity
|
- type: entity
|
||||||
id: LeftFootSkeleton
|
id: LeftFootSkeleton
|
||||||
|
|||||||
@@ -135,6 +135,7 @@
|
|||||||
- type: BodyPart
|
- type: BodyPart
|
||||||
partType: Leg
|
partType: Leg
|
||||||
symmetry: Left
|
symmetry: Left
|
||||||
|
- type: MovementSpeedModifier
|
||||||
|
|
||||||
- type: entity
|
- type: entity
|
||||||
id: RightLegSlime
|
id: RightLegSlime
|
||||||
@@ -151,6 +152,7 @@
|
|||||||
- type: BodyPart
|
- type: BodyPart
|
||||||
partType: Leg
|
partType: Leg
|
||||||
symmetry: Right
|
symmetry: Right
|
||||||
|
- type: MovementSpeedModifier
|
||||||
|
|
||||||
- type: entity
|
- type: entity
|
||||||
id: LeftFootSlime
|
id: LeftFootSlime
|
||||||
|
|||||||
@@ -136,6 +136,7 @@
|
|||||||
- type: BodyPart
|
- type: BodyPart
|
||||||
partType: Leg
|
partType: Leg
|
||||||
symmetry: Left
|
symmetry: Left
|
||||||
|
- type: MovementSpeedModifier
|
||||||
|
|
||||||
- type: entity
|
- type: entity
|
||||||
id: RightLegVox
|
id: RightLegVox
|
||||||
@@ -152,6 +153,7 @@
|
|||||||
- type: BodyPart
|
- type: BodyPart
|
||||||
partType: Leg
|
partType: Leg
|
||||||
symmetry: Right
|
symmetry: Right
|
||||||
|
- type: MovementSpeedModifier
|
||||||
|
|
||||||
- type: entity
|
- type: entity
|
||||||
id: LeftFootVox
|
id: LeftFootVox
|
||||||
|
|||||||
@@ -711,6 +711,7 @@
|
|||||||
speechSounds: Monkey
|
speechSounds: Monkey
|
||||||
- type: Body
|
- type: Body
|
||||||
prototype: Primate
|
prototype: Primate
|
||||||
|
requiredLegs: 1 # TODO: More than 1 leg
|
||||||
- type: DamageStateVisuals
|
- type: DamageStateVisuals
|
||||||
states:
|
states:
|
||||||
Alive:
|
Alive:
|
||||||
|
|||||||
@@ -50,6 +50,7 @@
|
|||||||
Piercing: 8
|
Piercing: 8
|
||||||
- type: Body
|
- type: Body
|
||||||
prototype: Rat
|
prototype: Rat
|
||||||
|
requiredLegs: 1 # TODO: More than 1 leg
|
||||||
- type: Hunger # probably should be prototyped
|
- type: Hunger # probably should be prototyped
|
||||||
thresholds:
|
thresholds:
|
||||||
Overfed: 200
|
Overfed: 200
|
||||||
@@ -225,6 +226,7 @@
|
|||||||
Piercing: 3
|
Piercing: 3
|
||||||
- type: Body
|
- type: Body
|
||||||
prototype: Rat
|
prototype: Rat
|
||||||
|
requiredLegs: 1 # TODO: More than 1 leg
|
||||||
- type: Hunger # probably should be prototyped
|
- type: Hunger # probably should be prototyped
|
||||||
thresholds:
|
thresholds:
|
||||||
Overfed: 200
|
Overfed: 200
|
||||||
|
|||||||
@@ -177,6 +177,7 @@
|
|||||||
species: Human
|
species: Human
|
||||||
- type: Body
|
- type: Body
|
||||||
prototype: Human
|
prototype: Human
|
||||||
|
requiredLegs: 2
|
||||||
- type: Damageable
|
- type: Damageable
|
||||||
damageContainer: Biological
|
damageContainer: Biological
|
||||||
- type: RadiationReceiver
|
- type: RadiationReceiver
|
||||||
@@ -366,6 +367,7 @@
|
|||||||
species: Human
|
species: Human
|
||||||
- type: Body
|
- type: Body
|
||||||
prototype: Human
|
prototype: Human
|
||||||
|
requiredLegs: 2
|
||||||
- type: Damageable
|
- type: Damageable
|
||||||
damageContainer: Biological
|
damageContainer: Biological
|
||||||
- type: MobState
|
- type: MobState
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
state: full
|
state: full
|
||||||
- type: Body
|
- type: Body
|
||||||
prototype: Diona
|
prototype: Diona
|
||||||
|
requiredLegs: 2
|
||||||
- type: Damageable
|
- type: Damageable
|
||||||
damageContainer: Biological
|
damageContainer: Biological
|
||||||
damageModifierSet: Diona
|
damageModifierSet: Diona
|
||||||
|
|||||||
@@ -24,6 +24,7 @@
|
|||||||
scale: 1, 0.8
|
scale: 1, 0.8
|
||||||
- type: Body
|
- type: Body
|
||||||
prototype: Human
|
prototype: Human
|
||||||
|
requiredLegs: 2
|
||||||
|
|
||||||
- type: entity
|
- type: entity
|
||||||
save: false
|
save: false
|
||||||
|
|||||||
@@ -14,6 +14,7 @@
|
|||||||
state: full
|
state: full
|
||||||
- type: Body
|
- type: Body
|
||||||
prototype: Reptilian
|
prototype: Reptilian
|
||||||
|
requiredLegs: 2
|
||||||
- type: LizardAccent
|
- type: LizardAccent
|
||||||
- type: Speech
|
- type: Speech
|
||||||
speechSounds: Lizard
|
speechSounds: Lizard
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
state: full
|
state: full
|
||||||
- type: Body
|
- type: Body
|
||||||
prototype: Skeleton
|
prototype: Skeleton
|
||||||
|
requiredLegs: 2
|
||||||
gibSound: /Audio/Effects/bone_rattle.ogg
|
gibSound: /Audio/Effects/bone_rattle.ogg
|
||||||
- type: Damageable
|
- type: Damageable
|
||||||
damageContainer: Biological
|
damageContainer: Biological
|
||||||
|
|||||||
@@ -11,6 +11,7 @@
|
|||||||
state: full
|
state: full
|
||||||
- type: Body
|
- type: Body
|
||||||
prototype: Slime
|
prototype: Slime
|
||||||
|
requiredLegs: 2
|
||||||
- type: Humanoid
|
- type: Humanoid
|
||||||
species: SlimePerson
|
species: SlimePerson
|
||||||
- type: Speech
|
- type: Speech
|
||||||
|
|||||||
@@ -81,6 +81,7 @@
|
|||||||
- map: [ "pocket2" ]
|
- map: [ "pocket2" ]
|
||||||
- type: Body
|
- type: Body
|
||||||
prototype: Vox
|
prototype: Vox
|
||||||
|
requiredLegs: 2
|
||||||
# Vox nitrogen stuff is handled in their metabolism
|
# Vox nitrogen stuff is handled in their metabolism
|
||||||
- type: Respirator
|
- type: Respirator
|
||||||
damage:
|
damage:
|
||||||
@@ -110,4 +111,5 @@
|
|||||||
species: Vox
|
species: Vox
|
||||||
- type: Body
|
- type: Body
|
||||||
prototype: Vox
|
prototype: Vox
|
||||||
|
requiredLegs: 2
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user