Files

210 lines
7.5 KiB
C#
Raw Permalink Normal View History

using System.Numerics;
2022-08-13 09:49:41 -04:00
using Content.Server.Actions;
using Content.Server.GameTicking;
2022-08-18 20:04:23 -04:00
using Content.Server.Store.Components;
using Content.Server.Store.Systems;
using Content.Shared._White.Chaplain;
using Content.Shared.Alert;
using Content.Shared.Damage;
using Content.Shared.DoAfter;
using Content.Shared.Examine;
using Content.Shared.Eye;
2022-08-13 09:49:41 -04:00
using Content.Shared.FixedPoint;
using Content.Shared.Interaction;
2022-08-13 09:49:41 -04:00
using Content.Shared.Maps;
using Content.Shared.Mobs.Systems;
2022-08-13 09:49:41 -04:00
using Content.Shared.Physics;
using Content.Shared.Popups;
using Content.Shared.Revenant;
using Content.Shared.Revenant.Components;
using Content.Shared.StatusEffect;
using Content.Shared.Stunnable;
using Content.Shared.Tag;
using Content.Shared.Weapons.Melee;
using Content.Shared.Weapons.Melee.Events;
using Robust.Server.GameObjects;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
2022-08-13 09:49:41 -04:00
namespace Content.Server.Revenant.EntitySystems;
public sealed partial class RevenantSystem : EntitySystem
{
[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly ActionsSystem _action = default!;
[Dependency] private readonly AlertsSystem _alerts = default!;
[Dependency] private readonly DamageableSystem _damage = default!;
[Dependency] private readonly EntityLookupSystem _lookup = default!;
[Dependency] private readonly MobStateSystem _mobState = default!;
[Dependency] private readonly PhysicsSystem _physics = default!;
[Dependency] private readonly SharedDoAfterSystem _doAfter = default!;
[Dependency] private readonly SharedEyeSystem _eye = default!;
2022-08-13 09:49:41 -04:00
[Dependency] private readonly StatusEffectsSystem _statusEffects = default!;
[Dependency] private readonly SharedInteractionSystem _interact = default!;
[Dependency] private readonly SharedPopupSystem _popup = default!;
[Dependency] private readonly SharedStunSystem _stun = default!;
2022-08-18 20:04:23 -04:00
[Dependency] private readonly StoreSystem _store = default!;
[Dependency] private readonly TagSystem _tag = default!;
2022-08-13 09:49:41 -04:00
[ValidatePrototypeId<EntityPrototype>]
private const string RevenantShopId = "ActionRevenantShop";
2022-08-13 09:49:41 -04:00
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<RevenantComponent, ComponentStartup>(OnStartup);
SubscribeLocalEvent<RevenantComponent, MapInitEvent>(OnMapInit);
2022-08-13 09:49:41 -04:00
2022-08-18 20:04:23 -04:00
SubscribeLocalEvent<RevenantComponent, RevenantShopActionEvent>(OnShop);
2022-08-13 09:49:41 -04:00
SubscribeLocalEvent<RevenantComponent, DamageChangedEvent>(OnDamage);
SubscribeLocalEvent<RevenantComponent, ExaminedEvent>(OnExamine);
SubscribeLocalEvent<RevenantComponent, StatusEffectAddedEvent>(OnStatusAdded);
SubscribeLocalEvent<RevenantComponent, StatusEffectEndedEvent>(OnStatusEnded);
SubscribeLocalEvent<RevenantComponent, AttackedEvent>(OnAttacked); // WD EDIT
2022-08-13 09:49:41 -04:00
InitializeAbilities();
}
// WD START
private void OnAttacked(Entity<RevenantComponent> ent, ref AttackedEvent args)
{
if (!HasComp<HolyWeaponComponent>(args.Used) || !TryComp(args.Used, out MeleeWeaponComponent? weapon))
return;
args.BonusDamage = weapon.Damage;
}
// WD END
2022-08-13 09:49:41 -04:00
private void OnStartup(EntityUid uid, RevenantComponent component, ComponentStartup args)
{
//update the icon
ChangeEssenceAmount(uid, 0, component);
//default the visuals
_appearance.SetData(uid, RevenantVisuals.Corporeal, false);
_appearance.SetData(uid, RevenantVisuals.Harvesting, false);
_appearance.SetData(uid, RevenantVisuals.Stunned, false);
//ghost vision
2023-02-12 07:39:14 -05:00
if (TryComp(uid, out EyeComponent? eye))
_eye.SetVisibilityMask(uid, eye.VisibilityMask | (int) (VisibilityFlags.Ghost), eye);
}
2022-08-13 09:49:41 -04:00
private void OnMapInit(EntityUid uid, RevenantComponent component, MapInitEvent args)
{
_action.AddAction(uid, ref component.Action, RevenantShopId);
2022-08-13 09:49:41 -04:00
}
private void OnStatusAdded(EntityUid uid, RevenantComponent component, StatusEffectAddedEvent args)
{
if (args.Key == "Stun")
_appearance.SetData(uid, RevenantVisuals.Stunned, true);
}
private void OnStatusEnded(EntityUid uid, RevenantComponent component, StatusEffectEndedEvent args)
{
if (args.Key == "Stun")
_appearance.SetData(uid, RevenantVisuals.Stunned, false);
}
private void OnExamine(EntityUid uid, RevenantComponent component, ExaminedEvent args)
{
if (args.Examiner == args.Examined)
{
args.PushMarkup(Loc.GetString("revenant-essence-amount",
("current", component.Essence.Int()), ("max", component.EssenceRegenCap.Int())));
}
}
private void OnDamage(EntityUid uid, RevenantComponent component, DamageChangedEvent args)
{
if (!HasComp<CorporealComponent>(uid) || args.DamageDelta == null)
return;
var essenceDamage = args.DamageDelta.GetTotal().Float() * component.DamageToEssenceCoefficient * -1;
2022-08-13 09:49:41 -04:00
ChangeEssenceAmount(uid, essenceDamage, component);
}
public bool ChangeEssenceAmount(EntityUid uid, FixedPoint2 amount, RevenantComponent? component = null, bool allowDeath = true, bool regenCap = false)
{
if (!Resolve(uid, ref component))
return false;
if (!allowDeath && component.Essence + amount <= 0)
return false;
component.Essence += amount;
Dirty(uid, component);
2022-08-13 09:49:41 -04:00
if (regenCap)
FixedPoint2.Min(component.Essence, component.EssenceRegenCap);
if (TryComp<StoreComponent>(uid, out var store))
2023-02-12 07:39:14 -05:00
_store.UpdateUserInterface(uid, uid, store);
_alerts.ShowAlert(uid, AlertType.Essence);
2022-08-13 09:49:41 -04:00
if (component.Essence <= 0)
{
Spawn(component.SpawnOnDeathPrototype, Transform(uid).Coordinates);
QueueDel(uid);
2022-08-13 09:49:41 -04:00
}
return true;
}
private bool TryUseAbility(EntityUid uid, RevenantComponent component, FixedPoint2 abilityCost, Vector2 debuffs)
{
if (component.Essence <= abilityCost)
{
_popup.PopupEntity(Loc.GetString("revenant-not-enough-essence"), uid, uid);
2022-08-13 09:49:41 -04:00
return false;
}
var tileref = Transform(uid).Coordinates.GetTileRef();
if (tileref != null)
{
if(_physics.GetEntitiesIntersectingBody(uid, (int) CollisionGroup.Impassable).Count > 0)
{
_popup.PopupEntity(Loc.GetString("revenant-in-solid"), uid, uid);
2022-08-13 09:49:41 -04:00
return false;
}
}
ChangeEssenceAmount(uid, abilityCost, component, false);
_statusEffects.TryAddStatusEffect<CorporealComponent>(uid, "Corporeal", TimeSpan.FromSeconds(debuffs.Y), false);
_stun.TryStun(uid, TimeSpan.FromSeconds(debuffs.X), false);
return true;
}
2022-08-18 20:04:23 -04:00
private void OnShop(EntityUid uid, RevenantComponent component, RevenantShopActionEvent args)
{
if (!TryComp<StoreComponent>(uid, out var store))
return;
2023-02-12 07:39:14 -05:00
_store.ToggleUi(uid, uid, store);
2022-08-18 20:04:23 -04:00
}
2022-08-13 09:49:41 -04:00
public override void Update(float frameTime)
{
base.Update(frameTime);
var query = EntityQueryEnumerator<RevenantComponent>();
while (query.MoveNext(out var uid, out var rev))
2022-08-13 09:49:41 -04:00
{
rev.Accumulator += frameTime;
if (rev.Accumulator <= 1)
continue;
rev.Accumulator -= 1;
if (rev.Essence < rev.EssenceRegenCap)
{
ChangeEssenceAmount(uid, rev.EssencePerSecond, rev, regenCap: true);
2022-08-13 09:49:41 -04:00
}
}
}
}