-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathguild.lua
More file actions
419 lines (318 loc) · 8.87 KB
/
guild.lua
File metadata and controls
419 lines (318 loc) · 8.87 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
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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
Guild = {
name,
members = {},
rank = 1,
MAX_MEMBERS = 20,
territory = tostring(0) ,
id = 0,
__data = {}
}
GUILD_PRICE = 500000
member_rank = {
"Master", "Apprentice", "Sentinel", "Trainee"
}
function Guild.new(name, founder)
-- PLAYER MUST NOT BE IN A GUILD
if not founder.IN_GUILD then
if founder.level >= 25 and founder.rank >= 5 and
Bag.gold >= GUILD_PRICE then
if name == nil then
print("Enter the name of your guild here:")
name = io.read()
end
-- GET THE GUILD NAME
while string.len(name) < 2 do
print("'guild 'name' is too short.")
name = io.read()
end
while string.len(name) > 20 do
print("'guild name' must be at least 20 in length.")
name = io.read()
end
--[[
local NAME_TAKEN = nil
for n=1, #Guild.__data do
if Guild.__data[n].name == name then
NAME_TAKEN = true
else
NAME_TAKEN = false
end
end
while not NAME_TAKEN do
print("Name already taken.")
name = io.read()
end
NAME_TAKEN = false
]]--
-----
if name ~= nil then
-- PAY MONEY TO MAKE GUILD
Bag.gold = Bag.gold - GUILD_PRICE
print("You have spent "..GUILD_PRICE.." "..gold.name)
-- CONSTRUCT THE GUILD
local guild = {}
-- PLAYER BECOMES THE FOUNDER
guild.name = name
guild.founder = founder.name
guild.rank = 1
guild.territory = tostring(0)
guild.members = {}
guild.position = member_rank
-- RANK 1: MASTER
founder.position = guild.position[1]
founder.IN_GUILD = true
-- PLAYER IS IN GUILD
--FOUNDER CANNOT BE CHANGED, BUT THE LEADER CAN
guild.leader = founder
founder.guild = guild
Guild.id = Guild.id + 1
guild.id = Guild.id
Guild.__data[#Guild.__data+1] = guild -- guild is added to the guild data storage
print("You have succeeded in created a guild!")
setmetatable(guild, {__index = Guild})
return guild
end
elseif founder.level < 25 and founder.rank < 5 then
print("You do not meet the requirements to establish a guild.")
elseif Bag.gold < GUILD_PRICE then
print("Not enough gold in your bag.")
end
else
print("You are already in a guild.")
end
end
-- MAKE A NEW GUILD
--[[
sid.level = 25
sid.rank = 5
Bag.gold = 500000
guild = Guild.new("Blue Warrior", sid)
jack =Player.new("Jack")
jack.level = 25
jack.rank = 5
Bag.gold = 500000
guild2 = Guild.new("Blue Warrior", jack)
]]--
--------------
--[[ USAGE:
player.level = 25; player.rank = 5; Bag.gold = 500000;
guild = Guild.new("The Guild of Gods", player)
]]--
--------------------
-- GUILD WINDOW
function Guild.open(guild)
guild_window = {
board,
info = {
guild.name, banner, founder, members_number, rank, territory
},
member_list,
contribution,
}
end
--[[
function Guild.invite() end -- all members and guild master
function Guild.upgrade() end -- guild masters only
function Guild.degrade() end -- guild masters and apprentices
function Guild.kick() end -- guild masters and apprentices only
function Guild.handOverAuthority() end -- guild master only
function Guild.disband() end -- guild master only
function Guild.leave() end -- player only
]]--
function Guild.invite(guild, member, player)
-- members and guild leaders
--THE GUILD MEMBER INVITES A PLAYER NOT IN A GUILD
if not player.IN_GUILD then
if member.IN_GUILD then
if member.position == guild.position[1] or member.position == guild.position[2] then
print("The Player can join the guild.")
-- ADD PLAYER TO MEMBER LIST
guild.members[#guild.members + 1] = player -- ADD PLAYER TO MEMBER LIST
player.IN_GUILD = true -- IS IN THE GUILD
player.guild = guild -- PLAYER'S GUILD
player.position = guild.position[4] -- RANK: TRAINEE
else
print("You are not qualified to do that!")
end
else
print("You are not in a guild!")
end
else
print("The Player is already in a guild.")
end
end
function Guild.upgrade(guild, member)
-- guild masters only
-- MEMBER IS IN THE GUILD, LEADER IS IN THE GUILD
if member.IN_GUILD and guild.leader.IN_GUILD then
if guild.leader.position == guild.position[1] then
print("Upgrade a member's position.")
-- MEMBER IS A TRAINEE, UPGRADE TO SENTINEL
if member.position == guild.position[4] then
member.position = guild.position[3]
end
-- MEMBER IS A SENTINEL, UPGRADE TO APPRENTICE
if member.position == guild.position[3] then
member.position = guild.position[2]
end
--NOONE CAN BE UPGRADED TO THE GUILD MASTER
-- THIS ACT IS FORBIDDEN!!
end
end
end
function Guild.degrade(guild, highranker, member)
-- guild masters and apprentices only
-- IN THE SAME GUILD
if guild.leader.guild == member.guild then
-- MEMBER IS IN THE GUILD, LEADER IS IN THE GUILD
if member.IN_GUILD and guild.leader.IN_GUILD then
if guild.leader.position == guild.position[1] or highranker.position == guild.position[2] then
print("Degrade a member's position.")
-- MEMBER IS AN APPRENTICE, DEGRADE TO SENTINEL
if member.position == guild.position[2] then
member.position = guild.position[3]
print(member.name.." has been degraded to "..guild.position[3])
end
-- MEMBER IS A SENTINEL, DEGRADE TO TRAINEE
if member.position == guild.position[3] then
member.position = guild.position[4]
print(member.name.." has been degraded to "..guild.position[4])
end
--NOONE CAN BE UPGRADED TO THE GUILD MASTER
-- THIS ACT IS FORBIDDEN!!
else
print("You are not qualified to degrade a member.")
end
elseif not member.IN_GUILD then
print("The member is not in the guild.")
elseif not guild.leader.IN_GUILD then
print("You are not in the guild.")
end
else
print("You are not in the same guild as [member]")
end
end
function Guild.kick(guild, highranker, member)
-- THEY ARE BOTH IN THE SAME GUILD
if highranker.guild == member.guild then
if highranker.position == guild.position[1] or highranker.position == guild.position[2] then
for m = 1, Guild.MAX_MEMBERS do
if guild.members[m] == member then
guild.members[m] = nil -- REMOVE MEMBER
print("You have been kicked out of the guild.")
member.IN_GUILD = false
member.guild = nil
member.position = nil
end
break
end
else
print("Your are not qualified to kick out a member.")
end
else
print("You are not in the same guild as the [member].")
end
end
function Guild.handOverAuthority(guild, leader, member)
if leader.IN_GUILD and member.IN_GUILD then
-- IN THE SAME GUILD
if guild.leader.guild == member.guild then
if leader == guild.leader then
if member.IN_GUILD then
-- MEMBER BECOMES THE MASTER
guild.leader = member
member.posititon = guild.position[1]
print(member.name.." is now "..guild.posititon[1])
-- DEGRADE THE PREVIOUS GUILD LEADER
guild.leader.position = guild.position[2]
else
print("This member does not exist in the guild.")
end
else
print("You are not the leader of the guild.")
end
else
print("Leader is not in the same guild as the member.")
end
elseif not leader.IN_GUILD then
print("You are not in any guild nor a guild leader.")
elseif not member.IN_GUILD then
print("You are not in any guild nor a guild member.")
end
end
-- GOOD!
function Guild.leave(guild, member)
--MEMBER IS IN THE GUILD
if member.IN_GUILD then
-- THE GUILD IS THE SAME AS THE MEMBER'S GUILD
if member.guild == guild then
-- THE MEMBER IS NOT THE GUILD LEADER
if member.position ~= guild.position[1] then
member.IN_GUILD = false
member.guild = nil
member.position = nil
else
print("Guild leaders cannot abandon their guild.")
end
else
print("This is not your guild.")
end
else
print("You are not in a guild.")
end
end
function Guild.disband(guild, leader)
-- GUILD LEADER CAN DISBAND THE GUILD
-- MUST BE IN A LEAGUE
if leader.IN_GUILD then
if leader.guild == guild then
if leader.position == guild.position[1] then
-- DESTROY THE GUILD
guild = nil
else
print("Only a guild leader can disband the league.")
end
else
end
print("This is not your guild.")
else
print("You are not in a league.")
end
end
-- Guild.__data = {} -- holds the names of all the guilds that have been created
-- GUILD ADVANTAGES--------------------------------
-- GUILD WAREHOUSE, BANNER, WDR
Guild_Storage = {}
GUILD_DATA = {}
function Guild.assist(guild)
end
function guildDataList()
for i = 1, 100 do
if guild_data[i] ~= nil then
print(guild_data[i].name)
end
end
end
function Guild.getID(guild)
if type(guild) == "table" then
for g=1, Guild.id do
if Guild.__data[g] == guild then
return Guild.__data[g].id
end
end
end
if type(guild) == "string" then
for g=1, Guild.id do
if Guild.__data[g].name == guild then
return Guild.__data[g].id
end
end
end
end
function Guild.getNameById(id)
for g=1, Guild.id do
if Guild.__data[g].id == id then
return Guild.__data[g].name
end
end
end