1-- Configurações da animação
2local FRAME_DURATION = 100 -- Duração de cada frame em milissegundos
3local ANIMATION_FRAMES = {
4 73, -- Frame (substitua pelos IDs corretos das outfits)
5 74, -- Frame
6 75, -- Frame
7 76, -- Frame
8 77, -- Frame
9 78,
10 45 -- Frame
11
12}
13
14-- Configurações do item temporário
15local tempItemId = 9078 -- ID do item temporário
16local tempItemDuration = 600 -- Tempo que o item fica no chão (230ms)
17
18-- Função que troca a outfit frame por frame
19local function changeOutfit(cid, originalOutfit, currentFrame)
20 local creature = Player(cid)
21 if not creature or not creature:isPlayer() then
22 return
23 end
24
25 if currentFrame <= #ANIMATION_FRAMES then
26 local newOutfit = {
27 lookType = ANIMATION_FRAMES[currentFrame],
28 lookHead = originalOutfit.lookHead,
29 lookBody = originalOutfit.lookBody,
30 lookLegs = originalOutfit.lookLegs,
31 lookFeet = originalOutfit.lookFeet,
32 lookAddons = originalOutfit.lookAddons,
33 lookMount = originalOutfit.lookMount
34 }
35 creature:setOutfit(newOutfit)
36 -- Agenda o próximo frame da animação
37 addEvent(changeOutfit, FRAME_DURATION, cid, originalOutfit, currentFrame + 1)
38 end
39 -- A restauração da outfit original será feita somente ao sair da magia.
40end
41
42-- Funções do efeito mágico
43local function targetEffect(cid)
44 local player = Player(cid)
45 if not player then
46 return
47 end
48
49 local effect = 237 -- Efeito elétrico azul
50 local orig = player:getPosition()
51 local d1, d2 = {z = orig.z}, {z = orig.z}
52
53 d1.x = orig.x - 5
54 d2.x = orig.x + 5
55 for i = -2, 2 do
56 d1.y = orig.y + i
57 d2.y = d1.y
58 orig:sendDistanceEffect(d1, effect)
59 orig:sendDistanceEffect(d2, effect)
60 end
61
62 d1.y = orig.y - 3
63 d2.y = orig.y + 3
64 for i = -4, 4 do
65 d1.x = orig.x + i
66 d2.x = d1.x
67 orig:sendDistanceEffect(d1, effect)
68 orig:sendDistanceEffect(d2, effect)
69 end
70end
71
72-- Função que retorna o jogador para a posição original, desativa ghost mode e restaura a outfit original
73local function backOldPosition(cid, oldPosition, originalOutfit)
74 local player = Player(cid)
75 if not player then
76 return
77 end
78
79 player:teleportTo(oldPosition)
80 player:setGhostMode(false)
81 player:setOutfit(originalOutfit)
82 -- Removido: player:setMovementBlocked(false)
83end
84
85local function jumpEffect(cid, target)
86 local player = Player(cid)
87 if not player then
88 return
89 end
90
91 local targetCreature = Creature(target)
92 if targetCreature then
93 player:getPosition():sendDistanceEffect(targetCreature:getPosition(), 237)
94 end
95end
96
97local function extractRandomValuesFromTable(tbl)
98 if #tbl == 0 then
99 return false
100 end
101 return table.remove(tbl, math.random(#tbl))
102end
103
104-- Modificada para receber originalOutfit e exibir o effect 237 enquanto pula,
105-- além de criar e remover o item temporário no alvo atingido.
106local function jumpOnTarget(cid, target, targetCount, oldPosition, originalOutfit)
107 local player = Player(cid)
108 if not player then
109 return
110 end
111
112 local targetCreature = Creature(target)
113 if targetCreature then
114 addEvent(targetEffect, 100, cid)
115 player:teleportTo(targetCreature:getPosition())
116 player:setGhostMode(true)
117 -- Exibe o effect 237 enquanto pula para o novo alvo
118 player:getPosition():sendMagicEffect(237)
119 targetCreature:getPosition():sendMagicEffect(237)
120 doTargetCombatHealth(cid, targetCreature, COMBAT_ENERGYDAMAGE, -50, -150, CONST_ME_ENERGYHIT)
121
122 -- Cria o item temporário no local do alvo atingido e agenda sua remoção
123 local tempItem = Game.createItem(tempItemId, 1, targetCreature:getPosition())
124 if tempItem then
125 addEvent(function(pos)
126 local tile = Tile(pos)
127 if tile then
128 local item = tile:getItemById(tempItemId)
129 if item then
130 item:remove()
131 end
132 end
133 end, tempItemDuration, targetCreature:getPosition())
134 end
135
136 if targetCount == 0 then
137 addEvent(backOldPosition, 400, cid, oldPosition, originalOutfit)
138 end
139 end
140end
141
142-- Função principal do feitiço
143function onCastSpell(creature, var)
144 local cid = creature:getId()
145 local originalPos = creature:getPosition()
146 local originalOutfit = creature:getOutfit()
147
148 -- Removida: Bloqueia o movimento do jogador enquanto durar a magia
149 -- creature:setMovementBlocked(true)
150
151 -- Ajusta o eixo para o efeito 192 antes da animação (exemplo, ajuste conforme necessário)
152 local pos = creature:getPosition()
153 pos.x = pos.x + 1
154 pos.y = pos.y
155 pos:sendMagicEffect(191)
156
157 -- Inicia a animação de troca de outfit frame por frame
158 changeOutfit(cid, originalOutfit, 1)
159
160 -- Agenda a execução do feitiço após o término da animação
161 addEvent(function()
162 local targets = {}
163 local playerPos = creature:getPosition()
164
165 -- Efeitos ao ativar a magia
166 playerPos:sendMagicEffect(236)
167 -- Obtém os espectadores dentro de um raio de 5x5
168 local spectators = Game.getSpectators(playerPos, false, false, 5, 5, 5, 5)
169 for i = 1, #spectators do
170 local specs = spectators[i]
171 if specs ~= creature and not specs:isNpc() and playerPos:getDistance(specs:getPosition()) <= 5 then
172 targets[#targets + 1] = specs
173 end
174 end
175
176 if #targets == 0 then
177 creature:sendCancelMessage('There are no targets in range (5x5).')
178 playerPos:sendMagicEffect(CONST_ME_POFF)
179 -- Removida: creature:setMovementBlocked(false)
180 return false
181 end
182
183 local targetCount = #targets
184 for i = 1, #targets do
185 local randTarget = extractRandomValuesFromTable(targets)
186 addEvent(jumpOnTarget, i * 200, cid, randTarget:getId(), targetCount - i, originalPos, originalOutfit)
187 addEvent(jumpEffect, i * 400, cid, randTarget:getId())
188 end
189 end, (#ANIMATION_FRAMES + 1) * FRAME_DURATION)
190 playSound(creature, "energy.ogg")
191 return false
192end
193