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
52 changes: 26 additions & 26 deletions msu/hooks/ai/tactical/agent.nut
Original file line number Diff line number Diff line change
@@ -1,32 +1,6 @@
::MSU.MH.hook("scripts/ai/tactical/agent", function(q) {
q.m.MSU_BehaviorStacks <- {};
q.m.MSU_BehaviorToRemove <- null;

q.addBehavior = @(__original) function( _behavior )
{
if (_behavior.getID() in this.m.MSU_BehaviorStacks)
{
++this.m.MSU_BehaviorStacks[_behavior.getID()];
return;
}

this.m.MSU_BehaviorStacks[_behavior.getID()] <- 1;
return __original(_behavior);
}

q.removeBehavior = @(__original) function( _id )
{
if (_id in this.m.MSU_BehaviorStacks) delete this.m.MSU_BehaviorStacks[_id];
return __original(_id);
}

// TODO: This function's name is temporary and is currently undocumented while we search for a better name
// Once we find a better name we will change it and add it to documentation
q.removeBehaviorByStack <- function( _id )
{
if (!(_id in this.m.MSU_BehaviorStacks) || --this.m.MSU_BehaviorStacks[_id] == 0)
return this.removeBehavior(_id);
}
});

::MSU.QueueBucket.VeryLate.push(function() {
Expand All @@ -41,5 +15,31 @@
}
return ret;
}

q.addBehavior = @(__original) function( _behavior )
{
if (_behavior.getID() in this.m.MSU_BehaviorStacks)
{
++this.m.MSU_BehaviorStacks[_behavior.getID()];
return;
}

this.m.MSU_BehaviorStacks[_behavior.getID()] <- 1;
return __original(_behavior);
}

q.removeBehavior = @(__original) function( _id )
{
if (_id in this.m.MSU_BehaviorStacks) delete this.m.MSU_BehaviorStacks[_id];
return __original(_id);
}

