patterns.lua
· 3.3 KiB · Lua
Orginalformat
Playground
--[[
|
lightning struck [x] [y]
, [something] is at [x] [y]?
, [something] has inventory [inventory]?
, [inventory] has item [item]?
, [item] is [class]?
, [class] is conductive?
|
[something] is struck by lightning
|| lightning struck 10 20,
$enemy is at 10 20,
$enemy has inventory $inventory,
$inventory has item $item,
$item is sword,
sword is conductive
]]
local match = {
lightning_struck_x_y = false,
something_is_at_x_y = false,
something_has_inventory_inventory = false,
inventory_has_item_item = false,
item_is_class = false,
class_is_conductive = false,
vars = {
x = nil, y = nil, something = nil, inventory = nil,
item = nil, class = nil }
}
function lightning_struck_x_y(match, patterns)
for x, y in patterns.lightning_struck_x_y:matches(match.x, match.y) do
match.lightning_struck_x_y = true
match.x = x
match.y = y
if match.something_is_at_x_y or something_is_at_x_y(patch, patterss) then
return true
end
end
return false
end
function something_is_at_x_y(match, patterns)
for something, x, y in patterns.something_is_at_x_y:matches(match.someting, match.x, match.y) do
match.something_is_at_x_y = true
match.something = something
match.x = x
match.y = y
if (match.lightning_struck_x_y or
lightning_struck_x_y(match, patterns))
and (match.something_has_inventory_inventory or something_has_inventory_inventory(match, patterns))
then
return true
end
end
return false
end
function something_has_inventory_inventory(match, patterns)
for something, inventory in patterns.something_has_inventory_inventory:matches(match.something, match.inventory) do
match.something_has_inventory_inventory = true
match.something = something
match.inventory = inventory
if (match.something_is_at_x_y or something_is_at_x_y(match, patterns))
and (match.inventory_has_item_item or inventory_has_item_item(match, patterns))
then
return true
end
end
return false
end
function inventory_has_item_item(match, patterns)
for inventory, item in patterns.inventory_has_item_item:matches(match.inventory, match.item) do
match.inventory = inventory
match.item = item
if (match.something_has_inventory_inventory or something_has_inventory_inventory(match, patterns))
and (match.item_is_class or item_is_class(match, patterns))
then
return true
end
end
return false
end
function item_is_class(match, patterns)
if item, class in patterns.item_is_class:matches(match.item, match.class) do
match.item = item
match.class = class
if (match.inventory_has_item_item or inventory_has_item_item(match, patterns))
and (match.class_is_conductive or class_is_conductive(match, patterns))
then
return true
end
end
return false
end
function class_is_conductive(match, patterns)
for class in patterns.class_is_conductive:matches(match.class) do
match.class = class
if (match.item_is_class or item_is_class(match, patterns)) then
return true
end
end
return false
end
1 | --[[ |
2 | | |
3 | lightning struck [x] [y] |
4 | , [something] is at [x] [y]? |
5 | , [something] has inventory [inventory]? |
6 | , [inventory] has item [item]? |
7 | , [item] is [class]? |
8 | , [class] is conductive? |
9 | | |
10 | [something] is struck by lightning |
11 | |
12 | || lightning struck 10 20, |
13 | $enemy is at 10 20, |
14 | $enemy has inventory $inventory, |
15 | $inventory has item $item, |
16 | $item is sword, |
17 | sword is conductive |
18 | ]] |
19 | |
20 | local match = { |
21 | lightning_struck_x_y = false, |
22 | something_is_at_x_y = false, |
23 | something_has_inventory_inventory = false, |
24 | inventory_has_item_item = false, |
25 | item_is_class = false, |
26 | class_is_conductive = false, |
27 | vars = { |
28 | x = nil, y = nil, something = nil, inventory = nil, |
29 | item = nil, class = nil } |
30 | } |
31 | |
32 | function lightning_struck_x_y(match, patterns) |
33 | for x, y in patterns.lightning_struck_x_y:matches(match.x, match.y) do |
34 | match.lightning_struck_x_y = true |
35 | match.x = x |
36 | match.y = y |
37 | if match.something_is_at_x_y or something_is_at_x_y(patch, patterss) then |
38 | return true |
39 | end |
40 | end |
41 | return false |
42 | end |
43 | |
44 | function something_is_at_x_y(match, patterns) |
45 | for something, x, y in patterns.something_is_at_x_y:matches(match.someting, match.x, match.y) do |
46 | match.something_is_at_x_y = true |
47 | match.something = something |
48 | match.x = x |
49 | match.y = y |
50 | if (match.lightning_struck_x_y or |
51 | lightning_struck_x_y(match, patterns)) |
52 | and (match.something_has_inventory_inventory or something_has_inventory_inventory(match, patterns)) |
53 | then |
54 | return true |
55 | end |
56 | end |
57 | return false |
58 | end |
59 | |
60 | function something_has_inventory_inventory(match, patterns) |
61 | for something, inventory in patterns.something_has_inventory_inventory:matches(match.something, match.inventory) do |
62 | match.something_has_inventory_inventory = true |
63 | match.something = something |
64 | match.inventory = inventory |
65 | |
66 | if (match.something_is_at_x_y or something_is_at_x_y(match, patterns)) |
67 | and (match.inventory_has_item_item or inventory_has_item_item(match, patterns)) |
68 | then |
69 | return true |
70 | end |
71 | end |
72 | return false |
73 | end |
74 | |
75 | function inventory_has_item_item(match, patterns) |
76 | for inventory, item in patterns.inventory_has_item_item:matches(match.inventory, match.item) do |
77 | match.inventory = inventory |
78 | match.item = item |
79 | |
80 | if (match.something_has_inventory_inventory or something_has_inventory_inventory(match, patterns)) |
81 | and (match.item_is_class or item_is_class(match, patterns)) |
82 | then |
83 | return true |
84 | end |
85 | end |
86 | return false |
87 | end |
88 | |
89 | function item_is_class(match, patterns) |
90 | if item, class in patterns.item_is_class:matches(match.item, match.class) do |
91 | match.item = item |
92 | match.class = class |
93 | |
94 | if (match.inventory_has_item_item or inventory_has_item_item(match, patterns)) |
95 | and (match.class_is_conductive or class_is_conductive(match, patterns)) |
96 | then |
97 | return true |
98 | end |
99 | end |
100 | return false |
101 | end |
102 | |
103 | function class_is_conductive(match, patterns) |
104 | for class in patterns.class_is_conductive:matches(match.class) do |
105 | match.class = class |
106 | if (match.item_is_class or item_is_class(match, patterns)) then |
107 | return true |
108 | end |
109 | end |
110 | return false |
111 | end |
112 | |
113 |