-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
60 additions
and
1 deletion.
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
TabletopTweaks/NewComponents/ContextRestoreResourcesFixed.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
using System; | ||
using Kingmaker; | ||
using Kingmaker.Blueprints; | ||
using Kingmaker.Blueprints.JsonSystem; | ||
using Kingmaker.EntitySystem.Entities; | ||
using Kingmaker.UnitLogic.Mechanics; | ||
using Kingmaker.UnitLogic.Mechanics.Actions; | ||
using Kingmaker.Utility; | ||
using UnityEngine; | ||
using UnityEngine.Serialization; | ||
|
||
namespace TabletopTweaks.NewComponents { | ||
[TypeId("febcdf299ca242a7be5bacfda8e4254f")] | ||
class ContextRestoreResourcesFixed : ContextAction { | ||
public BlueprintAbilityResource Resource { | ||
get { | ||
BlueprintAbilityResourceReference resource = this.m_Resource; | ||
if (resource == null) { | ||
return null; | ||
} | ||
return resource.Get(); | ||
} | ||
} | ||
|
||
public override string GetCaption() { | ||
return "Restore resource"; | ||
} | ||
|
||
public override void RunAction() { | ||
TargetWrapper target = base.Target; | ||
UnitEntityData unitEntityData = target?.Unit; | ||
if (unitEntityData == null) { | ||
PFLog.Default.Error("Target is missing", Array.Empty<object>()); | ||
return; | ||
} | ||
if (m_IsFullRestoreAllResources) { | ||
unitEntityData.Descriptor.Resources.FullRestoreAll(); | ||
return; | ||
} | ||
if (!ContextValueRestoration) { | ||
unitEntityData.Descriptor.Resources.Restore(Resource, 1); | ||
return; | ||
} | ||
unitEntityData.Descriptor.Resources.Restore(Resource, Value.Calculate(base.Context)); | ||
} | ||
|
||
public bool m_IsFullRestoreAllResources; | ||
|
||
[SerializeField] | ||
[FormerlySerializedAs("Resource")] | ||
[HideIf("m_IsFullRestoreAllResources")] | ||
private BlueprintAbilityResourceReference m_Resource; | ||
|
||
[HideIf("m_IsFullRestoreAllResources")] | ||
public bool ContextValueRestoration; | ||
|
||
[ShowIf("ContextValueRestoration")] | ||
public ContextValue Value; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters