Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 46 additions & 27 deletions msu/hooks/skills/skill_container.nut
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,18 @@
this.m.ScheduledChangesSkills.clear();
}

q.callSkillsFunction <- function( _function, _argsArray = null, _update = true, _aliveOnly = false )
q.callSkillsFunction <- function( _function, _argsArray = null, _update = true, _aliveOnly = false, _resetBusy = true )
{
if (_argsArray == null) _argsArray = [null];
else _argsArray.insert(0, null);

local wasUpdating = this.m.IsUpdating;
this.m.IsUpdating = true;
this.m.IsBusy = false;
this.m.BusyStack = 0;
if (_resetBusy)
{
this.m.IsBusy = false;
this.m.BusyStack = 0;
}

foreach (skill in this.m.Skills)
{
Expand All @@ -57,9 +60,9 @@
}
}

q.callSkillsFunctionWhenAlive <- function( _function, _argsArray = null, _update = true )
q.callSkillsFunctionWhenAlive <- function( _function, _argsArray = null, _update = true, _resetBusy = true )
{
this.callSkillsFunction(_function, _argsArray, _update, true);
this.callSkillsFunction(_function, _argsArray, _update, true, _resetBusy);
}

q.buildProperties <- function( _function, _argsArray )
Expand All @@ -84,22 +87,22 @@
this.callSkillsFunction("onMovementStarted", [
_tile,
_numTiles
]);
], true, false);
}

q.onMovementFinished <- function( _tile )
{
this.callSkillsFunction("onMovementFinished", [
_tile
]);
], true, false);
}

q.onMovementStep <- function( _tile, _levelDifference )
{
this.callSkillsFunction("onMovementStep", [
_tile,
_levelDifference
], false);
], false, false);
}

q.onAnySkillExecuted <- function( _skill, _targetTile, _targetEntity, _forFree )
Expand All @@ -113,7 +116,7 @@
_targetTile,
_targetEntity,
_forFree
], this.getActor().isPlacedOnMap());
], this.getActor().isPlacedOnMap(), false);
}

q.onBeforeAnySkillExecuted <- function( _skill, _targetTile, _targetEntity, _forFree )
Expand All @@ -123,7 +126,7 @@
_targetTile,
_targetEntity,
_forFree
]);
], true, false);
}

q.onUpdateLevel <- function()
Expand All @@ -133,7 +136,8 @@

q.onNewMorning <- function()
{
this.callSkillsFunctionWhenAlive("onNewMorning");
// Don't reset busy similar to vanilla onNewDay event
this.callSkillsFunctionWhenAlive("onNewMorning", null, true, false);
}

q.onGetHitFactors <- function( _skill, _targetTile, _tooltip )
Expand All @@ -142,7 +146,7 @@
_skill,
_targetTile,
_tooltip
], false);
], false, false);

local targetEntity = _targetTile.getEntity();
if (targetEntity != null && targetEntity.getID() != this.getActor().getID())
Expand All @@ -157,23 +161,23 @@
_skill,
_targetTile,
_tooltip
], false);
], false, false);
}

q.onQueryTileTooltip <- function( _tile, _tooltip )
{
this.callSkillsFunction("onQueryTileTooltip", [
_tile,
_tooltip
], false);
], false, false);
}

q.onQueryTooltip <- function( _skill, _tooltip )
{
this.callSkillsFunction("onQueryTooltip", [
_skill,
_tooltip
], false);
], false, false);
}

q.onDeathWithInfo <- function( _killer, _skill, _deathTile, _corpseTile, _fatalityType )
Expand All @@ -189,14 +193,15 @@

q.onOtherActorDeath <- function( _killer, _victim, _skill, _deathTile, _corpseTile, _fatalityType )
{
// Don't resetBusy similar to vanilla onTargetHit etc.
this.callSkillsFunction("onOtherActorDeath", [
_killer,
_victim,
_skill,
_deathTile,
_corpseTile,
_fatalityType
]);
], true, false);
}

q.onEnterSettlement <- function( _settlement )
Expand All @@ -208,16 +213,18 @@

q.onEquip <- function( _item )
{
// Is called during an item swap for example so we don't resetBusy yet
this.callSkillsFunction("onEquip", [
_item
]);
], true, false);
}

q.onUnequip <- function( _item )
{
// Is called during an item swap for example so we don't resetBusy yet
this.callSkillsFunction("onUnequip", [
_item
]);
], true, false);
}

q.onAffordablePreview <- function( _skill, _movementTile )
Expand Down Expand Up @@ -329,7 +336,8 @@

