try to attack & behavior annotation refactor
Co-authored-by: Ivan Yuriev <ivanyr44@gmail.com>
This commit is contained in:
parent
7ac0a53caa
commit
78f9347b86
5
dev_utils/annotations.lua
Normal file
5
dev_utils/annotations.lua
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
--- @meta _
|
||||||
|
Tree.behaviors.map = require "lib.character.behaviors.map"
|
||||||
|
Tree.behaviors.spellcaster = require "lib.character.behaviors.spellcaster"
|
||||||
|
Tree.behaviors.sprite = require "lib.character.behaviors.sprite"
|
||||||
|
Tree.behaviors.stats = require "lib.character.behaviors.stats"
|
||||||
@ -12,7 +12,7 @@ behavior.state = "idle"
|
|||||||
function behavior.new(spellbook)
|
function behavior.new(spellbook)
|
||||||
local spb = require "lib.spellbook" --- @todo временное добавление ходьбы (и читов) всем персонажам
|
local spb = require "lib.spellbook" --- @todo временное добавление ходьбы (и читов) всем персонажам
|
||||||
local t = {}
|
local t = {}
|
||||||
t.spellbook = spellbook or spb.of { spb.walk, spb.regenerateMana }
|
t.spellbook = spellbook or spb.of { spb.walk, spb.regenerateMana, spb.attack }
|
||||||
return setmetatable(t, behavior)
|
return setmetatable(t, behavior)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -84,6 +84,37 @@ function regenerateMana:cast(caster, target)
|
|||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local attack = setmetatable({}, spell)
|
||||||
|
|
||||||
|
function attack:cast(caster, target)
|
||||||
|
-- caster:try(Tree.behaviors.map, function(map)
|
||||||
|
-- local dist = math.ceil((target - map.position):length())
|
||||||
|
-- if dist >= 2 then
|
||||||
|
-- return false
|
||||||
|
-- end
|
||||||
|
-- end)
|
||||||
|
|
||||||
|
--- @type Character
|
||||||
|
local targetCharacter = Tree.level.characterGrid:get(target)
|
||||||
|
targetCharacter:try(Tree.behaviors.stats, function(stats)
|
||||||
|
stats.hp = stats.hp - 4
|
||||||
|
end)
|
||||||
|
|
||||||
|
caster:try(Tree.behaviors.sprite, function(sprite)
|
||||||
|
sprite:play("attack", function()
|
||||||
|
sprite:play("idle")
|
||||||
|
caster:has(Tree.behaviors.spellcaster):endCast()
|
||||||
|
end)
|
||||||
|
end)
|
||||||
|
targetCharacter:try(Tree.behaviors.sprite, function(sprite)
|
||||||
|
sprite:play("hurt", function()
|
||||||
|
sprite:play("idle")
|
||||||
|
end)
|
||||||
|
end)
|
||||||
|
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
----------------------------------------
|
----------------------------------------
|
||||||
local spellbook = {
|
local spellbook = {
|
||||||
walk = walk,
|
walk = walk,
|
||||||
|
|||||||
@ -44,7 +44,8 @@ function layout:build()
|
|||||||
ui.Row {
|
ui.Row {
|
||||||
children = {
|
children = {
|
||||||
setmetatable({ owner = Tree.level.characters[id], spellId = 1 }, { __index = SkillButton }),
|
setmetatable({ owner = Tree.level.characters[id], spellId = 1 }, { __index = SkillButton }),
|
||||||
setmetatable({ owner = Tree.level.characters[id], spellId = 2 }, { __index = SkillButton })
|
setmetatable({ owner = Tree.level.characters[id], spellId = 2 }, { __index = SkillButton }),
|
||||||
|
setmetatable({ owner = Tree.level.characters[id], spellId = 3 }, { __index = SkillButton })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
skillRows[id] = r
|
skillRows[id] = r
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user