mirror of
https://github.com/bryanthaboi/gen1recomp.git
synced 2026-08-17 11:11:10 +02:00
big ass modding update
This commit is contained in:
+30
-15
@@ -1,31 +1,46 @@
|
||||
-- Turn order, from engine/battle/core.asm MainInBattleLoop: compare
|
||||
-- effective speed; ties are a coin flip. QUICK_ATTACK moves first and
|
||||
-- COUNTER last (Gen 1 has only these two priority moves, checked by id).
|
||||
-- effective speed; ties are a coin flip. Move priority reads the move
|
||||
-- record's priority field; the id table below covers pre-existing
|
||||
-- imported caches (Gen 1 has only QUICK_ATTACK first and COUNTER last).
|
||||
|
||||
local Damage = require("src.battle.Damage")
|
||||
local Stats = require("src.pokemon.Stats")
|
||||
local Status = require("src.battle.Status")
|
||||
|
||||
local TurnOrder = {}
|
||||
|
||||
local function effectiveSpeed(battler)
|
||||
local spd = Stats.applyStage(battler.curStats.speed,
|
||||
battler.stages and battler.stages.speed or 0)
|
||||
-- ApplyBadgeStatBoosts: the SOULBADGE (bit 4) boosts speed
|
||||
if battler.badges and battler.badges.SOULBADGE then
|
||||
spd = math.floor(spd * 9 / 8)
|
||||
-- ApplyBadgeStatBoosts: the SOULBADGE boosts speed; the rows come from
|
||||
-- the battler's merged badgeBoosts with the vanilla list as fallback
|
||||
local badges = battler.badges
|
||||
if badges then
|
||||
for _, row in ipairs(battler.badgeBoosts or Damage.BADGE_BOOSTS) do
|
||||
if row.stat == "speed" and badges[row.badge] then
|
||||
spd = math.floor(spd * (row.num or 9) / (row.den or 8))
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
-- paralysis quarters speed; hazeStatReset suppresses it because Haze
|
||||
-- (haze.asm ResetStats) copied the unmodified speed over the quartered
|
||||
-- battle stat, lifting the penalty until the next stat recompute.
|
||||
if battler.mon.status == "PAR" and not battler.hazeStatReset then
|
||||
spd = math.max(1, math.floor(spd / 4))
|
||||
-- paralysis quarters speed (the status record's statPenalty);
|
||||
-- hazeStatReset suppresses it because Haze (haze.asm ResetStats)
|
||||
-- copied the unmodified speed over the quartered battle stat, lifting
|
||||
-- the penalty until the next stat recompute.
|
||||
local record = Status.recordFor(battler.statuses, battler.mon.status)
|
||||
local penalty = record and record.statPenalty
|
||||
if penalty and penalty.stat == "speed" and not battler.hazeStatReset then
|
||||
spd = math.max(1, math.floor(spd / penalty.div))
|
||||
end
|
||||
return spd
|
||||
end
|
||||
|
||||
local function priority(moveId)
|
||||
if moveId == "QUICK_ATTACK" then return 1 end
|
||||
if moveId == "COUNTER" then return -1 end
|
||||
return 0
|
||||
local PRIORITY = { QUICK_ATTACK = 1, COUNTER = -1 }
|
||||
|
||||
local function priority(move)
|
||||
if not move then return 0 end
|
||||
if move.priority then return move.priority end
|
||||
return PRIORITY[move.id] or 0
|
||||
end
|
||||
|
||||
-- Returns true when battler a moves before battler b. invertTie flips
|
||||
@@ -34,7 +49,7 @@ end
|
||||
-- who moves first.
|
||||
function TurnOrder.firstMover(a, aMove, b, bMove, rng, invertTie)
|
||||
rng = rng or love.math.random
|
||||
local pa, pb = priority(aMove and aMove.id), priority(bMove and bMove.id)
|
||||
local pa, pb = priority(aMove), priority(bMove)
|
||||
if pa ~= pb then return pa > pb end
|
||||
local sa, sb = effectiveSpeed(a), effectiveSpeed(b)
|
||||
if sa ~= sb then return sa > sb end
|
||||
|
||||
Reference in New Issue
Block a user