Skip to content

Commit

Permalink
fix wrath for enemies, move to abilities (#792)
Browse files Browse the repository at this point in the history
* fix wrath for enemies, move to abilities

* seriously luacheck, it's one tab

* move wrath_intensity adjustments to lua

* move wrath_intensity adjustments to lua

* remove variables.wrath*
  • Loading branch information
white-haired-uncle committed May 11, 2024
1 parent dee832c commit 5f9d6ce
Show file tree
Hide file tree
Showing 3 changed files with 156 additions and 395 deletions.
54 changes: 53 additions & 1 deletion lua/main.lua
Expand Up @@ -351,7 +351,9 @@ local function unit_information_part_1()
local starving = wml.variables["unit.variables.starving"]
local from_the_ashes_used = wml.variables["unit.variables.from_the_ashes_used"]
local from_the_ashes_cooldown = wml.variables["unit.variables.from_the_ashes_cooldown"]
local wrath = wml.variables["unit.variables.wrath_intensity"]
local wrath = nil
local latent_wrath = wml.get_child(wml.get_child(wml.variables["unit"], "abilities"), "damage", "latent_wrath")
if latent_wrath ~= nil then wrath = latent_wrath.add end

local result = ""
local span = "<span font_weight='bold'>"
Expand Down Expand Up @@ -1060,3 +1062,53 @@ function loti.util.list_attacks(unit)

return has_attack
end

function wesnoth.wml_actions.set_wrath_intensity(cfg)
local debug = cfg.debug or false
local unit_id = cfg.id or wml.error("[set_wrath_intensity]: missing required id=")
local unit = wesnoth.units.get(unit_id).__cfg
local abilities = wml.get_child(unit, "abilities")
local latent_wrath_special = wml.get_child(abilities, "damage", "latent_wrath")
local wrath_intensity = 0
if latent_wrath_special ~= nil then
wrath_intensity = latent_wrath_special.add
end
if debug then wesnoth.interface.add_chat_message(string.format("[set_wrath_intensity]: wrath_intensity was %d",wrath_intensity)) end
if cfg.set ~= nil then wrath_intensity = cfg.set end
if cfg.div ~= nil then
if math.abs(wrath_intensity) <= 1 then
wrath_intensity = 0
else
wrath_intensity = wrath_intensity / cfg.div
if wrath_intensity > 0 then
wrath_intensity = math.floor(wrath_intensity)
else
wrath_intensity = math.ceil(wrath_intensity)
end
end
end
if cfg.add ~= nil then wrath_intensity = wrath_intensity + cfg.add end
if cfg.sub ~= nil then wrath_intensity = wrath_intensity - cfg.sub end
if debug then wesnoth.interface.add_chat_message(string.format("[set_wrath_intensity]: \twrath_intensity is %d",wrath_intensity)) end
if wrath_intensity == 0 then
if debug then wesnoth.interface.add_chat_message(string.format("[set_wrath_intensity]: wrath_intensity == %d, removing ability",wrath_intensity)) end
local _,index = wml.find_child(abilities, "damage", { id = "latent_wrath" })
if debug then
if index ~= nil then
wesnoth.interface.add_chat_message(string.format("[set_wrath_intensity]: found id=latent_wrath at position %d",index))
table.remove(abilities,index)
else
wesnoth.interface.add_chat_message(string.format("[set_wrath_intensity]: no id=latent_wrath found"))
end
end
else
if latent_wrath_special == nil then
if debug then wesnoth.interface.add_chat_message(string.format("[set_wrath_intensity]: Didn't find latent_wrath_special, creating with add = %d",wrath_intensity)) end
table.insert(abilities, { "damage", { id = "latent_wrath", apply_to = "self", add = wrath_intensity }})
else
if debug then wesnoth.interface.add_chat_message(string.format("[set_wrath_intensity]: Found latent_wrath_special, setting add = %d",wrath_intensity)) end
latent_wrath_special.add = wrath_intensity
end
end
wesnoth.units.to_map(unit)
end
17 changes: 9 additions & 8 deletions lua/stats.lua
Expand Up @@ -604,14 +604,15 @@ function wesnoth.update_stats(original)
if best_backstab then
table.insert(specials, best_backstab)
end
local wrath_intensity = 0
if vars.wrath == true then
wrath_intensity = vars.wrath_intensity
end
table.insert(specials, { "damage", { id = "latent_wrath", apply_to = "self", add = wrath_intensity }})
end

-- PART VIII: Apply visual effects
-- PART VIII: Abilities
local latent_wrath_special = wml.get_child(wml.get_child(original, "abilities"), "damage", "latent_wrath")
if latent_wrath_special ~= nil then
table.insert(wml.get_child(remade, "abilities"), { "damage", latent_wrath_special })
end

-- PART IX: Apply visual effects
if #visual_effects > 0 then
local visual_obj = { visual_provider = true }
for i = 1,#visual_effects do
Expand Down Expand Up @@ -649,7 +650,7 @@ function wesnoth.update_stats(original)
table.insert(visible_modifications, overlays_object)


-- PART IX: Some final changes
-- PART X: Some final changes
for i = #vars,1,-1 do
if vars[i][1] == "disabled_defences" then
local found = false
Expand Down Expand Up @@ -682,7 +683,7 @@ function wesnoth.update_stats(original)
end
remade.advances_to = table.concat(new_advances_to, ",")

-- PART X: Call WML hooks
-- PART XI: Call WML hooks
for i = 1,#events_to_fire do
remade = call_event_on_unit(remade, events_to_fire[i])
end
Expand Down

0 comments on commit 5f9d6ce

Please sign in to comment.