Legend_of_the_Invincibles icon indicating copy to clipboard operation
Legend_of_the_Invincibles copied to clipboard

Picking best ability not working

Open dalong76 opened this issue 6 years ago • 6 comments

If a unit has a heal ability from itself or an amla, but an item gives a better heal ability, the item granted heal is ignored. The same happened with Despair - unit has Despair 25, add Touch of God for Despair 40, unit shows as having just Despair 25.

I also tested regeneration, but in that case both abilities show up and the best one actually happens.

dalong76 avatar Jan 22 '19 14:01 dalong76

That's the way wesnoth handles abilities.

I could possibly remove all abilities that are strictly inferior to others to correct these problems. It would, however, make LotI less consistent with the rest of wesnoth's user-made content.

Dugy avatar Jan 22 '19 15:01 Dugy

Once again I understood wrong. I was sure you had done something once to make only one instance of an ability appear, and only the best one. For example, not showing both absorb(1) and absorb(3), but only absorb(3). But I'm wrong - if you have absorb(1) and absorb(3), in the game right now, you show as having both and it really works as net 4. However, if you have absorb(1) twice, only one exists and you only get 1.

But all heal abilities seem to be considered the same, and the first one it finds takes affect. So the order of equiping heal items matters.

dalong76 avatar Jan 22 '19 19:01 dalong76

I could change it if you think it's suitable.

Dugy avatar Jan 22 '19 20:01 Dugy

I also think that lower-tier abilities should be suppressed/removed if a higher-tier ability (of the same type) is present. Unit with absorbs(1) and absorbs(3) should have exactly absorbs(3), not 1 or 4.

edwardspec avatar Jan 28 '19 04:01 edwardspec

With commit 40b5245 I have made absorb consistent with the way other abilities' values change.

I think that the easiest way to deal with this is to search for abilities with the same id and different values and delete the ones whose value isn't the highest.

Dugy avatar Jan 28 '19 23:01 Dugy

This is the code required to merge them supposing they are in one array:

local abilities = helper.get_child(remade, "abilities")
local basic_types = {}
local new_abilities = {}
wesnoth.dbms( abilities )
for _,ability in pairs(abilities) do
	if not basic_types[ability[1]] then
		basic_types[ability[1]] = {}
	end
	local sector = basic_types[ability[1]]
	if not ability[2].id then
		helper.wml_error("Ability of type " .. ability[1] .. " on " .. remade.name .. "lacks an id")
	end
	if not sector[ability[2].id] then
		if type(ability[2].value) == "number" then
			sector[ability[2].id] = ability[2]
		else
			table.insert(new_abilities, ability)
		end
	else
		local older = sector[ability[2].id]
		if type(ability[2].value) == "number" then
			if math.abs(older.value) <= math.abs(ability[2].value) then
				sector[ability[2].id] = ability[2]
			end
		else
			table.insert(new_abilities, ability)
		end
	end
end

for name, inner in pairs(basic_types) do
	for _, ability in pairs(inner) do
		table.insert(new_abilities, { name, ability })
	end
end

for i = 1,#remade do
	if remade[i][1] == "abilities" then
		remade[i][2] = new_abilities
		break
	end
end

However, the ability is removed already when the effect is applied, so the code has no effect. It would be much more comfortable to integrate once that the items are not applied from the unit's modifications, but from outside. This change is planned. I suggest to wait with this until the abilities-outside-unit-modifications change is implemented.

Dugy avatar Jan 29 '19 20:01 Dugy

Wesnoth in 1.16 changed the way negative leadership works, so the best despair applies now (like in the example case " has Despair 25, add Touch of God for Despair 40" nowadays it will be 40). Should the issue be closed?

Discontinuum avatar Jul 10 '23 00:07 Discontinuum

Yes.

Dugy avatar Jul 10 '23 00:07 Dugy

I am closing it because it was fixed by a change in Wesnoth.

Dugy avatar Jul 10 '23 00:07 Dugy