ReturnToOverworld¶
This terminal coroutine is the last one invoked to transition out of battle. It is always invoked in a finished battle except for a save reload serving as the last step before the battle is completely ended.
public IEnumerator ReturnToOverworld(bool flee)
Parameters¶
flee: Whether or not the battle ended as a result of fleeing
Procedure¶
The following sections are performed in order.
Fade out¶
- We enter a
minipause - MainManager.
battlenoexpis set to whether or notexprewardis exactly 0 - The
switchicon,cancelbandhexpcounterare destroyed - A fade out to pure black is done via PlayTransition with a speed of 0.075
- A frame is yielded
- All frames are yielded while
transitionobj[0]'s SpriteRenderer's alpha hasn't reached 95% opacity or MainManager.musiccoroutineis still in progress - 0.25 seconds are yielded
transitionobj[0]'s SpriteRenderer's alpha is set to fully opaque- A frame is yielded
Battle teardown¶
- The
battlemapis destroyed - instance.
globalcooldownis set to 30.0 frames - A frame is yielded
- MainManager.
mapis enabled - A frame is yielded
- For each player party members:
- If the player isn't a
submarine, theirentityis enabled - All matching
hudelements have their first child local position set to Vector3.zero
- If the player isn't a
- If the player is a
submarine, the player is enabled - If we weren't in a instance.
inevent:- MainManager.ResetCamera is called with instant
- instance.
camoffsetand instance.camangleoffsetare reset to their previous counterpart beingoldcamoffsetandoldcamrotationrespectively
- RestoreLimit is called on the
mapwith restoretemp - A frame is yielded
- The
fronticonandexpholderare destroyed - 0.1 seconds are yielded
- instance.
camspeedis reset to its previous counterpart beingoldcamspeed - A frame is yielded
Overworld setup¶
- MainManager.
battlefledis set to the sent flee value - MainManager.player.entity.
ongroundis set to false
The rest has multiple possibilities on how to setup the overworld, but they are mutually exclusive, only the first one mentioned applies. It is possible none applies.
Flee is true¶
This means the battle ended due to the player fleeing:
- MainManager.player.entity.
icooldownis set to 120.0 frames of invicibility - If the
callerexists, some adjustements needs to happen on it (it implies thecalleris an Enemy NPCControl):- STOP is called on the
callerwhich does the following if thecaller.entityisn'tdead:- Stop
behaviorroutineif it was in progress and set it to null - Set
forcebehaviorto null and call StopForceBehavior - Call StopForceMove on the entity
- Set the entity.
overrideflipand entity.overrideonlyflipto false - Set
attackingto false
- Stop
caller.entity.overrideanimis set to falsecaller.entity.overrideflipis set to falsecaller.entity.ongroundis set to false- If the
caller's regionalflag isn't negative, the slot value is set to false - If the
caller's activationflag isn't negative, the slot value is set to false - All collisions between the
caller.entity.ccoland the player.entity.ccolare ignored
- STOP is called on the
Flee is false and the caller exists¶
This means the battle ended without fleeing and it was caused by an Enemy NPCControl encounter:
- MainManager.player.entity.
icooldownis set to 120.0 frames of invicibility caller.entity.ongroundis set to falsecallet.entity.rigidvelocity is zeroed out- The
callertransform position is set to itslastpos(this was set by NPCControl.StartBattle so the positions is restored to the one before the battle started) caller.attackingis set to false- If
exprewardis 0,enemyfledis true and instance.lastdefeateddoesn't contain aGoldenSeedlingenemy:- MainManager.
battleenemyfledis set to true calleris disabled
- MainManager.
- Otherwise, if the
caller.entity.deathcoroutineisn't in progress:caller.entity.deathcoroutineis set to a new Death call with activatekill on thecaller.entity- If the
Death0wasn't playing or it was past the halfway point, it is played at 0.6 volume caller.entity.spitmoneyis set tomoneyreward, but it can get multipliers depending on some conditions (these multipliers aren't mutually exclusive, they can stack):
Flee is false, enemyfled is true and expreward is 0¶
The only thing that happens here is MainManager.battleenemyfled is set to true
Other teardown¶
- A frame is yielded
- instance.
inbattleis set to false - ItemList's
listredirectis set to -1 (this workarounds potential inlist issues) - player.entity.
hitwallis set to false - CancelAction is called on the player
- RefreshEntities is called with forceanim and refreshmap
- instance.
showmoneyand instance.hudcooldownare set to 0.0 (this hides all HUD elements) - All GameObjects with tag
DelAftBtlorProjectileare destroyed - The
dimmeris destroyed - A frame is yielded
Fade in¶
The logic here depends on instance.inevent.
We weren't in an event¶
- If
music[0]exists:- If
overworldmusicexists and its name isn't themusic[0]'s name,music[0].volume is set to 0.0 - If
music[0].name isLevelUpandmap.nobattlemusicis true, ChangeMusic is called which will change the music to either silence or tomap.music[map.musicid]if it exists
- If
- A frame is yielded
- If MainManager.
keepmusicafterbattleis true, MainManager.musicresumeis set toovermusic - ChangeMusic is called with the
overworldmusic. NOTE: It can mean ChangeMusic is called twice, but the second one will stop the first via a StopCoroutine - MainCamera's parent angles are set to instance.
camangleoffset - A frame is yielded
- A fade in from pure black is performed via PlayTransition with a speed of 0.05 which undoes the fade earlier
- We exit the
minipause
We were in an event¶
- If
keepmusicis false, ChangeMusic is called to silence with a fadespeed of 0.075 - ResetEntitySpeed is called which sets all
map.entititiesand all player party members's entityanim.speed to 1.0
This implies that events are responsible for doing the fade in themselves as well as the other logic mentioned above in the non event case.
Final cleanup¶
actiontextis destroyed- ForceHitWall is invoked on the player.entity in 0.2 seconds which will set its
hitwallto false - Every player party members with an
hpof 0 has theirhpset to 1 - CheckAchievement is invoked on the instance in 0.5 seconds
- This BattleControl is destroyed, the battle is now completely over and it cease to exist