Add reflection support for mobs, reflective vest, shuttle walls (#18186)

This commit is contained in:
avery
2023-07-30 18:07:45 -07:00
committed by GitHub
parent 8298b64a25
commit c15257fa21
6 changed files with 64 additions and 2 deletions

View File

@@ -9,6 +9,7 @@ public sealed class ReflectSystem : SharedReflectSystem
public override void Initialize() public override void Initialize()
{ {
base.Initialize(); base.Initialize();
SubscribeLocalEvent<ReflectComponent, EnergySwordActivatedEvent>(EnableReflect); SubscribeLocalEvent<ReflectComponent, EnergySwordActivatedEvent>(EnableReflect);
SubscribeLocalEvent<ReflectComponent, EnergySwordDeactivatedEvent>(DisableReflect); SubscribeLocalEvent<ReflectComponent, EnergySwordDeactivatedEvent>(DisableReflect);
SubscribeLocalEvent<ReflectComponent, ItemToggleActivatedEvent>(ShieldEnableReflect); SubscribeLocalEvent<ReflectComponent, ItemToggleActivatedEvent>(ShieldEnableReflect);

View File

@@ -5,6 +5,8 @@ using Content.Shared.Audio;
using Content.Shared.Database; using Content.Shared.Database;
using Content.Shared.Hands.Components; using Content.Shared.Hands.Components;
using Content.Shared.Weapons.Ranged.Events; using Content.Shared.Weapons.Ranged.Events;
using Content.Shared.Inventory;
using Content.Shared.Inventory.Events;
using Robust.Shared.Physics.Components; using Robust.Shared.Physics.Components;
using Content.Shared.Popups; using Content.Shared.Popups;
using Content.Shared.Projectiles; using Content.Shared.Projectiles;
@@ -27,15 +29,20 @@ public abstract class SharedReflectSystem : EntitySystem
[Dependency] private readonly SharedPhysicsSystem _physics = default!; [Dependency] private readonly SharedPhysicsSystem _physics = default!;
[Dependency] private readonly SharedAudioSystem _audio = default!; [Dependency] private readonly SharedAudioSystem _audio = default!;
[Dependency] private readonly SharedTransformSystem _transform = default!; [Dependency] private readonly SharedTransformSystem _transform = default!;
[Dependency] private readonly InventorySystem _inventorySystem = default!;
public override void Initialize() public override void Initialize()
{ {
base.Initialize(); base.Initialize();
SubscribeLocalEvent<HandsComponent, ProjectileReflectAttemptEvent>(OnHandReflectProjectile); SubscribeLocalEvent<HandsComponent, ProjectileReflectAttemptEvent>(OnHandReflectProjectile);
SubscribeLocalEvent<HandsComponent, HitScanReflectAttemptEvent>(OnHandsReflectHitscan); SubscribeLocalEvent<HandsComponent, HitScanReflectAttemptEvent>(OnHandsReflectHitscan);
SubscribeLocalEvent<ReflectComponent, ProjectileCollideEvent>(OnReflectCollide); SubscribeLocalEvent<ReflectComponent, ProjectileCollideEvent>(OnReflectCollide);
SubscribeLocalEvent<ReflectComponent, HitScanReflectAttemptEvent>(OnReflectHitscan); SubscribeLocalEvent<ReflectComponent, HitScanReflectAttemptEvent>(OnReflectHitscan);
SubscribeLocalEvent<ReflectComponent, GotEquippedEvent>(OnReflectEquipped);
SubscribeLocalEvent<ReflectComponent, GotUnequippedEvent>(OnReflectUnequipped);
} }
private void OnReflectCollide(EntityUid uid, ReflectComponent component, ref ProjectileCollideEvent args) private void OnReflectCollide(EntityUid uid, ReflectComponent component, ref ProjectileCollideEvent args)
@@ -160,4 +167,49 @@ public abstract class SharedReflectSystem : EntitySystem
return true; return true;
} }
private void OnReflectEquipped(EntityUid uid, ReflectComponent comp, GotEquippedEvent args)
{
if (!TryComp(args.Equipee, out ReflectComponent? reflection))
return;
reflection.Enabled = true;
// reflection probability should be: (1 - old probability) * newly-equipped item probability + old probability
// example: if entity has .25 reflection and newly-equipped item has .7, entity should have (1 - .25) * .7 + .25 = .775
reflection.ReflectProb += (1 - reflection.ReflectProb) * comp.ReflectProb;
}
private void OnReflectUnequipped(EntityUid uid, ReflectComponent comp, GotUnequippedEvent args)
{
if (!TryComp(args.Equipee, out ReflectComponent? reflection))
return;
if (!_inventorySystem.TryGetSlots(args.Equipee, out var slotDef))
return;
// you could recalculate reflectprob with new = (old - component) / (1 - component), but component=1 introduces loss
// still need to either maintain a counter or loop through all slots to determine reflection.enabled anyway?
float newProb = 1;
var reflecting = false;
foreach (var slot in slotDef)
{
if (!_inventorySystem.TryGetSlotEntity(args.Equipee, slot.Name, out var slotEnt))
continue;
if (!TryComp(slotEnt, out ReflectComponent? refcomp))
continue;
reflecting = true;
var prob = refcomp.ReflectProb;
newProb -= newProb * prob;
}
reflection.ReflectProb = 1 - newProb;
reflection.Enabled = reflecting;
}
} }

