Skip to content

Commit

Permalink
Merge pull request #996 from Darkmajia/ling-refine-economy-rebalance
Browse files Browse the repository at this point in the history
changeling economy rebalance
  • Loading branch information
formlessnameless authored Dec 12, 2024
2 parents e1d1917 + 3951231 commit 948a214
Show file tree
Hide file tree
Showing 9 changed files with 117 additions and 42 deletions.
4 changes: 2 additions & 2 deletions Content.Server/Store/Systems/StoreSystem.Refund.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ private void OnEntityRemoved(EntityUid uid, StoreRefundComponent component, EntR
if (component.StoreEntity == null || _actions.TryGetActionData(uid, out _, false) || !TryComp<StoreComponent>(component.StoreEntity.Value, out var storeComp))
return;

DisableRefund(component.StoreEntity.Value, storeComp);
DisableRefund(uid, component.StoreEntity.Value, storeComp);
}

private void OnEntityInserted(EntityUid uid, StoreRefundComponent component, EntInsertedIntoContainerMessage args)
{
if (component.StoreEntity == null || _actions.TryGetActionData(uid, out _) || !TryComp<StoreComponent>(component.StoreEntity.Value, out var storeComp))
return;

DisableRefund(component.StoreEntity.Value, storeComp);
DisableRefund(uid, component.StoreEntity.Value, storeComp);
}

private void OnStoreTerminating(Entity<StoreComponent> ent, ref EntityTerminatingEvent args)
Expand Down
20 changes: 19 additions & 1 deletion Content.Server/Store/Systems/StoreSystem.Ui.cs
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,9 @@ private void OnRequestRefund(EntityUid uid, StoreComponent component, StoreReque
RefreshAllListings(component);
component.BalanceSpent = new();
UpdateUserInterface(buyer, uid, component);

var ev = new StoreRefundedEvent();
RaiseLocalEvent(uid, ref ev, true);
}

private void HandleRefundComp(EntityUid uid, StoreComponent component, EntityUid purchase)
Expand All @@ -400,15 +403,30 @@ private bool IsOnStartingMap(EntityUid store, StoreComponent component)
return component.StartingMap == xform.MapUid;
}

/// <summary>
/// Enables refunds for this store
/// </summary>
public void EnableRefund(EntityUid buyer, EntityUid store, StoreComponent? component = null)
{
if (!Resolve(store, ref component))
return;

component.RefundAllowed = true;

UpdateUserInterface(buyer, store, component);
}

