This repository has been archived by the owner on Sep 11, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsanjuan.rb
2109 lines (1998 loc) · 59.1 KB
/
sanjuan.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
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Title:: San Juan
# Author:: Jay Thomas <[email protected]>
# Copyright:: (C) 2013 gfax
# License:: GPL
# Version:: 2013-05-19
#
class SanJuan
Max_Buildings = 12
Starting_Cards = 4
B = Bold
Cards = {
# Call these production to distinguish them
# from the other producer-phase cards.
indigo_plant: {
cost: 1,
phase: :production,
vps: 1,
keywords: [ /indigo/, /plant/ ],
text: 'owner produces 1 indigo',
quantity: 10
},
sugar_mill: {
cost: 2,
phase: :production,
vps: 1,
keywords: [ /sugar/, /mill/ ],
text: 'owner produces 1 sugar',
quantity: 8
},
tobacco_storage: {
phase: :production,
cost: 3,
vps: 2,
keywords: [ /tobacc?o/, /storage/ ],
text: 'owner produces 1 tobacco',
quantity: 8
},
coffee_roaster: {
phase: :production,
cost: 4,
vps: 2,
keywords: [ /coff?e/, /roa?ster/ ],
text: 'owner produces 1 coffee',
quantity: 8
},
silver_smelter: {
phase: :production,
cost: 5,
vps: 3,
keywords: [ /silver/, /smelter/ ],
text: 'owner produces 1 silver',
quantity: 8
},
smithy: {
phase: :builder,
cost: 1,
vps: 1,
keywords: [ /smithy/ ],
text: 'owner pays 1 card less when building a production building',
quantity: 3
},
gold_mine: {
phase: :prospector,
cost: 1,
vps: 1,
keywords: [ /gold/, /mine/ ],
text: 'owner turns up 4 cards from the supply; if all have ' +
'different building costs, he made add one to his hand',
quantity: 3
},
archive: {
phase: :councillor,
cost: 1,
vps: 1,
keywords: [ /archive/ ],
text: 'owner may discard hand cards in addition to drawn cards',
quantity: 3
},
market_stand: {
phase: :trader,
cost: 2,
vps: 1,
keywords: [ /stand/ ],
text: 'owner takes 1 card from the supply ' +
'when he sells at least 2 goods',
quantity: 3
},
poor_house: {
phase: :builder,
cost: 2,
vps: 1,
keywords: [ /poor/ ],
text: 'owner takes 1 card from the supply if ' +
'he has only 0 or 1 card after building',
quantity: 3
},
crane: {
phase: :builder,
cost: 2,
vps: 1,
keywords: [ /crane/ ],
text: 'owner may build over one of his building (and pay ' +
'the difference); specify the target building when ' +
'when building: p b# 2 3... (# being the building number)',
quantity: 3
},
black_market: {
phase: :builder,
cost: 2,
vps: 1,
keywords: [ /black/ ],
text: 'owner may discard any 1 or 2 goods and ' +
'reduce the building cost by 1 or 2 cards',
quantity: 3
},
well: {
phase: :producer,
cost: 2,
vps: 1,
keywords: [ /wish/, /well/ ],
text: 'owner takes 1 card from the supply ' +
'when he produces at least 2 goods',
quantity: 3
},
trading_post: {
phase: :trader,
cost: 2,
vps: 1,
keywords: [ /trading/, /post/ ],
text: 'owner may sell 2 additional goods',
quantity: 3
},
tower: {
phase: :governor,
cost: 3,
vps: 2,
keywords: [ /tower/ ],
text: 'owner may have up to 12 cards in his hand',
quantity: 3
},
carpenter: {
phase: :builder,
cost: 3,
vps: 2,
keywords: [ /carpenter/ ],
text: 'owner takes 1 card from the supply ' +
'after he builds a violet building',
quantity: 3
},
statue: {
phase: :monument,
cost: 3,
vps: 3,
keywords: [ /statue/ ],
text: 'no special function',
quantity: 3
},
prefecture: {
phase: :councillor,
cost: 3,
vps: 2,
keywords: [ /prefecture/ ],
text: 'owner keeps 1 card more from those drawn',
quantity: 3
},
chapel: {
phase: :governor,
cost: 3,
vps: 2,
keywords: [ /chapel/ ],
text: 'owner may place 1 hand card under his ' +
'chapel (each worth 1 VP at game end)',
quantity: 3
},
aqueduct: {
phase: :producer,
cost: 3,
vps: 2,
keywords: [ /aqu(e|a)duct/ ],
text: 'owner produces 1 more good',
quantity: 3
},
quarry: {
phase: :builder,
cost: 4,
vps: 2,
keywords: [ /quar/ ],
text: 'owner pays 1 card less when building a violet building',
quantity: 3
},
victory_column: {
phase: :monument,
cost: 4,
vps: 4,
keywords: [ /victory/, /column/ ],
text: 'no special function',
quantity: 3
},
market_hall: {
phase: :trader,
cost: 4,
vps: 2,
keywords: [ /hall/ ],
text: 'owner takes 1 card more for selling one good',
quantity: 3
},
hero: {
phase: :monument,
cost: 5,
vps: 5,
keywords: [ /hero/ ],
text: 'no special function',
quantity: 3
},
library: {
phase: :all,
cost: 5,
vps: 3,
keywords: [ /library/ ],
text: 'owner uses the privilege of his role twice',
quantity: 3
},
# End-game cards:
city_hall: {
phase: :end,
cost: 6,
keywords: [ /city/ ],
text: 'owner earns 1 additional victory point ' +
'for each of his violet buildings',
quantity: 2
},
guild_hall: {
phase: :end,
cost: 6,
keywords: [ /guild/ ],
text: 'owner earns 2 additional victory points ' +
'for each of his production buildings',
quantity: 2
},
triumphal_arch: {
phase: :end,
cost: 6,
keywords: [ /triump/ ],
text: 'owner earns an additional 4-6-8 ' +
'victory points for 1-2-3 monuments',
quantity: 2
},
palace: {
phase: :end,
cost: 6,
keywords: [ /palace/ ],
text: 'owner earns 1 additional victory point for every 4 victory points',
quantity: 2
},
# Expansion Cards:
office_building: {
expansion: true,
phase: :governor,
cost: 1,
vps: 1,
keywords: [ /off?ice/ ],
text: 'owner may discard 1 or 2 cards and draw 1 or 2 new cards',
quantity: 3
},
guard_room: {
expansion: true,
phase: :governor,
cost: 1,
vps: 1,
keywords: [ /guard/ ],
text: 'players without Guard room reduce their hand to 6 cards',
quantity: 3
},
caritas: {
expansion: true,
phase: :builder,
cost: 2,
vps: 1,
keywords: [ /caritas/ ],
text: 'owner takes 1 card from the supply if he has the fewest ' +
'buildings (does not take affect until the following phase). ' +
'note: owner does no need to build for it to take affect',
quantity: 3
},
customs_office: {
expansion: true,
phase: :councillor,
cost: 3,
vps: 2,
keywords: [ /customs/ ],
text: '1 good from supply on the customs office; ' +
' Trader phase: good brings in 2 cards with the sale',
quantity: 3
},
park: {
expansion: true,
phase: :builder,
cost: 3,
vps: 2,
keywords: [ /park/ ],
text: 'when the park is built over, the cost of the new building ' +
'is lowered by as much as 6 (requires a crane to be built over)',
quantity: 3
},
harbor: {
expansion: true,
phase: :trader,
cost: 4,
vps: 2,
keywords: [ /harbor/ ],
text: 'owner must put a sold good under his ' +
'harbor (each scores 1 VP at game end)',
quantity: 3
},
bank: {
expansion: true,
phase: :governor,
cost: 4,
vps: 2,
keywords: [ /bank/ ],
text: 'owner may put as many cards from his hand cards ' +
'under his bank (each scores 1 VP at game end). ' +
'note: this card can only be used once per game',
quantity: 3
},
goldsmith: {
expansion: true,
phase: :prospector,
cost: 5,
vps: 3,
keywords: [ /gold ?smith/ ],
text: 'owner draws 1 card from supply, keeping it if no one has built one',
quantity: 3
},
residence: {
expansion: true,
phase: :end,
cost: 6,
keywords: [ /residence/ ],
text: 'owner scores 4-3-2-1 VPs for each set of three ' +
'different buildings with the same building cost',
quantity: 2
},
# test this
cathedral: {
expansion: true,
phase: :end,
cost: 7,
keywords: [ /cathedral/ ],
text: 'owner scores 4-3-2-1-0 VPs for each opponents\' 6 buildings',
quantity: 1
},
# Events:
free_build: {
expansion: true,
phase: :event,
keywords: [ /free?buil/ ],
text: 'each player may build a building with ' +
'building costs of up to 4 free of charge',
quantity: 1
},
governor_visit: {
expansion: true,
phase: :event,
keywords: [ /visit/ ],
text: 'an already used role may be used again',
quantity: 1
},
taxes: {
expansion: true,
phase: :event,
keywords: [ /tax(es|ing)/ ],
text: 'each other player must discard 1 card from his hand',
quantity: 1
},
debt_relief: {
expansion: true,
phase: :event,
keywords: [ /debt/, /relief/ ],
text: 'each player draws 3 cards from the supply',
quantity: 1
},
earthquake: {
expansion: true,
phase: :event,
keywords: [ /earth/, /quake/ ],
text: 'each player must destroy any 1 of his buildings',
quantity: 1
},
general_amnesty: {
expansion: true,
phase: :event,
keywords: [ /general/, /amnest/ ],
text: 'each player may exchange any number of ' +
'cards from his hand with the supply',
quantity: 1
}
}
Colors = {
silver_smelter: Irc.color(:black, :lightgray),
indigo_plant: Irc.color(:white, :blue),
sugar_mill: Irc.color(:black, :white),
tobacco_storage: Irc.color(:black, :olive),
coffee_roaster: Irc.color(:white, :black),
violet: Irc.color(:purple, :black),
cost: Irc.color(:red)
}
Roles = [
:indigo_plant, :sugar_mill, :coffee_roaster,
:tobacco_storage, :silver_smelter
]
Title = 'San Juan'
class Building
attr_accessor :card, :goods, :stash
def initialize(card)
@card = card
@goods = nil # a card from stock will go here to represent produce
@stash = [] # cards stashed under bank/cathedral/harbor
end
def cost
card.cost
end
def id
card.id
end
def phase
card.phase
end
def production?
card.production?
end
def violet?
card.violet?
end
def vps
vps = card.vps
vps += stash.size
end
def to_s
color = Colors[id] || Colors[:violet]
g = goods ? '(*)' : ''
i = id.to_s.gsub('_',' ').capitalize
v = vps < 1 ? ' ?' : ' ' + vps.to_s
B + color + g + i + v + NormalText
end
def to_ss
color = Colors[id] || Colors[:violet]
g = goods ? '(*)' : ''
i = id.to_s.gsub('_',' ').capitalize
v = card.vps < 1 ? ' ?' : ' ' + card.vps.to_s
B + color + g + i + v + NormalText
end
end
class Card
attr_reader :id, :cost, :phase, :vps
def initialize(id)
@id = id
if Cards[id].nil?
raise "Invalid card name '#{id}'."
return
end
@cost = Cards[id][:cost] || 0
@phase = Cards[id][:phase]
@vps = Cards[id][:vps] || 0
end
def production?
return true if phase == :production
return false
end
def violet?
return true unless phase == :production
return false
end
def to_s
color = Colors[id] || Colors[phase] || Colors[:violet]
i = id.to_s.gsub('_',' ').capitalize
c = if cost.zero? then ''
else ' ' + Colors[:cost] + cost.to_s
end
v = if vps.zero? then ''
elsif c == '' then ' ' + vps.to_s
else '/' + vps.to_s
end
B + color + i + c + color + v + NormalText
end
end
class Player
attr_accessor :user, :banked, :buildings, :built, :cards, :discard,
:max_cards, :moved, :role, :time, :tmp_cards
def initialize(user)
@user = user
@banked = false # true once player has used bank
@buildings = [] # array of Buildings
@cards = [] # hand cards
@discard = 0 # number of cards to discard
@built = false # building id when built
@max_cards = 7 # dynamic hand card size limit
@moved = true # false until played or passed
@role = nil # resets during governor phase
@time = nil # time player joined game
@tmp_cards = [] # used for councillor, goldmine, etc.
end
def delete_cards(request)
request = [request] unless request.class == Array
request.each do |r|
# Grab an updated copy of the cards
# array before starting each iteration.
c = cards.dup
n = 0
n += 1 until c[n].id == r.id
@cards.delete_at(n)
end
end
def goods
# Returns array of occupied productions in
# order from least to greatest value goods.
g_array, n = [], 0
buildings.each { |b| g_array << n if b.goods; n += 0 }
return g_array
end
def has?(id=nil)
return false unless id
buildings.each { |b| return true if b.id == id }
return false
end
def open_productions
buildings.count { |b| b.production? and not b.goods }
end
def sort_cards
# .to_s => sorts by color then name
@cards = cards.sort {|x,y| x.to_s <=> y.to_s }
end
def to_s
B + @user.to_s + B
end
end
attr_reader :cathedral, :channel, :deck, :governor, :join_timer, :manager,
:market, :players, :phase, :roles, :started, :string
def initialize(plugin, channel, user)
@bot = plugin.bot
@channel = channel
@plugin = plugin
@registry = plugin.registry
@cathedral = @bot.config['sanjuan.expansion']
@deck = [] # card stock
@discard = [] # used cards
@join_timer = nil # timer for countdown
@manager = nil # player that started the game
@market = [] # market prices
@players = [] # players currently in game
@phase = nil # the current role being played out
@roles = [] # roles to choose from
@started = nil # time the game started
@string = nil # last message to channel
create_deck
add_player(user)
end
def add_player(user)
return if started
if player = get_player(user)
say "You're already in the game, #{player}."
return
end
player = Player.new(user)
@players << player
if manager.nil?
@manager = player
say "#{player} starts a game of #{Title}. Type 'j' to join."
else
say "#{player} joins #{Title}."
end
# Deal first building, then hand cards:
id = :indigo_plant
card, n = nil, 0
@deck.each do |c|
if c.id == id
card = c.dup
@deck.delete_at(n)
break
end
n += 1
end
card = Card.new(id) if card.nil?
player.buildings << Building.new(card)
#9.times { player.buildings << Building.new(@deck.pop) }
deal(player, Starting_Cards)
# Start game if there are enough players:
if @join_timer
@bot.timer.reschedule(@join_timer, 10)
elsif players.length > 1
countdown = @bot.config['sanjuan.countdown']
@join_timer = @bot.timer.add_once(countdown) { start_game }
say "Game will start in #{B}#{countdown}#{B} seconds."
end
end
def create_deck
# Extract information from card hashes.
Cards.each_pair do |key, value|
next if value[:phase] == :event and not @bot.config['sanjuan.events']
next if value[:expansion] and not @bot.config['sanjuan.expansion']
next if key == :cathedral
# Add an extra production card of each kind if using the expansion deck.
x = (@bot.config['sanjuan.expansion'] and value[:phase] == :production)
x = if x then 1 else 0 end
(value[:quantity] + x).times { @deck << Card.new(key) }
end
@deck.shuffle!
end
def deal(player, n=1)
return 0 if n < 1
cards = draw(n)
notify player, "You drew: #{cards.join(', ')}" if started
player.cards |= cards
player.sort_cards
show_cards(player)
return n
end
def deal_bank
@phase = :bank
p_string = 'Place cards under your bank or pass'
players.each do |p|
if p.has?(:bank) and p.cards.size > 0 and not p.banked
p_string << ", #{p}"
show_cards(p)
p.moved = false
end
end
if done?
do_turn
else
@string = p_string + '.'
show_string
end
end
def deal_chapel
@players << @players.shift
@roles = [ :builder, :councillor, :producer, :prospector, :trader ]
@phase = :chapel
players.each { |p| p.role = nil }
@governor = players.first
say "#{governor} is now governor."
p_string = 'Place a card under your chapel or pass'
players.each do |p|
if p.has?(:chapel) and p.cards.size > 0
p_string << ", #{p}"
show_cards(p)
p.moved = false
end
end
if done?
do_turn
else
@string = p_string + '.'
show_string
end
end
def deal_councillor(player)
n = if player.role == :councillor then 5 else 2 end
n += 3 if player.role == :councillor and player.has?(:library)
i = inventory(player)
cards = draw(n)
if i >= n
player.cards |= cards
say "#{player} keeps #{n} card#{s(n)}."
player.moved = true
else
if player.has?(:archive)
player.cards |= cards
player.discard = n - i
else
player.tmp_cards |= cards
end
show_councillor_cards(player)
@string << ", #{player}"
end
if player.has?(:customs_office)
n = 0
n += 1 until player.buildings[n].id == :customs_office
unless player.buildings[n].goods
player.buildings[n].goods = draw
say "#{player} puts a card on the customs office."
end
end
end
def deal_governor
@phase = :governor
p_string = 'The governor demands you discard down to a full hand'
players.each do |p|
if p.cards.length > p.max_cards or p.discard > 0
# p.discard if sanjuan.start_handicap is enabled
if p.cards.length - p.max_cards > 0
n = p.cards.length - p.max_cards
else
n = 0
end
n += p.discard
show_cards(p)
say "Please discard #{n} card#{s(n)}, #{p}."
p_string << ", #{p}"
p.moved = false
end
end
if done?
do_turn
else
@string = p_string + '.'
end
end
def deal_office
@phase = :office
p_string = 'Discard and draw 1 or 2 new cards ' +
'with the office building, or pass'
players.each do |p|
if p.has?(:office_building) and p.cards.size > 0
p_string << ", #{p}"
show_cards(p)
p.moved = false
end
end
if done?
do_turn
else
@string = p_string + '.'
show_string
end
end
def deal_producer(player)
n = inventory(player)
if n.zero?
say "#{player} can't produce anything."
player.moved = true
elsif n == player.open_productions
player.buildings.each do |b|
b.goods = draw if b.production? and not b.goods
end
say "#{player} produces #{n} good#{s(n)}."
if n > 1 and player.has?(:well)
deal(player)
say "#{player} draws a card using the well."
end
player.moved = true
else
notify player, "Pick #{n} good#{s(n)} to produce."
show_buildings(player)
@string << ", #{player}"
end
end
def deal_prospector(player)
if player.role == :prospector
n = inventory(player)
say "#{player} draws #{n} card#{s(n)}."
deal(player, n)
end
if player.has?(:goldsmith)
gold = draw
p_string = "#{player} draws a goldsmith card..."
p_array = []
players.each { |p| p_array << p if p.has?(gold.id) }
if p_array.empty?
say p_string + 'and keeps the card since no one has built it.'
player.cards << gold
show_cards(player)
else
p_string << 'no good! -- ' + gold.to_s
p_string << " has already been built by #{p_array.join(' and ')}."
say p_string
@discard << gold
end
end
if player.has?(:gold_mine)
player.tmp_cards = draw(4)
p_string = "#{player} draws 4 gold mine cards... "
values = []
player.tmp_cards.each { |e| values << e.cost }
cards = stringify(player.tmp_cards)
if values.length == values.uniq.length
p_string << 'and strikes gold!'
notify player, 'Pick a card to keep: ' + cards
@string << ", #{p}"
else
p_string << 'no good! -- ' + cards
@discard |= player.tmp_cards.pop(player.tmp_cards.length)
player.moved = true
end
say p_string
else
player.moved = true
end
end
def deal_trader(player)
if player.goods.empty?
player.moved = true
say "#{player} has nothing to trade."
else
show_buildings(player)
@string << ", #{player}"
end
end
def draw(n=:no_array)
# Don't return an array if no arguments
# were given; same way pop and shift work.
no_array = if n == :no_array then true else false end
n = 1 if n.class == Symbol
return [] if n < 1
if deck.length < n
n -= deck.length
cards = @deck.pop(deck.length)
@deck = @discard.dup
@discard = []
@bot.action channel, 'shuffles the stock.'
@deck.shuffle!
cards |= @deck.pop(n)
else
cards = @deck.pop(n)
end
cards = cards.first if no_array
return cards
end
def do_bank(player, a)
if a.first == 'pass'
say "#{player} passes."
else
cards = []
a.each do |e|
if player.cards[e].nil?
notify player, 'Specify cards from your hand.'
return false
end
cards << player.cards[e]
end
n = 0
player.buildings.each do |b|
break if b.id == :bank
n += 1
end
player.buildings[n].stash |= cards
player.delete_cards(cards)
say "#{player} puts #{cards.size} card#{s(cards.size)} under the bank."
player.banked = true
end
p_string = 'Place cards under your bank or pass'
players.each do |p|
next if p == player
p_string << ", #{p}" unless p.moved
@string = p_string + '.'
end
return true
end
def do_builder(player, a)
if a.first == 'pass'
player.built = false
say "#{player} passes."
else
cost = inventory(player)
crane = nil
if a.first =~ /^b/
if player.has?(:crane)
crane = a.first[1..-1].to_i - 1
if player.buildings[crane].nil? or crane < 0
notify player, 'You can only use the crane to ' +
'build over other buildings.'
return false
elsif player.buildings[crane].id == :crane
notify player, 'You can\'t build over the crane with itself.'
return false
end
cost -= player.buildings[crane].cost
cost -= 3 if player.buildings[crane].id == :park
end
a.delete_at(0)
end
cards = []
if a.first == 'cathedral'
if cathedral
cards << Card.new(:cathedral)
else
notify player, 'The Cathedral is not available to be built.'
return false
end
a.delete_at(0)
end
a.each do |e|
if e < 0 or player.cards[e].nil?
notify player, 'Specify cards from your hand.'
return false
end
cards << player.cards[e].dup
end
if player.has?(cards.first.id) and cards.first.violet?
notify player, 'You may only have one of each type of violet building.'
return false
end
cost += cards.first.cost
cost -= 1 if player.has?(:smithy) and player.cards[a.first].production?
cost -= 1 if player.has?(:quarry) and player.cards[a.first].violet?
cost = 0 if cost < 0
deficit = cost - (cards.size - 1)
open_market = deficit <= player.goods.size
if player.has?(:black_market) and open_market and deficit.between?(1,2)
player.goods[0..deficit-1].each do |e|
@discard << player.buildings[e].goods
player.buildings[e].goods = nil
cost -= 1
end
say "#{player} uses the black market to " +
"trade #{deficit} good#{s(deficit)}."
elsif deficit > 0
notify player, "Pick #{cost} card#{s(cost)} to discard to build that."
return false
end
if crane
say "#{player} builds over #{player.buildings[crane].card} " +
"using the crane."
# Cathedral never goes in the deck.
if player.buildings[crane].card.id == :cathedral
@cathedral = true
else
@discard << player.buildings[crane].card
end
player.buildings[crane].card = cards.first
# Move any goods to discard, but not stashes.
if player.buildings[crane].goods
@discard << player.buildings[crane].goods
player.buildings[crane].goods = nil
end
else
player.buildings << Building.new(cards.first)
end
player.built = cards.first.id
say "#{player} builds #{cards.first}."
player.delete_cards(cards[0..cost])
@discard |= cards[1..cost]
@cathedral = false if cards.first.id == :cathedral
bonus_string = ''
if player.has?(:carpenter) and cards.first.violet?
unless player.built == :carpenter
deal(player)
bonus_string << "#{player} draws a card using the carpenter. "
end
end
# Poor house conditions are checked after
# performing effects from other buildings.
if player.cards.length < 2 and player.has?(:poor_house)
unless player.built == :poor_house
deal(player)
bonus_string << "#{player} draws a card using the poor house. "
end
end
say bonus_string