-
Notifications
You must be signed in to change notification settings - Fork 194
/
Copy pathsanguosha.i
1293 lines (1066 loc) · 49.9 KB
/
sanguosha.i
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
%module sgs
%{
#include "structs.h"
#include "engine.h"
#include "client.h"
#include "wrapped-card.h"
#include "room.h"
#include "roomthread.h"
#include <QDir>
%}
%include "naturalvar.i"
%include "native.i"
%include "qvariant.i"
%include "list.i"
// ----------------------------------------
class QObject {
public:
QString objectName();
void setObjectName(const char *name);
bool inherits(const char *class_name);
bool setProperty(const char *name, const QVariant &value);
QVariant property(const char *name) const;
void setParent(QObject *parent);
void deleteLater();
};
class General: public QObject {
public:
explicit General(Package *package, const char *name, const char *kingdom, int max_hp = 4, bool male = true, bool hidden = false, bool never_shown = false);
// property getters/setters
int getMaxHp() const;
QString getKingdom() const;
bool isMale() const;
bool isFemale() const;
bool isNeuter() const;
bool isLord() const;
bool isHidden() const;
bool isTotallyHidden() const;
enum Gender { Sexless, Male, Female, Neuter };
Gender getGender() const;
void setGender(Gender gender);
void addSkill(Skill *skill);
void addSkill(const char *skill_name);
bool hasSkill(const char *skill_name) const;
QList<const Skill *> getSkillList() const;
QList<const Skill *> getVisibleSkillList() const;
QSet<const Skill *> getVisibleSkills() const;
QSet<const TriggerSkill *> getTriggerSkills() const;
void addRelateSkill(const char *skill_name);
QStringList getRelatedSkillNames() const;
QString getPackage() const;
QString getSkillDescription(bool include_name = false) const;
QString getBriefName() const;
void lastWord() const;
};
class Player: public QObject {
public:
enum Phase { RoundStart, Start, Judge, Draw, Play, Discard, Finish, NotActive, PhaseNone };
enum Place { PlaceHand, PlaceEquip, PlaceDelayedTrick, PlaceJudge, PlaceSpecial, DiscardPile, DrawPile, PlaceTable, PlaceUnknown };
enum Role { Lord, Loyalist, Rebel, Renegade };
explicit Player(QObject *parent);
void setScreenName(const char *screen_name);
QString screenName() const;
// property setters/getters
int getHp() const;
void setHp(int hp);
int getMaxHp() const;
void setMaxHp(int max_hp);
int getLostHp() const;
bool isWounded() const;
General::Gender getGender() const;
virtual void setGender(General::Gender gender);
bool isMale() const;
bool isFemale() const;
bool isNeuter() const;
bool hasShownRole() const;
void setShownRole(bool shown);
int getMaxCards() const;
QString getKingdom() const;
void setKingdom(const char *kingdom);
void setRole(const char *role);
QString getRole() const;
Role getRoleEnum() const;
void setGeneral(const General *general);
void setGeneralName(const char *general_name);
QString getGeneralName() const;
void setGeneral2Name(const char *general_name);
QString getGeneral2Name() const;
const General *getGeneral2() const;
void setState(const char *state);
QString getState() const;
int getSeat() const;
void setSeat(int seat);
bool isAdjacentTo(const Player *another) const;
QString getPhaseString() const;
void setPhaseString(const char *phase_str);
Phase getPhase() const;
void setPhase(Phase phase);
int getAttackRange(bool include_weapon = true) const;
bool inMyAttackRange(const Player *other, int distance_fix = 0) const;
bool isAlive() const;
bool isDead() const;
void setAlive(bool alive);
QString getFlags() const;
QStringList getFlagList() const;
void setFlags(const char *flag);
bool hasFlag(const char *flag) const;
void clearFlags();
bool faceUp() const;
void setFaceUp(bool face_up);
virtual int aliveCount() const = 0;
int distanceTo(const Player *other, int distance_fix = 0) const;
void setFixedDistance(const Player *player, int distance);
void removeFixedDistance(const Player *player, int distance);
void insertAttackRangePair(const Player *player);
void removeAttackRangePair(const Player *player);
const General *getAvatarGeneral() const;
const General *getGeneral() const;
bool isLord() const;
void acquireSkill(const char *skill_name);
void detachSkill(const char *skill_name);
void detachAllSkills();
virtual void addSkill(const char *skill_name);
virtual void loseSkill(const char *skill_name);
bool hasSkill(const char *skill_name, bool include_lose = false) const;
bool hasSkill(const Skill *skill, bool include_lose = false) const;
bool hasSkills(const char *skill_name, bool include_lose = false) const;
bool hasLordSkill(const char *skill_name, bool include_lose = false) const;
bool hasLordSkill(const Skill *skill, bool include_lose = false) const;
bool hasInnateSkill(const char *skill_name) const;
bool hasInnateSkill(const Skill *skill) const;
void setEquip(WrappedCard *equip);
void removeEquip(WrappedCard *equip);
bool hasEquip(const Card *card) const;
bool hasEquip() const;
QList<const Card *> getJudgingArea() const;
QList<int> getJudgingAreaID() const;
void addDelayedTrick(const Card *trick);
void removeDelayedTrick(const Card *trick);
bool containsTrick(const char *trick_name) const;
virtual int getHandcardNum() const = 0;
virtual void removeCard(const Card *card, Place place) = 0;
virtual void addCard(const Card *card, Place place) = 0;
virtual QList<const Card *> getHandcards() const = 0;
WrappedCard *getWeapon() const;
WrappedCard *getArmor() const;
WrappedCard *getDefensiveHorse() const;
WrappedCard *getOffensiveHorse() const;
WrappedCard *getTreasure() const;
QList<const Card *> getEquips() const;
const EquipCard *getEquip(int index) const;
bool hasWeapon(const char *weapon_name) const;
bool hasArmorEffect(const char *armor_name) const;
bool hasTreasure(const char *treasure_name) const;
bool isKongcheng() const;
bool isNude() const;
bool isAllNude() const;
bool canDiscard(const Player *to, const char *flags) const;
bool canDiscard(const Player *to, int card_id) const;
void addMark(const char *mark, int add_num = 1);
void removeMark(const char *mark, int remove_num = 1);
virtual void setMark(const char *mark, int value);
int getMark(const char *mark) const;
QStringList getMarkNames() const;
void setChained(bool chained);
bool isChained() const;
bool canSlash(const Player *other, const Card *slash, bool distance_limit = true,
int rangefix = 0, const QList<const Player *> &others = QList<const Player *>()) const;
bool canSlash(const Player *other, bool distance_limit = true,
int rangefix = 0, const QList<const Player *> &others = QList<const Player *>()) const;
int getCardCount(bool include_equip = true, bool include_judging = false) const;
QList<int> getPile(const char *pile_name);
QStringList getPileNames() const;
QString getPileName(int card_id) const;
bool pileOpen(const char *pile_name, const char *player) const;
void setPileOpen(const char *pile_name, const char *player);
QList<int> getHandPile() const;
void addHistory(const char *name, int times = 1);
void clearHistory(const char *name = "");
bool hasUsed(const char *card_class) const;
int usedTimes(const char *card_class) const;
int getSlashCount() const;
bool hasEquipSkill(const char *skill_name) const;
QSet<const TriggerSkill *> getTriggerSkills() const;
QSet<const Skill *> getSkills(bool include_equip = false, bool visible_only = true) const;
QList<const Skill *> getSkillList(bool include_equip = false, bool visible_only = true) const;
QSet<const Skill *> getVisibleSkills(bool include_equip = false) const;
QList<const Skill *> getVisibleSkillList(bool include_equip = false) const;
QStringList getAcquiredSkills() const;
QString getSkillDescription() const;
virtual bool isProhibited(const Player *to, const Card *card, const QList<const Player *> &others = QList<const Player *>()) const;
bool canSlashWithoutCrossbow() const;
virtual bool isLastHandCard(const Card *card, bool contain = false) const = 0;
bool isJilei(const Card *card, bool isHandcard = false) const;
bool isLocked(const Card *card, bool isHandcard = false) const;
void setCardLimitation(const char *limit_list, const char *pattern, bool single_turn = false);
void removeCardLimitation(const char *limit_list, const char *pattern);
void clearCardLimitation(bool single_turn = false);
bool isCardLimited(const Card *card, Card::HandlingMethod method, bool isHandcard = false) const;
// just for convenience
void addQinggangTag(const Card *card);
void removeQinggangTag(const Card *card);
void copyFrom(Player *p);
QList<const Player *> getSiblings() const;
QList<const Player *> getAliveSiblings() const;
static bool isNostalGeneral(const Player *p, const char *general_name);
};
%extend Player {
void setTag(const char *key, QVariant &value) {
$self->tag[key] = value;
}
QVariant getTag(const char *key) {
return $self->tag[key];
}
void removeTag(const char *tag_name) {
$self->tag.remove(tag_name);
}
};
class ServerPlayer: public Player {
public:
ServerPlayer(Room *room);
void setSocket(ClientSocket *socket);
QString reportHeader() const;
void drawCard(const Card *card);
Room *getRoom() const;
void broadcastSkillInvoke(const Card *card) const;
void broadcastSkillInvoke(const char *card_name) const;
int getRandomHandCardId() const;
const Card *getRandomHandCard() const;
void obtainCard(const Card *card, bool unhide = true);
void throwAllEquips();
void throwAllHandCards();
void throwAllHandCardsAndEquips();
void throwAllCards();
void bury();
void throwAllMarks(bool visible_only = true);
void clearOnePrivatePile(const char *pile_name);
void clearPrivatePiles();
void drawCards(int n, const char *reason = NULL);
bool askForSkillInvoke(const char *skill_name, const QVariant &data = QVariant());
bool askForSkillInvoke(const Skill *skill, const QVariant &data = QVariant());
QList<int> forceToDiscard(int discard_num, bool include_equip, bool is_discard = true, const char *pattern = ".");
QList<int> handCards() const;
virtual QList<const Card *> getHandcards() const;
QList<const Card *> getCards(const char *flags) const;
DummyCard *wholeHandCards() const;
bool hasNullification() const;
bool pindian(ServerPlayer *target, const char *reason, const Card *card1 = NULL);
void turnOver();
void play(QList<Player::Phase> set_phases = QList<Player::Phase>());
bool changePhase(Player::Phase from, Player::Phase to);
QList<Player::Phase> &getPhases();
void skip(Player::Phase phase, bool isCost = false);
void insertPhase(Player::Phase phase);
bool isSkipped(Player::Phase phase);
void gainMark(const char *mark, int n = 1);
void loseMark(const char *mark, int n = 1);
void loseAllMarks(const char *mark_name);
void setAI(AI *ai);
AI *getAI() const;
AI *getSmartAI() const;
virtual int aliveCount() const;
virtual int getHandcardNum() const;
virtual void removeCard(const Card *card, Place place);
virtual void addCard(const Card *card, Place place);
virtual bool isLastHandCard(const Card *card, bool contain = false) const;
void addVictim(ServerPlayer *victim);
QList<ServerPlayer *> getVictims() const;
void startRecord();
void saveRecord(const char *filename);
void setNext(ServerPlayer *next);
ServerPlayer *getNext() const;
ServerPlayer *getNextAlive(int n = 1) const;
// 3v3 methods
void addToSelected(const char *general);
QStringList getSelected() const;
QString findReasonable(QStringList generals, bool no_unreasonable = false);
void clearSelected();
int getGeneralMaxHp() const;
virtual QString getGameMode() const;
QString getIp() const;
void introduceTo(ServerPlayer *player);
void marshal(ServerPlayer *player) const;
void addToPile(const char *pile_name, const Card *card, bool open = true, QList<ServerPlayer *> open_players = QList<ServerPlayer *>());
void addToPile(const char *pile_name, int card_id, bool open = true, QList<ServerPlayer *> open_players = QList<ServerPlayer *>());
void addToPile(const char *pile_name, QList<int> card_ids, bool open = true, QList<ServerPlayer *> open_players = QList<ServerPlayer *>());
void addToPile(const char *pile_name, QList<int> card_ids, bool open, QList<ServerPlayer *> open_players, CardMoveReason reason);
void exchangeFreelyFromPrivatePile(const char *skill_name, const char *pile_name, int upperlimit = 1000, bool include_equip = false);
void gainAnExtraTurn();
};
%extend ServerPlayer {
void speak(const char *msg) {
QString str = QByteArray(msg).toBase64();
$self->getRoom()->speakCommand($self, str);
}
void removePileByName(const char *pile_name) {
$self->clearOnePrivatePile(pile_name);
}
};
class ClientPlayer: public Player {
public:
explicit ClientPlayer(Client *client);
virtual int aliveCount() const;
virtual int getHandcardNum() const;
virtual QList<const Card *> getHandcards() const;
virtual void removeCard(const Card *card, Place place);
virtual void addCard(const Card *card, Place place);
virtual void addKnownHandCard(const Card *card);
virtual bool isLastHandCard(const Card *card, bool contain = false) const;
};
extern ClientPlayer *Self;
class CardMoveReason {
public:
int m_reason;
QString m_playerId; // the cause (not the source) of the movement, such as "lusu" when "dimeng", or "zhanghe" when "qiaobian"
QString m_targetId; // To keep this structure lightweight, currently this is only used for UI purpose.
// It will be set to empty if multiple targets are involved. NEVER use it for trigger condition
// judgement!!! It will not accurately reflect the real reason.
QString m_skillName; // skill that triggers movement of the cards, such as "longdang", "dimeng"
QString m_eventName; // additional arg such as "lebusishu" on top of "S_REASON_JUDGE"
QVariant m_extraData; // additional data and will not be parsed to clients
CardMoveReason();
CardMoveReason(int moveReason, char *playerId);
CardMoveReason(int moveReason, char *playerId, char *skillName, char *eventName);
CardMoveReason(int moveReason, char *playerId, char *targetId, char *skillName, char *eventName);
static const int S_REASON_UNKNOWN = 0x00;
static const int S_REASON_USE = 0x01;
static const int S_REASON_RESPONSE = 0x02;
static const int S_REASON_DISCARD = 0x03;
static const int S_REASON_RECAST = 0x04; // ironchain etc.
static const int S_REASON_PINDIAN = 0x05;
static const int S_REASON_DRAW = 0x06;
static const int S_REASON_GOTCARD = 0x07;
static const int S_REASON_SHOW = 0x08;
static const int S_REASON_TRANSFER = 0x09;
static const int S_REASON_PUT = 0x0A;
//subcategory of use
static const int S_REASON_LETUSE = 0x11; // use a card when self is not current
//subcategory of response
static const int S_REASON_RETRIAL = 0x12;
//subcategory of discard
static const int S_REASON_RULEDISCARD = 0x13; // discard at one's Player::Discard for gamerule
static const int S_REASON_THROW = 0x23; /* gamerule(dying or punish)
as the cost of some skills */
static const int S_REASON_DISMANTLE = 0x33; // one throw card of another
//subcategory of gotcard
static const int S_REASON_GIVE = 0x17; // from one hand to another hand
static const int S_REASON_EXTRACTION = 0x27; // from another's place to one's hand
static const int S_REASON_GOTBACK = 0x37; // from placetable to hand
static const int S_REASON_RECYCLE = 0x47; // from discardpile to hand
static const int S_REASON_ROB = 0x57; // got a definite card from other's hand
static const int S_REASON_PREVIEWGIVE = 0x67; // give cards after previewing, i.e. Yiji & Miji
//subcategory of show
static const int S_REASON_TURNOVER = 0x18; // show n cards from drawpile
static const int S_REASON_JUDGE = 0x28; // show a card from drawpile for judge
static const int S_REASON_PREVIEW = 0x38; // Not done yet, plan for view some cards for self only(guanxing yiji miji)
static const int S_REASON_DEMONSTRATE = 0x48; // show a card which copy one to move to table
//subcategory of transfer
static const int S_REASON_SWAP = 0x19; // exchange card for two players
static const int S_REASON_OVERRIDE = 0x29; // exchange cards from cards in game
static const int S_REASON_EXCHANGE_FROM_PILE = 0x39;// exchange cards from cards moved out of game (for qixing only)
//subcategory of put
static const int S_REASON_NATURAL_ENTER = 0x1A; // a card with no-owner move into discardpile
static const int S_REASON_REMOVE_FROM_PILE = 0x2A; // cards moved out of game go back into discardpile
static const int S_REASON_JUDGEDONE = 0x3A; // judge card move into discardpile
static const int S_REASON_CHANGE_EQUIP = 0x4A; // replace existed equip
static const int S_MASK_BASIC_REASON = 0x0F;
};
struct DamageStruct {
DamageStruct();
DamageStruct(const Card *card, ServerPlayer *from, ServerPlayer *to, int damage = 1, DamageStruct::Nature nature = Normal);
DamageStruct(const char *reason, ServerPlayer *from, ServerPlayer *to, int damage = 1, DamageStruct::Nature nature = Normal);
enum Nature {
Normal, // normal slash, duel and most damage caused by skill
Fire, // fire slash, fire attack and few damage skill (Yeyan, etc)
Thunder // lightning, thunder slash, and few damage skill (Leiji, etc)
};
ServerPlayer *from;
ServerPlayer *to;
const Card *card;
int damage;
Nature nature;
bool chain;
bool transfer;
bool by_user;
QString reason;
QString transfer_reason;
bool prevented;
QString getReason() const;
};
struct CardEffectStruct {
CardEffectStruct();
const Card *card;
ServerPlayer *from;
ServerPlayer *to;
bool nullified;
};
struct SlashEffectStruct {
SlashEffectStruct();
int jink_num;
const Card *slash;
const Card *jink;
ServerPlayer *from;
ServerPlayer *to;
int drank;
DamageStruct::Nature nature;
bool nullified;
};
struct CardUseStruct {
enum CardUseReason {
CARD_USE_REASON_UNKNOWN = 0x00,
CARD_USE_REASON_PLAY = 0x01,
CARD_USE_REASON_RESPONSE = 0x02,
CARD_USE_REASON_RESPONSE_USE = 0x12
};
CardUseStruct();
CardUseStruct(const Card *card, ServerPlayer *from, QList<ServerPlayer *> to, bool isOwnerUse = true);
CardUseStruct(const Card *card, ServerPlayer *from, ServerPlayer *target, bool isOwnerUse = true);
bool isValid(const char *pattern) const;
void parse(const char *str, Room *room);
const Card *card;
ServerPlayer *from;
QList<ServerPlayer *> to;
bool m_isOwnerUse;
bool m_addHistory;
bool m_isHandcard;
QStringList nullified_list;
};
struct CardsMoveStruct {
CardsMoveStruct();
CardsMoveStruct(const QList<int> &ids, Player *from, Player *to, Player::Place from_place, Player::Place to_place, CardMoveReason reason);
CardsMoveStruct(const QList<int> &ids, Player *to, Player::Place to_place, CardMoveReason reason);
CardsMoveStruct(int id, Player *from, Player *to, Player::Place from_place, Player::Place to_place, CardMoveReason reason);
CardsMoveStruct(int id, Player *to, Player::Place to_place, CardMoveReason reason);
QList<int> card_ids;
Player::Place from_place, to_place;
QString from_player_name, to_player_name;
QString from_pile_name, to_pile_name;
Player *from, *to;
CardMoveReason reason;
bool open;
bool is_last_handcard;
};
struct CardsMoveOneTimeStruct {
QList<int> card_ids;
QList<Player::Place> from_places;
Player::Place to_place;
CardMoveReason reason;
Player *from, *to;
QStringList from_pile_names;
QString to_pile_name;
QList<bool> open; // helper to prevent sending card_id to unrelevant clients
bool is_last_handcard;
void removeCardIds(const QList<int> &to_remove);
};
struct DyingStruct {
DyingStruct();
ServerPlayer *who; // who is ask for help
DamageStruct *damage; // if it is NULL that means the dying is caused by losing hp
};
struct DeathStruct {
DeathStruct();
ServerPlayer *who; // who is ask for help
DamageStruct *damage; // if it is NULL that means the dying is caused by losing hp
};
struct RecoverStruct {
RecoverStruct(ServerPlayer *who = NULL, const Card *card = NULL, int recover = 1);
int recover;
ServerPlayer *who;
const Card *card;
};
struct JudgeStruct {
JudgeStruct();
bool isGood() const;
bool isBad() const;
bool isEffected() const;
void updateResult();
bool isGood(const Card *card) const; // For AI
bool negative;
bool play_animation;
ServerPlayer *who;
const Card *card;
QString pattern;
bool good;
QString reason;
bool time_consuming;
ServerPlayer *retrial_by_response; // record whether the current judge card is provided by a response retrial
};
struct PindianStruct {
PindianStruct();
ServerPlayer *from;
ServerPlayer *to;
const Card *from_card;
const Card *to_card;
int from_number;
int to_number;
QString reason;
bool success;
};
struct PhaseChangeStruct {
PhaseChangeStruct();
Player::Phase from;
Player::Phase to;
};
struct CardResponseStruct {
CardResponseStruct();
const Card *m_card;
ServerPlayer *m_who;
bool m_isUse;
bool m_isRetrial;
bool m_isHandcard;
};
enum TriggerEvent {
NonTrigger,
GameStart,
TurnStart,
EventPhaseStart,
EventPhaseProceeding,
EventPhaseEnd,
EventPhaseChanging,
EventPhaseSkipping,
DrawNCards,
AfterDrawNCards,
DrawInitialCards,
AfterDrawInitialCards,
PreHpRecover,
HpRecover,
PreHpLost,
HpLost,
HpChanged,
MaxHpChanged,
EventLoseSkill,
EventAcquireSkill,
StartJudge,
AskForRetrial,
FinishRetrial,
FinishJudge,
PindianVerifying,
Pindian,
TurnedOver,
ChainStateChanged,
ConfirmDamage, // confirm the damage's count and damage's nature
Predamage, // trigger the certain skill -- jueqing
DamageForseen, // the first event in a damage -- kuangfeng dawu
DamageCaused, // the moment for -- qianxi..
DamageInflicted, // the moment for -- tianxiang..
PreDamageDone, // before reducing Hp
DamageDone, // it's time to do the damage
Damage, // the moment for -- lieren..
Damaged, // the moment for -- yiji..
DamageComplete, // the moment for trigger iron chain
EnterDying,
Dying,
QuitDying,
AskForPeaches,
AskForPeachesDone,
Death,
BuryVictim,
BeforeGameOverJudge,
GameOverJudge,
GameFinished,
SlashEffected,
SlashProceed,
SlashHit,
SlashMissed,
JinkEffect,
NullificationEffect,
CardAsked,
PreCardResponded,
CardResponded,
BeforeCardsMove, // sometimes we need to record cards before the move
CardsMoveOneTime,
PreCardUsed, // for AI to filter events only.
CardUsed,
TargetSpecifying,
TargetConfirming,
TargetSpecified,
TargetConfirmed,
CardEffect, // for AI to filter events only
CardEffected,
PostCardEffected,
CardFinished,
TrickCardCanceling,
TrickEffect,
ChoiceMade,
StageChange, // For hulao pass only
FetchDrawPileCard, // For miniscenarios only
ActionedReset, // For 3v3 only
Debut, // For 1v1 only
TurnBroken, // For the skill 'DanShou'. Do not use it to trigger events
NumOfEvents
};
class Card: public QObject {
public:
// enumeration type
enum Suit { Spade, Club, Heart, Diamond, NoSuitBlack, NoSuitRed, NoSuit, SuitToBeDecided };
enum HandlingMethod { MethodNone, MethodUse, MethodResponse, MethodDiscard, MethodRecast, MethodPindian };
static const Suit AllSuits[4];
// card types
enum CardType { TypeSkill, TypeBasic, TypeTrick, TypeEquip };
// constructor
Card(Suit suit, int number, bool target_fixed = false);
// property getters/setters
QString getSuitString() const;
bool isRed() const;
bool isBlack() const;
int getId() const;
void setId(int id);
int getEffectiveId() const;
int getNumber() const;
void setNumber(int number);
QString getNumberString() const;
Suit getSuit() const;
void setSuit(Suit suit);
bool sameColorWith(const Card *other) const;
bool isEquipped() const;
QString getPackage() const;
QString getFullName(bool include_suit = false) const;
QString getLogName() const;
QString getName() const;
QString getSkillName(bool removePrefix = true) const;
void setSkillName(const char *skill_name);
QString getDescription() const;
bool isVirtualCard() const;
virtual bool match(const char *pattern) const;
void addSubcard(int card_id);
void addSubcard(const Card *card);
QList<int> getSubcards() const;
void clearSubcards();
QString subcardString() const;
void addSubcards(const QList<const Card *> &cards);
void addSubcards(const QList<int> &subcards_list);
int subcardsLength() const;
virtual QString getType() const = 0;
virtual QString getSubtype() const = 0;
virtual CardType getTypeId() const = 0;
virtual QString toString(bool hidden = false) const;
bool isNDTrick() const;
// card target selection
bool targetFixed() const;
virtual bool targetsFeasible(const QList<const Player *> &targets, const Player *self) const;
virtual bool targetFilter(const QList<const Player *> &targets, const Player *to_select, const Player *self) const;
virtual bool isAvailable(const Player *player) const;
virtual const Card *validate(CardUseStruct &card_use) const;
virtual const Card *validateInResponse(ServerPlayer *user) const;
bool isMute() const;
bool willThrow() const;
bool canRecast() const;
bool hasPreAction() const;
Card::HandlingMethod getHandlingMethod() const;
void setCanRecast(bool can);
void setFlags(const char *flag) const;
bool hasFlag(const char *flag) const;
void clearFlags() const;
void setTag(const char *key, const QVariant &data) const;
void removeTag(const char *key) const;
virtual void onUse(Room *room, const CardUseStruct &card_use) const;
virtual void use(Room *room, ServerPlayer *source, QList<ServerPlayer *> &targets) const;
virtual void onEffect(const CardEffectStruct &effect) const;
virtual bool isCancelable(const CardEffectStruct &effect) const;
virtual bool isKindOf(const char *cardType) const;
virtual QStringList getFlags() const;
virtual bool isModified() const;
virtual QString getClassName() const;
virtual const Card *getRealCard() const;
// static functions
static bool CompareByNumber(const Card *a, const Card *b);
static bool CompareBySuit(const Card *a, const Card *b);
static bool CompareByType(const Card *a, const Card *b);
static const Card *Parse(const char *str);
static Card *Clone(const Card *card);
static QString Suit2String(Suit suit);
};
%extend Card {
EquipCard *toEquipCard() {
return qobject_cast<EquipCard *>($self);
}
Weapon *toWeapon() {
return qobject_cast<Weapon *>($self);
}
WrappedCard *toWrapped() {
return qobject_cast<WrappedCard *>($self);
}
TrickCard *toTrick() {
return qobject_cast<TrickCard *>($self);
}
void cardOnUse(Room *room, const CardUseStruct &card_use) const{
$self->Card::onUse(room, card_use);
}
bool cardIsAvailable(const Player *player) const{
return $self->Card::isAvailable(player);
}
QVariant getTag(const char *key) const{
return $self->tag[key];
}
};
class WrappedCard: public Card {
public:
void takeOver(Card *card);
void copyEverythingFrom(Card *card);
void setModified(bool modified);
};
class SkillCard: public Card {
public:
SkillCard();
void setUserString(const char *user_string);
QString getUserString() const;
virtual QString getSubtype() const;
virtual QString getType() const;
virtual CardType getTypeId() const;
virtual QString toString(bool hidden = false) const;
protected:
QString user_string;
};
class DummyCard: public SkillCard {
public:
DummyCard();
DummyCard(const QList<int> &subcards);
};
class Package: public QObject {
public:
enum Type { GeneralPack, CardPack, SpecialPack };
Package(const char *name, Type pack_type = GeneralPack);
void insertRelatedSkills(const char *main_skill, const char *related_skill);
void insertConvertPairs(const char *from, const char *to);
};
class Engine: public QObject {
public:
void addTranslationEntry(const char *key, const char *value);
QString translate(const char *to_translate) const;
void addPackage(Package *package);
void addBanPackage(const char *package_name);
QStringList getBanPackages() const;
Card *cloneCard(const Card *card) const;
Card *cloneCard(const char *name, Card::Suit suit = Card::SuitToBeDecided, int number = -1, QStringList flags = QStringList()) const;
SkillCard *cloneSkillCard(const char *name) const;
QString getVersion() const;
QString getVersionName() const;
QStringList getExtensions() const;
QStringList getKingdoms() const;
QColor getKingdomColor(const char *kingdom) const;
QString getSetupString() const;
QMap<QString, QString> getAvailableModes() const;
QString getModeName(const char *mode) const;
int getPlayerCount(const char *mode) const;
QString getRoles(const char *mode) const;
QStringList getRoleList(const char *mode) const;
int getRoleIndex() const;
const CardPattern *getPattern(const char *name) const;
bool matchExpPattern(const char *pattern, const Player *player, const Card *card) const;
Card::HandlingMethod getCardHandlingMethod(const char *method_name) const;
QList<const Skill *> getRelatedSkills(const char *skill_name) const;
const Skill *getMainSkill(const char *skill_name) const;
QStringList getModScenarioNames() const;
void addScenario(Scenario *scenario);
const Scenario *getScenario(const char *name) const;
const General *getGeneral(const char *name) const;
int getGeneralCount(bool include_banned = false, const char *kingdom = "") const;
const Skill *getSkill(const char *skill_name) const;
const TriggerSkill *getTriggerSkill(const char *skill_name) const;
const ViewAsSkill *getViewAsSkill(const char *skill_name) const;
QList<const DistanceSkill *> getDistanceSkills() const;
QList<const MaxCardsSkill *> getMaxCardsSkills() const;
QList<const TargetModSkill *> getTargetModSkills() const;
QList<const InvaliditySkill *> getInvaliditySkills() const;
QList<const TriggerSkill *> getGlobalTriggerSkills() const;
void addSkills(const QList<const Skill *> &skills);
int getCardCount() const;
const Card *getEngineCard(int cardId) const;
Card *getCard(int cardId);
WrappedCard *getWrappedCard(int cardId);
QStringList getLords(bool contain_banned = false) const;
QStringList getRandomLords() const;
QStringList getRandomGenerals(int count, const QSet<QString> &ban_set = QSet<QString>(), const char *kingdom = "") const;
QList<int> getRandomCards() const;
QString getRandomGeneralName() const;
QStringList getLimitedGeneralNames(const char *kingdom = "") const;
QList<const General *> getAllGenerals() const;
void playSystemAudioEffect(const char *name, bool superpose = true) const;
void playAudioEffect(const char *filename, bool superpose = true) const;
void playSkillAudioEffect(const char *skill_name, int index, bool superpose = true) const;
const ProhibitSkill *isProhibited(const Player *from, const Player *to, const Card *card, const QList<const Player *> &others = QList<const Player *>()) const;
int correctDistance(const Player *from, const Player *to) const;
int correctMaxCards(const Player *target) const;
int correctCardTarget(const TargetModSkill::ModType type, const Player *from, const Card *card) const;
bool correctSkillValidity(const Player *player, const Skill *skill) const;
Room *currentRoom();
QString getCurrentCardUsePattern();
CardUseStruct::CardUseReason getCurrentCardUseReason();
QString findConvertFrom(const char *general_name) const;
bool isGeneralHidden(const char *general_name) const;
};
extern Engine *Sanguosha;
class Skill: public QObject {
public:
enum Frequency { Frequent, NotFrequent, Compulsory, Limited, Wake, NotCompulsory };
explicit Skill(const char *name, Frequency frequent = NotFrequent);
bool isLordSkill() const;
bool isAttachedLordSkill() const;
QString getDescription() const;
bool isVisible() const;
virtual int getEffectIndex(const ServerPlayer *player, const Card *card) const;
virtual QDialog *getDialog() const;
void initMediaSource();
void playAudioEffect(int index = -1, bool superpose = true) const;
virtual Frequency getFrequency(const Player *target = NULL) const;
QStringList getSources() const;
};
%extend Skill {