Repository navigation
Expand file tree
/
Copy pathchecks.js
More file actions
561 lines (523 loc) · 16.2 KB
/
Copy pathchecks.js
File metadata and controls
561 lines (523 loc) · 16.2 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
//CHECKS
//These are GAME MECHANIC checks (not internal execution checks) and take inputs that make sense in terms of the game e.g. card object, server object, integer value
/**
* Check whether an installed card can be advanced.
*
* @method CheckAdvance
* @param {Card} card the card to check
* @returns {Boolean} true if card can be advanced, false if not
*/
function CheckAdvance(card) {
if (card != null) {
if (card.canBeAdvanced) {
return true;
}
return false;
}
return false;
}
/**
* Check whether an installed card can be rezzed.
*
* @method CheckRez
* @param {Card} card the card to check for rez (permission check only, not cost check)
* @param {String[]} validCardTypes array of card type strings that can be rezzed
* @returns {Boolean} true if card can be rezzed, false if not
*/
function CheckRez(card, validCardTypes) {
if (card != null) {
if (CheckCardType(card, validCardTypes)) {
if (typeof card.rezzed !== "undefined") {
if (card.rezzed) {
return false;
}
}
if (typeof card.rezCost !== "undefined") {
//only check if it has a rez cost, doesn't check whether we have the credits for it
return true;
}
}
}
return false;
}
/**
* Checks whether the player is in action phase and has at least the required clicks remaining.
*
* @method CheckActionClicks
* @param {Player} player whose action phase is required
* @param {int} num number of clicks required
* @returns {Boolean} true if check passes, false if not
*/
function CheckActionClicks(player, num) {
checkedClick = true;
//clicks can only be spent during action phase (and they all have to be spent so maybe this check should not be required)
var actionPhase = false;
if (player == corp && currentPhase.identifier == "Corp 2.2")
actionPhase = true;
else if (player == runner && currentPhase.identifier == "Runner 1.3")
actionPhase = true;
if (!actionPhase) {
return false;
}
//check quantity remaining
if (player.clickTracker < num) {
return false;
}
return true;
}
/**
* Checks whether the runner is accessing a card.
*
* @method CheckAccessing
* @returns {Boolean} true if check passes, false if not
*/
function CheckAccessing() {
if (typeof player === "undefined") player = activePlayer;
checkedAccess = true;
if (accessingCard == null) return false;
return true;
}
/**
* Checks whether the player has at least the required clicks remaining (does not require action phase or set checkedClick).
*
* @method CheckClicks
* @param {Player} player to check clicks for
* @param {int} num number of clicks required
* @returns {Boolean} true if check passes, false if not
*/
function CheckClicks(player, num) {
if (player.clickTracker < num) {
return false;
}
return true;
}
/**
* Checks whether a card has at least the required counters.
*
* @method CheckCounters
* @param {Card} card card to check
* @param {String} counter type of counter
* @param {int} [num] number of counters required (1 if omitted)
* @returns {Boolean} true if check passes, false if not
*/
function CheckCounters(card, counter, num = 1) {
var numCounters = Counters(card, counter);
if (numCounters < num) {
return false;
}
return true;
}
/**
* Checks whether the player has at least the required credits in their pool.
*
* @method CheckCredits
* @param {Player} player to check clicks for
* @param {int} num number of credits required
* @param {String} [doing] for 'recurring credit' checks
* @param {Card} [card] for 'recurring credit' checks
* @returns {Boolean} true if check passes, false if not
*/
function CheckCredits(player, num, doing = "", card = null) {
var availableCred = AvailableCredits(player, doing, card); //unlike Credits(player) this includes recurring credit possibilities
if (availableCred < num) {
return false;
}
return true;
}
/**
* Checks whether the runner has at least the required number of tags.
*
* @method CheckTags
* @param {int} num number of tags required
* @returns {Boolean} true if check passes, false if not
*/
function CheckTags(num) {
if (runner.tags >= num) {
return true;
}
return false;
}
/**
* Checks whether a card has any of a list of card types.
*
* @method CheckCardType
* @param {Card} card to check type for
* @param {String[]} valid array of card type strings to check against
* @returns {Boolean} true if card contains one of the types in valid, false if not
*/
function CheckCardType(card, valid) {
for (var i = 0; i < valid.length; i++) {
if (card.cardType == valid[i]) {
return true;
}
}
var outstr = "Card type must be ";
for (var i = 0; i < valid.length; i++) {
outstr += valid[i];
if (i < valid.length - 2) outstr += ", ";
else if (i < valid.length - 1) outstr += " or ";
}
outstr += " (" + card.title + " is " + card.cardType + ")";
return false;
}
/**
* Check if a card has a certain subtype.<br/>Nothing is logged.
*
* @method CheckSubType
* @param {Card} card card object to check
* @param {String} subtype subtype to check for
* @returns {Boolean} true if card object contains the subtype, otherwise false
*/
function CheckSubType(card, subtype) {
if (card) {
//from effects (assumes automatic)
var callbackName = "modifySubTypes";
var triggerList = ChoicesActiveTriggers(callbackName);
for (var i = 0; i < triggerList.length; i++) {
var mod = triggerList[i].card[callbackName].Resolve.call(
triggerList[i].card,
card
);
if (typeof mod.add != 'undefined') {
if (mod.add.includes(subtype)) return true;
}
if (typeof mod.remove != 'undefined') {
if (mod.remove.includes(subtype)) return false;
}
}
//from card definition
if (typeof card.subTypes != "undefined") {
if (card.subTypes.includes(subtype)) return true;
}
}
return false;
}
/**
* Check if strength of a card is sufficient to interact with the currently encountered ice.
*
* @method CheckStrength
* @param {Card} card card object to check
* @returns {Boolean} true if card's strength is >= encountered ice, otherwise false
*/
function CheckStrength(card) {
if (attackedServer == null || approachIce < 0 || !encountering) {
return false;
}
var cardStrength = Strength(card);
var iceStrength = Strength(attackedServer.ice[approachIce]);
if (card.onlyInterfaceEqualStrength) {
if (cardStrength > iceStrength) {
return false;
}
}
if (cardStrength >= iceStrength) {
return true;
}
return false;
}
/**
* Checks if a run is in progress.
*
* @method CheckRunning
* @returns {Boolean} true if a run is in progress, false otherwise
*/
function CheckRunning() {
if (attackedServer != null) {
return true;
}
return false;
}
/**
* Checks if ice is being approached but not encountered.
*
* @method CheckApproach
* @returns {Boolean} true if ice is being approached, false otherwise
*/
function CheckApproach() {
if (
attackedServer != null &&
approachIce > -1 &&
!encountering &&
!movement
) {
return true;
}
return false;
}
/**
* Checks if ice is being encountered.
*
* @method CheckEncounter
* @returns {Boolean} true if ice is being encountered, false otherwise
*/
function CheckEncounter() {
//you might be tempted to check things to do with runs and approaches but don't! Encounters can be triggered outside such structures.
if (encountering) {
return true;
}
return false;
}
/**
* Check whether a card can be trashed (ignoring costs).
*
* @method CheckTrash
* @param {Card} card card object to check
* @returns {Boolean} true if card can be trashed, false otherwise
*/
function CheckTrash(card) {
if (card == null) {
return false;
}
if (card.cardLocation == corp.archives.cards) {
return false;
}
if (card.cardLocation == runner.heap) {
return false;
}
if (CardEffectsForbid("trash", card)) return false; //forbidden by card effects
return true;
}
/**
* Checks whether a card can be installed (ignoring costs).<br/>Does not check where card is.
*
* @method CheckInstall
* @param {Card} card card object to check
* @returns {Boolean} true if card can be installed, false otherwise
*/
function CheckInstall(card) {
//check card exists
if (card == null) {
return false;
}
//make sure card is correct type
if (card.cardType == "operation" || card.cardType == "event") {
return false;
}
return true;
}
/**
* Checks whether a card can be played (ignoring costs).<br/>Does not check where card is.
*
* @method CheckPlay
* @param {Card} card card object to check
* @returns {Boolean} true if card can be played, false otherwise
*/
function CheckPlay(card) {
//check card exists
if (card == null) {
return false;
}
//make sure card is correct type
if (card.cardType != "operation" && card.cardType != "event") {
return false;
}
return true;
}
/**
* Checks whether currently encountered ice has any unbroken subroutines.
*
* @method CheckUnbrokenSubroutines
* @returns {Boolean} true if there are unbroken subroutines, false otherwise
*/
function CheckUnbrokenSubroutines() {
if (!CheckRunning()) return false;
for (var i = 0; i < attackedServer.ice[approachIce].subroutines.length; i++) {
if (!attackedServer.ice[approachIce].subroutines[i].broken) {
return true;
}
}
return false;
}
/**
* Checks whether a subroutine can be broken (ignoring costs).
*
* @method CheckBreak
* @param {Subroutine} subroutine the subroutine to check
* @returns {Boolean} true if subroutine can be broken, false otherwise
*/
function CheckBreak(subroutine) {
if (!CheckRunning()) return false;
//check subroutine exists
if (subroutine == null) {
return false;
}
//make sure it's on the currently encountered ice
var srExist = false;
for (var i = 0; i < attackedServer.ice[approachIce].subroutines.length; i++) {
if (attackedServer.ice[approachIce].subroutines[i] == subroutine) {
srExist = true;
break;
}
}
if (!srExist) {
return false;
}
//and not already broken
if (subroutine.broken) {
return false;
}
return true;
}
/**
* Checks whether currently accessed card can be stolen.<br/>Logdebugs the result.
*
* @method CheckSteal
* @returns {Boolean} true if can be stolen, false otherwise (e.g. not an agenda)
*/
function CheckSteal() {
if (typeof accessingCard === "undefined") return false;
if (accessingCard == null) return false;
if (accessingCard.cardType != "agenda") return false;
if (CardEffectsForbid("steal", accessingCard)) return false; //forbidden by card effects
return true;
}
/**
* Checks whether a card can be scored.<br/>Logdebugs the result.
*
* @method CheckScore
* @param [Boolean] ignoreRequirement set true to ignore advancement requirement
* @returns {Boolean} true if can be scored, false otherwise (e.g. not an agenda)
*/
function CheckScore(card,ignoreRequirement=false) {
if (card.cardType !== "agenda") return false;
if (!ignoreRequirement) {
if (typeof card.advancement == "undefined") return false;
if (card.advancement < AdvancementRequirement(card)) return false;
}
if (CardEffectsForbid("score", card)) return false; //forbidden by card effects
return true;
}
/**
* Checks whether a card is installed.
*
* @method CheckInstalled
* @param {Card} card card object to check
* @returns {Boolean} true if card is installed, false otherwise
*/
function CheckInstalled(card) {
var ret = false;
if (typeof card.host !== "undefined") {
//hosted cards are assumed to be installed by default
if (card.host != null) ret = true;
}
if (card.player == corp) {
if (card.cardLocation == corp.RnD.root) ret = true;
else if (card.cardLocation == corp.RnD.ice) ret = true;
else if (card.cardLocation == corp.HQ.root) ret = true;
else if (card.cardLocation == corp.HQ.ice) ret = true;
else if (card.cardLocation == corp.archives.root) ret = true;
else if (card.cardLocation == corp.archives.ice) ret = true;
else {
for (var i = 0; i < corp.remoteServers.length; i++) {
if (card.cardLocation == corp.remoteServers[i].root) ret = true;
else if (card.cardLocation == corp.remoteServers[i].ice) ret = true;
}
}
} else if (card.player == runner) {
if (card.cardLocation == runner.rig.programs) ret = true;
else if (card.cardLocation == runner.rig.hardware) ret = true;
else if (card.cardLocation == runner.rig.resources) ret = true;
}
return ret;
}
/**
* Checks whether a card is active.
*
* @method CheckActive
* @param {Card} card card object to check
* @returns {Boolean} true if card is active, false otherwise
*/
function CheckActive(card) {
//check card exists
if (card == null) {
return false;
}
var ret = false;
if (card.player == corp) {
if (CheckInstalled(card)) ret = card.rezzed;
else if (card.cardLocation == corp.scoreArea) ret = true;
else if (card == corp.identityCard) ret = true;
else if (card.cardLocation == corp.resolvingCards) ret = true;
} else if (card.player == runner) {
if (CheckInstalled(card)) ret = true;
else if (card == runner.identityCard) ret = true;
else if (card.cardLocation == runner.resolvingCards) ret = true;
} else {
LogError(GetTitle(card) + " does not have .player set");
return false;
}
return ret;
}
/**
* Checks whether a card is permitted to have abilities (returns false if a 'loses all abilities' applies).
*
* @method CheckHasAbilities
* @param {Card} card card object to check
* @returns {Boolean} true if card can have abilities, false otherwise
*/
function CheckHasAbilities(card) {
//from effects (assumes automatic)
var callbackName = "modifyHasAbilities";
var triggerList = ChoicesActiveTriggers(callbackName);
for (var i = 0; i < triggerList.length; i++) {
if (!triggerList[i].card[callbackName].Resolve.call(
triggerList[i].card,
card
)) return false;
}
return true;
}
/**
* Checks whether a card callback should be called (has callback and is either active or has callbackName.availableWhenInactive).
*
* @method CheckCallback
* @param {Card} card card object to check
* @param {String} callbackName callback name to check
* @returns {Boolean} true if card is should be called, false otherwise
*/
function CheckCallback(card, callbackName) {
var ret = false;
if (typeof card[callbackName] !== "undefined") {
if (
CheckActive(card) || card[callbackName].availableWhenInactive ||
(callbackName == "automaticOnAccess" && card == accessingCard) ||
(callbackName == "responseOnAccess" && card == accessingCard) ||
(callbackName == "responseOnStolen" && card == intended.steal)
) {
//to prevent infinite loop, canHaveAbilities is assumed true when checking modifyHasAbilities
var canHaveAbilities = true;
if (callbackName != "modifyHasAbilities") canHaveAbilities = CheckHasAbilities(card);
if ( canHaveAbilities || card[callbackName].availableWhenInactive ) ret = true;
}
}
return ret;
}
/**
* Checks whether purge is possible.
*
* @method CheckPurge
* @returns {Boolean} true if purge is possible, false otherwise
*/
function CheckPurge() {
//"The Corp can always use a purge effect, even if there are no virus counters currently hosted on any cards." - CR 10.1.2
/*
var installedRunnerCards = InstalledCards(runner);
for (var i = 0; i < installedRunnerCards.length; i++) {
if (typeof installedRunnerCards[i].virus !== "undefined") {
if (installedRunnerCards[i].virus > 0) {
return true;
}
}
}
var installedCorpCards = InstalledCards(corp);
for (var i = 0; i < installedCorpCards.length; i++) {
if (typeof installedCorpCards[i].virus !== "undefined") {
if (installedCorpCards[i].virus > 0) {
return true;
}
}
}
return false;
*/
return true;
}