Skip to content
31 changes: 31 additions & 0 deletions msu/hooks/entity/tactical/actor.nut
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
::MSU.MH.hook("scripts/entity/tactical/actor", function(q) {
q.m.MSU_PreviewSkill <- null;
q.m.MSU_PreviewMovement <- null;

q.setActionPoints = @() function( _a )
{
this.m.ActionPoints = ::Math.round(_a);
if (!this.getSkills().m.IsPreviewing)
this.setPreviewActionPoints(_a);
}

q.onMovementStart = @(__original) function ( _tile, _numTiles )
{
__original(_tile, _numTiles);
Expand Down Expand Up @@ -114,6 +124,27 @@
}
}
}

q.isPreviewing <- function()
{
return this.getSkills().m.IsPreviewing;
}

q.getPreviewSkill <- function()
{
return this.m.MSU_PreviewSkill;
}

q.getPreviewMovement <- function()
{
return this.m.MSU_PreviewMovement;
}

q.clearPreview <- function()
{
this.m.MSU_PreviewSkill = null;
this.m.MSU_PreviewMovement = null;
}
});

::MSU.QueueBucket.VeryLate.push(function() {
Expand Down
27 changes: 24 additions & 3 deletions msu/hooks/skills/skill.nut
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@
q.m.ItemActionOrder <- ::Const.ItemActionOrder.Any;

q.m.IsBaseValuesSaved <- false;
q.m.ScheduledChanges <- [];
q.m.ScheduledChanges <- []; // Deprecated

q.m.IsApplyingPreview <- false;
q.m.PreviewField <- {};
q.m.IsApplyingPreview <- false; // Deprecated - Only needed for the legacy onAffordablePreview system -- use the new onUpdatePreview and onAfterUpdatePreview system
q.m.PreviewField <- {}; // Deprecated - Only needed for the legacy onAffordablePreview system -- use the new onUpdatePreview and onAfterUpdatePreview system

q.isType = @() function( _t, _any = true, _only = false )
{
Expand Down Expand Up @@ -93,12 +93,14 @@
else throw ::MSU.Exception.KeyNotFound(_t);
}

// Deprecated
q.scheduleChange <- function( _field, _change, _set = false )
{
this.m.ScheduledChanges.push({Field = _field, Change = _change, Set = _set});
this.getContainer().m.ScheduledChangesSkills.push(this);
}

// Deprecated
q.executeScheduledChanges <- function()
{
if (this.m.ScheduledChanges.len() == 0)
Expand Down Expand Up @@ -335,15 +337,28 @@
{
}

q.onUpdatePreview <- function( _properties, _previewedSkill, _previewedMovement )
{
this.onUpdate(_properties);
}

q.onAfterUpdatePreview <- function( _properties, _previewedSkill, _previewedMovement )
{
this.onAfterUpdate(_properties);
}

// Deprecated - Only needed for the legacy onAffordablePreview system -- use the new onUpdatePreview and onAfterUpdatePreview system
q.onAffordablePreview <- function( _skill, _movementTile )
{
}

// Deprecated - Only needed for the legacy onAffordablePreview system -- use the new onUpdatePreview and onAfterUpdatePreview system
q.modifyPreviewField <- function( _skill, _field, _newChange, _multiplicative )
{
::MSU.Skills.modifyPreview(this, _skill, _field, _newChange, _multiplicative);
}

// Deprecated - Only needed for the legacy onAffordablePreview system -- use the new onUpdatePreview and onAfterUpdatePreview system
q.modifyPreviewProperty <- function( _skill, _field, _newChange, _multiplicative )
{
::MSU.Skills.modifyPreview(this, null, _field, _newChange, _multiplicative);
Expand Down Expand Up @@ -486,6 +501,7 @@

::MSU.QueueBucket.VeryLate.push(function() {
::MSU.MH.hook("scripts/skills/skill", function(q) {
// Deprecated - Only needed for the legacy onAffordablePreview system -- use the new onUpdatePreview and onAfterUpdatePreview system
foreach (func in ::MSU.Skills.PreviewApplicableFunctions)
{
q[func] = @(__original) function()
Expand Down Expand Up @@ -547,6 +563,7 @@
}
}

// Deprecated - Only needed for the legacy onAffordablePreview system -- use the new onUpdatePreview and onAfterUpdatePreview system
q.isAffordablePreview = @(__original) function()
{
if (!this.getContainer().m.IsPreviewing) return __original();
Expand All @@ -562,9 +579,13 @@
local preview = ::Tactical.TurnSequenceBar.m.ActiveEntityCostsPreview;
if (preview != null && preview.id == this.getContainer().getActor().getID())
{
this.getContainer().update();
this.m.IsApplyingPreview = true;
local ret = __original();
this.m.IsApplyingPreview = false;
this.getContainer().m.IsPreviewing = false;
this.getContainer().update();
this.getContainer().m.IsPreviewing = true;
local skillID = this.getContainer().getActor().getPreviewSkillID();
local str = " after " + (skillID == "" ? "moving" : "using " + this.getContainer().getSkillByID(skillID).getName());
ret = ::MSU.String.replace(ret, "Fatigue[/color]", "Fatigue[/color]" + str);
Expand Down
43 changes: 15 additions & 28 deletions msu/hooks/skills/skill_container.nut
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
::MSU.MH.hook("scripts/skills/skill_container", function(q) {
q.m.ScheduledChangesSkills <- [];
q.m.ScheduledChangesSkills <- []; // Deprecated
q.m.IsPreviewing <- false;
q.m.PreviewProperty <- {};
q.m.PreviewProperty <- {}; // Deprecated - Only needed for the legacy onAffordablePreview system -- use the new onUpdatePreview and onAfterUpdatePreview system

q.update = @(__original) function()
{
Expand All @@ -17,12 +17,13 @@

__original();

// Deprecated
foreach (skill in this.m.ScheduledChangesSkills)
{
if (!skill.isGarbage()) skill.executeScheduledChanges();
}

this.m.ScheduledChangesSkills.clear();
this.m.ScheduledChangesSkills.clear(); // Deprecated
}

q.callSkillsFunction <- function( _function, _argsArray = null, _update = true, _aliveOnly = false )
Expand Down Expand Up @@ -220,19 +221,18 @@
]);
}

// Deprecated - Only needed for the legacy onAffordablePreview system -- use the new onUpdatePreview and onAfterUpdatePreview system
q.onAffordablePreview <- function( _skill, _movementTile )
{
this.m.PreviewProperty.clear();

foreach (skill in this.m.Skills)
{
skill.m.PreviewField.clear();
if (!skill.isGarbage())
skill.onAffordablePreview(_skill, _movementTile);
}

this.callSkillsFunction("onAffordablePreview", [
_skill,
_movementTile,
], false);

if (::MSU.Skills.QueuedPreviewChanges.len() == 0) return;

local propertiesClone = this.getActor().getBaseProperties().getClone();
Expand Down Expand Up @@ -286,39 +286,23 @@

getChange("onUpdate");
getChange("onAfterUpdate");
getChange("executeScheduledChanges");
getChange("executeScheduledChanges"); // Deprecated

foreach (changes in ::MSU.Skills.QueuedPreviewChanges)
{
foreach (change in changes)
{
local target;
local previewTable;
if (change.TargetSkill != null)
{
target = change.TargetSkill.m;
previewTable = change.TargetSkill.m.PreviewField;
}
else
{
target = this.getActor().getCurrentProperties();
previewTable = this.m.PreviewProperty;
}
local previewTable = change.TargetSkill == null ? this.m.PreviewProperty : change.TargetSkill.m.PreviewField;

if (!(change.Field in previewTable)) previewTable[change.Field] <- { Change = change.Multiplicative ? 1 : 0, Multiplicative = change.Multiplicative };
if (!(change.Field in previewTable))
previewTable[change.Field] <- { Change = change.Multiplicative ? 1 : 0, Multiplicative = change.Multiplicative };

if (change.Multiplicative)
{
previewTable[change.Field].Change *= change.NewChange / (change.CurrChange == 0 ? 1 : change.CurrChange);
}
else if (typeof change.NewChange == "bool")
{
previewTable[change.Field].Change = change.NewChange;
}
else
{
previewTable[change.Field].Change += change.NewChange - change.CurrChange;
}
}
}

Expand Down Expand Up @@ -384,12 +368,14 @@
q.onTurnEnd = @() function()
{
this.m.IsPreviewing = false;
this.getActor().clearPreview();
this.callSkillsFunctionWhenAlive("onTurnEnd");
}

q.onWaitTurn = @() function()
{
this.m.IsPreviewing = false;
this.getActor().clearPreview();
this.callSkillsFunctionWhenAlive("onWaitTurn");
}

Expand Down Expand Up @@ -487,6 +473,7 @@
q.onCombatFinished = @() function()
{
this.m.IsPreviewing = false;
this.getActor().clearPreview();
this.callSkillsFunction("onCombatFinished");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,37 +32,47 @@

q.setActiveEntityCostsPreview = @(__original) function( _costsPreview )
{
if (::MSU.Mod.ModSettings.getSetting("ExpandedSkillTooltips").getValue())
{
local activeEntity = this.getActiveEntity();
if (activeEntity != null)
{
local skillID = "SkillID" in _costsPreview ? _costsPreview.SkillID : "";
local skill;
local movementTile;
if (skillID == "")
{
local movement = ::Tactical.getNavigator().getCostForPath(activeEntity, ::Tactical.getNavigator().getLastSettings(), activeEntity.getActionPoints(), activeEntity.getFatigueMax() - activeEntity.getFatigue());
movementTile = movement.End;
}
else skill = activeEntity.getSkills().getSkillByID(skillID);
if (!::MSU.Mod.ModSettings.getSetting("ExpandedSkillTooltips").getValue())
return __original(_costsPreview);

activeEntity.getSkills().m.IsPreviewing = true;
activeEntity.getSkills().onAffordablePreview(skill, movementTile);
}
}
local activeEntity = this.getActiveEntity();
if (activeEntity == null)
return __original(_costsPreview);

local skillID = "SkillID" in _costsPreview ? _costsPreview.SkillID : "";
local skill;
local movement;
if (skillID == "")
movement = ::Tactical.getNavigator().getCostForPath(activeEntity, ::Tactical.getNavigator().getLastSettings(), activeEntity.getActionPoints(), activeEntity.getFatigueMax() - activeEntity.getFatigue());
else
skill = activeEntity.getSkills().getSkillByID(skillID);

activeEntity.getSkills().m.IsPreviewing = true;
activeEntity.getSkills().onAffordablePreview(skill, movement == null ? null : movement.End); // Deprecated - Only needed for the legacy onAffordablePreview system -- use the new onUpdatePreview and onAfterUpdatePreview system
activeEntity.m.MSU_PreviewSkill = skill;
activeEntity.m.MSU_PreviewMovement = movement;
activeEntity.getSkills().update();

this.m.MSU_JSHandle.__JSHandle = this.m.JSHandle;
this.m.JSHandle = this.m.MSU_JSHandle;
__original(_costsPreview);
local ret = __original(_costsPreview);
this.m.JSHandle = this.m.MSU_JSHandle.__JSHandle;
this.m.JSHandle.asyncCall("updateCostsPreview", this.m.ActiveEntityCostsPreview);

activeEntity.getSkills().m.IsPreviewing = false;
activeEntity.getSkills().update();
activeEntity.getSkills().m.IsPreviewing = true;
return ret;
}

q.resetActiveEntityCostsPreview = @(__original) function()
{
local activeEntity = this.getActiveEntity();
if (activeEntity != null) activeEntity.getSkills().m.IsPreviewing = false;
if (activeEntity != null)
{
activeEntity.getSkills().m.IsPreviewing = false;
activeEntity.clearPreview();
}
__original();
}
});
6 changes: 4 additions & 2 deletions msu/utils/skills.nut
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
::MSU.Skills <- {
PreviewApplicableFunctions = [
PreviewApplicableFunctions = [ // Deprecated - Only needed for the legacy onAffordablePreview system -- use the new onUpdatePreview and onAfterUpdatePreview system
"getActionPointCost",
"getFatigueCost"
],
QueuedPreviewChanges = {},
QueuedPreviewChanges = {}, // Deprecated - Only needed for the legacy onAffordablePreview system -- use the new onUpdatePreview and onAfterUpdatePreview system
SoftResetFields = [
"ActionPointCost",
"FatigueCost",
Expand Down Expand Up @@ -48,6 +48,7 @@
});
}

// Deprecated - Only needed for the legacy onAffordablePreview system -- use the new onUpdatePreview and onAfterUpdatePreview system
function addPreviewApplicableFunction( _name )
{
::MSU.requireString(_name);
Expand All @@ -65,6 +66,7 @@
if (idx != null) this.SoftResetFields.remove(idx);
}

// Deprecated - Only needed for the legacy onAffordablePreview system -- use the new onUpdatePreview and onAfterUpdatePreview system
// Private
function modifyPreview( _caller, _targetSkill, _field, _newChange, _multiplicative )
{
Expand Down