Skip to content

Commit

Permalink
Move over to NetEntity
Browse files Browse the repository at this point in the history
  • Loading branch information
vaketola committed Nov 14, 2023
1 parent 6544c37 commit 63b830a
Show file tree
Hide file tree
Showing 11 changed files with 68 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ private void OnShutdown(EntityUid uid, ShadowkinDarkSwappedComponent component,
RemoveOverlay();
}

private void OnPlayerAttached(EntityUid uid, ShadowkinDarkSwappedComponent component, PlayerAttachedEvent args)
private void OnPlayerAttached(EntityUid uid, ShadowkinDarkSwappedComponent component)//, PlayerAttachedEvent args)
{
AddOverlay();
}

private void OnPlayerDetached(EntityUid uid, ShadowkinDarkSwappedComponent component, PlayerDetachedEvent args)
private void OnPlayerDetached(EntityUid uid, ShadowkinDarkSwappedComponent component)//, PlayerDetachedEvent args)
{
RemoveOverlay();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ public override void Initialize()

private void OnBlackeye(ShadowkinBlackeyeEvent ev)
{
SetColor(ev.Uid, Color.Black);
var uid = _entity.GetEntity(ev.Ent);
SetColor(uid, Color.Black);
}


Expand All @@ -36,8 +37,9 @@ private void OnInit(EntityUid uid, ShadowkinComponent component, ComponentInit a
// Blackeye if none of the RGB values are greater than 75
if (layer.Color.R * 255 < 75 && layer.Color.G * 255 < 75 && layer.Color.B * 255 < 75)
{
// TODO Need to move this to server somehow, can't trust the client with this
RaiseNetworkEvent(new ShadowkinBlackeyeEvent(uid, false));
// TODO Need to move this to server somehow, can't trust the client with this
var ent = _entity.GetNetEntity(uid);
RaiseNetworkEvent(new ShadowkinBlackeyeEvent(ent, false));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ private void OnShutdown(EntityUid uid, ShadowkinComponent component, ComponentSh
_overlay.RemoveOverlay(_tintOverlay);
}

private void OnPlayerAttached(EntityUid uid, ShadowkinComponent component, PlayerAttachedEvent args)
private void OnPlayerAttached(EntityUid uid, ShadowkinComponent component)// , PlayerAttachedEvent args)
{
_overlay.AddOverlay(_tintOverlay);
}

private void OnPlayerDetached(EntityUid uid, ShadowkinComponent component, PlayerDetachedEvent args)
private void OnPlayerDetached(EntityUid uid, ShadowkinComponent component)// , PlayerDetachedEvent args)
{
_overlay.RemoveOverlay(_tintOverlay);
}
Expand Down
6 changes: 3 additions & 3 deletions Content.Server/SimpleStation14/Chat/ESayCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ internal sealed class ESayCommand : IConsoleCommand

public void Execute(IConsoleShell shell, string argStr, string[] args)
{
if (shell.Player is not IPlayerSession player)
/*if (shell.Player is not IPlayerSession player)
{
shell.WriteError("This command cannot be run from the server.");
return;
Expand All @@ -31,7 +31,7 @@ public void Execute(IConsoleShell shell, string argStr, string[] args)
{
shell.WriteError("You don't have an entity!");
return;
}
}*/

if (args.Length < 1)
return;
Expand All @@ -40,6 +40,6 @@ public void Execute(IConsoleShell shell, string argStr, string[] args)
if (string.IsNullOrEmpty(message))
return;

EntitySystem.Get<ChatSystem>().TrySendInGameICMessage(playerEntity, message, InGameICChatType.Empathy, false, false, shell, player, checkRadioPrefix: false);
// EntitySystem.Get<ChatSystem>().TrySendInGameICMessage(playerEntity, message, InGameICChatType.Empathy, false, false, shell, player, checkRadioPrefix: false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using Content.Server.NPC.Systems;
using Content.Server.SimpleStation14.Species.Shadowkin.Components;
using Content.Server.SimpleStation14.Species.Shadowkin.Events;
using Content.Server.Visible;
using Content.Shared.Actions;
using Content.Shared.CombatMode.Pacification;
using Content.Shared.Cuffs.Components;
Expand Down Expand Up @@ -64,6 +63,8 @@ private void Shutdown(EntityUid uid, ShadowkinDarkSwapPowerComponent component,

private void DarkSwap(EntityUid uid, ShadowkinDarkSwapPowerComponent component, ShadowkinDarkSwapEvent args)
{
var performer = _entity.GetNetEntity(args.Performer);

// Need power to drain power
if (!_entity.HasComponent<ShadowkinComponent>(args.Performer))
return;
Expand All @@ -77,7 +78,7 @@ private void DarkSwap(EntityUid uid, ShadowkinDarkSwapPowerComponent component,
var hasComp = _entity.HasComponent<ShadowkinDarkSwappedComponent>(args.Performer);

SetDarkened(
args.Performer,
performer,
!hasComp,
!hasComp,
!hasComp,
Expand All @@ -98,7 +99,7 @@ private void DarkSwap(EntityUid uid, ShadowkinDarkSwapPowerComponent component,


public void SetDarkened(
EntityUid performer,
NetEntity performer,
bool addComp,
bool invisible,
bool pacify,
Expand All @@ -114,34 +115,36 @@ public void SetDarkened(
ShadowkinDarkSwapEvent? args
)
{
var ev = new ShadowkinDarkSwapAttemptEvent(performer);
var performerUid = _entity.GetEntity(performer);

var ev = new ShadowkinDarkSwapAttemptEvent(performerUid);
RaiseLocalEvent(ev);
if (ev.Cancelled)
return;

if (addComp)
{
var comp = _entity.EnsureComponent<ShadowkinDarkSwappedComponent>(performer);
var comp = _entity.EnsureComponent<ShadowkinDarkSwappedComponent>(performerUid);
comp.Invisible = invisible;
comp.Pacify = pacify;
comp.Darken = darken;

RaiseNetworkEvent(new ShadowkinDarkSwappedEvent(performer, true));

_audio.PlayPvs(soundOn, performer, AudioParams.Default.WithVolume(volumeOn));
_audio.PlayPvs(soundOn, performerUid, AudioParams.Default.WithVolume(volumeOn));

_power.TryAddPowerLevel(performer, -powerCostOn);
_stamina.TakeStaminaDamage(performer, staminaCostOn);
_power.TryAddPowerLevel(performerUid, -powerCostOn);
_stamina.TakeStaminaDamage(performerUid, staminaCostOn);
}
else
{
_entity.RemoveComponent<ShadowkinDarkSwappedComponent>(performer);
_entity.RemoveComponent<ShadowkinDarkSwappedComponent>(performerUid);
RaiseNetworkEvent(new ShadowkinDarkSwappedEvent(performer, false));

_audio.PlayPvs(soundOff, performer, AudioParams.Default.WithVolume(volumeOff));
_audio.PlayPvs(soundOff, performerUid, AudioParams.Default.WithVolume(volumeOff));

_power.TryAddPowerLevel(performer, -powerCostOff);
_stamina.TakeStaminaDamage(performer, staminaCostOff);
_power.TryAddPowerLevel(performerUid, -powerCostOff);
_stamina.TakeStaminaDamage(performerUid, staminaCostOff);
}

if (args != null)
Expand Down Expand Up @@ -198,8 +201,8 @@ public void SetVisibility(EntityUid uid, bool set)
eye.VisibilityMask |= (uint) VisibilityFlags.DarkSwapInvisibility;*/

// Make other entities unable to see the entity unless also DarkSwapped
_visibility.AddLayer(uid, visibility, (int) VisibilityFlags.DarkSwapInvisibility, false);
_visibility.RemoveLayer(uid, visibility, (int) VisibilityFlags.Normal, false);
// _visibility.AddLayer(uid, visibility, (int) VisibilityFlags.DarkSwapInvisibility, false);
// _visibility.RemoveLayer(uid, visibility, (int) VisibilityFlags.Normal, false);
_visibility.RefreshVisibility(uid);

// If not a ghost, add a stealth shader to the entity
Expand All @@ -213,8 +216,8 @@ public void SetVisibility(EntityUid uid, bool set)
eye.VisibilityMask &= ~(uint) VisibilityFlags.DarkSwapInvisibility;*/

// Make other entities able to see the entity again
_visibility.RemoveLayer(uid, visibility, (int) VisibilityFlags.DarkSwapInvisibility, false);
_visibility.AddLayer(uid, visibility, (int) VisibilityFlags.Normal, false);
// _visibility.RemoveLayer(uid, visibility, (int) VisibilityFlags.DarkSwapInvisibility, false);
// _visibility.AddLayer(uid, visibility, (int) VisibilityFlags.Normal, false);
_visibility.RefreshVisibility(uid);

// Remove the stealth shader from the entity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ private void Startup(EntityUid uid, ShadowkinTeleportPowerComponent component, C
{
var componentActionShadowkinTeleport = component.ActionShadowkinTeleport;
_actions.AddAction(uid, ref componentActionShadowkinTeleport, "ActionShadowkinTeleport");
// _actions.AddAction(uid, new WorldTargetAction(_prototype.Index<WorldTargetActionPrototype>("ShadowkinTeleport")), null);
// // _actions.AddAction(uid, new WorldTargetAction(_prototype.Index<WorldTargetActionPrototype>("ShadowkinTeleport")), null);
}

private void Shutdown(EntityUid uid, ShadowkinTeleportPowerComponent component, ComponentShutdown args)
{
_actions.RemoveAction(uid, component.ActionShadowkinTeleport);
// _actions.RemoveAction(uid, new WorldTargetAction(_prototype.Index<WorldTargetActionPrototype>("ShadowkinTeleport")));
// // _actions.RemoveAction(uid, new WorldTargetAction(_prototype.Index<WorldTargetActionPrototype>("ShadowkinTeleport")));
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,9 @@ public void SetPowerLevel(EntityUid uid, float newPowerLevel)
/// </summary>
public bool TryBlackeye(EntityUid uid)
{
var ent = _entity.GetNetEntity(uid);
// Raise an attempted blackeye event
var ev = new ShadowkinBlackeyeAttemptEvent(uid);
var ev = new ShadowkinBlackeyeAttemptEvent(ent);
RaiseLocalEvent(ev);
if (ev.Cancelled)
return false;
Expand All @@ -215,6 +216,8 @@ public bool TryBlackeye(EntityUid uid)
/// </summary>
public void Blackeye(EntityUid uid)
{
var ent = _entity.GetNetEntity(uid);

// Get shadowkin component
if (!_entity.TryGetComponent<ShadowkinComponent>(uid, out var component))
{
Expand All @@ -223,8 +226,8 @@ public void Blackeye(EntityUid uid)
}

component.Blackeye = true;
RaiseNetworkEvent(new ShadowkinBlackeyeEvent(uid));
RaiseLocalEvent(new ShadowkinBlackeyeEvent(uid));
RaiseNetworkEvent(new ShadowkinBlackeyeEvent(ent));
RaiseLocalEvent(new ShadowkinBlackeyeEvent(ent));
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ namespace Content.Server.SimpleStation14.Species.Shadowkin.Systems;

public sealed class ShadowkinBlackeyeTraitSystem : EntitySystem
{
[Dependency] private readonly IEntityManager _entity = default!;

public override void Initialize()
{
base.Initialize();
Expand All @@ -15,7 +17,8 @@ public override void Initialize()

private void OnStartup(EntityUid uid, ShadowkinBlackeyeTraitComponent _, ComponentStartup args)
{
RaiseLocalEvent(uid, new ShadowkinBlackeyeEvent(uid, false));
RaiseNetworkEvent(new ShadowkinBlackeyeEvent(uid, false));
var ent = _entity.GetNetEntity(uid);
RaiseLocalEvent(uid, new ShadowkinBlackeyeEvent(ent, false));
RaiseNetworkEvent(new ShadowkinBlackeyeEvent(ent, false));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,54 +34,57 @@ public override void Initialize()

private void OnBlackeyeAttempt(ShadowkinBlackeyeAttemptEvent ev)
{
if (!_entity.TryGetComponent<ShadowkinComponent>(ev.Uid, out var component) ||
var uid = _entity.GetEntity(ev.Ent);
if (!_entity.TryGetComponent<ShadowkinComponent>(uid, out var component) ||
component.Blackeye ||
!(component.PowerLevel <= ShadowkinComponent.PowerThresholds[ShadowkinPowerThreshold.Min] + 5))
ev.Cancel();
}

private void OnBlackeye(ShadowkinBlackeyeEvent ev)
{
var uid = _entity.GetEntity(ev.Ent);

// Check if the entity is a shadowkin
if (!_entity.TryGetComponent<ShadowkinComponent>(ev.Uid, out var component))
if (!_entity.TryGetComponent<ShadowkinComponent>(uid, out var component))
return;

// Stop gaining power
component.Blackeye = true;
component.PowerLevelGainEnabled = false;
_power.SetPowerLevel(ev.Uid, ShadowkinComponent.PowerThresholds[ShadowkinPowerThreshold.Min]);
_power.SetPowerLevel(uid, ShadowkinComponent.PowerThresholds[ShadowkinPowerThreshold.Min]);

// Update client state
Dirty(component);

// Remove powers
_entity.RemoveComponent<ShadowkinDarkSwapPowerComponent>(ev.Uid);
_entity.RemoveComponent<ShadowkinDarkSwappedComponent>(ev.Uid);
_entity.RemoveComponent<ShadowkinRestPowerComponent>(ev.Uid);
_entity.RemoveComponent<ShadowkinTeleportPowerComponent>(ev.Uid);
_entity.RemoveComponent<ShadowkinDarkSwapPowerComponent>(uid);
_entity.RemoveComponent<ShadowkinDarkSwappedComponent>(uid);
_entity.RemoveComponent<ShadowkinRestPowerComponent>(uid);
_entity.RemoveComponent<ShadowkinTeleportPowerComponent>(uid);


if (!ev.Damage)
return;

// Popup
_popup.PopupEntity(Loc.GetString("shadowkin-blackeye"), ev.Uid, ev.Uid, PopupType.Large);
_popup.PopupEntity(Loc.GetString("shadowkin-blackeye"), uid, uid, PopupType.Large);

// Stamina crit
if (_entity.TryGetComponent<StaminaComponent>(ev.Uid, out var stamina))
if (_entity.TryGetComponent<StaminaComponent>(uid, out var stamina))
{
_stamina.TakeStaminaDamage(ev.Uid, stamina.CritThreshold, null, ev.Uid);
_stamina.TakeStaminaDamage(uid, stamina.CritThreshold, null, uid);
}

// Nearly crit with cellular damage
// If already 5 damage off of crit, don't do anything
if (!_entity.TryGetComponent<DamageableComponent>(ev.Uid, out var damageable) ||
!_mobThreshold.TryGetThresholdForState(ev.Uid, MobState.Critical, out var key))
if (!_entity.TryGetComponent<DamageableComponent>(uid, out var damageable) ||
!_mobThreshold.TryGetThresholdForState(uid, MobState.Critical, out var key))
return;

var minus = damageable.TotalDamage;

_damageable.TryChangeDamage(ev.Uid,
_damageable.TryChangeDamage(uid,
new DamageSpecifier(_prototype.Index<DamageTypePrototype>("Cellular"),
Math.Max((double) (key.Value - minus - 5), 0)),
true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ namespace Content.Shared.SimpleStation14.Species.Shadowkin.Events;
/// </summary>
public sealed class ShadowkinBlackeyeAttemptEvent : CancellableEntityEventArgs
{
public readonly EntityUid Uid;
public readonly NetEntity Ent;

public ShadowkinBlackeyeAttemptEvent(EntityUid uid)
public ShadowkinBlackeyeAttemptEvent(NetEntity ent)
{
Uid = uid;
Ent = ent;
}
}

Expand All @@ -21,12 +21,12 @@ public ShadowkinBlackeyeAttemptEvent(EntityUid uid)
[Serializable, NetSerializable]
public sealed class ShadowkinBlackeyeEvent : EntityEventArgs
{
public readonly EntityUid Uid;
public readonly NetEntity Ent;
public readonly bool Damage;

public ShadowkinBlackeyeEvent(EntityUid uid, bool damage = true)
public ShadowkinBlackeyeEvent(NetEntity ent, bool damage = true)
{
Uid = uid;
Ent = ent;
Damage = damage;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ namespace Content.Shared.SimpleStation14.Species.Shadowkin.Events;
[Serializable, NetSerializable]
public sealed class ShadowkinDarkSwappedEvent : EntityEventArgs
{
public EntityUid Performer { get; }
public NetEntity Performer { get; }
public bool DarkSwapped { get; }

public ShadowkinDarkSwappedEvent(EntityUid performer, bool darkSwapped)
public ShadowkinDarkSwappedEvent(NetEntity performer, bool darkSwapped)
{
Performer = performer;
DarkSwapped = darkSwapped;
Expand Down

0 comments on commit 63b830a

Please sign in to comment.