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?
What does Champion:damage() actually do?
- DaggorathMaster
- Posts: 37
- Joined: Thu Sep 08, 2022 7:29 pm
Re: What does Champion:damage() actually do?
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.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)?
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
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
- DaggorathMaster
- Posts: 37
- Joined: Thu Sep 08, 2022 7:29 pm
Re: What does Champion:damage() actually do?
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?
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?
- DaggorathMaster
- Posts: 37
- Joined: Thu Sep 08, 2022 7:29 pm
Re: What does Champion:damage() actually do?
I don't see pierce or protection in that code.
So that's calculated before it gets this far?
So that's calculated before it gets this far?
Re: What does Champion:damage() actually do?
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).
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.