Skip to content

Commit

Permalink
Merge branch 'main' into development
Browse files Browse the repository at this point in the history
  • Loading branch information
LordMidas committed Sep 21, 2023
2 parents 57cfdad + e0f6edf commit f6ca66d
Show file tree
Hide file tree
Showing 13 changed files with 68 additions and 29 deletions.
6 changes: 5 additions & 1 deletion msu/hooks/ai/tactical/behaviors/ai_switchto_melee.nut
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
o.onExecute = 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++)
{
itemsBefore[i] = clone _entity.getItems().m.Items[i];
Expand All @@ -14,8 +16,10 @@

if (ret)
{
if (this.m.IsNegatingDisarm)
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
Expand Down
22 changes: 5 additions & 17 deletions msu/hooks/items/item_container.nut
Original file line number Diff line number Diff line change
Expand Up @@ -46,27 +46,15 @@

o.getStaminaModifier <- function( _slots = null )
{
if (_slots == null)
{
_slots = clone ::Const.ItemSlot;
delete _slots.None;
delete _slots.COUNT;
}
else
{
if (typeof _slots == "integer") _slots = [_slots];
}

local ret = 0;

foreach (slot in _slots)
if (_slots == null) _slots = ::Const.ItemSlotSpaces; // We use the ItemSlotSpaces array because its indices align perfectly with the actually usable ItemSlots
else if (typeof _slots == "integer") _slots = [_slots];

for (local i = 0; i < _slots.len(); i++)
{
local items = this.getAllItemsAtSlot(slot);
foreach (item in items)
foreach (item in this.getAllItemsAtSlot(_slots == ::Const.ItemSlotSpaces ? i : _slots[i]))
{
// Avoid exceptions for items which don't have getStaminaModifier()
// This handles cases such as Quivers in ammo slot which don't have
// this function in vanilla but do in mods like Legends
if (::MSU.isIn("getStaminaModifier", item, true)) ret += item.getStaminaModifier();
}
}
Expand Down
1 change: 1 addition & 0 deletions msu/hooks/items/weapons/weapon.nut
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
local ret = addSkill(_skill);
if (::MSU.isIn("AdditionalAccuracy", _skill.m, true))
{
_skill.resetField("AdditionalAccuracy");
_skill.m.AdditionalAccuracy += this.m.AdditionalAccuracy;
_skill.setBaseValue("AdditionalAccuracy", _skill.m.AdditionalAccuracy);
}
Expand Down
13 changes: 7 additions & 6 deletions msu/hooks/skills/skill.nut
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@
this.m.DamageType.add(::Const.Damage.DamageType.Unknown);
}
}

if (this.getID() in ::MSU.AI.VanillaSkillIDToBehaviorIDMap)
this.m.AIBehaviorID = ::MSU.AI.VanillaSkillIDToBehaviorIDMap[this.getID()];
}
}
});
Expand Down Expand Up @@ -238,10 +235,14 @@
this.saveBaseValues();
setContainer(_c);

if (this.m.AIBehaviorID != null && this.getContainer().getActor().getAIAgent().getID() != ::Const.AI.Agent.ID.Player)
if (this.m.AIBehaviorID != null && !::MSU.isNull(this.getContainer().getActor()))
{
this.getContainer().getActor().getAIAgent().addBehavior(::new(::MSU.AI.getBehaviorScriptFromID(this.m.AIBehaviorID)));
this.getContainer().getActor().getAIAgent().finalizeBehaviors();
local agent = this.getContainer().getActor().getAIAgent();
if (!::MSU.isNull(agent) && agent.getID() != ::Const.AI.Agent.ID.Player)
{
agent.addBehavior(::new(::MSU.AI.getBehaviorScriptFromID(this.m.AIBehaviorID)));
agent.finalizeBehaviors();
}
}
}

Expand Down
13 changes: 12 additions & 1 deletion msu/systems/keybinds/key_static.nut
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,17 @@
}
}

function getMouseState( _rawMouseState )
{
switch (_rawMouseState)
{
case 0:
return this.KeyState.Press;
case 1:
return this.KeyState.Release;
}
}

