-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOrder.lua
More file actions
116 lines (112 loc) · 3.22 KB
/
Order.lua
File metadata and controls
116 lines (112 loc) · 3.22 KB
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
require 'AI/Const'
local Set = require('./AI/USER_AI/Set')
local vector2 = require('./AI/USER_AI/Geometry').vector2
local Command = {}
Command.new = function(class, state, msg, env, reserved)
local obj = {}
if not msg or not env then
-- nil
elseif msg[1] == NONE_CMD then
-- nil
elseif msg[1] == MOVE_CMD then
local ground = vector2(msg[2], msg[3])
if reserved then
local targets = env:getActorsByPosition(ground)
local monster = targets and targets:filter(function(actor) return actor:isMonster() end):getFirst()
local organic = targets and targets:filter(function(actor) return not actor:isMonster() end):getFirst()
if organic and monster then
-- nil
elseif organic then
obj.assist = true
obj.target = organic:getID()
elseif monster then
obj.attend = true
obj.target = monster:getID()
else
obj.patrol = true
obj.ground = ground
end
else
obj.moving = true
obj.ground = ground
end
elseif msg[1] == ATTACK_OBJECT_CMD then
local target = env:getActorByID(msg[2])
if target then
if target:isMonster() then
obj.attack = true
obj.target = target:getID()
obj.append = reserved
elseif reserved then
obj.select = true
obj.target = target:getID()
end
end
elseif msg[1] == ATTACK_AREA_CMD then
local ground = vector2(msg[2], msg[3])
obj.attack = true
obj.ground = ground
elseif msg[1] == PATROL_CMD then
local ground = vector2(msg[2], msg[3])
obj.patrol = true
obj.ground = ground
elseif msg[1] == HOLD_CMD then
obj.keepup = true
elseif msg[1] == SKILL_OBJECT_CMD then
obj.arting = true
obj.target = msg[4]
obj.level, obj.skill = msg[2], msg[3]
elseif msg[1] == SKILL_AREA_CMD then
local ground = vector2(msg[4], msg[5])
obj.arting = true
obj.level, obj.skill = msg[2], msg[3]
obj.ground = ground
elseif msg[1] == FOLLOW_CMD then -- Custom ordering by Alt + T
local master = env:getMaster()
local ground = master and master:isSit() and master:getPosition()
if ground then
obj.design = true
obj.ground = ground
else
local clock = env:getClock()
obj.revise = true
obj.forced = state.revise and state.revise - clock < 1
state.revise = clock
end
end
return setmetatable(obj, {__index=class, __tostring=class.tostring})
end
Command.tostring = function(self, visit)
local check = visit or Set:new()
local index = check:insert(self)
return string.format('Command<table %d>', self.raw[1])
end
local Order = {}
Order.new = function(class)
local obj = {}
obj.state = {}
return setmetatable(obj, {__index=class, __tostring=class.tostring})
end
Order.store = function(self)
return self
end
Order.restore = function(self)
return self
end
Order.observe = function(self, id, env)
local msg = GetMsg(id)
local res = GetResMsg(id)
if not env then
-- nil
elseif msg and msg[1] and msg[1] ~= NONE_CMD then
return Command:new(self.state, msg, env, false)
elseif res and res[1] and res[1] ~= NONE_CMD then
return Command:new(self.state, res, env, true)
end
end
Order.tostring = function(self, visit)
local check = visit or Set:new()
local index = check:insert(self)
return string.format('Order<table %d>', index)
end
return Order