View File

@@ -94,6 +94,8 @@
Slash: 0.9 Slash: 0.9
Piercing: 0.9 Piercing: 0.9
Heat: 0.4 # this technically means it protects against fires pretty well? -heat is just for lasers and stuff, not atmos temperature Heat: 0.4 # this technically means it protects against fires pretty well? -heat is just for lasers and stuff, not atmos temperature
- type: Reflect
reflectProb: 1
- type: entity - type: entity
parent: ClothingOuterBaseLarge parent: ClothingOuterBaseLarge
@@ -246,7 +248,7 @@
Radiation: 0.8 Radiation: 0.8
- type: ClothingSpeedModifier - type: ClothingSpeedModifier
walkModifier: 0.7 walkModifier: 0.7
sprintModifier: 0.65 sprintModifier: 0.65
- type: ExplosionResistance - type: ExplosionResistance
damageCoefficient: 0.5 damageCoefficient: 0.5
- type: GroupExamine - type: GroupExamine

View File

@@ -93,4 +93,4 @@
- type: Sprite - type: Sprite
sprite: Clothing/Uniforms/Jumpsuit/ce_syndie.rsi sprite: Clothing/Uniforms/Jumpsuit/ce_syndie.rsi
- type: Clothing - type: Clothing
sprite: Clothing/Uniforms/Jumpsuit/ce_syndie.rsi sprite: Clothing/Uniforms/Jumpsuit/ce_syndie.rsi

View File

@@ -149,6 +149,9 @@
visible: false visible: false
- type: Physics - type: Physics
bodyType: KinematicController bodyType: KinematicController
- type: Reflect
enabled: false
reflectProb: 0
- type: Fixtures - type: Fixtures
fixtures: # TODO: This needs a second fixture just for mob collisions. fixtures: # TODO: This needs a second fixture just for mob collisions.
fix1: fix1:

View File

@@ -672,6 +672,8 @@
damageModifierSet: Metallic damageModifierSet: Metallic
- type: Physics - type: Physics
bodyType: Static bodyType: Static
- type: Reflect
reflectProb: 1
- type: Pullable - type: Pullable
- type: Airtight - type: Airtight
noAirWhenFullyAirBlocked: false noAirWhenFullyAirBlocked: false
@@ -743,6 +745,8 @@
acts: ["Destruction"] acts: ["Destruction"]
destroySound: destroySound:
path: /Audio/Effects/metalbreak.ogg path: /Audio/Effects/metalbreak.ogg
- type: Reflect
reflectProb: 1
- type: IconSmooth - type: IconSmooth
key: walls key: walls
base: state base: state