SteelRook Posted February 20, 2016 Author Share Posted February 20, 2016 I'm not seeing why this would be the case, unless you are doing something unusual that I'm not understanding. 1. When starting a tactical mission, the abilities are gathered, and instanced into XComGameState_Ability classes that are stored in the Abilities array in the XComGameState_Unit. That's what makes them persist through save/quit/load cycle when in the tactical game.2. If the ability has a trigger PostUnitBeginPlay then any effect it has will create an XComGameState_Effect class instance attached to the XComGameState_Unit. This is what makes effects persist through save/quit/load cycle. This trigger can be created using : Template.AbilityTriggers.AddItem(default.UnitPostBeginPlayTrigger); I haven't been able to get it to work, unfortunately. I tried doing that with the function which fires once on loading a new save without the mod and that successfully changed the stats once. Then as soon as I quit and reloaded the tactical game in progress, the ability was back to its default stats from the unmodded game. The only way I could get this to work was to use the UIListener you suggested in the other thread, with a single-iteration boolean check to make sure it doesn't keep messing with stats constantly. That's what eventually fixed it for me, and now it works consistently just because I force the change at the first available UI element. Originally, I thought for sure that weapon stats would be remembered in the save game itself but - as I said - that hasn't worked for me. Save games made with modded items and abilities will "un-mod" themselves on game restart for me. I'm almost done with the thing anyway, so I can show you the whole thing as soon as it's viable for the Workshop. I'd love to be able to pull the BonusDmg value out of the template for 'Blademaster' but so far I haven't been able to do that. It's probably useful to change its text description, too, though I haven't been able to find where those are set. I don't want to post humongous code blocks in the posts themselves, which is why I want to push this to the Workshop at first available opportunity and disseminate it that way. Link to comment Share on other sites More sharing options...
SteelRook Posted February 21, 2016 Author Share Posted February 21, 2016 OK, the mod has been updated to the Steam Workshop. It seems to work so far. If anyone is interested in the full source code (what little of it there is), feel free to check it out. In fact, I would very much appreciate some amount of feedback because this really is... Kind of a mess :) http://steamcommunity.com/sharedfiles/filedetails/?id=629508924 Link to comment Share on other sites More sharing options...
davidlallen Posted February 21, 2016 Share Posted February 21, 2016 I love the splash screen. While it is fresh in your mind, could you write something like a "walkthrough" of your code? Not the gaming sense of walkthrough, but the code review sense. Maybe 2-3 paragraphs of "this class does this, I needed to do this because the other way didn't work", etc. Even if it isn't a guide, it will be easier to get and give feedback on that, rather than looking at the mod code cold. Link to comment Share on other sites More sharing options...
SteelRook Posted February 21, 2016 Author Share Posted February 21, 2016 Certainly, though mine is a tale of woe :) I spent a lot of time trying to figure out how the abilities worked, and ended up trying to create a mash-up of three things. Bladestorm uses a X2Effect_BonusWeaponDamage object to deliver its extra damage, but it doesn't check for weapon tech level. I knew Gremlin skills check for weapon tech level, so I discovered that Aid Protocol uses a X2Effect_AidProtocol special effect to deliver its defence. Internally, that effect pulls the Gremlin template and draws on special variables written in the weapon itself. I tracked down where the weapon is defined in X2Item_DefaultWeapons.uc and saw that these values are given to it at weapon initialisation. This originally prompted me to try and do the same for swords. I would override the three sword-creation functions in X2Item_DefaultWeapons, then redesign them to create a special sword template of my own. This sword template would inherit X2WeaponTemplate and basically just add two extra variables - a damage boost and an AP boost. I'd then do what Aid Protocol did and create a unique damage effect class of my own which would directly ask the sword for those values and add them to the returned damage. This, in turn, would require me to overwrite the ability template creation function responsible for the creation of Blademaster. The above attempt failed spectacularly, by which I mean it failed to work consistently. I did actually manage to overwrite both static functions, but in a very weird way. If I replaced the X2WeaponTemplate in X2Item_DefaultWeapons with another class, then the overwrite would fail - either at the overwrite stage or somewhere down the line. If I didn't, it would work and accept my additional values. So that didn't work at all. This is where this thread ballooned as much as it did as I tried a whole bunch of other methods to replace the weapon and skill templates. Originally, I tried X2DownloadableContentInfo class and its OnLoadedSavedGame() function, but that only worked the first time a non-modded save was loaded. Restarting the game would wipe my changes. I then tried a UIScreen listener as per this thread, and that worked... Kind of. I still couldn't replace the weapon template as that would only replace them for the "default" difficulty, which I believe is Veteran. I couldn't replace the templates for other difficulties, since there's no way to get them without literally changing the game's difficulty, which doesn't work in the main menu and works in a difficult fashion in a Tactical mission, that I could determine. In the end, I scrapped altering the weapon template AT ALL and just altered the Blademaster ability template itself. I replaced it entirely with a brand new ability template of my own creation, one which used my own version of the bonus damage effect. The idea was that that extra bonus damage effect would poll the swords for their tech level and assign bonus damage accordingly. This was until I found that the Magnetic Sword's tech level is set to Conventional in the files, likely a copy/paste error. I ended up having to dig through the class files and eventually decided to check for DataName. That's great, except it won't work for any new sword weapons added to the game, such as the Katana. And this is where I am now. Let me give you a class-by-class breakdown. --- *ModInitialiser. This is the "hook" I'm using to put my new code in the game. This class is nothing more than a UIScreenListener set to listen to every screen in the game, so it fires right in the main menu. It has a run-once check, however, so it shouldn't kill performance. What that class does is it pulls the Bladestorm template out of the ability template manager, creates a brand new ability template, copies all of the values from the old ability, then replaces the new ability in the template manager. I'm having some odd icon issues with the thing - if I copy the icon from the old template into the new one, it doesn't show up at all. I had to put the icon string directly in the mod initialiser. Not sure what's going on in there. Basically, this is an attempt to copy the exact same Blademaster ability, except put a X2Effect_BonusEffect_Blademaster effect in it instead of the X2Effect_BonusWeaponDamage one that it has. I didn't want to change anything else. *X2Effect_BonusEffect_Blademaster. This is where the "magic" happens. This class models my unique bonus effect. It extends the basic X2Effect_Persistent, it has seven internal variables (3 for damage, 3 for AP, one for "base") which it pulls out of its own config file for easy adjustment. X2Effect_BonusEffect_Blademaster is a combination of the way Blademaster gets its bonus damage and the way AP Rounds add their armour penetration. Both use a version of X2Effect_Persistent but override different functions, so I just put both functions in the same class. The functions check the weapon which called the skill. If it's a sword, they do something. They then check the sword template's name and return bonus damage or AP accordingly. Bonus damage is calculated as base damage + bonus damage, obviously. *XComBlademasterEnhancement.ini. This is the config file where all seven variables' values are defined. I could have hard-coded that in the script, but I like to give users an easy way to tweak stats. I put BonusDmamageBase in there because I couldn't figure out a way to copy the bonus damage of the vanilla Blademaster skill. I originally had it hardcoded to +2, but decided it's better to let players set it themselves. It's not as good as using what's in the game's own ini files, but at least it's not hardcoded. I still don't know how to change the ability's textual description and its icon is behaving... Oddly. But it works for the moment. Link to comment Share on other sites More sharing options...
SteelRook Posted February 23, 2016 Author Share Posted February 23, 2016 (edited) OK, I'm running into severe problems, and this is BAD because the mod's actually on the Workshop now. Something is horribly wrong with the way I insert the Blademaster skill into the game. It has the following behaviour - when loading a saved Tactical game where the soldier already has Blademaster, everything works as intended. When loading a Strategic game where a soldier has Blademaster, that skill simply doesn't end up making it into the character's skillset when a Tactical game is loaded. I'm really at a loss as to what's going on here. Clearly, I failed to comprehend something that was being said here. Clearly, I'm doing something wrong and I may end up having to replace an entire class. I have to ask, then - suppose I want to replace an entire ability (in this case Blademaster) - with an entire other ability, but without using mod class overrides. How could I accomplish this? Because creating a brand new ability just doesn't seem to be working. I can't use the ability class defaults since I need to extend UIScreenListener, and I'm out of ideas as to how to do this without overriding stuff in the Ranger class. I really, REALLY need help for this one because that's starting to not work for people... *edit*Because people are actually using the mod now, I had to make it work RITE NAO. For this reason I had to go with the "nuclear option" of overriding the X2Ability_RangerAbilitySet class. I don't like doing this because it's hell on mod compatibility, but I know it works 100% of the time (unlike overriding DefaultWeapons). I definitely want to go back to changing this via a listener, but it's clear I'm not smart enough to make that happen on my own. I'm really, REALLY going to need help getting this to work. There's something about this that I simply don't understand, some step where all of the abilities are "written down" and don't get lost between loads. I don't know how to do this. Edited February 23, 2016 by SteelRook Link to comment Share on other sites More sharing options...
Recommended Posts