revenant cleanup (#10662)

This commit is contained in:
Nemanja
2022-08-18 20:04:23 -04:00
committed by GitHub
parent b8ce23f666
commit d7e0b70e2c
18 changed files with 92 additions and 388 deletions

View File

@@ -23,7 +23,9 @@ using Content.Shared.MobState;
using Content.Server.Explosion.EntitySystems;
using System.Linq;
using Content.Server.Emag;
using Content.Server.Store.Components;
using Content.Shared.CharacterAppearance.Components;
using Content.Shared.FixedPoint;
using Robust.Shared.Utility;
namespace Content.Server.Revenant.EntitySystems;
@@ -177,7 +179,9 @@ public sealed partial class RevenantSystem : EntitySystem
essence.Harvested = true;
ChangeEssenceAmount(uid, essence.EssenceAmount, component);
component.StolenEssence += essence.EssenceAmount;
if (TryComp<StoreComponent>(uid, out var store))
_store.TryAddCurrency(new Dictionary<string, FixedPoint2>()
{ {component.StolenEssenceCurrencyPrototype, essence.EssenceAmount} }, store);
if (!TryComp<MobStateComponent>(args.Target, out var mobstate))
return;

View File

@@ -1,69 +0,0 @@
using System.Linq;
using Content.Shared.Revenant;
using Content.Server.UserInterface;
using Robust.Server.GameObjects;
using Robust.Server.Player;
using Content.Shared.Actions.ActionTypes;
namespace Content.Server.Revenant.EntitySystems;
// TODO: Delete and replace all of this with StoreSystem once that's merged
// i'm sorry, but i'm not ultra-optimizing something that's getting deleted in a week.
// 8/7/22 -emo (bully me if this exists in the future)
public sealed partial class RevenantSystem : EntitySystem
{
private void InitializeShop()
{
SubscribeLocalEvent<RevenantComponent, RevenantShopActionEvent>(OnShop);
SubscribeLocalEvent<RevenantComponent, RevenantBuyListingMessage>(OnBuy);
}
private void OnShop(EntityUid uid, RevenantComponent component, RevenantShopActionEvent args)
{
if (!TryComp<ActorComponent>(uid, out var actor))
return;
ToggleUi(component, actor.PlayerSession);
}
private void OnBuy(EntityUid uid, RevenantComponent component, RevenantBuyListingMessage ev)
{
RevenantStoreListingPrototype? targetListing = null;
foreach (var listing in component.Listings)
{
if (listing.Key.ID == ev.Listing.ID)
targetListing = listing.Key;
}
if (targetListing == null)
return;
component.Listings[targetListing] = false;
if (component.StolenEssence < ev.Listing.Price)
return;
component.StolenEssence -= ev.Listing.Price;
if (_proto.TryIndex<InstantActionPrototype>(ev.Listing.ActionId, out var action))
_action.AddAction(uid, new InstantAction(action), null);
UpdateUserInterface(component);
}
public void ToggleUi(RevenantComponent component, IPlayerSession session)
{
var ui = component.Owner.GetUIOrNull(RevenantUiKey.Key);
ui?.Toggle(session);
UpdateUserInterface(component);
}
private void UpdateUserInterface(RevenantComponent component)
{
var ui = component.Owner.GetUIOrNull(RevenantUiKey.Key);
if (ui == null)
return;
var filterlistings = (from e in component.Listings where e.Value select e.Key).ToList();
ui.SetState(new RevenantUpdateState(component.StolenEssence.Float(), filterlistings));
}
}

View File

@@ -16,6 +16,8 @@ using Robust.Shared.Prototypes;
using Content.Shared.Actions.ActionTypes;
using Content.Shared.Tag;
using Content.Server.Polymorph.Systems;
using Content.Server.Store.Components;
using Content.Server.Store.Systems;
using Content.Shared.FixedPoint;
using Robust.Shared.Player;
using Content.Shared.Movement.Systems;
@@ -42,6 +44,7 @@ public sealed partial class RevenantSystem : EntitySystem
[Dependency] private readonly SharedStunSystem _stun = default!;
[Dependency] private readonly TagSystem _tag = default!;
[Dependency] private readonly MovementSpeedModifierSystem _movement = default!;
[Dependency] private readonly StoreSystem _store = default!;
public override void Initialize()
{
@@ -49,13 +52,13 @@ public sealed partial class RevenantSystem : EntitySystem
SubscribeLocalEvent<RevenantComponent, ComponentStartup>(OnStartup);
SubscribeLocalEvent<RevenantComponent, RevenantShopActionEvent>(OnShop);
SubscribeLocalEvent<RevenantComponent, DamageChangedEvent>(OnDamage);
SubscribeLocalEvent<RevenantComponent, ExaminedEvent>(OnExamine);
SubscribeLocalEvent<RevenantComponent, StatusEffectAddedEvent>(OnStatusAdded);
SubscribeLocalEvent<RevenantComponent, StatusEffectEndedEvent>(OnStatusEnded);
InitializeAbilities();
InitializeShop();
}
private void OnStartup(EntityUid uid, RevenantComponent component, ComponentStartup args)
@@ -72,10 +75,6 @@ public sealed partial class RevenantSystem : EntitySystem
if (TryComp(component.Owner, out EyeComponent? eye))
eye.VisibilityMask |= (uint) (VisibilityFlags.Ghost);
//get all the abilities
foreach (var listing in _proto.EnumeratePrototypes<RevenantStoreListingPrototype>())
component.Listings.Add(listing, true);
var shopaction = new InstantAction(_proto.Index<InstantActionPrototype>("RevenantShop"));
_action.AddAction(uid, shopaction, null);
}
@@ -133,7 +132,8 @@ public sealed partial class RevenantSystem : EntitySystem
_polymorphable.PolymorphEntity(uid, "Ectoplasm");
}
UpdateUserInterface(component);
if (TryComp<StoreComponent>(uid, out var store))
_store.UpdateUserInterface(uid, store);
return true;
}
@@ -163,6 +163,13 @@ public sealed partial class RevenantSystem : EntitySystem
return true;
}
private void OnShop(EntityUid uid, RevenantComponent component, RevenantShopActionEvent args)
{
if (!TryComp<StoreComponent>(uid, out var store))
return;
_store.ToggleUi(uid, store);
}
public override void Update(float frameTime)
{
base.Update(frameTime);

View File

@@ -4,6 +4,7 @@ using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
using System.Threading;
using Content.Shared.FixedPoint;
using Content.Shared.Store;
namespace Content.Server.Revenant;
@@ -17,11 +18,8 @@ public sealed class RevenantComponent : SharedRevenantComponent
[ViewVariables(VVAccess.ReadWrite)]
public FixedPoint2 Essence = 75;
/// <summary>
/// Used for purchasing shop items.
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
public FixedPoint2 StolenEssence = 0;
[DataField("stolenEssenceCurrencyPrototype", customTypeSerializer: typeof(PrototypeIdSerializer<CurrencyPrototype>))]
public string StolenEssenceCurrencyPrototype = "StolenEssence";
/// <summary>
/// The entity's current max amount of essence. Can be increased
@@ -189,12 +187,6 @@ public sealed class RevenantComponent : SharedRevenantComponent
[ViewVariables(VVAccess.ReadWrite), DataField("malfunctionRadius")]
public float MalfunctionRadius = 3.5f;
#endregion
/// <summary>
/// Stores all of the currently unlockable abilities in the shop.
/// </summary>
[ViewVariables]
public Dictionary<RevenantStoreListingPrototype, bool> Listings = new ();
}
public sealed class SoulSearchDoAfterComplete : EntityEventArgs