forked from zhandouxiaojiji/behavior3lua
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.lua
79 lines (65 loc) · 1.37 KB
/
test.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
local behavior_tree = require "behavior3.behavior_tree"
local behavior_node = require "behavior3.behavior_node"
behavior_node.process(require "example.process")
local json = require "json"
local function load_tree(path)
local file, err = io.open(path, 'r')
assert(file, err)
local str = file:read('*a')
file:close()
return json.decode(str)
end
local monster = {
hp = 100,
x = 200,
y = 0,
}
local hero = {
hp = 100,
x = 0,
y = 0,
}
local ctx = {
time = 0,
avatars = {monster, hero},
}
function ctx:find(func)
local list = {}
for _, v in pairs(ctx.avatars) do
if func(v) then
list[#list+1] = v
end
end
return list
end
local function test_moster()
local btree = behavior_tree.new("monster", load_tree("workspace/trees/monster.json"), {
ctx = ctx,
owner = monster,
})
monster.hp = 100
btree:run()
monster.hp = 20
btree:run()
end
local function test_hero()
local btree = behavior_tree.new("hero", load_tree("workspace/trees/hero.json"), {
ctx = ctx,
owner = hero,
})
-- 移动到目标并攻击
btree:run()
btree:run()
btree:run()
btree:run()
btree:run()
btree:run()
-- 后摇
btree:run()
btree:interrupt()
btree:run()
ctx.time = 20
btree:run()
end
test_hero()
test_moster()