Login
Topic: Weapon skills lost on load if multiple skills call unequip and equip in onAdded
Home › Forums › Battle Brothers: Bug Reports › Weapon skills lost on load if multiple skills call unequip and equip in onAdded
- This topic has 0 replies, 1 voice, and was last updated 3 years, 4 months ago by
lordmidas.
-
AuthorPosts
-
15. August 2022 at 21:11 #29140
lordmidasParticipantThe
addfunction ofskill_containerdoes not check for!skill.isGarbage()for skills in theSkillsToAddarray, causing it to return from the function too early if a skill exists inSkillsToAddwhich is garbage. This didn’t use to be an issue because skills inSkillsToAddaren’t expected to be garbage, but, it is now possible.Take a look at the vanilla skill
orc_warlord_potion_effectwhich callsunequipand thenequipon the character’s Mainhand item in itsonAddedfunction. This doesn’t cause any issues right now as it is the only skill in the game that does this. However, even if ONE other such skill exists which does the same thing, this will result in the character losing the equipped weapon skills upon loading as saved game. The user will then be required to unequip and re-equip the weapon manually to get the skills.The reason it happens is the following:
1. Upon loading a saved game, the character equips the weapon he was saved with. This adds the weapon’s skills to the character.
2. During skill_container deserialization, the skills are added to the character. This callsonAddedon all such skills.
3. During theonAddedfunction of a skill, the character unequips the weapon. This sets the weapon’s skills currently in theSkillsarray of the skill_container toGarbage.
4. Then the skill callsequipon the weapon. This adds the weapon’s skills to theSkillsToAddarray of the character’s skill_container because the skill_container’sIsUpdatingboolean is true during deserialization.
5. Now, imagine we have another skill that does the same process of callingunequipandequipin itsonAddedfunction.
6. The character again unequips the weapon. This calls<skill_container>.remove( _skill )function for all the skills of the weapon. As the parameter_skillis passed by reference, it sets the skills toGarbageeven while they are in theSkillsToAddarray from point 4.
7. The skill now callsequipon the weapon. But the skills are not added to the character as they already exist inSkillsToAddand the function returns because of the following code (marked by a comment):function add( _skill, _order = 0 ) { if (!_skill.isStacking()) { foreach( i, skill in this.m.Skills ) { if (!skill.isGarbage() && skill.getID() == _skill.getID()) { skill.onRefresh(); return; } } foreach( i, skill in this.m.SkillsToAdd ) { if (skill.getID() == _skill.getID()) { return; // Function returns here } } } _skill.setContainer(this); _skill.setOrder(_skill.getOrder() + _order); if (this.m.IsUpdating) { this.m.SkillsToAdd.push(_skill); } else { this.m.Skills.push(_skill); _skill.onAdded(); _skill.m.IsNew = false; this.m.Skills.sort(this.compareSkillsByOrder); this.update(); } }8. Then when the skills are added to the character, they get removed during the next
collectGarbagebecause they were added asGarbage.This entire problem can be solved by changing the
ifstatement in theforeachloop that iterates overSkillsToAddtoif (!skill.isGarbage() && skill.getID() == _skill.getID())This is NOT solely a modding related bug. It is an oversight in vanilla code which will cause a bug in vanilla game too if any vanilla skill is added which calls
unequipandequipin itsonAddedfunction. -
AuthorPosts
- You must be logged in to reply to this topic.
