Page 1 of 1
What does Champion:damage() actually do?
Posted: Wed Jul 19, 2023 2:57 pm
by DaggorathMaster
What does Champion:damage() actually do?
It accepts damage type, but doesn't know about the attack's "pierce" rating, so how can it do anything but raw damage, in which case why does it take damage type in the first place (unless it's sound or something superficial)?
Basically I'm redoing melee attacks in some cases, like for diagonal attacks.
Just making sure none of what I've done, or plan to, is redundant (resistances/protection, obviously enough accuracy/evasion isn't in that function), and that I get either reasonably close to "correct", or something better...
Is the function just reduceHealth(), type barely matters, and death is correctly applied?
Re: What does Champion:damage() actually do?
Posted: Wed Jul 19, 2023 10:03 pm
by minmay
DaggorathMaster wrote: ↑Wed Jul 19, 2023 2:57 pmIt accepts damage type, but doesn't know about the attack's "pierce" rating, so how can it do anything but raw damage, in which case why does it take damage type in the first place (unless it's sound or something superficial)?
The damage type is used to determine whether to apply fire/cold/shock/poison resistance, and is also passed to the party's onDamage hook. Also, if the damage type is "dispel", the function call has no effect.
Damage type does not interact with pierce or protection. Here's the source code of Champion:damage() from the umod pack:
Code: Select all
function Champion:damage(dmg, damageType)
damageType = damageType or "physical"
dmg = math.floor(dmg)
if damageType == "dispel" then return end
if self:isAlive() and not self:hasCondition("petrified") then
-- apply damage resistance
if damageType ~= "physical" and damageType ~= "drowning" and damageType ~= "pure" then
local resist = self:getResistance(damageType)
if resist == 100 then
dmg = 0
elseif resist > 0 then
dmg = math.floor(dmg * (100 - resist) / 100 + 0.5)
end
end
if party:callHook("onDamage", objectToProxy(self), dmg, damageType) == false then
return
end
-- trigger minotaur rage?
if self:hasTrait("rage") then
local oldHealth = self:getHealth() / self:getMaxHealth()
local newHealth = (self:getHealth() - dmg) / self:getMaxHealth()
local threshold = 0.2
if oldHealth > threshold and newHealth <= threshold then
self:setConditionValue("rage", self:getConditionValue("rage") + 20)
end
end
if dmg > 0 then
self:modifyBaseStat("health", -dmg)
self:showDamageIndicator(dmg)
messageSystem:sendMessageNEW("onChampionDamaged", self, dmg, damageType)
end
-- champion died?
if not self:isAlive() then
if party:callHook("onDie", objectToProxy(self)) == false then
if self:getBaseStat("health") < 1 then self:setBaseStat("health", 1) end
return
end
self:die()
end
end
end
Re: What does Champion:damage() actually do?
Posted: Thu Jul 20, 2023 1:19 am
by DaggorathMaster
OK so TRANSLATION: umod covers a LOT of this and I should take a serious look?
I've been hesitant to use other people's code because I WANT to "develop" the chops myself.
But a big part of doing programming as more than a hobby IS proper use of preexisting code, n'est-ce pas?
Re: What does Champion:damage() actually do?
Posted: Thu Jul 20, 2023 10:36 am
by DaggorathMaster
I don't see pierce or protection in that code.
So that's calculated before it gets this far?
Re: What does Champion:damage() actually do?
Posted: Thu Jul 20, 2023 6:29 pm
by minmay
Protection handling is in MonsterAttackComponent:attackParty() and MonsterChargeComponent:chargeHit(). Other sources of damage are not affected by champions' protection (and even these don't use the protection stat directly).