// TODO: This function's name is temporary and is currently undocumented while we search for a better name
// Once we find a better name we will change it and add it to documentation
q.removeBehaviorByStack <- function( _id )
{
if (!(_id in this.m.MSU_BehaviorStacks) || --this.m.MSU_BehaviorStacks[_id] == 0)
return this.removeBehavior(_id);
}
});
});
46 changes: 24 additions & 22 deletions msu/hooks/ai/tactical/behaviors/ai_pickup_weapon.nut
Original file line number Diff line number Diff line change
@@ -1,33 +1,35 @@
::MSU.MH.hook("scripts/ai/tactical/behaviors/ai_pickup_weapon", function(q) {
q.onExecute = @(__original) function( _entity )
{
local itemsBefore = array(::Const.ItemSlot.COUNT);
for (local i = 0; i < ::Const.ItemSlot.COUNT; i++)
::MSU.QueueBucket.VeryLate.push(function() {
::MSU.MH.hook("scripts/ai/tactical/behaviors/ai_pickup_weapon", function(q) {
q.onExecute = @(__original) function( _entity )
{
itemsBefore[i] = clone _entity.getItems().m.Items[i];
}
local itemsBefore = array(::Const.ItemSlot.COUNT);
for (local i = 0; i < ::Const.ItemSlot.COUNT; i++)
{
itemsBefore[i] = clone _entity.getItems().m.Items[i];
}

_entity.getItems().m.MSU_IsIgnoringItemAction = true;
local ret = __original(_entity);
_entity.getItems().m.MSU_IsIgnoringItemAction = false;
_entity.getItems().m.MSU_IsIgnoringItemAction = true;
local ret = __original(_entity);
_entity.getItems().m.MSU_IsIgnoringItemAction = false;

if (ret)
{
local items = [];
for (local i = 0; i < ::Const.ItemSlot.COUNT; i++)
if (ret)
{
foreach (j, item in _entity.getItems().m.Items[i])
local items = [];
for (local i = 0; i < ::Const.ItemSlot.COUNT; i++)
{
if (item != itemsBefore[i][j] && items.find(item) == null)
foreach (j, item in _entity.getItems().m.Items[i])
{
if (item != null && item != -1) items.push(item);
if (itemsBefore[i][j] != null && itemsBefore[i][j] != -1) items.push(itemsBefore[i][j]);
if (item != itemsBefore[i][j] && items.find(item) == null)
{
if (item != null && item != -1) items.push(item);
if (itemsBefore[i][j] != null && itemsBefore[i][j] != -1) items.push(itemsBefore[i][j]);
}
}
}
_entity.getItems().payForAction(items);
}
_entity.getItems().payForAction(items);
}

return ret;
}
return ret;
}
});
});
64 changes: 33 additions & 31 deletions msu/hooks/ai/tactical/behaviors/ai_switchto_melee.nut
Original file line number Diff line number Diff line change
@@ -1,44 +1,46 @@
::MSU.MH.hook("scripts/ai/tactical/behaviors/ai_switchto_melee", function(q) {
q.onExecute = @(__original) function( _entity )
{
local itemsBefore = array(::Const.ItemSlot.COUNT);
// We need to cache this as it is set to false in onExecute
local wasNegatingDisarm = this.m.IsNegatingDisarm;
for (local i = 0; i < ::Const.ItemSlot.COUNT; i++)
::MSU.QueueBucket.VeryLate.push(function() {
::MSU.MH.hook("scripts/ai/tactical/behaviors/ai_switchto_melee", function(q) {
q.onExecute = @(__original) function( _entity )
{
itemsBefore[i] = clone _entity.getItems().m.Items[i];
}

_entity.getItems().m.MSU_IsIgnoringItemAction = true;
local ret = __original(_entity);
_entity.getItems().m.MSU_IsIgnoringItemAction = false;

if (ret)
{
if (wasNegatingDisarm)
local itemsBefore = array(::Const.ItemSlot.COUNT);
// We need to cache this as it is set to false in onExecute
local wasNegatingDisarm = this.m.IsNegatingDisarm;
for (local i = 0; i < ::Const.ItemSlot.COUNT; i++)
{
// Once to use up quickhands, once to actually pay for the cost
_entity.getItems().payForAction([_entity.getMainhandItem()]);
_entity.getItems().payForAction([_entity.getMainhandItem()]);
itemsBefore[i] = clone _entity.getItems().m.Items[i];
}
else

_entity.getItems().m.MSU_IsIgnoringItemAction = true;
local ret = __original(_entity);
_entity.getItems().m.MSU_IsIgnoringItemAction = false;

if (ret)
{
local items = [];
for (local i = 0; i < ::Const.ItemSlot.COUNT; i++)
if (wasNegatingDisarm)
{
// Once to use up quickhands, once to actually pay for the cost
_entity.getItems().payForAction([_entity.getMainhandItem()]);
_entity.getItems().payForAction([_entity.getMainhandItem()]);
}
else
{
foreach (j, item in _entity.getItems().m.Items[i])
local items = [];
for (local i = 0; i < ::Const.ItemSlot.COUNT; i++)
{
if (item != itemsBefore[i][j] && items.find(item) == null)
foreach (j, item in _entity.getItems().m.Items[i])
{
if (item != null && item != -1) items.push(item);
if (itemsBefore[i][j] != null && itemsBefore[i][j] != -1) items.push(itemsBefore[i][j]);
if (item != itemsBefore[i][j] && items.find(item) == null)
{
if (item != null && item != -1) items.push(item);
if (itemsBefore[i][j] != null && itemsBefore[i][j] != -1) items.push(itemsBefore[i][j]);
}
}
}
_entity.getItems().payForAction(items);
}
_entity.getItems().payForAction(items);
}
}

return ret;
}
return ret;
}
});
});
48 changes: 25 additions & 23 deletions msu/hooks/ai/tactical/behaviors/ai_switchto_ranged.nut
Original file line number Diff line number Diff line change
@@ -1,34 +1,36 @@
::MSU.MH.hook("scripts/ai/tactical/behaviors/ai_switchto_ranged", function(q) {
q.onExecute = @(__original) function( _entity )
{
local itemsBefore = array(::Const.ItemSlot.COUNT);
for (local i = 0; i < ::Const.ItemSlot.COUNT; i++)
::MSU.QueueBucket.VeryLate.push(function() {
::MSU.MH.hook("scripts/ai/tactical/behaviors/ai_switchto_ranged", function(q) {
q.onExecute = @(__original) function( _entity )
{
itemsBefore[i] = clone _entity.getItems().m.Items[i];
}

_entity.getItems().m.MSU_IsIgnoringItemAction = true;
local ret = __original(_entity);
_entity.getItems().m.MSU_IsIgnoringItemAction = false;
local itemsBefore = array(::Const.ItemSlot.COUNT);
for (local i = 0; i < ::Const.ItemSlot.COUNT; i++)
{
itemsBefore[i] = clone _entity.getItems().m.Items[i];
}

if (ret)
{
_entity.getItems().m.MSU_IsIgnoringItemAction = true;
local ret = __original(_entity);
_entity.getItems().m.MSU_IsIgnoringItemAction = false;

local items = [];
for (local i = 0; i < ::Const.ItemSlot.COUNT; i++)
if (ret)
{
foreach (j, item in _entity.getItems().m.Items[i])

local items = [];
for (local i = 0; i < ::Const.ItemSlot.COUNT; i++)
{
if (item != itemsBefore[i][j] && items.find(item) == null)
foreach (j, item in _entity.getItems().m.Items[i])
{
if (item != null && item != -1) items.push(item);
if (itemsBefore[i][j] != null && itemsBefore[i][j] != -1) items.push(itemsBefore[i][j]);
if (item != itemsBefore[i][j] && items.find(item) == null)
{
if (item != null && item != -1) items.push(item);
if (itemsBefore[i][j] != null && itemsBefore[i][j] != -1) items.push(itemsBefore[i][j]);
}
}
}
_entity.getItems().payForAction(items);
}
_entity.getItems().payForAction(items);
}

return ret;
}
return ret;
}
});
});
46 changes: 24 additions & 22 deletions msu/hooks/ai/tactical/behaviors/ai_throw_bomb.nut
Original file line number Diff line number Diff line change
@@ -1,33 +1,35 @@
::MSU.MH.hook("scripts/ai/tactical/behaviors/ai_throw_bomb", function(q) {
q.onExecute = @(__original) function( _entity )
{
local itemsBefore = array(::Const.ItemSlot.COUNT);
for (local i = 0; i < ::Const.ItemSlot.COUNT; i++)
::MSU.QueueBucket.VeryLate.push(function() {
::MSU.MH.hook("scripts/ai/tactical/behaviors/ai_throw_bomb", function(q) {
q.onExecute = @(__original) function( _entity )
{
itemsBefore[i] = clone _entity.getItems().m.Items[i];
}
local itemsBefore = array(::Const.ItemSlot.COUNT);
for (local i = 0; i < ::Const.ItemSlot.COUNT; i++)
{
itemsBefore[i] = clone _entity.getItems().m.Items[i];
}

_entity.getItems().m.MSU_IsIgnoringItemAction = true;
local ret = __original(_entity);
_entity.getItems().m.MSU_IsIgnoringItemAction = false;
_entity.getItems().m.MSU_IsIgnoringItemAction = true;
local ret = __original(_entity);
_entity.getItems().m.MSU_IsIgnoringItemAction = false;

if (ret && this.m.Skill == null)
{
local items = [];
for (local i = 0; i < ::Const.ItemSlot.COUNT; i++)
if (ret && this.m.Skill == null)
{
foreach (j, item in _entity.getItems().m.Items[i])
local items = [];
for (local i = 0; i < ::Const.ItemSlot.COUNT; i++)
{
if (item != itemsBefore[i][j] && items.find(item) == null)
foreach (j, item in _entity.getItems().m.Items[i])
{
if (item != null && item != -1) items.push(item);
if (itemsBefore[i][j] != null && itemsBefore[i][j] != -1) items.push(itemsBefore[i][j]);
if (item != itemsBefore[i][j] && items.find(item) == null)
{
if (item != null && item != -1) items.push(item);
if (itemsBefore[i][j] != null && itemsBefore[i][j] != -1) items.push(itemsBefore[i][j]);
}
}
}
_entity.getItems().payForAction(items);
}
_entity.getItems().payForAction(items);
}

return ret;
}
return ret;
}
});
});
Loading