-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayer.adept
237 lines (189 loc) · 9.07 KB
/
Player.adept
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
import 'main.adept'
alias PlayerID = usize
struct Player (
player_id PlayerID,
name String,
starting_hearts, hearts, mana, supply, draw_cost int,
hand <CardInstance> List,
board <CardInstance> List,
stat_card <CardInstance> Optional,
done, sent_done bool,
super, thrift int,
future_extra_mana int
) {
func drawCardFromDeck(blueprint_name String) {
// Assumes that this player is user's player
blueprint *CardBlueprint = gamedata.deck.getCardBlueprint(blueprint_name)
unless blueprint, print("WARNING: Player.drawCard() couldn't find blueprint '%'" % blueprint_name); return
this.hand.add(cardInstance(blueprint))
}
func drawCardsFromDeck(amount usize, is_me bool, global_mana int) {
// Bonus card draws for cheater AI
bonus usize = !is_me && gamedata.gamekind == GameKind::VERSUS_AI && meets(gamedata.ai_difficulty, AIDifficulty::CHEATER) ? random(2) as int : 0
repeat static amount + bonus {
unless gamedata.gamekind == GameKind::VERSUS_AI && !is_me {
// Hand limit doesn't apply to AI
// Maximum hand limit of 10 cards for now
if this.hand.length >= 10, return
}
card CardInstance = gamedata.deck.randomCard()
#if enable_debugging_hotkeys
if glfwGetKey(_captain_window, GLFW_KEY_RIGHT_SHIFT) == GLFW_PRESS {
card = gamedata.deck.getCardByName(glfwGetKey(_captain_window, GLFW_KEY_RIGHT_CONTROL) == GLFW_PRESS ? "king_slime" : "pickle_guy")
}
#end
faux_cards bool = !is_me && gamedata.gamekind != GameKind::VERSUS_AI
// Draw viable creature card if no friendly cards on board and able
if !faux_cards && this.board.length == 0 && !this.hasPlayableCreature(global_mana) && this.drawPlayableCreature(global_mana), continue
// Try to avoid redrawing cards
unless faux_cards, repeat redrawing : 10 {
each CardInstance in this.hand {
if it.name == card.name {
card = gamedata.deck.randomCard()
continue redrawing
}
}
break
}
this.hand.add(card)
}
}
func hasPlayableCreature(global_mana int) bool {
each CardInstance in static this.hand, if it.kind == CardKind::CREATURE && this.getDiscountedCardCost(it.cost) <= this.getManaAllowance(global_mana), return true
return false
}
func drawPlayableCreature(global_mana int) successful {
repeat 100 {
blueprint *CardBlueprint = gamedata.deck.blueprints.getRandomPointer()
if blueprint.kind == CardKind::CREATURE && this.getDiscountedCardCost(blueprint.cost) <= this.getManaAllowance(global_mana),
this.drawCardFromDeck(blueprint.name); return true
}
return false
}
func getManaAllowance(global_mana int) int {
return global_mana + (gamedata.gamemode.exclusive_heart_mana_bonus && this.hearts <= this.starting_hearts ? this.starting_hearts - this.hearts : 0)
}
func spawnCard(blueprint_name String, unique_network_id CardNetworkID, relation String, related_unique_network_id CardNetworkID,
out particles *<*CardParticle> List, is_me bool, global_dancing int) {
destination usize = 0
blueprint *CardBlueprint = gamedata.deck.getCardBlueprint(blueprint_name)
unless blueprint {
print("ERROR: GameState.spawnCard() failed to find card blueprint for '%'" % blueprint_name)
return
}
// Handle if the card is a stat card
if blueprint.kind == CardKind::STAT {
// Bypass normal spawning process if it's a stat card
this.stat_card.rid()
// Manually set stat card
if this.stat_card.has, this.stat_card.value.?__defer__()
this.stat_card.value = cardInstance(blueprint)
this.stat_card.has = true
return
}
// Find where to put the creature card
if related_unique_network_id != 0, each CardInstance in static this.board {
if it.network_id == related_unique_network_id {
destination = relation == "leftof" ? idx : idx + 1
break
}
}
this.board.insert(destination, cardInstance(blueprint))
card *CardInstance = this.board.getPointer(destination)
card.assignNetworkID(unique_network_id)
// Apply battlecry-adjacent
if card.traits.battlecry_adjacent != 0 {
left *CardInstance = destination == 0 ? null as *CardInstance : this.board.getPointer(destination - 1)
right *CardInstance = destination + 1 == this.board.length ? null as *CardInstance : this.board.getPointer(destination + 1)
if left {
left.attack += card.traits.battlecry_adjacent
if particles, particles.addAttackBonus(left.network_id)
}
if right {
right.attack += card.traits.battlecry_adjacent
if particles, particles.addAttackBonus(right.network_id)
}
}
// Apply global_dancing
if global_dancing > 0 && global_dancing > card.traits.dancing {
card.traits.dancing = global_dancing
}
// reinforced-shields (via stat card)
if card.traits.shield == 1 && this.stat_card.has && this.stat_card.getPointer().traits.reinforced_shields {
card.traits.shield *= 2
}
// Don't keep track of supply for ourselves here, because it depends on the network
unless is_me || blueprint.traits.separation {
this.supply++
}
// Don't keep track of mana for ourselves here, because it depends on the network
unless is_me {
this.mana -= this.getDiscountedCardCost(blueprint.cost)
}
}
func getCardOnBoardByNetworkId(network_id CardNetworkID) *CardInstance {
each CardInstance in this.board, if it.network_id == network_id, return &it
return null
}
func addCardStatusesToList(out list_to_add_to *<CardStatus> List) {
each CardInstance in this.board, list_to_add_to.add(cardStatus(&it))
}
func removeDeadCards(is_me bool, global_mana int, out removed_network_ids *<CardNetworkID> List) {
// NOTE: 'is_me' is whether this player is the "actual" player
each CardInstance in this.board, if it.isDead() {
// revive <amount> (for creatures)
if it.traits.revive {
it.traits.revive--
it.hp = it.max_hp
it.traits.unhealable = false
continue
}
unless it.traits.separation, this.supply--
if it.traits.recycle, this.drawCardsFromDeck(it.traits.recycle, is_me, global_mana)
if it.traits.refund > 0, this.future_extra_mana += it.cost
// deathcry-adjacent (non-immediate version)
if it.traits.deathcry_adjacent {
left *CardInstance = null
right *CardInstance = null
if idx != 0, left = this.board.getPointer(idx - 1)
if idx + 1 < this.board.length, right = this.board.getPointer(idx + 1)
if left, left.attack += it.traits.deathcry_adjacent
if right, right.attack += it.traits.deathcry_adjacent
// Use up deathcry adjacent
it.traits.deathcry_adjacent = 0
}
removed_network_ids.add(it.network_id)
this.board.remove(idx--)
}
}
func getDrawCost int {
unless this.stat_card.has, return this.draw_cost
discount int = this.stat_card.getPointer().traits.draw_cost_reduction != 0
if discount != 0 {
return discount >= this.draw_cost ? 1 : this.draw_cost - discount
}
return this.draw_cost
}
func getDiscountedCardCost(initial_cost int) int {
return max(initial_cost - this.thrift, 0)
}
}
func addPlayer(this *<Player> List, player_id PlayerID, name String) *Player {
unless this.add(), return null
new_player *Player = this.items at (this.length - 1)
new_player.player_id = player_id
new_player.name = name.clone()
new_player.starting_hearts = 3
new_player.hearts = 3
new_player.mana = 0
new_player.supply = 0
new_player.draw_cost = 2
// new_player.hand is left empty
// new_player.board is left empty
// new_player.stat_card is left with nothing
new_player.done = false
new_player.super = 0
new_player.thrift = 0
new_player.future_extra_mana = 0
return new_player
}