-
Notifications
You must be signed in to change notification settings - Fork 8
/
factions.lua
237 lines (213 loc) · 6.63 KB
/
factions.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
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
banners.power_per_banner = 10.
-- items
minetest.register_craftitem("banners:golden_finial", {
groups = {},
description = "Golden finial",
inventory_image = "gold_finial.png",
})
minetest.register_craftitem("banners:silver_pole", {
groups = {},
description = "Silver pole",
inventory_image = "silver_pole.png"
})
minetest.register_craftitem("banners:power_pole", {
groups = {},
description = "Power pole",
inventory_image = "power_pole.png"
})
minetest.register_craftitem("banners:golden_sheet", {
groups = {},
description = "Golden sheet",
inventory_image = "golden_sheet.png"
})
minetest.register_craftitem("banners:death_pole", {
groups = {},
description = "Death pole",
inventory_image = "death_pole.png"
})
minetest.register_craftitem("banners:death_sheet", {
groups = {},
description = "Death sheet",
inventory_image = "death_sheet.png"
})
minetest.register_craftitem("banners:death_base", {
groups = {},
description = "Death base",
inventory_image = "death_base.png"
})
-- crafts
minetest.register_craft( -- silver flag pole
{
output = "banners:silver_pole 1",
recipe = {
{"", "", "moreores:silver_ingot"},
{"", "moreores:silver_ingot", ""},
{"moreores:silver_ingot", "", ""}
}
}
)
minetest.register_craft( -- death flag pole
{
output = "banners:death_pole 1",
recipe = {
{"", "", "default:diamond"},
{"", "default:obsidian", ""},
{"default:obsidian", "", ""}
}
}
)
minetest.register_craft( -- golden finial
{
output = "banners:golden_finial",
recipe = {
{"", "default:gold_ingot", "default:gold_ingot"},
{"", "default:gold_ingot", "default:gold_ingot"},
{"default:gold_ingot", "", ""}
}
}
)
minetest.register_craft( -- power flag pole
{
output = "banners:power_pole 1",
recipe = {
{"", "", ""},
{"", "banners:golden_finial", ""},
{"banners:silver_pole", "", ""}
}
}
)
minetest.register_craft( -- golden sheet
{
output = "banners:golden_sheet 1",
type = "shapeless",
recipe = { "default:gold_ingot", "banners:banner_sheet"}
}
)
minetest.register_craft( -- death sheet
{
output = "banners:death_sheet 1",
type = "shapeless",
recipe = { "default:obsidian", "banners:banner_sheet"}
}
)
minetest.register_craft( -- death sheet
{
output = "banners:death_base 1",
recipe = {
{"", "", ""},
{"", "banners:steel_base", ""},
{"default:obsidian", "default:obsidian", "default:obsidian"}
}
}
)
minetest.register_craft( -- power banner
{
output = "banners:power_banner",
recipe = {
{"", "banners:golden_sheet", ""},
{"", "banners:power_pole", ""},
{"", "banners:steel_base", ""}
}
}
)
minetest.register_craft( -- death banner
{
output = "banners:death_banner",
recipe = {
{"", "banners:death_sheet", ""},
{"", "banners:death_pole", ""},
{"", "banners:death_base", ""}
}
}
)
-- nodes
minetest.register_node("banners:power_banner", {
drawtype = "mesh",
mesh = "banner_support.x",
tiles = {"gold_support.png"},
description = "Power Banner",
groups = {cracky=3},
is_ground_content = false,
diggable = true,
stack_max = 1,
paramtype = "light",
paramtype2 = "facedir",
after_place_node = function (pos, player, itemstack, pointed_thing)
banners.after_powerbanner_placed(pos, player, itemstack, pointed_thing)
end,
on_destruct = function(pos)
banners.banner_on_destruct(pos)
end,
on_dig = function(pos, n, p)
if minetest.is_protected(pos, p:get_player_name()) then
return
end
local meta = minetest.get_meta(pos)
local facname = meta:get_string("faction")
if facname then
local faction = factions.factions[facname]
if faction then
faction:decrease_maxpower(banners.power_per_banner)
end
end
banners.banner_on_dig(pos, n, p)
end,
})
minetest.register_node("banners:death_banner", {
drawtype = "mesh",
mesh = "banner_support.x",
tiles = {"death_uv.png"},
description = "Death Banner",
groups = {cracky=3},
is_ground_content = false,
diggable = true,
stack_max = 1,
paramtype = "light",
paramtype2 = "facedir",
after_place_node = function (pos, player, itemstack, pointed_thing)
banners.after_deathbanner_placed(pos, player, itemstack, pointed_thing)
end,
on_destruct = function(pos)
banners.banner_on_destruct(pos)
end,
on_dig = function(pos, n, p)
if minetest.is_protected(pos, p:get_player_name()) then
return
end
local meta = minetest.get_meta(pos)
local defending_facname = meta:get_string("faction")
local parcelpos = factions.get_parcel_pos(pos)
if defending_facname then
local faction = factions.factions[defending_facname]
if faction then
faction:stop_attack(parcelpos)
end
end
minetest.remove_node(pos)
end,
})
banners.after_powerbanner_placed = function(pos, player, itemstack, pointed_thing)
minetest.get_node(pos).param2 = banners.determine_flag_direction(pos, pointed_thing)
local faction = factions.players[player:get_player_name()]
if not faction then
minetest.get_meta(pos):set_string("banner", "bg_white.png")
else
local banner_string = factions.factions[faction].banner
minetest.get_meta(pos):set_string("banner", banner_string)
minetest.get_meta(pos):set_string("faction", faction)
factions.factions[faction]:increase_maxpower(banners.power_per_banner)
end
minetest.add_entity(pos, "banners:banner_ent")
end
banners.after_deathbanner_placed = function(pos, player, itemstack, pointed_thing)
minetest.get_node(pos).param2 = banners.determine_flag_direction(pos, pointed_thing)
local attacking_faction = factions.players[player:get_player_name()]
if attacking_faction then
local parcelpos = factions.get_parcel_pos(pos)
attacking_faction = factions.factions[attacking_faction]
attacking_faction:attack_parcel(parcelpos)
minetest.get_meta(pos):set_string("faction", attacking_faction.name)
end
minetest.get_meta(pos):set_string("banner", "death_uv.png")
minetest.add_entity(pos, "banners:banner_ent")
end