-
Notifications
You must be signed in to change notification settings - Fork 194
/
Copy pathluaskills.i
1677 lines (1273 loc) · 43.5 KB
/
luaskills.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
class LuaTriggerSkill: public TriggerSkill {
public:
LuaTriggerSkill(const char *name, Frequency frequency, const char *limit_mark);
void addEvent(TriggerEvent event);
void setViewAsSkill(ViewAsSkill *view_as_skill);
void setGlobal(bool global);
void insertPriorityTable(TriggerEvent triggerEvent, int priority);
void setGuhuoDialog(const char *type);
virtual Frequency getFrequency(const Player *target) const;
virtual bool triggerable(const ServerPlayer *target, Room *room) const;
virtual bool trigger(TriggerEvent event, Room *room, ServerPlayer *player, QVariant &data) const;
LuaFunction on_trigger;
LuaFunction can_trigger;
LuaFunction dynamic_frequency;
int priority;
};
class GameStartSkill: public TriggerSkill {
public:
GameStartSkill(const QString &name);
virtual bool trigger(TriggerEvent event, Room *room, ServerPlayer *player, QVariant &data) const;
virtual void onGameStart(ServerPlayer *player) const = 0;
};
class ProhibitSkill: public Skill {
public:
ProhibitSkill(const QString &name);
virtual bool isProhibited(const Player *from, const Player *to, const Card *card, const QList<const Player *> &others = QList<const Player *>()) const = 0;
};
class DistanceSkill: public Skill {
public:
DistanceSkill(const QString &name);
virtual int getCorrect(const Player *from, const Player *to) const = 0;
};
class MaxCardsSkill: public Skill {
public:
MaxCardsSkill(const QString &name);
virtual int getExtra(const Player *target) const;
virtual int getFixed(const Player *target) const;
};
class TargetModSkill: public Skill {
public:
enum ModType {
Residue,
DistanceLimit,
ExtraTarget
};
TargetModSkill(const QString &name);
virtual QString getPattern() const;
virtual int getResidueNum(const Player *from, const Card *card) const;
virtual int getDistanceLimit(const Player *from, const Card *card) const;
virtual int getExtraTargetNum(const Player *from, const Card *card) const;
protected:
QString pattern;
};
class InvaliditySkill: public Skill {
public:
InvaliditySkill(const QString &name);
virtual bool isSkillValid(const Player *player, const Skill *skill) const = 0;
};
class AttackRangeSkill: public Skill{
public:
AttackRangeSkill(const QString &name);
virtual int getExtra(const Player *target, bool include_weapon) const;
virtual int getFixed(const Player *target, bool include_weapon) const;
};
class LuaAttackRangeSkill: public AttackRangeSkill{
public:
LuaAttackRangeSkill(const char *name);
virtual int getExtra(const Player *target, bool include_weapon) const;
virtual int getFixed(const Player *target, bool include_weapon) const;
LuaFunction extra_func;
LuaFunction fixed_func;
};
class LuaProhibitSkill: public ProhibitSkill {
public:
LuaProhibitSkill(const char *name);
virtual bool isProhibited(const Player *from, const Player *to, const Card *card, const QList<const Player *> &others = QList<const Player *>()) const;
LuaFunction is_prohibited;
};
class ViewAsSkill: public Skill {
public:
ViewAsSkill(const QString &name);
virtual bool viewFilter(const QList<const Card *> &selected, const Card *to_select) const = 0;
virtual const Card *viewAs(const QList<const Card *> &cards) const = 0;
virtual bool isEnabledAtPlay(const Player *player) const;
virtual bool isEnabledAtResponse(const Player *player, const char *pattern) const;
bool isResponseOrUse() const;
QString getExpandPile() const;
};
class LuaViewAsSkill: public ViewAsSkill {
public:
LuaViewAsSkill(const char *name, const char *response_pattern, bool response_or_use, const char *expand_pile);
virtual bool viewFilter(const QList<const Card *> &selected, const Card *to_select) const;
virtual const Card *viewAs(const QList<const Card *> &cards) const;
virtual bool shouldBeVisible(const Player *player) const;
LuaFunction should_be_visible;
LuaFunction view_filter;
LuaFunction view_as;
LuaFunction enabled_at_play;
LuaFunction enabled_at_response;
LuaFunction enabled_at_nullification;
void setGuhuoDialog(const char *type);
};
class OneCardViewAsSkill: public ViewAsSkill {
public:
OneCardViewAsSkill(const QString &name);
virtual bool viewFilter(const QList<const Card *> &selected, const Card *to_select) const;
virtual const Card *viewAs(const QList<const Card *> &cards) const;
virtual bool viewFilter(const Card *to_select) const = 0;
virtual const Card *viewAs(const Card *originalCard) const = 0;
};
class FilterSkill: public OneCardViewAsSkill {
public:
FilterSkill(const QString &name);
};
class LuaFilterSkill: public FilterSkill {
public:
LuaFilterSkill(const char *name);
virtual bool viewFilter(const Card *to_select) const;
virtual const Card *viewAs(const Card *originalCard) const;
LuaFunction view_filter;
LuaFunction view_as;
};
class LuaDistanceSkill: public DistanceSkill {
public:
LuaDistanceSkill(const char *name);
virtual int getCorrect(const Player *from, const Player *to) const;
LuaFunction correct_func;
};
class LuaMaxCardsSkill: public MaxCardsSkill {
public:
LuaMaxCardsSkill(const char *name);
virtual int getExtra(const Player *target) const;
virtual int getFixed(const Player *target) const;
LuaFunction extra_func;
LuaFunction fixed_func;
};
class LuaTargetModSkill: public TargetModSkill {
public:
LuaTargetModSkill(const char *name, const char *pattern);
virtual int getResidueNum(const Player *from, const Card *card) const;
virtual int getDistanceLimit(const Player *from, const Card *card) const;
virtual int getExtraTargetNum(const Player *from, const Card *card) const;
LuaFunction residue_func;
LuaFunction distance_limit_func;
LuaFunction extra_target_func;
};
class LuaInvaliditySkill: public InvaliditySkill {
public:
LuaInvaliditySkill(const char *name);
virtual bool isSkillValid(const Player *player, const Skill *skill) const;
LuaFunction skill_valid;
};
class LuaSkillCard: public SkillCard {
public:
LuaSkillCard(const char *name, const char *skillName);
void setTargetFixed(bool target_fixed);
void setWillThrow(bool will_throw);
void setCanRecast(bool can_recast);
void setHandlingMethod(Card::HandlingMethod handling_method);
void setMute(bool mute);
LuaSkillCard *clone() const;
LuaFunction filter;
LuaFunction feasible;
LuaFunction about_to_use;
LuaFunction on_use;
LuaFunction on_effect;
LuaFunction on_validate;
LuaFunction on_validate_in_response;
};
class LuaBasicCard: public BasicCard {
public:
LuaBasicCard(Card::Suit suit, int number, const char *obj_name, const char *class_name, const char *subtype);
LuaBasicCard *clone(Card::Suit suit = Card::SuitToBeDecided, int number = -1) const;
void setTargetFixed(bool target_fixed);
void setCanRecast(bool can_recast);
virtual void onUse(Room *room, const CardUseStruct &card_use) const;
virtual void onEffect(const CardEffectStruct &effect) const;
virtual void use(Room *room, ServerPlayer *source, QList<ServerPlayer *> &targets) 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 QString getClassName() const;
virtual QString getSubtype() const;
virtual bool isKindOf(const char *cardType) const;
// the lua callbacks
LuaFunction filter;
LuaFunction feasible;
LuaFunction available;
LuaFunction about_to_use;
LuaFunction on_use;
LuaFunction on_effect;
};
class LuaTrickCard: public TrickCard {
public:
enum SubClass { TypeNormal, TypeSingleTargetTrick, TypeDelayedTrick, TypeAOE, TypeGlobalEffect };
LuaTrickCard(Card::Suit suit, int number, const char *obj_name, const char *class_name, const char *subtype);
LuaTrickCard *clone(Card::Suit suit = Card::SuitToBeDecided, int number = -1) const;
void setTargetFixed(bool target_fixed);
void setCanRecast(bool can_recast);
virtual void onUse(Room *room, const CardUseStruct &card_use) const;
virtual void onEffect(const CardEffectStruct &effect) const;
virtual void use(Room *room, ServerPlayer *source, QList<ServerPlayer *> &targets) const;
virtual void onNullified(ServerPlayer *target) const;
virtual bool isCancelable(const CardEffectStruct &effect) 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 QString getClassName() const;
void setSubClass(SubClass subclass);
SubClass getSubClass() const;
virtual QString getSubtype() const;
virtual bool isKindOf(const char *cardType) const;
// the lua callbacks
LuaFunction filter;
LuaFunction feasible;
LuaFunction available;
LuaFunction is_cancelable;
LuaFunction about_to_use;
LuaFunction on_use;
LuaFunction on_effect;
LuaFunction on_nullified;
};
class LuaWeapon: public Weapon {
public:
LuaWeapon(Card::Suit suit, int number, int range, const char *obj_name, const char *class_name);
LuaWeapon *clone(Card::Suit suit = Card::SuitToBeDecided, int number = -1) const;
virtual void onInstall(ServerPlayer *player) const;
virtual void onUninstall(ServerPlayer *player) const;
virtual QString getClassName();
virtual bool isKindOf(const char *cardType);
// the lua callbacks
LuaFunction on_install;
LuaFunction on_uninstall;
};
class LuaArmor: public Armor {
public:
LuaArmor(Card::Suit suit, int number, const char *obj_name, const char *class_name);
LuaArmor *clone(Card::Suit suit = Card::SuitToBeDecided, int number = -1) const;
virtual void onInstall(ServerPlayer *player) const;
virtual void onUninstall(ServerPlayer *player) const;
virtual QString getClassName();
virtual bool isKindOf(const char *cardType);
// the lua callbacks
LuaFunction on_install;
LuaFunction on_uninstall;
};
class LuaTreasure: public Treasure {
public:
LuaTreasure(Card::Suit suit, int number, const char *obj_name, const char *class_name);
LuaTreasure *clone(Card::Suit suit = Card::SuitToBeDecided, int number = -1) const;
virtual void onInstall(ServerPlayer *player) const;
virtual void onUninstall(ServerPlayer *player) const;
virtual QString getClassName();
virtual bool isKindOf(const char *cardType);
// the lua callbacks
LuaFunction on_install;
LuaFunction on_uninstall;
};
%{
#include "lua-wrapper.h"
#include "clientplayer.h"
bool LuaTriggerSkill::triggerable(const ServerPlayer *target, Room *room) const
{
if (can_trigger == 0)
return TriggerSkill::triggerable(target, room);
lua_State *L = room->getLuaState();
// the callback function
lua_rawgeti(L, LUA_REGISTRYINDEX, can_trigger);
SWIG_NewPointerObj(L, this, SWIGTYPE_p_LuaTriggerSkill, 0);
SWIG_NewPointerObj(L, target, SWIGTYPE_p_ServerPlayer, 0);
SWIG_NewPointerObj(L, room, SWIGTYPE_p_Room, 0);
int error = lua_pcall(L, 3, 1, 0);
if (error) {
const char *error_msg = lua_tostring(L, -1);
lua_pop(L, 1);
room->output(error_msg);
return false;
} else {
bool result = lua_toboolean(L, -1);
lua_pop(L, 1);
return result;
}
}
bool LuaTriggerSkill::trigger(TriggerEvent event, Room *room, ServerPlayer *player, QVariant &data) const
{
if (on_trigger == 0)
return false;
lua_State *L = room->getLuaState();
int e = static_cast<int>(event);
// the callback
lua_rawgeti(L, LUA_REGISTRYINDEX, on_trigger);
LuaTriggerSkill *self = const_cast<LuaTriggerSkill *>(this);
SWIG_NewPointerObj(L, self, SWIGTYPE_p_LuaTriggerSkill, 0);
// the first argument: event
lua_pushinteger(L, e);
// the second argument: player
SWIG_NewPointerObj(L, player, SWIGTYPE_p_ServerPlayer, 0);
// the last event: data
SWIG_NewPointerObj(L, &data, SWIGTYPE_p_QVariant, 0);
// append Room as an argument
SWIG_NewPointerObj(L, room, SWIGTYPE_p_Room, 0);
int error = lua_pcall(L, 5, 1, 0);
if (error) {
const char *error_msg = lua_tostring(L, -1);
lua_pop(L, 1);
room->output(error_msg);
return false;
} else {
bool result = lua_toboolean(L, -1);
lua_pop(L, 1);
return result;
}
}
#include <QMessageBox>
static void Error(lua_State *L)
{
const char *error_string = lua_tostring(L, -1);
lua_pop(L, 1);
QMessageBox::warning(NULL, "Lua script error!", error_string);
}
Skill::Frequency LuaTriggerSkill::getFrequency(const Player *target) const
{
if (dynamic_frequency == 0)
return Skill::getFrequency(target);
lua_State *L = Sanguosha->getLuaState();
lua_rawgeti(L, LUA_REGISTRYINDEX, dynamic_frequency);
SWIG_NewPointerObj(L, this, SWIGTYPE_p_LuaTriggerSkill, 0);
SWIG_NewPointerObj(L, target, SWIGTYPE_p_Player, 0);
int error = lua_pcall(L, 2, 1, 0);
if (error) {
Error(L);
return Skill::getFrequency(target);
}
int result = lua_tointeger(L, -1);
lua_pop(L, 1);
return (Skill::Frequency)result;
}
bool LuaProhibitSkill::isProhibited(const Player *from, const Player *to, const Card *card, const QList<const Player *> &others) const
{
if (is_prohibited == 0)
return false;
lua_State *L = Sanguosha->getLuaState();
lua_rawgeti(L, LUA_REGISTRYINDEX, is_prohibited);
SWIG_NewPointerObj(L, this, SWIGTYPE_p_LuaProhibitSkill, 0);
SWIG_NewPointerObj(L, from, SWIGTYPE_p_Player, 0);
SWIG_NewPointerObj(L, to, SWIGTYPE_p_Player, 0);
SWIG_NewPointerObj(L, card, SWIGTYPE_p_Card, 0);
lua_createtable(L, others.length(), 0);
for (int i = 0; i < others.length(); i++) {
const Player *player = others[i];
SWIG_NewPointerObj(L, player, SWIGTYPE_p_Player, 0);
lua_rawseti(L, -2, i + 1);
}
int error = lua_pcall(L, 5, 1, 0);
if (error) {
Error(L);
return false;
}
bool result = lua_toboolean(L, -1);
lua_pop(L, 1);
return result;
}
int LuaDistanceSkill::getCorrect(const Player *from, const Player *to) const
{
if (correct_func == 0)
return 0;
lua_State *L = Sanguosha->getLuaState();
lua_rawgeti(L, LUA_REGISTRYINDEX, correct_func);
SWIG_NewPointerObj(L, this, SWIGTYPE_p_LuaDistanceSkill, 0);
SWIG_NewPointerObj(L, from, SWIGTYPE_p_Player, 0);
SWIG_NewPointerObj(L, to, SWIGTYPE_p_Player, 0);
int error = lua_pcall(L, 3, 1, 0);
if (error) {
Error(L);
return 0;
}
int correct = lua_tointeger(L, -1);
lua_pop(L, 1);
return correct;
}
int LuaMaxCardsSkill::getExtra(const Player *target) const
{
if (extra_func == 0)
return MaxCardsSkill::getExtra(target);
lua_State *L = Sanguosha->getLuaState();
lua_rawgeti(L, LUA_REGISTRYINDEX, extra_func);
SWIG_NewPointerObj(L, this, SWIGTYPE_p_LuaMaxCardsSkill, 0);
SWIG_NewPointerObj(L, target, SWIGTYPE_p_Player, 0);
int error = lua_pcall(L, 2, 1, 0);
if (error) {
Error(L);
return MaxCardsSkill::getExtra(target);
}
int extra = lua_tointeger(L, -1);
lua_pop(L, 1);
return extra;
}
int LuaMaxCardsSkill::getFixed(const Player *target) const
{
if (fixed_func == 0)
return MaxCardsSkill::getFixed(target);
lua_State *L = Sanguosha->getLuaState();
lua_rawgeti(L, LUA_REGISTRYINDEX, fixed_func);
SWIG_NewPointerObj(L, this, SWIGTYPE_p_LuaMaxCardsSkill, 0);
SWIG_NewPointerObj(L, target, SWIGTYPE_p_Player, 0);
int error = lua_pcall(L, 2, 1, 0);
if (error) {
Error(L);
return MaxCardsSkill::getFixed(target);
}
int extra = lua_tointeger(L, -1);
lua_pop(L, 1);
return extra;
}
int LuaTargetModSkill::getResidueNum(const Player *from, const Card *card) const
{
if (residue_func == 0)
return 0;
lua_State *L = Sanguosha->getLuaState();
lua_rawgeti(L, LUA_REGISTRYINDEX, residue_func);
SWIG_NewPointerObj(L, this, SWIGTYPE_p_LuaTargetModSkill, 0);
SWIG_NewPointerObj(L, from, SWIGTYPE_p_Player, 0);
SWIG_NewPointerObj(L, card, SWIGTYPE_p_Card, 0);
int error = lua_pcall(L, 3, 1, 0);
if (error) {
Error(L);
return 0;
}
int residue = lua_tointeger(L, -1);
lua_pop(L, 1);
return residue;
}
int LuaTargetModSkill::getDistanceLimit(const Player *from, const Card *card) const
{
if (distance_limit_func == 0)
return 0;
lua_State *L = Sanguosha->getLuaState();
lua_rawgeti(L, LUA_REGISTRYINDEX, distance_limit_func);
SWIG_NewPointerObj(L, this, SWIGTYPE_p_LuaTargetModSkill, 0);
SWIG_NewPointerObj(L, from, SWIGTYPE_p_Player, 0);
SWIG_NewPointerObj(L, card, SWIGTYPE_p_Card, 0);
int error = lua_pcall(L, 3, 1, 0);
if (error) {
Error(L);
return 0;
}
int distance_limit = lua_tointeger(L, -1);
lua_pop(L, 1);
return distance_limit;
}
int LuaTargetModSkill::getExtraTargetNum(const Player *from, const Card *card) const
{
if (extra_target_func == 0)
return 0;
lua_State *L = Sanguosha->getLuaState();
lua_rawgeti(L, LUA_REGISTRYINDEX, extra_target_func);
SWIG_NewPointerObj(L, this, SWIGTYPE_p_LuaTargetModSkill, 0);
SWIG_NewPointerObj(L, from, SWIGTYPE_p_Player, 0);
SWIG_NewPointerObj(L, card, SWIGTYPE_p_Card, 0);
int error = lua_pcall(L, 3, 1, 0);
if (error) {
Error(L);
return 0;
}
int extra_target_func = lua_tointeger(L, -1);
lua_pop(L, 1);
return extra_target_func;
}
int LuaAttackRangeSkill::getExtra(const Player *target, bool include_weapon) const
{
if (extra_func == 0)
return AttackRangeSkill::getExtra(target, include_weapon);
lua_State *l = Sanguosha->getLuaState();
lua_rawgeti(l, LUA_REGISTRYINDEX, extra_func);
SWIG_NewPointerObj(l, this, SWIGTYPE_p_LuaAttackRangeSkill, 0);
SWIG_NewPointerObj(l, target, SWIGTYPE_p_Player, 0);
lua_pushboolean(l, include_weapon);
int error = lua_pcall(l, 3, 1, 0);
if (error) {
Error(l);
return AttackRangeSkill::getExtra(target, include_weapon);
}
int extra = lua_tointeger(l, -1);
lua_pop(l, 1);
return extra;
}
int LuaAttackRangeSkill::getFixed(const Player *target, bool include_weapon) const
{
if (fixed_func == 0)
return AttackRangeSkill::getFixed(target, include_weapon);
lua_State *l = Sanguosha->getLuaState();
lua_rawgeti(l, LUA_REGISTRYINDEX, fixed_func);
SWIG_NewPointerObj(l, this, SWIGTYPE_p_LuaAttackRangeSkill, 0);
SWIG_NewPointerObj(l, target, SWIGTYPE_p_Player, 0);
lua_pushboolean(l, include_weapon);
int error = lua_pcall(l, 3, 1, 0);
if (error) {
Error(l);
return AttackRangeSkill::getFixed(target, include_weapon);
}
int extra = lua_tointeger(l, -1);
lua_pop(l, 1);
return extra;
}
bool LuaInvaliditySkill::isSkillValid(const Player *player, const Skill *skill) const
{
if (skill_valid == 0)
return 0;
lua_State *L = Sanguosha->getLuaState();
lua_rawgeti(L, LUA_REGISTRYINDEX, skill_valid);
SWIG_NewPointerObj(L, this, SWIGTYPE_p_LuaInvaliditySkill, 0);
SWIG_NewPointerObj(L, player, SWIGTYPE_p_Player, 0);
SWIG_NewPointerObj(L, skill, SWIGTYPE_p_Skill, 0);
int error = lua_pcall(L, 3, 1, 0);
if (error) {
Error(L);
return true;
}
bool validity = lua_toboolean(L, -1);
lua_pop(L, 1);
return validity;
}
bool LuaFilterSkill::viewFilter(const Card *to_select) const
{
if (view_filter == 0)
return false;
lua_State *L = Sanguosha->getLuaState();
lua_rawgeti(L, LUA_REGISTRYINDEX, view_filter);
SWIG_NewPointerObj(L, this, SWIGTYPE_p_LuaFilterSkill, 0);
SWIG_NewPointerObj(L, to_select, SWIGTYPE_p_Card, 0);
int error = lua_pcall(L, 2, 1, 0);
if (error) {
Error(L);
return false;
}
bool result = lua_toboolean(L, -1);
lua_pop(L, 1);
return result;
}
const Card *LuaFilterSkill::viewAs(const Card *originalCard) const
{
if (view_as == 0)
return NULL;
lua_State *L = Sanguosha->getLuaState();
lua_rawgeti(L, LUA_REGISTRYINDEX, view_as);
SWIG_NewPointerObj(L, this, SWIGTYPE_p_LuaFilterSkill, 0);
SWIG_NewPointerObj(L, originalCard, SWIGTYPE_p_Card, 0);
int error = lua_pcall(L, 2, 1, 0);
if (error) {
Error(L);
return NULL;
}
void *card_ptr;
int result = SWIG_ConvertPtr(L, -1, &card_ptr, SWIGTYPE_p_Card, 0);
lua_pop(L, 1);
if (SWIG_IsOK(result)) {
const Card *card = static_cast<const Card *>(card_ptr);
return card;
} else
return NULL;
}
// ----------------------
void LuaViewAsSkill::pushSelf(lua_State *L) const
{
LuaViewAsSkill *self = const_cast<LuaViewAsSkill *>(this);
SWIG_NewPointerObj(L, self, SWIGTYPE_p_LuaViewAsSkill, 0);
}
bool LuaViewAsSkill::viewFilter(const QList<const Card *> &selected, const Card *to_select) const
{
if (view_filter == 0)
return false;
lua_State *L = Sanguosha->getLuaState();
lua_rawgeti(L, LUA_REGISTRYINDEX, view_filter);
pushSelf(L);
lua_createtable(L, selected.length(), 0);
for (int i = 0; i < selected.length(); i++) {
const Card *card = selected[i];
SWIG_NewPointerObj(L, card, SWIGTYPE_p_Card, 0);
lua_rawseti(L, -2, i + 1);
}
const Card *card = to_select;
SWIG_NewPointerObj(L, card, SWIGTYPE_p_Card, 0);
int error = lua_pcall(L, 3, 1, 0);
if (error) {
Error(L);
return false;
} else {
bool result = lua_toboolean(L, -1);
lua_pop(L, 1);
return result;
}
}
const Card *LuaViewAsSkill::viewAs(const QList<const Card *> &cards) const
{
if (view_as == 0)
return NULL;
lua_State *L = Sanguosha->getLuaState();
lua_rawgeti(L, LUA_REGISTRYINDEX, view_as);
pushSelf(L);
lua_createtable(L, cards.length(), 0);
for (int i = 0; i < cards.length(); i++) {
const Card *card = cards[i];
SWIG_NewPointerObj(L, card, SWIGTYPE_p_Card, 0);
lua_rawseti(L, -2, i + 1);
}
int error = lua_pcall(L, 2, 1, 0);
if (error) {
Error(L);
return NULL;
}
void *card_ptr;
int result = SWIG_ConvertPtr(L, -1, &card_ptr, SWIGTYPE_p_Card, 0);
lua_pop(L, 1);
if (SWIG_IsOK(result)) {
const Card *card = static_cast<const Card *>(card_ptr);
return card;
} else
return NULL;
}
bool LuaViewAsSkill::shouldBeVisible(const Player *player) const
{
if (should_be_visible == 0)
return ViewAsSkill::shouldBeVisible(player);
lua_State *L = Sanguosha->getLuaState();
// the callback
lua_rawgeti(L, LUA_REGISTRYINDEX, should_be_visible);
pushSelf(L);
SWIG_NewPointerObj(L, player, SWIGTYPE_p_Player, 0);
int error = lua_pcall(L, 2, 1, 0);
if (error) {
Error(L);
return false;
} else {
bool result = lua_toboolean(L, -1);
lua_pop(L, 1);
return result;
}
}
bool LuaViewAsSkill::isEnabledAtPlay(const Player *player) const
{
if (enabled_at_play == 0)
return ViewAsSkill::isEnabledAtPlay(player);
lua_State *L = Sanguosha->getLuaState();
// the callback
lua_rawgeti(L, LUA_REGISTRYINDEX, enabled_at_play);
pushSelf(L);
SWIG_NewPointerObj(L, player, SWIGTYPE_p_Player, 0);
int error = lua_pcall(L, 2, 1, 0);
if (error) {
Error(L);
return false;
} else {
bool result = lua_toboolean(L, -1);
lua_pop(L, 1);
return result;
}
}
bool LuaViewAsSkill::isEnabledAtResponse(const Player *player, const QString &pattern) const
{
if (enabled_at_response == 0)
return ViewAsSkill::isEnabledAtResponse(player, pattern);
lua_State *L = Sanguosha->getLuaState();
// the callback
lua_rawgeti(L, LUA_REGISTRYINDEX, enabled_at_response);
pushSelf(L);
SWIG_NewPointerObj(L, player, SWIGTYPE_p_Player, 0);
lua_pushstring(L, pattern.toLatin1());
int error = lua_pcall(L, 3, 1, 0);
if (error) {
Error(L);
return false;
} else {
bool result = lua_toboolean(L, -1);
lua_pop(L, 1);
return result;
}
}
bool LuaViewAsSkill::isEnabledAtNullification(const ServerPlayer *player) const
{
if (enabled_at_nullification == 0)
return ViewAsSkill::isEnabledAtNullification(player);
lua_State *L = Sanguosha->getLuaState();
// the callback
lua_rawgeti(L, LUA_REGISTRYINDEX, enabled_at_nullification);
pushSelf(L);
SWIG_NewPointerObj(L, player, SWIGTYPE_p_ServerPlayer, 0);
int error = lua_pcall(L, 2, 1, 0);
if (error) {
Error(L);
return false;
} else {
bool result = lua_toboolean(L, -1);
lua_pop(L, 1);
return result;
}
}
// ---------------------
void LuaSkillCard::pushSelf(lua_State *L) const
{
LuaSkillCard *self = const_cast<LuaSkillCard *>(this);
SWIG_NewPointerObj(L, self, SWIGTYPE_p_LuaSkillCard, 0);
}
bool LuaSkillCard::targetFilter(const QList<const Player *> &targets, const Player *to_select, const Player *self,
int &maxVotes) const
{
if (filter == 0) {
return SkillCard::targetFilter(targets, to_select, self, maxVotes);
}
lua_State *L = Sanguosha->getLuaState();
// the callback
lua_rawgeti(L, LUA_REGISTRYINDEX, filter);
pushSelf(L);
lua_createtable(L, targets.length(), 0);
for (int i = 0; i < targets.length(); ++i) {
SWIG_NewPointerObj(L, targets.at(i), SWIGTYPE_p_Player, 0);
lua_rawseti(L, -2, i + 1);
}
SWIG_NewPointerObj(L, to_select, SWIGTYPE_p_Player, 0);
SWIG_NewPointerObj(L, self, SWIGTYPE_p_Player, 0);
int error = lua_pcall(L, 4, 2, 0);
if (error) {
Error(L);
return false;
} else {
if (lua_isnumber(L, -1) && lua_isboolean(L, -2)) {
int vote = lua_tointeger(L, -1);
maxVotes = vote;
bool result = lua_toboolean(L, -2);
lua_pop(L, 2);
return result;
}
}
return false;
}
bool LuaSkillCard::targetsFeasible(const QList<const Player *> &targets, const Player *self) const
{
if (feasible == 0)
return SkillCard::targetsFeasible(targets, self);
lua_State *L = Sanguosha->getLuaState();
// the callback
lua_rawgeti(L, LUA_REGISTRYINDEX, feasible);
pushSelf(L);
lua_createtable(L, targets.length(), 0);
for (int i = 0; i < targets.length(); i++) {
SWIG_NewPointerObj(L, targets.at(i), SWIGTYPE_p_Player, 0);
lua_rawseti(L, -2, i + 1);
}
SWIG_NewPointerObj(L, self, SWIGTYPE_p_Player, 0);
int error = lua_pcall(L, 3, 1, 0);
if (error) {
Error(L);
return false;
} else {
bool result = lua_toboolean(L, -1);
lua_pop(L, 1);
return result;
}
}
void LuaSkillCard::onUse(Room *room, const CardUseStruct &card_use) const
{
if (about_to_use == 0)
return SkillCard::onUse(room, card_use);