forked from kevinkey/klank
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcard.rb
727 lines (667 loc) · 27 KB
/
card.rb
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
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
module Klank
class Card
attr_reader :name
attr_reader :type
attr_reader :cost
attr_reader :attack
attr_reader :danger
attr_reader :dragon
attr_reader :roll_pyramid_die
attr_reader :play_count
attr_accessor :num_times_discarded
def initialize(game, hash)
@game = game
@name = hash["name"]
@type = hash["type"] || ""
@cost = hash["cost"] || 1000000
@attack = hash["attack"] || 1000000
@special = hash["special"] || ""
@danger = hash.key?("danger")
@dragon = hash.key?("dragon")
@roll_pyramid_die = hash.key?("roll_pyramid_die")
@play_count = 0
@num_times_discarded = 0
@hash = hash
end
def player_cost(player, pickpocket = false)
cost = 0
if (@type == :gem) and player.has_played?("Gem Collector")
cost = @cost - 2
elsif !pickpocket
cost = @cost
end
cost
end
def points(player)
total = 0
if @hash.key?("points")
total += @hash["points"].to_i
end
case @name
when "Book of the Dead"
total += player.curses
when "Dragon's Eye"
if player.mastery
total += 10
end
when "Dwarven Peddler"
things = 0
if player.has_item?("Chalice")
things += 1
end
if player.has_item?("Dragon Egg")
things += 1
end
if player.has_monkey_idol?()
things += 1
end
if things >= 2
total += 4
end
when "Grand Plan"
things = 0
things += player.item_count("Backpack")
things += player.item_count("Crown (10)")
things += player.item_count("Crown (9)")
things += player.item_count("Crown (8)")
things += player.item_count("Master Key")
things += player.item_count("Scuba")
if things >= 3
total += 7
end
when "Purify"
fewest_curses = true
@game.player.each do |p|
if p.curses < player.curses
fewest_curses = false
end
end
if fewest_curses
total += 5
end
when "The Duke"
total += (player.coins / 5)
when "Wizard"
total += (player.deck.active_cards.select { |c| c.name == "Tome" }.count * 2)
end
total
end
def arrive()
case @name
when "Eye-in-the-Water", "Friendly Watcher", "Overlord", "Tomb Snake", "Watcher"
@game.player.each do |p|
p.clank(@name == "Eye-in-the-Water" ? 2 : 1)
end
when "Shrine"
@game.dragon.add_dragon_cubes()
end
end
def acquire(player, pickpocket = false)
success = false
cost = player_cost(player, pickpocket)
if @type == :monster
player.output("Can't buy a monster!")
elsif @hash.key?("depths") and !@game.map.depths?(player)
player.output("Must be in the depths to acquire!")
elsif player.skill >= cost
success = true
case @name
when "Door to Before"
player.door_before_teleport += 1
when "Dragon Shrine"
menu = [
["C", {"DESC" => "+2 coins", "COINS" => player.coins}],
["T", {"DESC" => "Trash a card"}]
]
loop do
case player.menu("DRAGON SHRINE", menu, true)
when "C"
player.collect_coins(2)
break
when "T"
break if player.trash_card()
else
success = false
break
end
end
when "Pipe Organ"
menu = [["U", "Move the Dragon marker one space up"], ["D", "Move the Dragon marker one space down"]]
@game.dragon.move_marker(player.menu("PIPE ORGAN", menu) == "U" ? 1 : -1)
when "Ring of Wishes"
actions = 0
menu = [
["D", {"DESC" => "+1 coin", "CURRENT" => player.coins}],
["M", {"DESC" => "+1 move", "CURRENT" => player.move}],
["C", {"DESC" => "-1 curse", "CURRENT" => player.curses}]
]
loop do
case player.menu("RING OF WISHES", menu, true)
when "D"
player.collect_coins(1)
actions += 1
when "M"
@game.broadcast("#{player.name} gained +1 move!")
player.move += 1
actions += 1
when "C"
player.curse(-1)
actions += 1
when "N"
break
end
break if (actions == 3)
end
when "Shrine"
menu = [
["C", {"DESC" => "+1 coin", "CURRENT" => player.coins}],
["H", {"DESC" => "+1 health", "CURRENT" => player.health}]
]
case player.menu("SHRINE", menu, true)
when "C"
player.collect_coins(1)
when "H"
player.heal(1)
else
success = false
end
when "Shrine of the Mermaid"
menu = [["C", "2 coins"], ["T", "Teleport to an adjacent room"]]
if player.menu("SHRINE OF THE MERMAID", menu) == "C"
player.collect_coins(2)
else
player.shrine_mermaid_teleport += 1
end
when "Snack Table"
@game.player.select { |p| p.coins > 0 and p != player and !p.dead?() and !p.mastery}.each do |p|
if ("Y" == p.input("Do you want to pay #{player.name} 1 coin for +1 heal? (Y: yes)").upcase)
@game.broadcast("#{p.name} paid #{player.name} 1 coin for +1 heal")
p.coins -= 1
player.coins += 1
p.heal(1)
end
end
when "Tower of Babble"
actual = [player.cubes, 3].min
@game.broadcast("#{player.name} moved #{actual} cube(s) from their bank to the tower.")
player.clank_babble += actual
player.cubes -= actual
when "Wishing Well"
actions = 0
menu = [
["A", {"DESC" => "+2 attack", "CURRENT" => player.attack}],
["H", {"DESC" => "+1 health", "CURRENT" => player.health}],
["M", {"DESC" => "+2 move", "CURRENT" => player.move}],
["T", {"DESC" => "Trash a card"}]
]
loop do
case player.menu("WISHING WELL", menu, true)
when "A"
@game.broadcast("#{player.name} gained +2 attack!")
player.attack += 2
if (actions == 0)
menu.delete_at(0)
end
actions += 1
when "H"
player.heal(1)
if (actions == 0)
menu.delete_at(1)
end
actions += 1
when "M"
@game.broadcast("#{player.name} gained +2 move!")
player.move += 2
if (actions == 0)
menu.delete_at(2)
end
actions += 1
when "T"
player.trash_card()
if (actions == 0)
menu.delete_at(3)
end
actions += 1
when "N"
break
end
break if (actions == 2)
end
end
if success
player.skill -= cost
if @hash.key?("acquire")
abilities(player, @hash["acquire"])
end
end
else
player.output("Not enough skill!")
end
success
end
def defeat(player)
success = false
if @type != :monster
player.output("That's not a monster!")
elsif @hash.key?("depths") && !@game.map.depths?(player)
player.output("Must be in the depths to defeat!")
elsif @hash.key?("crystal cave") && !@game.map.crystal_cave?(player)
player.output("Must be in a crystal cave to defeat!")
elsif @name == "Crystal Fish" && !@game.map.crystal_cave?(player) && !@game.map.flooded?(player)
player.output("Must be in a crystal cave or flooded room to defeat!")
elsif player.attack >= @attack
success = true
player.attack -= @attack
player.num_monsters_killed += 1
player.num_damage_dealt += @attack
case @name
when "Eye-in-the-Water"
menu = [["C", "-2 clank"], ["S", "+2 Coins"]]
if player.menu("EYE-IN-THE-WATER", menu) == "S"
player.collect_coins(2)
else
player.clank(-2)
@game.broadcast("#{player.name} gained -2 clank from defeating Eye-in-the-Water!")
end
when "Scorpion Queen"
@hash["defeat"]["coins"] -= [player.curses, @hash["defeat"]["coins"]].min
when "Stone Simian"
if player.has_monkey_idol?()
player.heal(1)
end
when "Watcher"
@game.broadcast("All other players +1 clank")
@game.player.each do |p|
if p.index != player.index
p.clank(1)
end
end
end
if @hash.key?("defeat")
abilities(player, @hash["defeat"])
end
else
player.output("Not enough attack!")
end
success
end
def equip(player)
case @name
when "Alchemist"
if player.has_played?("Tome") or player.deck.pile.any? { |c| c.name == "Tome" }
player.collect_coins(2)
end
when "Apothecary"
if player.discard_card()
menu = [
["A", {"DESC" => "+3 attack", "CURRENT" => player.attack}],
["C", {"DESC" => "+2 coins", "CURRENT" => player.coins}],
["H", {"DESC" => "+1 health", "CURRENT" => player.health}]
]
case player.menu("APOTHECARY", menu)
when "A"
player.attack += 3
@game.broadcast("#{player.name} gained +3 attack from Apothecary!")
when "C"
player.collect_coins(2)
when "H"
player.heal(1)
end
end
when "Archaeologist"
if player.has_monkey_idol?()
player.skill += 2
end
when "Aspiration"
if player.has_crown?()
player.draw(1)
end
when "Brawn vs Boots"
menu = [["A", "+2 Attack"], ["M", "+2 Move"]]
if player.menu("BRAWN VS BOOTS", menu) == "A"
player.attack += 2
else
player.move += 2
end
when "Burglar's Boots"
menu = [["C", "-2 clank"], ["M", "+1 Move"], ["S", "+1 Coin"]]
case player.menu("BURGLAR'S BOOTS", menu)
when "C"
player.clank(-2)
when "M"
player.move += 1
when "S"
player.collect_coins(1)
end
when "Climbing Gear"
if player.discard_card()
player.move += 1
end
when "Crystal Skull"
if (player.played.select { |c| c.type == :gem }.count + player.deck.pile.select { |c| c.type == :gem }.count) >= 2
player.tome(1)
end
when "Deep Dive"
if ((player.hand.length >= 3) and player.discard_card(3))
player.draw(5)
end
when "Dire Wolf"
count = @game.dungeon.hand.select { |c| c.type == :monster }.count + 1 + (@game.sunken_treasures?() ? 1 : 0) #+1 for Goblin and +1 for Goldfish
player.clank(count)
player.attack += count
when "Doomsayer"
if @game.dragon.clank_in_bank?(player)
@game.broadcast("All other players +1 curse")
@game.player.each do |p|
if p.index != player.index
p.curse(1)
end
end
end
when "Enchanted Dice"
@game.dragon.reveal(2).each do |c|
if c.to_s == "D"
@game.broadcast("A dragon cube was revealed.")
player.collect_coins(1)
else
@game.broadcast("#{@game.player[c.to_i].name}'s cube was revealed.")
if (@game.player[c.to_i] == player)
player.collect_coins(1)
end
end
end
when "Fishing Pole"
player.draw(1)
player.discard_card(1, true)
when "Friendly Watcher", "Tattle"
@game.broadcast("All other players +1 clank")
@game.player.each do |p|
if p.index != player.index
p.clank(1)
end
end
when "Historian"
if @game.dragon.clank_in_bank?(player)
player.trash_card()
end
when "Kittypatra"
menu = [["C", "-2 Clank"], ["D", "-1 Curse"]]
if player.menu("KITTYPATRA", menu) == "C"
player.reclaim_clank(2)
else
player.curse(-1)
end
when "Kobold Merchant"
if player.has_artifact?()
player.skill += 2
end
when "Magic Spectacles"
if player.deck.remaining() == 0
player.deck.reshuffle(player, @game)
end
player.output("\nTOP CARD OF DECK\n#{Klank.table([player.deck.peek.play_desc])}")
menu = [["T", "Keep card at top of deck"], ["B", "Move card to bottom of deck"]]
if player.menu("MAGIC SPECTACLES", menu) == "T"
@game.broadcast("#{player.name} kept the top card of their deck at the top!")
else
@game.broadcast("#{player.name} moved the top card of their deck to the bottom!")
player.move_card_to_bottom
end
player.draw(1)
when "Master Burglar"
player.trash_card("Burgle")
when "Medic"
if player.discard_card()
player.heal(1)
end
when "Mister Whiskers"
@game.broadcast("#{player.name} played Mister Whiskers!")
menu = [["D", "Dragon Attack"], ["C", "-2 clank"]]
if player.menu("MISTER WHISKERS", menu) == "D"
player.reclaim_clank()
@game.dragon.attack()
else
player.clank(-2)
@game.broadcast("#{player.name} gained -2 clank from Mister Whiskers!")
end
when "Need For Greed"
if player.discard_card()
player.collect_coins(2)
end
when "Pickpocket"
@game.dungeon.pickpocket(player, 3, false)
when "Rebel Brawler", "Rebel Burglar", "Rebel Captain", "Rebel Miner", "Rebel Mystic", "Rebel Scholar", "Rebel Scout", "Rebel Soldier"
if @name == "Rebel Burglar"
player.trash_card("Burgle")
end
if player.played.any? { |c| (c.type == :companion) and (c.name != @name) }
player.draw(1)
end
when "Siren"
@game.dungeon.pickpocket(player, 1000000, true)
when "Sleight of Hand", "Black Pearl", "Silver Pearl", "White Pearl"
if player.discard_card()
player.draw(2)
end
when "Staff of the Ancients"
if player.played.any? { |c| c.type == :gem } or player.deck.pile.any? { |c| c.type == :gem }
player.teleport += 1
end
when "The Mountain King"
if player.has_crown?()
player.attack += 1
player.move += 1
end
when "The Queen of Hearts"
if player.has_crown?()
player.heal(1)
end
when "Thrill Seeker"
if @game.dragon.clank_in_bank?(player)
@game.broadcast("#{player.name} gained +2 move!")
player.move += 2
end
when "Tomb Robber"
if player.has_artifact?()
player.collect_coins(2)
end
when "Treasure Hunter"
@game.dungeon.replace_card(player)
when "Underworld Dealing"
remaining = @game.reserve[:t].remaining
if (player.coins < 7) or (remaining == 0)
player.collect_coins(1)
else
menu = [["C", "1 coin"], ["T", "7 coins for #{[2, remaining].min} Tomes. There are #{@game.reserve[:t].remaining} Tome(s) left!"]]
if player.menu("UNDERWORLD DEALING", menu) == "C"
player.collect_coins(1)
else
player.coins -= 7
@game.map.bank += 7
player.tome(2)
@game.broadcast("Through some Underworld Dealing, #{player.name} gained +#{[2, remaining].min} Tome(s)! There are #{@game.reserve[:t].remaining} Tome(s) left!")
end
end
when "Wand of Recall"
if player.has_artifact?()
player.teleport += 1
end
when "Wand of Time"
if player.deck.pile.count == 0
player.draw(2)
else
player.retrieve_card_from_discard()
end
when "Wand of Wind"
loop do
menu = [["T", "Teleport to an adjacent room"], ["S", "Take a secret from an adjacent room"]]
if player.menu("WAND OF WIND", menu) == "T"
player.teleport += 1
break
elsif @game.map.take_adjacent_secret(player)
break
end
end
end
if @hash.key?("equip")
abilities(player, @hash["equip"])
end
@play_count += 1
end
def play_desc()
desc = {"NAME" => @name, "TYPE" => @type.to_s.upcase}
if @hash.key?("equip")
if @hash["equip"].key?("skill")
desc["SKILL"] = @hash["equip"]["skill"]
end
if @hash["equip"].key?("move")
desc["MOVE"] = @hash["equip"]["move"]
end
if @hash["equip"].key?("attack")
desc["ATTACK"] = @hash["equip"]["attack"]
end
if @hash["equip"].key?("teleport")
desc["MISC"] = "TELEPORT"
end
if @hash["equip"].key?("coins")
desc["COINS"] = @hash["equip"]["coins"]
end
if @hash["equip"].key?("draw")
desc["DRAW"] = @hash["equip"]["draw"]
end
if @hash["equip"].key?("clank")
desc["CLANK"] = @hash["equip"]["clank"]
end
if @hash["equip"].key?("curse")
desc["CURSE"] = @hash["equip"]["curse"]
end
if @hash["equip"].key?("heal")
desc["HEAL"] = @hash["equip"]["heal"]
end
end
if @hash.key?("special")
desc["SPECIAL"] = @special
end
desc
end
def buy_desc(gem_collector)
desc = {"NAME" => @name, "TYPE" => @type.to_s.upcase}
if @hash.key?("cost")
cost = 0
if (@type == :gem) and gem_collector
cost = @cost - 2
else
cost = @cost
end
desc["COST"] = cost
end
if @hash.key?("attack")
desc["COST"] = @hash["attack"]
end
if @hash.key?("points")
desc["POINTS"] = @hash["points"]
end
if @hash.key?("acquire")
acquire = []
if @hash["acquire"].key?("skill")
acquire << "SKILL: #{@hash["acquire"]["skill"]}"
end
if @hash["acquire"].key?("move")
acquire << "MOVE: #{@hash["acquire"]["move"]}"
end
if @hash["acquire"].key?("attack")
acquire << "ATTACK: #{@hash["acquire"]["attack"]}"
end
if @hash["acquire"].key?("teleport")
acquire << "TELEPORT"
end
if @hash["acquire"].key?("coins")
acquire << "COINS: #{@hash["acquire"]["coins"]}"
end
if @hash["acquire"].key?("clank")
acquire << "CLANK: #{@hash["acquire"]["clank"]}"
end
if @hash["acquire"].key?("curse")
acquire << "CURSE: #{@hash["acquire"]["curse"]}"
end
if @hash["acquire"].key?("heal")
acquire << "HEAL: #{@hash["acquire"]["heal"]}"
end
desc["ACQUIRE"] = "#{acquire.join(", ")}"
end
if @hash.key?("defeat")
if @hash["defeat"].key?("skill")
desc["SKILL"] = @hash["defeat"]["skill"]
end
if @hash["defeat"].key?("move")
desc["MOVE"] = @hash["defeat"]["move"]
end
if @hash["defeat"].key?("coins")
desc["COINS"] = @hash["defeat"]["coins"]
end
if @hash["defeat"].key?("draw")
desc["DRAW"] = @hash["defeat"]["draw"]
end
if @hash["defeat"].key?("clank")
desc["CLANK"] = @hash["defeat"]["clank"]
end
if @hash["defeat"].key?("curse")
desc["CURSE"] = @hash["defeat"]["curse"]
end
if @hash["defeat"].key?("heal")
desc["HEAL"] = @hash["defeat"]["heal"]
end
if @hash["defeat"].key?("tomes")
desc["TOMES"] = @hash["defeat"]["tomes"]
end
end
if @danger
desc["MISC"] = "DANGER"
end
if @hash.key?("depths")
desc["MISC"] = "DEPTHS"
end
if @hash.key?("crystal cave")
desc["MISC"] = "CRYSTAL CAVE"
end
if @name == "Crystal Fish"
desc["MISC"] = "CRYSTAL CAVE OR FLOODED ROOM"
end
desc.merge(play_desc())
end
def abilities(player, hash)
if hash.key?("skill")
player.skill += hash["skill"]
end
if hash.key?("move")
player.move += hash["move"]
end
if hash.key?("attack")
player.attack += hash["attack"]
end
if hash.key?("teleport")
player.teleport += hash["teleport"]
end
if hash.key?("coins")
player.collect_coins(hash["coins"])
end
if hash.key?("draw")
player.draw(hash["draw"])
end
if hash.key?("clank")
player.clank(hash["clank"])
end
if hash.key?("curse")
player.curse(hash["curse"])
end
if hash.key?("heal")
player.heal(hash["heal"])
end
if hash.key?("tomes")
remaining = @game.reserve[:t].remaining
player.tome(hash["tomes"])
@game.broadcast("#{player.name} gained +#{[hash["tomes"], remaining].min} Tome(s)! There are #{@game.reserve[:t].remaining} Tome(s) left!")
end
end
end
end