/// <summary>
/// Disables refunds for this store
/// </summary>
public void DisableRefund(EntityUid store, StoreComponent? component = null)
public void DisableRefund(EntityUid buyer, EntityUid store, StoreComponent? component = null)
{
if (!Resolve(store, ref component))
return;

component.RefundAllowed = false;

UpdateUserInterface(buyer, store, component);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,22 +161,20 @@ private void OnAbsorbDoAfter(EntityUid uid, ChangelingComponent comp, ref Absorb
var popupOthers = Loc.GetString("changeling-absorb-end-others", ("user", Identity.Entity(uid, EntityManager)), ("target", Identity.Entity(target, EntityManager)));

var bonusChemicals = 0f;
var bonusEvolutionPoints = 0f;
var bonusEvolutionPoints = 0;

if (TryComp<ChangelingComponent>(target, out var targetComp))
{
popupSelf = Loc.GetString("changeling-absorb-end-self-ling", ("target", Identity.Entity(target, EntityManager)));
bonusChemicals += targetComp.MaxChemicals / 2;
bonusEvolutionPoints += 10;
bonusEvolutionPoints += 2;
comp.MaxBiomass += targetComp.MaxBiomass / 2;
}
else
{
bonusChemicals += 10;

if (!reducedBiomass)
bonusEvolutionPoints += 2;
else
if (reducedBiomass)
popupSelf = Loc.GetString("changeling-absorb-end-self-reduced-biomass", ("target", Identity.Entity(target, EntityManager)));
}

Expand All @@ -187,11 +185,13 @@ private void OnAbsorbDoAfter(EntityUid uid, ChangelingComponent comp, ref Absorb
TryStealDNA(uid, target, comp, true);
comp.TotalAbsorbedEntities++;
comp.MaxChemicals += bonusChemicals;
comp.MaxEvolutionPoints += bonusEvolutionPoints;

if (TryComp<StoreComponent>(args.User, out var store))
{
_store.TryAddCurrency(new Dictionary<string, FixedPoint2> { { "EvolutionPoint", bonusEvolutionPoints } }, args.User, store);
_store.UpdateUserInterface(args.User, args.User, store);
_store.EnableRefund(uid, args.User, store);
}

if (_mind.TryGetMind(uid, out var mindId, out var mind))
Expand Down
55 changes: 47 additions & 8 deletions Content.Server/_Goobstation/Changeling/ChangelingSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@
using Content.Shared.Jittering;
using Content.Server.Explosion.EntitySystems;
using System.Linq;
using Content.Server.Flash.Components;
using Content.Shared.Stealth.Components;

namespace Content.Server.Changeling;

Expand Down Expand Up @@ -122,9 +124,10 @@ public override void Initialize()
SubscribeLocalEvent<ChangelingComponent, MobStateChangedEvent>(OnMobStateChange);
SubscribeLocalEvent<ChangelingComponent, DamageChangedEvent>(OnDamageChange);
SubscribeLocalEvent<ChangelingComponent, ComponentRemove>(OnComponentRemove);

SubscribeLocalEvent<ChangelingComponent, RefreshMovementSpeedModifiersEvent>(OnRefreshSpeed);

SubscribeLocalEvent<StoreComponent, StoreRefundedEvent>(OnStoreRefunded);

SubscribeAbilities();
}

Expand Down Expand Up @@ -635,15 +638,31 @@ public bool TryTransform(EntityUid target, ChangelingComponent comp, bool sting

public void RemoveAllChangelingEquipment(EntityUid target, ChangelingComponent comp)
{
// check if there's no entities or all entities are null
if (comp.Equipment.Values.Count == 0
|| comp.Equipment.Values.All(ent => ent == null ? true : false))
return;
var playSound = false;

// check if there's no entities in equipment, or all entities are null
if (comp.Equipment.Values.Count != 0
|| comp.Equipment.Values.All(ent => ent == null ? false : true))
{
foreach (var equip in comp.Equipment.Values)
QueueDel(equip);

comp.Equipment.Clear();
playSound = true;
}

// check if there's no entities in armor, or all entities are null
if (comp.ActiveArmor != null)
{
foreach (var armor in comp.ActiveArmor)
QueueDel(armor);

foreach (var equip in comp.Equipment.Values)
QueueDel(equip);
comp.ActiveArmor = null;
playSound = true;
}

PlayMeatySound(target, comp);
if (playSound)
PlayMeatySound(target, comp);
}

#endregion
Expand Down Expand Up @@ -698,5 +717,25 @@ private void OnComponentRemove(Entity<ChangelingComponent> ent, ref ComponentRem
RemoveAllChangelingEquipment(ent, ent.Comp);
}

private void OnStoreRefunded(Entity<StoreComponent> ent, ref StoreRefundedEvent args)
{
var comp = EnsureComp<ChangelingComponent>(ent);

RemoveAllChangelingEquipment(ent, comp);
comp.StrainedMusclesActive = false;
RemComp<FlashImmunityComponent>(ent); // augmented vision, yes this sucks. refactor one day i prommy - last online 9740 days ago
RemComp<StealthComponent>(ent); // chameleon skin. as above
RemComp<StealthOnMoveComponent>(ent); // chameleon skin

if (HasComp<HivemindComponent>(ent))
{
RemComp<HivemindComponent>(ent);
_popup.PopupEntity(Loc.GetString("changeling-hivemind-end"), ent, ent, PopupType.MediumCaution);
}

_speed.RefreshMovementSpeedModifiers(ent);
_store.DisableRefund(ent.Owner, ent, ent.Comp);
}

#endregion
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,14 @@ public bool MakeChangeling(EntityUid target, ChangelingRuleComponent rule)
_npcFaction.AddFaction(target, ChangelingFactionId);

// make sure it's initial chems are set to max
EnsureComp<ChangelingComponent>(target);
var changelingComp = EnsureComp<ChangelingComponent>(target);

// add store
var store = EnsureComp<StoreComponent>(target);
foreach (var category in rule.StoreCategories)
store.Categories.Add(category);
store.CurrencyWhitelist.Add(Currency);
store.Balance.Add(Currency, 16);
store.Balance.Add(Currency, changelingComp.MaxEvolutionPoints);

rule.ChangelingMinds.Add(mindId);

Expand Down
13 changes: 13 additions & 0 deletions Content.Shared/Store/Components/StoreComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,19 @@ public sealed partial class StoreComponent : Component
/// </summary>
[ByRefEvent]
public readonly record struct StoreRemovedEvent;
/// <summary>
/// Event that is broadcast when a store is refunded
/// </summary>
[ByRefEvent]
public readonly struct StoreRefundedEvent
{
public EntityUid Uid { get; }

public StoreRefundedEvent(EntityUid uid)
{
Uid = uid;
}
}

/// <summary>
/// Broadcast when an Entity with the <see cref="StoreRefundComponent"/> is deleted
Expand Down
3 changes: 3 additions & 0 deletions Content.Shared/_Goobstation/Changeling/ChangelingComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ public sealed partial class ChangelingComponent : Component
public float BiomassUpdateTimer = 0f;
public float BiomassUpdateCooldown = 60f;

[DataField, AutoNetworkedField]
public int MaxEvolutionPoints = 10;

[ViewVariables(VVAccess.ReadOnly)]
public List<TransformData> AbsorbedDNA = new();
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,4 @@ changeling-chameleon-start = We adapt our skin to the environment.
changeling-chameleon-end = Our skin no longer blends in.
changeling-hivemind-start = We attune our brainwaves to match the greater hivemind.
changeling-hivemind-end = Our connection to the greater hivemind is severed.
Loading

0 comments on commit 948a214

Please sign in to comment.