q.onAfterDamageReceived = @() function()
{
this.callSkillsFunctionWhenAlive("onAfterDamageReceived");
// Vanilla doesn't resetBusy here, so we don't either
this.callSkillsFunctionWhenAlive("onAfterDamageReceived", null, true, false);
}

q.buildPropertiesForUse = @() function( _caller, _targetEntity )
Expand Down Expand Up @@ -363,7 +371,8 @@

q.onBeforeActivation = @() function()
{
this.callSkillsFunctionWhenAlive("onBeforeActivation");
// Vanilla doesn't resetBusy here so we don't either
this.callSkillsFunctionWhenAlive("onBeforeActivation", null, true, false);
}

q.onTurnStart = @() function()
Expand Down Expand Up @@ -400,16 +409,18 @@

q.onNewDay = @() function()
{
this.callSkillsFunctionWhenAlive("onNewDay");
// Vanilla doesn't resetBusy here so we don't either
this.callSkillsFunctionWhenAlive("onNewDay", null, true, false);
}

q.onDamageReceived = @() function( _attacker, _damageHitpoints, _damageArmor )
{
// Vanilla doesn't resetBusy here so we don't either
this.callSkillsFunction("onDamageReceived", [
_attacker,
_damageHitpoints,
_damageArmor
]);
], null, true, false);
}

q.onBeforeTargetHit = @() function( _caller, _targetEntity, _hitInfo )
Expand Down Expand Up @@ -437,46 +448,54 @@
}
}

// Vanilla doesn't resetBusy here so we don't either
this.callSkillsFunction("onBeforeTargetHit", [
_caller,
_targetEntity,
_hitInfo
]);
], null, true, false);
}

q.onTargetHit = @() function( _caller, _targetEntity, _bodyPart, _damageInflictedHitpoints, _damageInflictedArmor )
{
// Vanilla doesn't resetBusy here so we don't either
this.callSkillsFunction("onTargetHit", [
_caller,
_targetEntity,
_bodyPart,
_damageInflictedHitpoints,
_damageInflictedArmor
]);
], null, true, false);
}

q.onTargetMissed = @() function( _caller, _targetEntity )
{
// Vanilla doesn't resetBusy here so we don't either
this.callSkillsFunction("onTargetMissed", [
_caller,
_targetEntity
]);
], null, true, false);
}

q.onTargetKilled = @() function( _targetEntity, _skill )
{
// Vanilla doesn't resetBusy here so we don't either
this.callSkillsFunction("onTargetKilled", [
_targetEntity,
_skill
]);
], null, true, false);
}

q.onMissed = @() function( _attacker, _skill )
{
// Vanilla only resets this.m.IsBusy to false here but doesn't reset this.m.BusyStack to 0.
// So we set this.m.IsBusy to false manually here and then pass false for resetBusy
this.m.IsBusy = false;

this.callSkillsFunction("onMissed", [
_attacker,
_skill
]);
], true, false);
}

q.onCombatStarted = @() function()
Expand Down
6 changes: 3 additions & 3 deletions msu/utils/skills.nut
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"MaxRange"
],

function addEvent( _name, _function = null, _update = true, _aliveOnly = false )
function addEvent( _name, _function = null, _update = true, _aliveOnly = false, _resetBusy = true )
{
::MSU.MH.hook("scripts/skills/skill", function(q) {
q[_name] <- _function == null ? function() {} : _function;
Expand All @@ -21,7 +21,7 @@
::MSU.MH.hook("scripts/skills/skill_container", function(q) {
if (_function == null || _function.getinfos().parameters.len() == 1) // for parameterless functions it should be a len 1 array containing "this"
{
q[_name] <- @() this.callSkillsFunction(_name, null, _update, _aliveOnly);
q[_name] <- @() this.callSkillsFunction(_name, null, _update, _aliveOnly, _resetBusy);
}
else
{
Expand Down Expand Up @@ -55,7 +55,7 @@
}
}

q[_name] <- compilestring(format("return function (%s) { return this.callSkillsFunction(\"%s\", [%s], %s, %s); }", declarationParams.reduce(@(a, b) a + ", " + b), _name, wrappedParams.reduce(@(a, b) a + ", " + b), _update + "", _aliveOnly + ""))();
q[_name] <- compilestring(format("return function (%s) { return this.callSkillsFunction(\"%s\", [%s], %s, %s, %s); }", declarationParams.reduce(@(a, b) a + ", " + b), _name, wrappedParams.reduce(@(a, b) a + ", " + b), _update + "", _aliveOnly + "", _resetBusy + ""))();
}
});
}
Expand Down