BL Coding Patching/Overriding XML nodes

Users who are viewing this thread

tase

Recruit
Let's say I want my Imperial Recruits to start out barehanded because swords are too expensive.

I see the file Modules\SandBoxCore\ModuleData\spnpccharacters.xml has a NPCCharacter node with the id imperial_recruit with a subnode equipmentSet having itself 3 equipment subnodes. I want to remove the one with the id Item.empire_sword_1_t2.

What's the best way to create a mod for this file? Looking around the documentation and existing mods, the main topic is modding via DLLs, and looking at other mods, the best I've seen is replacing the whole XML file (i.e Bannerlord BannerEditor Enhancer). That feels too heavy-handed. I just want my barehanded recruits in a nice and compact, compatible format.

Edit: Or is there a way to do this via an on-load call in a DLL module?
 
Last edited:

lzh

Regular
All the three equipment has weapon with id Item.empire_sword_1_t2.
You can overwrite the character in a new mod by creating a new xml file and put your character in it. You should specify the xml in SubModule.xml in your mod.
The character loaded later will overwrite the character with the same id loaded earlier, except that equipments will be merged.
If you want to replace the weapon, as I know, you can overwrite the equipment by specifying an equipment element directly in NPCCharacter element. This will replace equipment in the corresponding slot in every equipmentSet defined earlier.
For example, in NPCCharacter with id imperial_recruit:
Code:
...
    <equipmentSet>
      <equipment slot="Item0"
                 id="Item.empire_sword_1_t2" />
      <equipment slot="Body"
                 id="Item.cloth_tunic" />
      <equipment slot="Leg"
                 id="Item.empire_horseman_boots" />
    </equipmentSet>
...
You can add an equipment after it:
Code:
...
    <equipmentSet>
      <equipment slot="Item0"
                 id="Item.empire_sword_1_t2" />
      <equipment slot="Body"
                 id="Item.cloth_tunic" />
      <equipment slot="Leg"
                 id="Item.empire_horseman_boots" />
    </equipmentSet>
    <equipment slot="Item0"
               id="......" />
...
As previously mentioned, the later character will overwrite the earlier character with the same id. So you can copy the definition of imperial_recruit into the xml in your mod and replace code from <equipmentSet> to </equipmentSet> with
Code:
<equipment slot="Item0" id="......" />
Not confirmed though. I just read the decompiled code and infer that it should work.
 
Last edited:
Upvote 0

tase

Recruit
I see the code with presumedObject.Deserialize but not all the things in Deserialize are "mergable".

There are 2 issues here.

1) is I see a lot of default values if the node or attribute isn't present in the XML. I.e the level
Code:
this.Level = attribute5 != null ? Convert.ToInt32(attribute5.InnerText) : 1;
So it won't merge the level but reset it to 1 when it sees the new definition with just the equipment node
If it was something like
Code:
if(attribute5 != null)
{ 
   this.Level = Convert.ToInt32(attribute5.InnerText);
}
else if(!this.Level.HasValue)
{
   this.Level = 1;
}
it would have worked, assuming Level was int?.

2) The loading only adds equipment so the first definition of imperial_recruit will add the equipment, but there is no way for me to remove it, at best I can override the slot with a different item, but that might not work since the behavior is probably undefined if a unit's equipment has 2 items with the same slot.

I tried going the code route but there's no RemoveEquipment on the units
 
Upvote 0
Top Bottom