-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgame.rb
More file actions
671 lines (566 loc) · 21.1 KB
/
Copy pathgame.rb
File metadata and controls
671 lines (566 loc) · 21.1 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
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
require "json"
"""
todo:
can only travel to nearby location before traveling to further location. map must progress in a line. - buy teleport scroll,
when classes level up they get more points to affiliated skills
starting villiage does not actually exist on the map. once players travel to the homecity they can not go back.
statmults by race affinity, levelup
each class has its own story.
area random enemy encounters less by stealth. hit chance by stealth. attack speed by agility. put in agility in class info.
check event on travel
battles have battle id, event given battle id lets users use battle commands to interact with battle.
migrate chatacter dialouge in story class to dialouge class. maybe narrator too?
"""
def save_data user_data
for x, y in user_data
obj_hash = Hash[y.instance_variables.map { |var| [var.to_s[1..-1], y.instance_variable_get(var)] } ]
stats_hash = Hash[y.stats.instance_variables.map { |var| [var.to_s[1..-1], y.stats.instance_variable_get(var)] } ]
obj_hash["stats"] = stats_hash
@user_data[x] = obj_hash
end
File.write('gamedata.txt', user_data.to_json)
end
def load_data
userdata = {}
data = File.read("gamedata.txt")
if data.length > 0
data = JSON.parse(data)
for x, y in data
_stats = NewObj.new(**y["stats"])
y["stats"] = _stats
_user = NewObj.new(**y)
userdata[x] = _user
end
end
return userdata
end
class Game
attr_accessor :user_data, :response, :user
def initialize username, command, args
@username = username
@command = ("com_"+command.downcase)
@args = args.downcase
#@commands = Commands.new
@classes = [Thief.new, Mage.new, Warrior.new]
@user_data = load_data
if @user_data.keys.include? @username.downcase
@registered = true
else
@registered = false
end
if @registered
@user = @user_data[@username]
end
command_call
end
def command_call
commands = Commands.new(@user_data, @username)
if @registered
if commands.respond_to?(@command)
@response = commands.send(@command, @args)
else
@response = "That is not a valid command."
end
else
if @command == "com_register"
@response = commands.com_register(@args)
else
@response = "You have not registered for the game yet. Use the command \"info register\" to get started. The command \"info\" will teach you about any game commands or items in the game. All game commands must have the word \"game\" in front of them, including any command prefix, unless using the terminal on your computer. Chatbot example: \"$game info register\". Terminal example: \"info register\"."
end
end
end
end
############
# #
# COMMANDS #
# #
############
class Commands
def initialize user_data, username
@user_data = user_data
@user = @user_data[username]
end
def com_register
if !@registered
_class, race = @args.split(" ")[0], @args.split(" ")[1]
for i in @classes
if i.name = _class
user_class = i
break
end
end
pnum, mnum, snum, hnum = 10,10,10,100
pnum *= user_class.statmult.physical
mnum *= user_class.statmult.magic
snum *= user_class.statmult.stealth
hnum *= user_class.statmult.health
homecity = user_class.homecity
homevillage = Homevillages.new(homecity, race).name
@user = User.new(500,
[],
@username,
0,
"gamestart",
homecity,
{"physical": pnum, "magic": mnum, "stealth": snum, "health": hnum},
0,
0,
homevillage,
user_class.name,
race,
nil,
@username,
nil,
nil,
nil
)
@user_data[@username.downcase] = @user
save_data @user_data
@response = "You have now begun your journey. You were born in a small villiage named #{@user.homevillage} near the city #{@user.homecity}. To begin your adventure you must make your way to the guild in #{@user.homecity}. You own an a magic encyclopedia passed down to you from your parents. It only shows you the information you need to see. It is used by the command \"info\" Use the command \"info commands\" to get started."
else
@response = "You are already registered."
end
end
def com_progress
return Story.new(@user, "check").response
end
def com_wallet
return ("In your wallet you have: " + Money.new.calc_money(@user.money))
end
def com_location
location = @user.location
if location == "gamestart"
village = Homevillages.new(@user.homecity, @user.race)
@response = "You are in your home village, #{village.name}. It's description: #{village.description}"
return
end
/for x, y in @gdata.locations
loc = y[:id]
if loc == location
desc = y[:desc]
@response = "You are in ."
end
end/
end
def com_dice
return "derp"
end
def com_travel
/once traveled,
random chance to assign battle event in wilderness
story = Story.new(@user)
if story.event != nil #check for quests too.
@response = story.response
@user.event = story.event
@user_data[@user.name] = @user
save_data @user_data
return
can not travel or leave event location until event is over
/
end
def com_ joinguild
if @user.event == "joinguild"
if @user.location == (@user.homecity+"-guild")
@user.guild = guilds[@user.homecity]
@user.progress = 1
@response = "Congradulations, you have joined the local guild. Your next goal is to buy weapons, armor, and any items before getting your first quest from the guild. It is dangerous out in the wild, so a quest is a good place to start."
@user.event = nil
@user_data[@user.name] = @user
save_data @user_data
return
end
end
end
def com_attack
if @user.event in battles
battle = Battles.new(@user.event)
end
end
def com_leave #guild, item shop, etc.
end
def com_talk
#get quests from npc. story events.
end
end
#######################
# #
# GAME OBJECT CLASSES #
# #
#######################
class NewObj
def initialize(**args)
for key, value in args
singleton_class.class_eval { attr_accessor "#{key}" }
send("#{key}=", value)
end
end
end
#########
# #
# MONEY #
# #
#########
class Money
attr_accessor
def initialize
@bronze = 1
@brass = 100
@silver = 1000
@gold = 10000
end
def calc_money money
list = []
_money = money
if _money > @gold
_gold = _money / @gold
_money -= @gold * _gold
if _gold > 1 then list.append("#{_gold.to_s} gold coins") else list.append("#{_gold.to_s} gold coin") end
end
if _money > @silver
_silver = _money / @silver
_money -= @silver * _silver
if _silver > 1 then list.append("#{_silver.to_s} silver coins") else list.append("#{_silver.to_s} silver coin") end
end
if _money > @brass
_brass = _money / @brass
_money -= @brass * _brass
if _brass > 1 then list.append("#{_brass.to_s} brass coins") else list.append("#{_brass.to_s} brass coin") end
end
if _money > @bronze
_bronze = _money
if _bronze > 1 then list.append("#{_bronze.to_s} bronze coins") else list.append("#{_bronze.to_s} bronze coin") end
end
return (list.join(", ") + ".")
end
end
#############
# #
# LOCATIONS #
# #
#############
class Homevillages
attr_accessor :name, :description
def initialize homecity, race
@race = race
self.send(homecity.gsub(" ", "_"))
end
def aurendale
case @race
when "human"
@name = "villagename"
@description = "description"
when "druidim"
@name = "villagename"
@description = "description"
when "harissif"
@name = "villagename"
@description = "description"
end
end
def flora_city
case @race
when "human"
@name = "villagename"
@description = "description"
when "druidim"
@name = "villagename"
@description = "description"
when "harissif"
@name = "villagename"
@description = "description"
end
end
def lorienna
case @race
when "human"
@name = "villagename"
@description = "description"
when "druidim"
@name = "villagename"
@description = "description"
when "harissif"
@name = "villagename"
@description = "description"
end
end
end
class Locations
attr_accessor :description, :shops, :education, :quests
def initialize loc
case loc
when "aurendale"
@de
##########
# #
# EVENTS #
# #
##########
class Quests
#return info on travel if quest #id and progress, and character location is a match
#handle quest event code here. if match happens
end
class Story
attr_accessor :response
def initialize user, action
@action = action
_class = user.uclass
@user = user
@location = user.location
@progress = user.progress
self.send(_class)
end
def mage
case @progress
when 0
if @location == "gamestart"
@response = "You are in your home village, #{@user.homevillage}. It is time to leave behind life as your family has known it for generations and -travel- to the guild in #{@user.homecity}. once you leave your village you will never return..."
@event = nil
elsif @location == "#{@user.homecity}-guild"
@response = "You have entered the Guild that you have set out to join. The clerk at the counter looks up at you, looking quite bored. \"Are you here to join the guild? He asks shyly. If you wish to join the guild, Say the command \"joinguild\" and you will be signed up."
@event = "joinguild"
else
if @action == "check"
@response = "I have left my village and am now in #{@user.homecity}. My task is to -travel- to the guild here."
end
end
when 1
if @location == "#{@user.homecity}-guild"
@response = "congradulations You have joined the guild!!! You have gained your first level and your guild card. You can now gain experience and level up further. You will be able to leave the city to explore as well. It is now time to -leave- the guild to buy some basic supplies, and -travel- to a -combat shop- and -item shop- in your city."
@event = nil
end
end
end
def thief
case @progress
when 0
if @location == "gamestart"
@response = "You are in your home village, #{@user.homevillage}. It is time to leave behind life as your family has known it for generations and -travel- to the guild in #{@user.homecity}. once you leave your village you will never return..."
@event = nil
elsif @location == "#{@user.homecity}-guild"
@response = "You have entered the Guild that you have set out to join. The clerk at the counter looks up at you, looking quite bored. \"Are you here to join the guild? He asks shyly. If you wish to join the guild, Say the command \"joinguild\" and you will be signed up."
@event = "joinguild"
else
if @action == "check"
@response = "I have left my village and am now in #{@user.homecity}. My task is to -travel- to the guild here."
end
end
when 1
if @location == "#{@user.homecity}-guild"
@response = "congradulations You have joined the guild!!! You have gained your first level and your guild card. You can now gain experience and level up further. You will be able to leave the city to explore as well. It is now time to -leave- the guild to buy some basic supplies, and -travel- to a -combat shop- and -item shop- in your city."
@event = nil
end
end
end
def warrior
case @progress
when 0
if @location == "gamestart"
@response = "You are in your home village, #{user.homevillage}. It is time to leave behind life as your family has known it for generations and -travel- to the guild in #{@user.homecity}. once you leave your village you will never return..."
@event = nil
elsif @location == "#{@user.homecity}-guild"
@response = "You have entered the Guild that you have set out to join. The clerk at the counter looks up at you, looking quite bored. \"Are you here to join the guild? He asks shyly. If you wish to join the guild, Say the command \"joinguild\" and you will be signed up."
@event = "joinguild"
else
if @action == "check"
@response = "I have left my village and am now in #{@user.homecity}. My task is to -travel- to the guild here."
end
end
when 1
if @location == "#{@user.homecity}-guild"
@response = "congradulations You have joined the guild!!! You have gained your first level and your guild card. You can now gain experience and level up further. You will be able to leave the city to explore as well. It is now time to -leave- the guild to buy some basic supplies, and -travel- to a -combat shop- and -item shop- in your city."
@event = nil
end
end
end
end
class Battles
end
##############
# #
# CHARACTERS #
# #
##############
class User
attr_accessor :money, :weapons, :title, :progress, :location, :homecity, :stats, :level, :exp, :homevillage, :uclass, :race, :guild, :name, :event, :quest, :qprogress
def initialize money, weapons, title, progress, location, homecity, stats, level, exp, homevillage, uclass, race, guild, username, event, quest, qprogress
@money = money
@weapons = weapons
@title = title
@progress = progress
@location = location
@homecity = homecity
@stats = NewObj.new(**stats)
@level = level
@exp = exp
@homevillage = homevillage
@uclass = uclass
@race = race
@guild = guild
@name = username
@event = event
@quest = quest
@qprogress = qprogress
end
end
class Dialouge
attr_accessor :response
def initialize username, character, user_data, args
@user = user_data[username]
@user_data
@args = args
@character = character
@progress = @user.progress
@qprogress = @user.qprogress
@com_quests = @user.com_quest
@quest = @user.quest #@user.quest is quest #id
self.send(@character)
end
def kahn
if @quest == nil
if @qprogress = 0
if !@com_quests.include? 2173426243
@user.quest = 2173426243
@user_data[@user.name] = @user
save_data @user_data
@response = "I have a quest for you. blahblah blah. do you wish to accept it? [\"talk kahn yes\", \"talk kahn no\"]"
return
elsif !@com_quests.include? 4267379352
@user.quest = 4267379352
@user_data[@user.name] = @user
save_data @user_data
@response = "I have another quest for you. blahblah blah. do you wish to accept it? [\"talk kahn yes\", \"talk kahn no\"]"
return
end
end
if @quest == 2173426243
case @qprogress
when 0
if @args == "no"
@user.quest = nil
@user_data[@user.name] = @user
save_data @user_data
@response = "Come back to me if you want to accept it;"
return
elsif @args == "yes"
@user.qprogress = 1
@user_data[@user.name] = @user
save_data @user_data
@response = "Thanks. THis is what i want you to do."
return
end
when 1
#if condition not completed, @response = "Have you not completed it yet? come back to me "
end
elsif @quest == 4267379352
case @qprogress
when 1
end
end
end
class Races
def initialize race
case race
when "druidim"
@name = "druidim"
@description = "description"
when "harissif"
@name = "harissif"
@description = "description"
when "human"
@name = "druidim"
@description = "description"
end
end
end
class Mage
attr_accessor :homecity, :raceaff, :statmult, :raceunaff, :name, :special_abilities, :waff, :wunaff
def initialize
@name = "mage"
@homecity = "lorienna"
@raceaff = "druidim"
@statmult = NewObj.new(**{"physical": 0.6, "magic": 1.8, "stealth": 1.2, "health": 1.1})
@raceunaff = "human"
@waff = "magic"
@wunaff = "mele"
end
end
class Warrior
attr_accessor :homecity, :raceaff, :statmult, :raceunaff, :name, :special_abilities, :waff, :wunaff
def initialize
@name = "warrior"
@homecity = "aurendale"
@raceaff = "harissif"
@statmult = NewObj.new(**{"physical": 1.8, "magic": 0.7, "stealth": 0.8, "health": 1.4})
@raceunaff = "druidim"
@waff = "mele"
@wunaff = "magic"
end
end
class Thief
attr_accessor :homecity, :raceaff, :statmult, :raceunaff, :name, :special_abilities, :waff, :wunaff
def initialize
@name = "thief"
@homecity = "flora city"
@raceaff = "human"
@statmult = NewObj.new(**{"physical": 1.2, "magic": 0.9, "stealth": 1.8, "health": 0.8})
@raceunaff = "harissif"
@waff = "none"
@wunaff = "nome"
end
end
#########
# #
# ITEMS #
# #
#########
class Weapons
attr_accessor :unarmed, :rusty_sword, :flimsy_bow, :training_staff, :pocket_knife
def initialize
@unarmed = NewObj.new(**{
"wtype": "dagger",
"type": "mele",
"damage": 1,
"ammo": nil,
"speed": 1
})
@rusty_sword = NewObj.new(**{
"wtype": "sword",
"type": "mele",
"damage": 5,
"ammo": nil,
"speed": 3
})
@flimsy_bow = NewObj.new(**{
"wtype": "bow",
"type": "mele",
"damage": 3,
"ammo": nil,
"speed": 5
})
@rusty_sword = NewObj.new(**{
"wtype": "sword",
"type": "mele",
"damage": 1,
"ammo": nil,
"speed": 3
})
end
end
def sym x
return :"#{x}"
end
def gen_id
return rand(1000000000, 9999999999)
end
game = Game.new("herenti", "register", "thief human")
puts game.response
sleep 1
game = Game.new("herenti", "location", "")
puts game.response
sleep 1
game = Game.new("herenti", "progress", "")
puts game.response
sleep 1
game = Game.new("herenti", "wallet", "")
puts game.response
sleep 1