From 715ebe95fcae19725cee66f54ba5bafc7db6069e Mon Sep 17 00:00:00 2001
From: yutio888 <yutio888@qq.com>
Date: Sun, 13 Jun 2021 20:30:29 +0800
Subject: [PATCH] Rework Step Up: Each kill provides a 2-turn buff that gives
 1000% movement speed for several moves, and any action other than moving will
 remove the buff. Reasons: 1. removes raw talent level usage & removes
 old-fashioned callback in Actor.lua 2. makes it more predictable and reliable
 3. talent level above 5 gives small bonus

---
 game/modules/tome/class/Actor.lua                 |  4 ----
 .../data/talents/techniques/battle-tactics.lua    | 15 ++++++++++++---
 game/modules/tome/data/timed_effects/physical.lua | 15 ++++++++++++---
 3 files changed, 24 insertions(+), 10 deletions(-)

diff --git a/game/modules/tome/class/Actor.lua b/game/modules/tome/class/Actor.lua
index 16746f9be7..5c0de7ef62 100644
--- a/game/modules/tome/class/Actor.lua
+++ b/game/modules/tome/class/Actor.lua
@@ -3344,10 +3344,6 @@ function _M:die(src, death_note)
 		p.kills = p.kills + 1
 	end
 
-	if src and src.knowTalent and src:knowTalent(src.T_STEP_UP) and rng.percent(src:getTalentLevelRaw(src.T_STEP_UP) * 20) then
-		game:onTickEnd(function() src:setEffect(self.EFF_STEP_UP, 1, {}) end)
-	end
-
 	if src and self.reset_rush_on_death and self.reset_rush_on_death == src then
 		game:onTickEnd(function()
 			src:alterTalentCoolingdown(src.T_RUSH, -1000)
diff --git a/game/modules/tome/data/talents/techniques/battle-tactics.lua b/game/modules/tome/data/talents/techniques/battle-tactics.lua
index 3c80ee93fc..103a1139b8 100644
--- a/game/modules/tome/data/talents/techniques/battle-tactics.lua
+++ b/game/modules/tome/data/talents/techniques/battle-tactics.lua
@@ -40,16 +40,25 @@ newTalent{
 	end,
 }
 
-newTalent{ -- Doesn't scale past level 5, could use some bonus for higher talent levels
+newTalent{
 	name = "Step Up",
 	type = {"technique/battle-tactics", 2},
 	require = techs_req_high2,
 	mode = "passive",
 	points = 5,
+	getSteps = function(self, t)
+		local globalSpeedBonus = math.max(1, self.global_speed or 1)
+		return math.ceil(self:combatTalentScale(t, 1, 7) * globalSpeedBonus)
+	end,
+	callbackOnKill = function(self, t)
+		game:onTickEnd(function() self:setEffect(self.EFF_STEP_UP, 2, { nb = t.getSteps(self, t)}) end)
+	end,
 	info = function(self, t)
-		return ([[After killing a foe, you have a %d%% chance to gain a 1000%% movement speed bonus for 1 game turn.
+		local steps = t.getSteps(self, t)
+		return ([[After killing a foe, you gain a 1000%% movement speed bonus in next %d steps for 2 turns.
 		The bonus disappears as soon as any action other than moving is done.
-		Note: since you will be moving very fast, game turns will pass very slowly.]]):tformat(math.min(100, self:getTalentLevelRaw(t) * 20))
+		The maximum steps increases with your current global speed.
+		Note: since you will be moving very fast, game turns will pass very slowly.]]):tformat(steps)
 	end,
 }
 
diff --git a/game/modules/tome/data/timed_effects/physical.lua b/game/modules/tome/data/timed_effects/physical.lua
index 29f5967f4a..63dc0ede53 100644
--- a/game/modules/tome/data/timed_effects/physical.lua
+++ b/game/modules/tome/data/timed_effects/physical.lua
@@ -1277,21 +1277,30 @@ newEffect{
 newEffect{
 	name = "STEP_UP", image = "talents/step_up.png",
 	desc = _t"Step Up",
-	long_desc = function(self, eff) return ("Movement is %d%% faster."):tformat(eff.power) end,
+	long_desc = function(self, eff) return ("Movement is 1000%% faster for next %d moves."):tformat(eff.nb or 1) end,
 	type = "physical",
 	subtype = { speed=true, tactic=true },
 	status = "beneficial",
 	parameters = {power=1000},
 	on_gain = function(self, err) return _t"#Target# prepares for the next kill!", _t"+Step Up" end,
 	on_lose = function(self, err) return _t"#Target# slows down.", _t"-Step Up" end,
+	charges = function(self, eff) return eff.nb or 1 end,
 	get_fractional_percent = function(self, eff)
 		local d = game.turn - eff.start_turn
 		return util.bound(360 - d / eff.possible_end_turns * 360, 0, 360)
 	end,
 	lists = 'break_with_step_up',
+	callbackOnMove = function(self, eff, moved, force, ox, oy)
+		if not moved or force then return end
+		if self:attr("free_movement") then return end
+		eff.nb = (eff.nb or 1) - 1
+		if eff.nb <= 0 then
+			self:removeEffect(self.EFF_STEP_UP, false, true)
+		end
+	end,
 	activate = function(self, eff)
 		eff.start_turn = game.turn
-		eff.possible_end_turns = 10 * (eff.dur+1)
+		eff.possible_end_turns = 10 * (eff.dur+2)
 		eff.tmpid = self:addTemporaryValue("step_up", 1)
 		eff.moveid = self:addTemporaryValue("movement_speed", eff.power/100)
 -- should change priorities rather than forbid all talents
@@ -1300,7 +1309,7 @@ newEffect{
 	deactivate = function(self, eff)
 		self:removeTemporaryValue("step_up", eff.tmpid)
 		if eff.aiid then self:removeTemporaryValue("ai_state", eff.aiid) end
-		self:removeTemporaryValue("movement_speed", eff.moveid)
+		if eff.moveid then self:removeTemporaryValue("movement_speed", eff.moveid) end
 	end,
 }
 
-- 
GitLab