Action Upgrade System (#22277)
* Adds uses before delay so actions can be used multiple times before cooldown * adds methods to get remaining charges, to set uses before delay, and to set use delay * adds method to change action name * moves set usedelay * action upgrade ECS * adds method to reset remaining uses * adds upgrade events * refactors action upgrade event and adds logic to parse it * fix serialization issue * adds level up draft method * adds action commands and a command to upgrade an action * more warning lines to help * Gets action to upgrade properly * Removes unneeded fields from the action upgrade component and now properly raises the level of the new action * Cleans up dead code and comments * Fixes punctuation in actions-commands and adds a TryUpgradeAction method. * removes TODO comment * robust fix * removes RT * readds RT * update RT to 190 * removes change name method * removes remaining uses & related fields and adds that functionality to charges * Adds Charges to action tooltips that require it
This commit is contained in:
@@ -30,11 +30,16 @@ public abstract class SharedActionsSystem : EntitySystem
|
||||
[Dependency] private readonly SharedAudioSystem _audio = default!;
|
||||
[Dependency] private readonly SharedTransformSystem _transformSystem = default!;
|
||||
[Dependency] private readonly ActionContainerSystem _actionContainer = default!;
|
||||
[Dependency] private readonly MetaDataSystem _metaData = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<InstantActionComponent, MapInitEvent>(OnInit);
|
||||
SubscribeLocalEvent<EntityTargetActionComponent, MapInitEvent>(OnInit);
|
||||
SubscribeLocalEvent<WorldTargetActionComponent, MapInitEvent>(OnInit);
|
||||
|
||||
SubscribeLocalEvent<ActionsComponent, DidEquipEvent>(OnDidEquip);
|
||||
SubscribeLocalEvent<ActionsComponent, DidEquipHandEvent>(OnHandEquipped);
|
||||
SubscribeLocalEvent<ActionsComponent, DidUnequipEvent>(OnDidUnequip);
|
||||
@@ -56,6 +61,12 @@ public abstract class SharedActionsSystem : EntitySystem
|
||||
SubscribeAllEvent<RequestPerformActionEvent>(OnActionRequest);
|
||||
}
|
||||
|
||||
private void OnInit(EntityUid uid, BaseActionComponent component, MapInitEvent args)
|
||||
{
|
||||
if (component.Charges != null)
|
||||
component.MaxCharges = component.Charges.Value;
|
||||
}
|
||||
|
||||
private void OnShutdown(EntityUid uid, ActionsComponent component, ComponentShutdown args)
|
||||
{
|
||||
foreach (var act in component.Actions)
|
||||
@@ -165,6 +176,31 @@ public abstract class SharedActionsSystem : EntitySystem
|
||||
Dirty(actionId.Value, action);
|
||||
}
|
||||
|
||||
public void SetUseDelay(EntityUid? actionId, TimeSpan? delay)
|
||||
{
|
||||
if (!TryGetActionData(actionId, out var action) || action.UseDelay == delay)
|
||||
return;
|
||||
|
||||
action.UseDelay = delay;
|
||||
UpdateAction(actionId, action);
|
||||
Dirty(actionId.Value, action);
|
||||
}
|
||||
|
||||
public void ReduceUseDelay(EntityUid? actionId, TimeSpan? lowerDelay)
|
||||
{
|
||||
if (!TryGetActionData(actionId, out var action))
|
||||
return;
|
||||
|
||||
if (action.UseDelay != null && lowerDelay != null)
|
||||
action.UseDelay = action.UseDelay - lowerDelay;
|
||||
|
||||
if (action.UseDelay < TimeSpan.Zero)
|
||||
action.UseDelay = null;
|
||||
|
||||
UpdateAction(actionId, action);
|
||||
Dirty(actionId.Value, action);
|
||||
}
|
||||
|
||||
private void OnRejuventate(EntityUid uid, ActionsComponent component, RejuvenateEvent args)
|
||||
{
|
||||
foreach (var act in component.Actions)
|
||||
@@ -218,6 +254,51 @@ public abstract class SharedActionsSystem : EntitySystem
|
||||
Dirty(actionId.Value, action);
|
||||
}
|
||||
|
||||
public int? GetCharges(EntityUid? actionId)
|
||||
{
|
||||
if (!TryGetActionData(actionId, out var action))
|
||||
return null;
|
||||
|
||||
return action.Charges;
|
||||
}
|
||||
|
||||
public void AddCharges(EntityUid? actionId, int addCharges)
|
||||
{
|
||||
if (!TryGetActionData(actionId, out var action) || action.Charges == null || addCharges < 1)
|
||||
return;
|
||||
|
||||
action.Charges += addCharges;
|
||||
UpdateAction(actionId, action);
|
||||
Dirty(actionId.Value, action);
|
||||
}
|
||||
|
||||
public void RemoveCharges(EntityUid? actionId, int? removeCharges)
|
||||
{
|
||||
if (!TryGetActionData(actionId, out var action) || action.Charges == null)
|
||||
return;
|
||||
|
||||
if (removeCharges == null)
|
||||
action.Charges = removeCharges;
|
||||
else
|
||||
action.Charges -= removeCharges;
|
||||
|
||||
if (action.Charges is < 0)
|
||||
action.Charges = null;
|
||||
|
||||
UpdateAction(actionId, action);
|
||||
Dirty(actionId.Value, action);
|
||||
}
|
||||
|
||||
public void ResetCharges(EntityUid? actionId)
|
||||
{
|
||||
if (!TryGetActionData(actionId, out var action))
|
||||
return;
|
||||
|
||||
action.Charges = action.MaxCharges;
|
||||
UpdateAction(actionId, action);
|
||||
Dirty(actionId.Value, action);
|
||||
}
|
||||
|
||||
private void OnActionsGetState(EntityUid uid, ActionsComponent component, ref ComponentGetState args)
|
||||
{
|
||||
args.State = new ActionsComponentState(GetNetEntitySet(component.Actions));
|
||||
@@ -261,9 +342,14 @@ public abstract class SharedActionsSystem : EntitySystem
|
||||
return;
|
||||
|
||||
var curTime = GameTiming.CurTime;
|
||||
// TODO: Check for charge recovery timer
|
||||
if (action.Cooldown.HasValue && action.Cooldown.Value.End > curTime)
|
||||
return;
|
||||
|
||||
// TODO: Replace with individual charge recovery when we have the visuals to aid it
|
||||
if (action is { Charges: < 1, RenewCharges: true })
|
||||
ResetCharges(actionEnt);
|
||||
|
||||
BaseActionEvent? performEvent = null;
|
||||
|
||||
// Validate request by checking action blockers and the like:
|
||||
@@ -438,12 +524,12 @@ public abstract class SharedActionsSystem : EntitySystem
|
||||
{
|
||||
dirty = true;
|
||||
action.Charges--;
|
||||
if (action.Charges == 0)
|
||||
if (action is { Charges: 0, RenewCharges: false })
|
||||
action.Enabled = false;
|
||||
}
|
||||
|
||||
action.Cooldown = null;
|
||||
if (action.UseDelay != null)
|
||||
if (action is { UseDelay: not null, Charges: null or < 1 })
|
||||
{
|
||||
dirty = true;
|
||||
action.Cooldown = (curTime, curTime + action.UseDelay.Value);
|
||||
|
||||
Reference in New Issue
Block a user