StartBattle - Post halfload¶
This is the last of 3 phases of StartBattle.
This section occurs after halfload is set to true and the coroutine yielded making the new value visible to the rest of the game.
Last player and enemy setup¶
This part only contains miscellaneous initialisations logic mainly about the playerdata and enemydata:
- All
enemydatabattleentity have theirrigidgravity enabled - The
dimmergets childed to thebattlemapwith a clear color and then disabled (this reveals the scene as it was hidden earlier) - If instance.
firstbattleactionis false (this is the first StartBattle call since the save was loaded)- A DoAction call starts with the first
playerdatabattleentity with action -555. -555 is a special value that will bypass most meaningful logic of the coroutine. In other words, it can be viewed as doing a blank call: nothing of note will happen and no actual action will be processed. The reason this is done has to do with a performance issue with DoAction where its IL code is large enough to stutter the game when compiling it with the JIT and this provokes this stutters early. Because this is done right before the battle out transition, it's less perceivable than if it was on the first action, hence this odd logic. - All frames are yielded while
actionis true until it goes to false - 0.5 seconds are yielded
- instance.
firstbattleactiongets set to true
- A DoAction call starts with the first
- A frame is yielded
Battle out transition¶
This part only plays the battle out transition by calling PlayTransition with id 3 (the battle out transition), the data being the map.battleleaftype at 0.025 speed and the color being the same one used for the previous transition played earlier.
0.2 seconds are yielded after.
dizzytime logic¶
This party only happens if calledfrom exists with a dizzytime above 0.0 (the player should get the advantage):
- The
playerdatawith atrueid(which is the animid) that matches the firstpartypointeris found and itscantmoveis set to -1 andreceivedrelayof the correspondingplayerdataindex is set to true. This essentially gives an additional turn to the lead party member and also allows theirtiredpartto be enabled by UpdateAnim - calledfrom.
dizzytimeis set to 0.0 - If at least one
Ambushmedal is equipped:- Yield for 0.5 seconds
- Each enemy party member has DoDamage called with them as the target, null attacker and NoExceptions property for a damageammount that is the amount of
Ambushmedals equipped. NOTE: This can't be lethal because if thehpof the enemy party members becomes 0, it is set to 1 - Yield for 0.5 seconds
- Yield return DropEenemies with all enemy party members so that if they need to be dropped, it will be done immediately before resuming
switchicon initialisation¶
This part initialises the switchicon if it didn't exist as a new GameObject with name switchicon childed to the GUICamera with a local position of (0.0, 99.0, 0.0).
It also causes 3 children to get added to it:
- A new UI object named
arrow0with size Vector3.one * 0.4 using the spriteguisprites[92](right turn black arrow) with a sortingOrder of 3 with angles (0.0, 0.0, 180.0). The local y/z positions is 0 and the x is -1.0 except iflongcancelis true where it becomes -1.25 - Another instance of the above, but the name is
arrow1, there is no angles and the x position is the positive version instead of the negative one - A new GameObject named
buttonwith a ButtonSprite component with SetUp called on it using input 5 (Cancel), -1 as onlytype, no description, local position of Vector3.zero, iconsize of Vector3.on * 0.4, sortingOrder of 0 and theswitchiconas the parent making it also the actual parent when its Start occurs
State reset¶
This resets some important state fields:
currentturnsis set to -1 (no player selected)turnsis set to 0cancelupdateis set to falseenemyis set to false- instance.
inbattleis set to true - if
sadvis not negative, adv is set to it sadvis set to adv (which only does anything if it was 3)
Enemy first strike¶
This part only happens if adv is 3:
enemyis set to true (we temporarilly go into the enemy phase)- firststrike is set to true
- UpdateAnim is called
- instance.
hudcooldownis set to 10.0 which shows the main HP / TP HUD - instance.
showmoneyis set to -1.0 which hides the berry count HUD actionis set to true (enter an uncontrolled flow)- RefreshEnemyHP is called
- 0.15 seconds are yielded
- A DoAction call is started on
enemydata[0] - All frames are yielded while
actionis true until it goes to false. This yield doesn't just yield until DoAction is done because Update has priority over StartBattle as StartBattle is a coroutine. It will yield until enemydata[0].tiredis set to 0enemydata[0].cantmoveis set to 0actionis set to true (goes back into an uncontrolled flow)- A CheckDead is started with the coroutine being stored in
checkingdead - All frames are yielded while
checkingdeadis in progress - All
enemydatahave theirtiredandcantmoveset to 0. NOTE: This is incorrect and it should been set to -moves + 1. The overall effect of this error is enemies with amovesof 2 or above looses all, but one actor turn on the battle's first main turn currentturnsis set to -1actionis set to false (resets to a uncontrolled flow)- firststrike is set to false
enemyis set to false (reset to be in the player phase)- SetLastTurns is called which resets
lastturnsto a new array with the length being the amount of free players - 1 and all elements being -1
Conditions special logic¶
This part manages the player and enemies conditions as they have special logic to them that must occur at the very end.
If saveddata is true (this is a retry), SetStartConditions is called which will do the following:
- Add all the corresponding
sdata.pscto eachplayerdata's condition from the existing ones - Add all the corresponding
sdata.escto eachenemydata's condition from the existing ones - Add all the corresponding
sdata.enemyweaknessto eachenemydata's weakness from the existing ones - SetLastTurns is called which resets
lastturnsto a new aray with the length being the amount of free players - 1 and all elements being -1
After, all playerdata's condition's element that have a turn count of 0 or below are removed
From there, the RandomStart medal takes effect if it's equipped for each playerdata that has it. The effec involves a GetChance test that is performed with 16 weights with outcomes from 0 to 6 and what happens here depends on the result:
- 0 (3/16): StatusEffect is called on the
playerdatawith AttackUp for 2 actor turns with effect - 1 (3/16): StatusEffect is called on the
playerdatawith DefenseUp for 2 actor turns with effect - 2 (2/16):
- The
StatUpsound is played if it wasn't already - StatEffect is called with the battleentity using type 4 (green up arrow)
- The player party member's
chargeis incremented
- The
- 3 (2/16): If the
playerdata'spoisonresis 100 or above (it's immune to poison), this is treated as an outcome of 2 described above. If it's not:- The
Poisonsound is played if it wasn't already - The
PoisonEffectparticles are played on the battleentity position - SetCondition is called with Poison on the player party member for 2 actor turns unless the
Eternal Venommedal is equipped on it where it's 99999 actor turns instead
- The
- 4 (2/16): The
StatUpsound is played if it wasn't already followed by a StatEffect coroutine being started with the battleentity using type 5 (yellow up arrow) followed by theplayerdata'scantmovebeing decremented (gives an additional actor turn) - 5 (2/16):
- The
Heal3sound is played if it wasn't already - The
MagicUpparticles being played on the battleentity position without sound - SetCondition is called with GradualHP on the player party member for 2 actor turns
- The
- 6 (2/16):
- The
Heal3sound is played if it wasn't already - The
MagicUpparticles are played on the battleentity position without sound - SetCondition is called with GradualTP on the player party member for 2 actor turns
- The
Finally, UpdateConditionIcons is called which calls UpdateConditionBubbles on the battleentity (all playerdata with right to false and all enemydata with hp above 0 with right to true)
Final setup¶
These are the final steps of StartBattle:
turnsis set to 0- MainManager.SortLights is called
- If MainManagr.
music[0]is played and its clip exists,sdata.musicis set to the clip's name saveddatais set to true