function isKnownKey( _key )
{
return _key.getKey().tostring() in this.KeyMapSQ;
Expand Down Expand Up @@ -200,7 +211,7 @@
},
ReverseKeyMapJS = {
"backspace" : "8",
"tabulator" : "9",
"tab" : "9",
"return" : "13",
"shift" : "16",
"ctrl" : "17",
Expand Down
2 changes: 1 addition & 1 deletion msu/systems/keybinds/keybinds_system.nut
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
function onMouseInput( _mouse, _environment, _state )
{
local keyAsString = ::MSU.Key.MouseMapSQ[_mouse.getID().tostring()];
return this.onInput(_mouse, _environment, _state, keyAsString, _mouse.getState());
return this.onInput(_mouse, _environment, _state, keyAsString, ::MSU.Key.getMouseState(_mouse.getState()));
}

// Private
Expand Down
8 changes: 8 additions & 0 deletions msu/systems/mod_settings/elements/keybind_setting.nut
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
::MSU.Class.KeybindSetting <- class extends ::MSU.Class.StringSetting
{
static Type = "Keybind";

// Temporary to fix savegames
// TODO Remove with 1.3.0
function __setFromSerializationTable( _table )
{
_table.Value = ::String.replace(_table.Value, "tabulator", "tab");
base.__setFromSerializationTable(_table);
}
}
19 changes: 19 additions & 0 deletions msu/systems/serialization/load.nut
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,22 @@ includeFile("deserialization_emulator");
includeFile("serialization_system.nut");
::MSU.System.Serialization <- ::MSU.Class.SerializationSystem();
includeFile("serialization_mod_addon.nut");

::MSU.UI.addOnConnectCallback(function()
{
local worldState = ::new("scripts/states/world_state");
local serEm = ::MSU.Class.SerializationEmulator(::MSU.ID, "WorldStateOnBeforeSerialize", ::new("scripts/tools/tag_collection"), ::MSU.Class.MetaDataEmulator());
::MSU.System.Serialization.MetaData = serEm.getMetaData();
::World.Assets <- {
getName = @() "msuDummy",
getBanner = @() "msuDummy",
getCombatDifficulty = @() 1,
getEconomicDifficulty = @() 1,
isIronman = @() false,
}
::World.Assets.setdelegate({ // attempted patch for any other function calls
_get = @(_k)@(...)""
});
worldState.onBeforeSerialize(serEm);
delete ::World.Assets;
});
6 changes: 6 additions & 0 deletions msu/systems/serialization/metadata_emulator.nut
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,10 @@
{
return "";
}

function _cloned( _original )
{
this.Data = clone _original.Data;
this.Version = _original.Version;
}
}
2 changes: 1 addition & 1 deletion msu/systems/serialization/serde_emulator.nut
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

constructor(_mod, _id, _flagContainer, _metaDataEmulator = null)
{
if (_metaDataEmulator == null) _metaDataEmulator = ::MSU.Class.MetaDataEmulator();
if (_metaDataEmulator == null) _metaDataEmulator = clone ::MSU.System.Serialization.MetaData;
if (this.__IDRegex.match(_id))
{
::logError("the ID passed to flag serialization cannot end with a full stop followed by digits so it doesn't collide with internal MSU flags");
Expand Down
1 change: 1 addition & 0 deletions msu/systems/serialization/serialization_system.nut
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{
Mods = null;
EmulatorsToClear = null;
MetaData = null;

constructor()
{
Expand Down
2 changes: 1 addition & 1 deletion scripts/config/!msu.nut
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
::MSU <- {
Version = "1.2.2",
Version = "1.2.7",
ID = "mod_msu",
Name = "Modding Standards & Utilities (MSU)",
VanillaID = "vanilla",
Expand Down
2 changes: 1 addition & 1 deletion ui/mods/msu/keybinds/key_static.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ MSU.Key = {
},
KeyMapJS : {
8 :"backspace",
9 :"tabulator",
9 :"tab",
13 :"return",
16 :"shift",
17 :"ctrl",
Expand Down

0 comments on commit f6ca66d

Please sign in to comment.