TryFlee¶
This action coroutine allows the player to attempt to flee from the battle if an action command is passed. This allows to go directly to the ReturnToOverworld in a terminal flow if the action command is passed. If the action command is failed, all player party members gets all their action turns exhausted which leads to EndPlayerTurn earlier than usual.
Command preparation¶
actionis set to true changing to a controlled flowcommandsuccessis reset to false- instance.
showmoneyis set to 100000000.0 which effectively makes the berry count HUD element shown permanently for now - The instance.
camtargetposis set to (-4.5, 0.0, 2.5) with an instance.camspeedof 0.075 - 10 RigidBodies are initialised to hold lost berries (they each get a SpriteRenderer using the
MoneySmall'sitemsprites) childed to thebattlemapin kinematic mode, but initially placed offscreen at (0.0, 999.0, 0.0) - The
FlipNoisesound is played - For each player party member that isn't IsStopped, the following adjustements happens on their battleentity (this setups their walk in place animations):
- 0.4 seconds are yielded
- A DoCommand coroutine is started with a commandtype of
SequentialKeysusing 250.0 as the timer and the data being one element whose value is 6 unless theSpeedUpmedal is equipped which makes the value 3 instead
Performing the action command¶
This section is in effect as long as doingaction is true. It's where the berry loss happens periodically when applicable. A frame is yielded at the end of every cycle when this section is in effect.
In order for a berry to be lost, the following must be true:
- instance.
moneymust be above 0 - The
SecurePouchmedal is unequipped - flags 162 is false (We aren't in a B.O.S.S or Cave of Trials session)
- A certain amount of frames has passed (tracked by a local framecounter using instance.
framestepas the increment)
The amount of frames that needs to pass to loose a berry depends on estimatedexp. It is calculated by taking (30 - estimatedexp) / 2, clamping it from 5 to instance.neededexp / 2 and finally, multiply the result by 2.0 which also casts it to a float for the counter comparison. What this intuitively mean is that the amount of frames before a berry is lost is always between 5 and 15, but the base amount decreases the more EXP has been accumulated so far. As for the upper clamping bound, it doesn't do anything because the minimum value of instance.neededexp is normally 100 making its half 50 which is higher than 15, the upper bound of the base value if estimatedexp is 0.
All in all, this can be reduced to just (30 - estimatedexp) / 2 clamped from 5 making the overall result from 5 to 15 frames between loosing a berry.
If no berry losses occurs, the local counter is incremented by instance.framestep.
If a berry loss occurs, the following is done on one of the 10 RigidBodies initialised earlier (the index starts at 0 and increments each berry loss, resetting to 0 when reaching 10):
- position is set to a randomly selected player party member's battleentity's position
- kinematic mode is turned off
- velocity is set to RandomItemBounce(4.0, 15.0)
The berry loss ends by decrementing instance.money and resetting the local frame counter to 0.0.
Handling the action command result¶
The rest of the coroutine depends on commandsuccess being true or not indicating the command was succeeded or failed. In either outcome, all RigidBodies initialised earlier are destroyed at the very end.
Success¶
This section is applicable if commandsuccess is true:
- MainManager.
battleresultis set to false - For each player party member that isn't IsStopped, Jump is called on their battleentity
- 0.45 seconds are yielded
- The
Fleesound is played - For each player party member that isn't IsStopped, the following happens on their battleentitty:
- The y position is set to 0.0
- The
rigid's gravity is disabled - MoveTowards is called to move to (-20.0, 0.0, 0.0) with a multiplier of 5.0
- All frames are yielded until the
forcemoveof the battleentity of the last player party member that isn't IsStopped goes to false (meaning the last player party member that was moved is done with itsforcemove) - flagvar 42 (number of fleed battles) is incremented
- ReturnToOverworld is called with flee
Fail¶
This section is applicable if commandsuccess is false:
- The
Failsound is played - For each player party member that isn't IsStopped, the following happens on their battleentitty (this undo what was done on the command preparations with some more animations):
- 0.1 seconds are yielded
- For each player party member that isn't IsStopped, the following happens on their battleentitty:
- DeathSmoke is called with the battleentity
- animstate is set to 18 (
KO) - The
Dropsound is played on the entity (not the battleentity)
- If flags 162 is false (we aren't in a B.O.S.S or Cave of Trials session), all of the 10 RigidBodies will count as a berry loss meaning up to 10 berries are lost (or instance.
moneyberries is lost if less than 10 remained). The following happens for each loss on the concerned RigidBody:- position is set to a randomly selected player party member's battleentity's position
- kinematic mode is turned off
- velocity is set to RandomItemBounce(4.0, 15.0)
- instance.
moneyis decremented - A frame is yielded
- 0.85 seconds are yielded
- SetDefaultCamera is called
- For each player party member that isn't IsStopped, the following happens on their battleentitty:
overridejumpis set to falseoverrideanimis set to falseflipis set to true- The player party member's
cantmoveis set to 1 except for thecurrentturnone where it's set to 0 (this is because its turn will be exhausted soon so all member'scantmovewill end up at 1)
- A frame is yielded
- UpdateAnim is called
- instance.
showmoneyis set to -1 which hides the berry count HUD - EndPlayerTurn is called (which will increment the
currentturnplayer party member so all members'scantmoveends up at 1) actionis set to false switching back to a controlled flow