Skip to content

Commit

Permalink
Merge branch 'master' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
brightrim committed Dec 10, 2024
2 parents b8b54e9 + c29e645 commit e5eda77
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ function M.checkIfLongEnoughTimePassedSinceEquip(user, itempos)

local time = common.GetCurrentTimestamp()

local foundtime, savedTime = myEffect:findValue(itempos)
local foundtime, savedTime = myEffect:findValue(tostring(itempos))

if not foundtime then
return true
Expand Down
42 changes: 30 additions & 12 deletions magic/magicfighting.lua
Original file line number Diff line number Diff line change
Expand Up @@ -79,25 +79,42 @@ local function checkMissedAttack(attackerStruct)
return common.Chance(chance, 100)
end

local function initiateList(attacker)
MAGIC_LOAD_LIST[attacker.id] = {}
end

local function update(attacker, defender, attackerStruct)
MAGIC_LOAD_LIST[attacker.id]["started"] = world:getTime("unix")
MAGIC_LOAD_LIST[attacker.id]["weapon"] = attackerStruct.WeaponItem.id
MAGIC_LOAD_LIST[attacker.id]["target"] = defender.id
MAGIC_LOAD_LIST[attacker.id]["position"] = attacker.pos.x.." "..attacker.pos.y.." "..attacker.pos.z
end

local function isMagicAttackLoaded(attackerStruct, defender, neededCastTime)
local attacker = attackerStruct["Char"]
local mageLoad = MAGIC_LOAD_LIST[attacker.id]

-- Check if the player has changed his target/weapon/position or if he attacks for the first time
if mageLoad == nil or (
attackerStruct.WeaponItem.id ~= mageLoad["weapon"] or defender.id ~= mageLoad["target"] or
attacker.pos.x.." "..attacker.pos.y.." "..attacker.pos.z ~= mageLoad["position"]) then
MAGIC_LOAD_LIST[attacker.id] = {}
MAGIC_LOAD_LIST[attacker.id]["started"] = world:getTime("unix")
MAGIC_LOAD_LIST[attacker.id]["weapon"] = attackerStruct.WeaponItem.id
MAGIC_LOAD_LIST[attacker.id]["target"] = defender.id
MAGIC_LOAD_LIST[attacker.id]["position"] = attacker.pos.x.." "..attacker.pos.y.." "..attacker.pos.z
local firstTime = mageLoad == nil

if firstTime then -- no list exists
initiateList(attacker)
update(attacker, defender, attackerStruct)
return false
end

if not mageLoad["tanCheckedThisCycle"] then
local weaponChanged = attackerStruct.WeaponItem.id ~= mageLoad["weapon"]
local targetChanged = defender.id ~= mageLoad["target"]
local positionChanged = attacker.pos.x.." "..attacker.pos.y.." "..attacker.pos.z ~= mageLoad["position"]

if weaponChanged or targetChanged or positionChanged then --This way we update the timer, target, weapon and position but we keep Tan info
update(attacker, defender, attackerStruct)
return false
end

if not mageLoad["tanCheckedThisCycle"] then -- We only check once per cast
if tan.reduceCastTime(attackerStruct.Char) then
mageLoad["tan"] = true
mageLoad["tan"] = true --The next cast gets reduced cast time, even if it happens far into the future as long as the table data is kept, this because otherwise the glyph will just get drained without ever casting if you dont finish the cast it procced for
end
mageLoad["tanCheckedThisCycle"] = true
end
Expand All @@ -124,8 +141,6 @@ local function isMagicAttackLoaded(attackerStruct, defender, neededCastTime)
return false
end

mageLoad["tanCheckedThisCycle"] = false
mageLoad["tan"] = false
return true
end

Expand Down Expand Up @@ -343,6 +358,9 @@ function M.onMagicAttack(attackerStruct, defenderStruct)

magic.wandDegrade(attackerStruct.Char, attackerStruct.WeaponItem)

MAGIC_LOAD_LIST[attackerStruct.Char.id]["tanCheckedThisCycle"] = false -- We finished a cast, so tan can now be checked again next time you cast
MAGIC_LOAD_LIST[attackerStruct.Char.id]["tan"] = false

return true
end

Expand Down

0 comments on commit e5eda77

Please sign in to comment.