-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheffect.go
252 lines (200 loc) · 6.26 KB
/
effect.go
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
package main
import (
"fmt"
)
type effect struct {
Priority int
Description func() string
Call func(card supplyCard, rlr *player, p *player, c int, pc *playerCard, specialRoll int)
}
type prereq struct {
Desc string
Call func(card supplyCard, rlr *player, p *player, c int, pc *playerCard, specialRoll int) bool
}
var nullPrereq = prereq{
Desc: "",
Call: func(card supplyCard, rlr *player, p *player, c int, pc *playerCard, specialRoll int) bool {
return true
},
}
func landmarkCardAgumentedPayout(payout int, card supplyCard, p *player) int {
if p.LandmarkCards["Shopping Mall"] && (card.Icon == "Cup" || card.Icon == "Bread") {
return payout + 1
}
return payout
}
func newBankPayoutWithPrereq(payout int, onlyCurrent bool, fromBank bool, pr prereq) effect {
var coins string
var receiverName string
if payout == 1 {
coins = "1 coin"
} else {
coins = fmt.Sprintf("%d coins", payout)
}
if onlyCurrent {
receiverName = "your turn only"
} else {
receiverName = "anyone's turn"
}
return effect{
Priority: 1,
Description: func() string {
if fromBank {
return pr.Desc + fmt.Sprintf("Get %s from the bank on %s", coins, receiverName)
}
return pr.Desc + fmt.Sprintf("Pay %s to the bank on %s", coins, receiverName)
},
Call: func(card supplyCard, rlr *player, p *player, c int, pc *playerCard, specialRoll int) {
if onlyCurrent && p != rlr {
return
}
if !pr.Call(card, rlr, p, c, pc, specialRoll) {
return
}
totalPayout := landmarkCardAgumentedPayout(payout, card, p) * c
fmt.Printf("Player %d gets %d coins from the bank [%s].\n", p.ID, totalPayout, card.Name)
remainder := bank.TransferTo(totalPayout, &p.Coins)
if remainder > 0 {
fmt.Printf("Bank did not have enough money. Missing: %d\n", remainder)
}
},
}
}
func newAllBankPayout(r int) effect {
return newBankPayoutWithPrereq(r, false, true, nullPrereq)
}
func newAllBankPayoutWithPrereq(r int, pr prereq) effect {
return newBankPayoutWithPrereq(r, false, true, pr)
}
func newRollerBankPayout(r int) effect {
return newBankPayoutWithPrereq(r, true, true, nullPrereq)
}
func newBankRollerPayout(r int) effect {
return newBankPayoutWithPrereq(r, true, false, nullPrereq)
}
func newRollerBankPayoutWithPrereq(r int, pr prereq) effect {
return newBankPayoutWithPrereq(r, true, true, pr)
}
func newRollerPayoutWithPrereq(payout int, pr prereq) effect {
var coins string
if payout == 1 {
coins = "1 coin"
} else {
coins = fmt.Sprintf("%d coins", payout)
}
return effect{
Priority: 0,
Description: func() string {
desc := pr.Desc + fmt.Sprintf("Get %s from the player who rolled the dice", coins)
return desc
},
Call: func(card supplyCard, rlr *player, p *player, c int, pc *playerCard, specialRoll int) {
if p == rlr {
return
}
if !pr.Call(card, rlr, p, c, pc, specialRoll) {
return
}
totalPayout := landmarkCardAgumentedPayout(payout, card, p) * c
fmt.Printf("Player %d gets %d coins from the player %d [%s].\n", p.ID, totalPayout, rlr.ID, card.Name)
remainder := rlr.Coins.TransferTo(totalPayout, &p.Coins)
if remainder > 0 {
fmt.Printf("Roller did not have enough money. Missing: %d\n", remainder)
}
},
}
}
func newLandmarkPrereq(name string, forRoller bool) prereq {
return prereq{
Desc: fmt.Sprintf("If you have the [%s] landmark. ", name),
Call: func(card supplyCard, rlr *player, p *player, c int, pc *playerCard, specialRoll int) bool {
if forRoller {
return rlr.LandmarkCards[name]
}
return p.LandmarkCards[name]
},
}
}
func newLandmarkMaxPrereq(max int) prereq {
return prereq{
Desc: fmt.Sprintf("If player has the less than %d constructed landmarks (excluding City Hall). ", max+1),
Call: func(card supplyCard, rlr *player, p *player, c int, pc *playerCard, specialRoll int) bool {
return landmarkCount(rlr) < max
},
}
}
func landmarkCount(p *player) int {
var count int
for name, active := range p.LandmarkCards {
if name == "City Hall" {
continue
}
if active {
count++
}
}
return count
}
func newLandmarkMinPrereq(min int) prereq {
return prereq{
Desc: fmt.Sprintf("If player has the more than %d constructed landmarks (excluding City Hall). ", min+1),
Call: func(card supplyCard, rlr *player, p *player, c int, pc *playerCard, specialRoll int) bool {
return landmarkCount(rlr) > min
},
}
}
func newRollerPayout(payout int) effect {
return newRollerPayoutWithPrereq(payout, nullPrereq)
}
func newIconCardPayout(payout int, icon string) effect {
return effect{
Priority: 1,
Description: func() string {
return fmt.Sprintf("Get %d coins from the bank for each [%s] establishment that you own on your turn only", payout, icon)
},
Call: func(card supplyCard, rlr *player, p *player, c int, pc *playerCard, specialRoll int) {
if p != rlr {
return
}
iconCards := market.FindByIcon(icon)
iconCardCount := 0
for _, iconCard := range iconCards {
iconCardCount += p.SupplyCards[iconCard.Name].Total
}
totalPayout := landmarkCardAgumentedPayout(payout, card, p) * iconCardCount * c
fmt.Printf("Player %d gets %d coins from the bank [%s].\n", p.ID, totalPayout, card.Name)
remainder := bank.TransferTo(totalPayout, &rlr.Coins)
if remainder > 0 {
fmt.Printf("Bank did not have enough money. Missing: %d\n", remainder)
}
},
}
}
func newCardPayout(payout int, cardName string) effect {
return effect{
Priority: 1,
Description: func() string {
return fmt.Sprintf("Get %d coins from the bank for each [%s] establishment that you own on your turn only", payout, cardName)
},
Call: func(card supplyCard, rlr *player, p *player, c int, pc *playerCard, specialRoll int) {
if p != rlr {
return
}
cardCount := p.SupplyCards[cardName].Total
totalPayout := landmarkCardAgumentedPayout(payout, card, p) * cardCount * c
fmt.Printf("Player %d gets %d coins from the bank [%s].\n", p.ID, totalPayout, card.Name)
remainder := bank.TransferTo(totalPayout, &rlr.Coins)
if remainder > 0 {
fmt.Printf("Bank did not have enough money. Missing: %d\n", remainder)
}
},
}
}
func counterClockwise(all []*player, rlr *player) []*player {
var reversed []*player
index := rlr.ID
for i := 0; i < len(all); i++ {
reversed = append(reversed, all[(len(all)+index-i)%len(all)])
}
return reversed
}