Skip to content

Commit

Permalink
dwyfol works for monster magic too now
Browse files Browse the repository at this point in the history
  • Loading branch information
brightrim committed Mar 1, 2025
1 parent ad02139 commit e7243e0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
6 changes: 4 additions & 2 deletions magic/arcane/dealMagicDamage.lua
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,6 @@ function M.dealMagicDamage(user, target, spell, damage, level, DoT, castTime)

if DoT then castTime = castTime/15 end -- DoTs have 15 ticks, so this prevents them from giving 15 times the MR

M.learnMagicResistance(target, castTime, level)

local dwyfolTriggered = false

if user and damage ~= 0 then --It still gets here on DoTs that have 0 damage to deal
Expand All @@ -126,6 +124,10 @@ function M.dealMagicDamage(user, target, spell, damage, level, DoT, castTime)
end
end

if not dwyfolTriggered and character.IsPlayer(target) then
M.learnMagicResistance(target, castTime, level)
end

if character.IsPlayer(target) and character.WouldDie(target, damage + 1) then
if character.AtBrinkOfDeath(target) then
if target:isAdmin() then
Expand Down
12 changes: 11 additions & 1 deletion monster/base/spells/base.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ local magicResistance = require("magic.arcane.magicResistance")
local magicPenetration = require("magic.arcane.magicPenetration")
local magicDamage = require("magic.arcane.magicDamage")
local magic = require("base.magic")
local dwyfol = require("magic.arcane.enchanting.effects.dwyfol")

local M = {}

Expand All @@ -44,6 +45,16 @@ function M.dealMagicDamage(target, damage, usedMovepoints, level, monster)
if damage < 100 then
damage = 100 --At least deal some symbolic damage even if the player fully resists the attack
end


if dwyfol.deflectAttackAsLightning(target, monster) then -- This glyph if activated deflects the attack, dealing the same amount they would have taken as magic damage to the attacker instead in the form of a lightning strike
target = monster --The monster becomes the new target as the spell damage is deflected
damage = math.min(damage, 1000) -- It shouldn't be possible to luck into killing off a max skill chara with a no skill character!
elseif character.IsPlayer(target) then
arcaneMagicDamage.learnMagicResistance(target, usedMovepoints/3, level+20) -- Since monster magic uses movepoints instead of cast time, we scale the learning based on that similar to how fighting does it by dividing it by three
end


-- Check for damage + 1 to avoid the case that a regular hit lowers the hitpoints down to 1 and directly sends a
-- character to the brink of death.
if character.IsPlayer(target) and character.WouldDie(target, damage + 1) then
Expand All @@ -65,7 +76,6 @@ function M.dealMagicDamage(target, damage, usedMovepoints, level, monster)
chr_reg.stallRegeneration(target, 60 / timeFactor)
end
else
arcaneMagicDamage.learnMagicResistance(target, usedMovepoints/3, level+20) -- Since monster magic uses movepoints instead of cast time, we scale the learning based on that similar to how fighting does it by dividing it by three
target:increaseAttrib("hitpoints", -damage)
end
end
Expand Down

0 comments on commit e7243e0

Please sign in to comment.