Battle System

Tarochi features a battle system use to fight against NPCs, wild monsters or PVP.
== Fight ==
In Tarochi, battles are fought up to 3v3 monsters at a time, and for each turn you can chain up to 2 moves to perform during your turn. A monster may be in the FRONT, MID or BACK position.
The FRONT monster will also always be the one to receive attacks from the opponent. If your FRONT monster is defeated in battle, they will be replaced by your MID monster, and then BACK after. Placing your strongest monsters in the BACK is not always a winning strategy though, as MID monsters only deal 75% damage, and BACK monsters only deal 50% damage.
=== Whisps ===
To avoid wild monster battles turning into a 1v3, every wild monster will be accompanied by two whisps of a random type. Wisps cannot be captured, and do not need to be defeated for the battle to end.
=== Speed bar ===
When you can attack is decided by the yellow bar (the "speed bar") that is based on the speed of your monster in the FRONT position.
=== Health & Healing ===
Each monster has its own health bar.
Health can be recovered in multiple ways:
# Use the recover health move if your monster has one.
# Use a Health Potion (can be used outside of battle).
# Talk to a Healer.
=== Resurrection ===
Monsters who fainted do not come back to life after a battle. You can resurrect a monster in a few ways:
# Use a Resurrection Potion
# Talk to a Healer.
# Have all your monsters faint (they will all come back to life with 1 hp)
=== Stamina ===
Each monster has its own stamina, and every attack consumes a certain amount of stamina. 
Stamina can be recovered in multiple ways:
# Use the recover stamina move. Recovers 30% of your stamina
# 80% is healed after each battle
# When a battle starts, you will recover 12pts per 1 minute since your last fight with that monster.
# Use a Stamina Potion (can be used outside of battle).
# Talk to a Healer.
If you submit an attack that you end up not having enough stamina to perform, recover stamina will instead be used.
=== Monster types ===
Monsters come in a variety of colors. Each color is strong against another color
Monster type 	Blue	Green	Yellow	Red	Grey
Blue attack 	0.9 	1 	0.8 	1.5	1
Green attack 	1 	0.9 	1.5 	0.8	1
Yellow attack	1.5 	0.8 	0.9 	1 	1
Red attack 	0.8 	1.5 	1 	0.9	1
Grey attack 	1 	1 	1 	1 	1.2
=== Status effects ===
There are a variety of straight-forward buffs, there are also poison types for every color 
Each different move has its own "special chance" of succeeding. 
Effects on self only depend on your monster's stats. However, when inflicting a status on an enemy, you need to both roll to successfully apply the effect your attack, and roll a 2nd time to see if the enemy resists the effect. 
Name 	Effect
atk+ 	1.5x base atk
satk+ 	2x base satk
def+ 	+(-4/5 * base_def + 74)% def
sdef+ 	2x base sdef
spd+ 	1.5x base spd
luck+ 	2x base luck
atk- 	0.7x base atk
satk- 	0.5x base satk
def- 	0.7x base def
sdef- 	0.5x base def
spd- 	0.7x base spd
luck- 	0.5x base luck
sleep 	target does not attack
steal life	Steals target monster life
Affected by: dmg, satk and opponent sdef
self-heal 	Heals between 6~16 (before stats & effects)
Affected by: sdef
poison
(see table below for more)	Deals at least 5% of target max health (min 5 dmg).
Affected by: satk, sdef
Poison colors
Name 	Affects color	Effect of debuff
Overgrowth 	green 	poison
Overcharge 	yellow 	poison
Overheat 	red 	poison
Hypothermia	blue 	poison
Statis 	grey 	poison
=== Stats ===
Name	Effect
HP 	Max health. Linear scaling
STM 	Max stamina. Linear scaling
ATK 	Increases both min and max dmg dealt by an attack for each ATK/30
DEF 	Lowers the enemy's attack by (d/100) where d is calculated as a normal distribution with max value DEF
SPD 	Increases attack speed. Double your speed → attack twice as fast
LUCK	
* Increase chance your special effects apply to yourself (baseProbability + luck)
* Increase chance your special effects apply to enemy (baseProbability + luck)
* Reduce chance enemy's special effects apply (baseProbability - luck)
* Increase the mean amount healed by self-heal
* Increase the mean amount of damage when attacking
* Reduce the mean amount of damage when defending
SDEF	
* Reduce chance enemy's special effects apply (baseProbability - sdef)
* Increases max amount healed by self-heal by 20% of SDEF
* Reduce amount of life stolen by SDEF percent
* Reduce poison dmg by (SDEF-50) percent
SATK	
* Increase chance your special effects apply to enemy (baseProbability + satk)
* Increase amount of life stolen by SATK/2 percent
* Increase poison dmg by SATK/3 percent
== Rarity ==
Monsters come in different rarities
Rarity 	Respawn time
Common 	Instant
Uncommon 	Instant
Rare 	1hr
Epic 	4hrs
Legendary	17hrs
== Capture ==
You can capture monsters with capture cards you buy at the Capture Shop. You can only equip two capture cards at once. To equip any capture card you have, you need to return to a city (safe zones not included)
The capture probability is based on the following formula
const levelDiff = maxLevel - monster.monsterStats.level;
let levelFactor = 1;
// If level difference is more than 5 levels, capture probability is 0.
if (levelDiff < -5) levelFactor = 0;
// If level difference is more than 3 levels, capture probability is 0.3
if (levelDiff < -3) levelFactor = 0.3;
// If level difference is more than 1 levels, capture probability is 0.5
if (levelDiff < -1) levelFactor = 0.5;
// If level difference is more than 0 levels, capture probability is 0.7
if (levelDiff < 0) levelFactor = 0.7;
// Power 150 - 200
const captureProbability = (-6 / 5) * monster.monsterData.power + 255; // [150, 200] => [75, 15]
const inverseHPPercent = 1 - monster.health / monster.monsterStats.max_health;
if (WISP_LIST.includes(monster.monsterData.id)) {
 return { captureProbability: 0, inverseHPPercent, levelFactor };
}
const rankModifier = is_rare_plus ? F2(rank) : 1.0;
const baseProbability = captureProbability * inverseHPPercent * levelFactor * (is_rare_plus ? 1/(1.125 * 1.05) : 1/1.125);
if (ownsGenesisTrainer) {
 gt_score = F1(genesis_trainer_points)
 return baseProbability * gt_score
} else {
 return baseProbability;
}
Notably, the capture chance is boosted by your Genesis Trainer Points 
Additionally, just for monsters with a rarity of rare or higher, your player rank also affects the capture chance.
E.g.
* normal monster (power 150), same level with 33% hp = 50% chance of capture
* legendary monster (power 200) 2 levels above with 50% hp = 5% chance of capture
Captured monsters will always start at level 1 (and not the level they were when you captured them)
== Party ==
You can swap the position of your monster during a fight
== Flee ==
Once you visit the next city, the route between the 2 cities will be "Conquered". This will allow you to unlock fleeing for that route. In this way it should be challenging to get from one city to the next as you progress through the game, but once you have then going through the areas in the route will be a breeze, also making it faster to do your Daily Quests.
Flee probability (between 0~100) is defined by the function below
const hp = this.player2.getBattleTeam().front!._health;
const maxHP = this.player2.getBattleTeam().front!.monsterStats.max_health;
const hpPercent = hp / maxHP;
const prob = 33 + 100 * (Math.log10(this.round) / 10) + 100 * (1 - hpPercent);
// console.log({ hp, maxHP, hpPercent, prob });
const baseProbability = Math.min(75, prob);
if (ownsGenesisTrainer) {
 return baseProbability * 0.15; // 15% bonus
} else {
 return baseProbability;
}
== Battle rewards ==
Battles reward you with experience based on the following formula
if (maxLevel(yourMonsters) > maxLevel(enemyMonsters) + 4) {
 // do not award.
 return 0;
}
// award = [slope x=my-level, y=opponent-level] c * x2-x1 / y2-y1;
// 100/c battles with same levels monsters
let slope = 100 / (maxLevel(yourMonsters) + 1);
// Encounter: -50%; lvl1 vs lvl1: 100/3 * 0.5 = 16xp
// PVE: +30%; lvl1 vs lvl1: 100/3 * 1.3 = 43xp
// PVP: 0xp
switch (battleType) {
 case BattleType.arena:
 slope *= 0.75;
 break;
 case BattleType.encounter:
 slope *= 0.5;
 break;
 case BattleType.pve:
 slope *= 1.3;
 break;
 case BattleType.pvp:
 default:
 slope = 0;
 break;
}
const levelSplit = Math.min(2.0, this.aiMaxLevel / this.playerMaxLevel);
const xpAward = (levelSplit * slope) | 0;
const adjustedXp = hasGenesisTrainer
 // 20% bonus, and a random chance of a bonus +1 exp
 ? (xpAward * 1.2) + random(0, 1)
 : xpAward;
const clampedXp = Math.floor(Math.min(adjustedXp, 100));
switch (battleType) {
 case BattleType.arena:
 return clampedXp / (1 + numArenaWins)
 case BattleType.encounter:
 return clampedXp;
 case BattleType.pve:
 // battling the same NPC multiple times in 24hrs reduces the XP awarded every time
 return ((numTrainerMonsters / 3) * clampedXp) / (1 + sameTrainerBattles24hrs);
 case BattleType.pvp:
 default:
 return 0;
}
Additionally, battles may drop Items