-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathplayer.lua
1661 lines (1524 loc) · 52.5 KB
/
player.lua
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
Player = class()
-- 使用某张卡
Player.use = {}
-- 响应某张卡或某个技能
Player.respond = {}
-- 使用某个技能
Player.skill = {}
-- 检查某个主动技能是否可以发动
Player.check_skill = {}
-- 获取某张卡或某个技能可以操作的目标玩家
Player.get_targets = {}
-- 获取一个t, 该t存储某个技能可以操作的玩家和卡, 不同技能的t的内部结构也不同, 但都是key_value的形式
Player.get_t = {}
function Player:ctor(id, hero_id, order)
self.id = id
self.hero_id = hero_id
self.order = order
self.name = resmng[hero_id].name
self.sex = resmng[hero_id].sex
self.hand_cards = {}
self.judge_cards = {}
self.arm = nil
self.armor = nil
self.add_horese = nil
self.sub_horse = nil
self.skills = {}
helper.insert(self.skills, resmng[hero_id].skills)
self.flags = {}
self.toward = macro.toward.up
self.life = resmng[hero_id].life
self.life_limit = resmng[hero_id].life
end
function Player:has_skill(skill_name)
for _, id in ipairs(self.skills) do
if resmng[id] == skill_name then
return true
end
end
end
function Player:has_flag(flag_name)
return self.flags[flag_name]
end
function Player:get_hand_cards_limit()
return self.life
end
function Player:has_equip(type)
return self[type] and true or false
end
function Player:get_equip_cards()
local cards = {}
if self.arm then
helper.insert(cards, self.arm)
end
if self.armor then
helper.insert(cards, self.armor)
end
if self.add_horse then
helper.insert(cards, self.add_horse)
end
if self.sub_horse then
helper.insert(cards, self.sub_horse)
end
return cards
end
function Player:put_on_equip(id)
local type = resmng[id].type
self[type] = id
if type == "arm" or type == "armor" then
helper.insert(self.skills, resmng[id].skill)
end
end
function Player:take_off_equip(id)
local type = resmng[id].type
self[type] = nil
if type == "arm" or type == "armor" then
helper.remove(self.skills, resmng[id].skill)
end
end
function Player:get_distance(another)
local i1 = self.order
local i2 = another.order
local dis = math.min(math.abs(i1 - i2), #game.players - math.abs(i1 - i2))
if self.sub_horse then
dis = dis - 1
end
if another.add_horse then
dis = dis + 1
end
return dis > 0 and dis or 0
end
function Player:get_players_in_attack_range()
local targets = {}
local attack_range = self.arm and resmng[self.arm].range or 1
for _, target in ipairs(game:get_other_players(self)) do
if self:get_distance(target) <= attack_range then
helper.insert(targets, target)
end
end
return targets
end
function Player:get_suit(id)
return resmng[id].suit
end
function Player:get_color(id)
local suit = self:get_suit(id)
if suit == macro.suit.spade or suit == macro.suit.club then
return macro.color.black
else
return macro.color.red
end
end
function Player:get_cards(func, use_hand_cards, use_equip_cards, use_judge_cards)
local cards = {}
if use_hand_cards then
for _, id in ipairs(self.hand_cards) do
if func and func(id) or not func then
helper.insert(cards, id)
end
end
end
if use_equip_cards then
for _, id in ipairs(self:get_equip_cards()) do
if func and func(id) or not func then
helper.insert(cards, id)
end
end
end
if use_judge_cards then
for _, id in ipairs(self.judge_cards) do
if func and func(id) or not func then
helper.insert(cards, id)
end
end
end
return cards
end
function Player:check_alive()
return game.players[self.order] == self
end
function Player:check_jump_turn()
if self.toward == macro.toward.down then
self:flip()
return true
end
end
function Player:flip()
if self.toward == macro.toward.up then
self.toward = macro.toward.down
helper.remove(self.skills, resmng[self.hero_id].skills)
else
self.toward = macro.toward.up
helper.insert(self.skills, resmng[self.hero_id].skills)
end
end
function Player:before_turn()
game.whose_turn = self
self.flags["杀-剩余次数"] = 1
end
function Player:turn()
self:start()
self:judge()
if not self:check_alive() or game.finish then
return
end
self:draw()
if not self:check_alive() or game.finish then
return
end
self:play()
if not self:check_alive() or game.finish then
return
end
self:discard()
if not self:check_alive() or game.finish then
return
end
self:finish()
end
Player.skill["回合开始阶段"] = function (self)
end
function Player:start()
text("现在是%s的回合开始阶段", self.name)
self.skill["回合开始阶段"](self)
end
Player.skill["判定阶段开始前"] = function (self)
end
function Player:judge()
text("现在是%s的判定阶段", self.name)
self.skill["判定阶段开始前"](self)
if self:has_flag("跳过判定") then
return
end
local judge_cards = {}
for _, id in ipairs(self.judge_cards) do
helper.insert(judge_cards, id)
end
for _, id in ipairs(judge_cards) do
local name = game:get_judge_card_name(id)
self.respond[name](self, id)
if name == "乐不思蜀" then
game.transfer_delay_tactics[id] = nil
end
end
end
Player.skill["摸牌阶段开始前"] = function (self)
end
function Player:draw()
text("现在是%s的摸牌阶段", self.name)
self.skill["摸牌阶段开始前"](self)
if self:has_flag("跳过摸牌") then
return
end
helper.insert(self.hand_cards, deck:draw(2))
end
Player.skill["出牌阶段开始前"] = function (self)
end
function Player:play()
text("现在是%s的出牌阶段", self.name)
self.skill["出牌阶段开始前"](self)
if self:has_flag("跳过出牌") then
return
end
while true do
print_game_info()
local id = query["出牌阶段"](self)
if resmng.check_card(id) then
self:use_card(id)
elseif resmng.check_skill(id) then
self:use_skill(id)
else
break
end
if not self:check_alive() or game.finish then
return
end
end
end
Player.skill["弃牌阶段开始前"] = function (self)
end
function Player:discard()
text("现在是%s的弃牌阶段", self.name)
self.skill["弃牌阶段开始前"](self)
if self:has_flag("跳过弃牌") then
return
end
local hand_cards_limit = self:get_hand_cards_limit()
local n = #self.hand_cards - hand_cards_limit
if n > 0 then
local cards = opt["弃置n张牌"](self, self, "普通弃牌", true, false, n)
local settle_players = game:get_settle_players_except_self(self)
for _, player in ipairs(settle_players) do
if player:has_skill("固政") then
player.skill["固政"](player, self, cards)
break
end
end
end
end
Player.skill["回合结束阶段"] = function (self)
end
function Player:finish()
text("现在是%s的回合结束阶段", self.name)
self.skill["回合结束阶段"](self)
end
function Player:after_turn()
helper.clear(self.flags)
end
function Player:before_settle(id)
helper.put(game.settling_card, id)
end
function Player:after_settle(id)
-- 结算完的牌可能由于曹操-奸雄等技能已经从结算区被拿走,所以要判断下再放入弃牌区
if not helper.equal(game.settling_card[#game.settling_card], id) then
return
end
helper.pop(game.settling_card)
if type(id) == "number" and resmng[id].name == "南蛮入侵" then
local settle_players = game:get_settle_players(game.whose_turn)
local need_discard = true
for _, player in ipairs(settle_players) do
if player:has_skill("巨象") then
if player.skill["巨象"](player, id) then
need_discard = false
end
break
end
end
if need_discard then
helper.insert(deck.discard_pile, id)
end
else
helper.insert(deck.discard_pile, id)
end
end
Player.skill["失去手牌"] = function (self, causer, responder, reason)
end
Player.skill["失去装备"] = function (self)
end
Player.skill["改判"] = function (self, id, judge_player, reason)
end
function Player:use_card(id)
local type = resmng[id].type
local name = resmng[id].name
helper.remove(self.hand_cards, id)
game.skill["失去手牌"](game, self, self, "使用")
if type == "basic" then
self:before_settle(id)
if name == "杀" then
self.use["杀"](self, {id = id})
elseif name == "桃" then
self.use["桃"](self, self)
end
self:after_settle(id)
elseif type == "tactic" then
if name == "乐不思蜀" or name == "闪电" then
self.use[name](self, id)
else
if self:has_skill("集智") then
self.skill["集智"](self)
end
self:before_settle(id)
self.use[name](self, id)
self:after_settle(id)
end
else
if not self:has_equip(type) then
self:put_on_equip(id)
else
local old_equip_id = self[type]
self:take_off_equip(old_equip_id)
helper.insert(deck.discard_pile, old_equip_id)
self:put_on_equip(id)
end
end
end
function Player:get_can_use_cards()
local cards = {}
for _, id in ipairs(self.hand_cards) do
local type = resmng[id].type
local name = resmng[id].name
if type ~= "basic" and type ~= "tactic" then
helper.insert(cards, id)
elseif name == "杀" then
if self:check_can_kill() and next(self.get_targets["杀"](self, {id = id})) then
helper.insert(cards, id)
end
elseif name == "闪" or name == "无懈可击" then
goto continue
elseif name == "桃" then
if self.life == self.life_limit then
goto continue
end
helper.insert(cards, id)
elseif name == "无中生有" or name == "五谷丰登" or name == "桃园结义" then
helper.insert(cards, id)
elseif name == "闪电" then
if self:has_skill("帷幕") and self:get_color(id) == macro.color.black then
goto continue
end
helper.insert(cards, id)
else
if not next(self.get_targets[name](self, id)) then
goto continue
end
helper.insert(cards, id)
end
::continue::
end
return cards
end
function Player:get_can_use_skills()
local skills = {}
for _, id in ipairs(self.skills) do
if self.check_skill[resmng[id]] and self.check_skill[resmng[id]](self) then
helper.insert(skills, id)
end
end
return skills
end
function Player:use_skill(id)
if resmng[id] == "武圣" then
self.skill["武圣"](self, "正常出杀")
elseif resmng[id] == "龙胆" then
self.skill["龙胆"](self, "正常出杀")
else
self.skill[resmng[id]](self)
end
end
Player.skill["杀"] = function (self, id, reason, ...)
self.skill[resmng[id]](self, reason, ...)
end
Player.skill["闪"] = function (self, id, reason)
self.skill[resmng[id]](self, reason)
end
Player.skill["桃"] = function (self, id)
self.skill[resmng[id]](self)
end
Player.skill["无懈可击"] = function (self, id)
self.skill[resmng[id]](self)
end
function Player:get_skills_can_be_card(card_name)
local skills = {}
if card_name == "杀" then
for _, id in ipairs(self.skills) do
if resmng[id] == "武圣" then
local func = function (id1) return self:get_color(id1) == macro.color.red end
if next(self:get_cards(func, true, true)) then
helper.insert(skills, id)
end
elseif resmng[id] == "龙胆" then
local func = function (id1) return resmng[id1].name == "闪" end
if next(self:get_cards(func, true)) then
helper.insert(skills, id)
end
elseif resmng[id] == "丈八蛇矛" then
if self.hand_cards >= 2 then
helper.insert(skills, id)
end
end
end
elseif card_name == "闪" then
for _, id in ipairs(self.skills) do
if resmng[id] == "倾国" then
local func = function (id1) return self:get_color(id1) == macro.color.black end
if next(self:get_cards(func, true)) then
helper.insert(skills, id)
end
elseif resmng[id] == "龙胆" then
local func = function (id1) return resmng[id1].name == "杀" end
if next(self:get_cards(func, true)) then
helper.insert(skills, id)
end
end
end
elseif card_name == "无懈可击" then
for _, id in ipairs(self.skills) do
if resmng[id] == "看破" then
local func = function (id1) return self:get_color(id1) == macro.color.black end
local cards = self:get_cards(func, true)
if next(cards) then
helper.insert(skills, id)
end
elseif resmng[id] == "解围" then
local cards = self:get_cards(nil, false, true)
if next(cards) then
helper.insert(skills, id)
end
end
end
end
return skills
end
Player.get_targets["乱武"] = function (self)
local targets = {}
local min_dis
for _, target in ipairs(self:get_players_in_attack_range()) do
local dis = self:get_distance(target)
if next(targets) then
if dis < min_dis then
min_dis = dis
targets = {target}
elseif dis == min_dis then
helper.insert(targets, target)
end
else
min_dis = dis
targets = {target}
end
end
for _, target in ipairs(targets) do
if target:has_skill("空城") and #target.hand_cards == 0 then
helper.remove(targets, target)
end
end
return targets
end
Player.respond["乱武"] = function (self)
local targets = self.get_targets["乱武"](self)
if not next(targets) then
self:sub_life({causer = self, type = macro.sub_life_type.life_loss, name = "乱武", card_id = nil, n = 1})
return
end
if not helper.element(self:get_players_in_attack_range(), targets[1]) then
self:sub_life({causer = self, type = macro.sub_life_type.life_loss, name = "乱武", card_id = nil, n = 1})
return
end
local func = function (id) return resmng[id].name == "杀" end
local kills = self:get_cards(func, true)
local skills = self:get_skills_can_be_card("杀")
if next(kills) or next(skills) then
local id = query["询问出牌"](kills, skills, "杀")
if resmng.check_card(id) then
helper.remove(self.hand_cards, id)
game.skill["失去手牌"](game, self, self, "使用")
self:before_settle(id)
self.use["杀"](self, {id = id}, "乱武", targets)
self:after_settle(id)
elseif resmng.check_skill(id) then
self.skill["杀"](self, id, "乱武", targets)
else
self:sub_life({causer = self, type = macro.sub_life_type.life_loss, name = "乱武", card_id = nil, n = 1})
end
else
self:sub_life({causer = self, type = macro.sub_life_type.life_loss, name = "乱武", card_id = nil, n = 1})
end
end
function Player:check_can_kill()
if self:has_flag("天义-输") then
return false
end
if not (self:has_skill("诸葛连弩") or self:has_skill("咆哮") or self.flags["杀-剩余次数"] > 0) then
return false
end
return true
end
-- 杀的t结构示例
-- t = {is_transfer = true,
-- transfer_type = "神速",
-- id = 1,
-- targets = {},
-- invalid = {},
-- can_dodge = {},
-- need_dodge = 2,
-- damage = {}}
Player.use["杀"] = function (self, t, reason, ...)
if self:has_skill("克己") and game.whose_turn == self then
self.flags["使用或打出过杀"] = true
end
if not reason then
reason = "正常出杀"
end
if reason == "正常出杀" then
self.flags["杀-剩余次数"] = self.flags["杀-剩余次数"] - 1
self:kill_set_target(t, self.get_targets["杀"](self, t))
elseif reason == "神速" then
self:kill_set_target(t, self.get_targets["杀"](self, t))
elseif reason == "借刀杀人" or reason == "挑衅" then
local target = ...
t.targets = {target}
self:kill_set_extra_target(t)
elseif reason == "青龙偃月刀" then
local target = ...
t.targets = {target}
self:kill_set_args(t)
elseif reason == "乱武" then
local targets = ...
self:kill_set_target(t, targets)
end
end
function Player:kill_set_target(t, targets)
t.targets = {}
local target = query["选择一名玩家"](targets, "杀")
helper.insert(t.targets, target)
self:kill_set_extra_target(t)
end
local function adjust_kill_targets_order(causer, targets)
local targets1 = {}
local settle_players = game:get_settle_players_except_self(causer)
for _, target in ipairs(settle_players) do
local flag = true
-- targets中同一个target可能有多个,所以要用while
while flag do
if helper.element(targets, target) then
helper.remove(targets, target)
helper.insert(targets1, target)
else
flag = false
end
end
end
return targets1
end
function Player:kill_set_extra_target(t)
local n = 0
if self:has_flag("天义-赢") then
n = n + 1
end
if self:has_skill("方天画戟") and #self.hand_cards == 0 and t.transfer_type ~= "神速" then
n = n + 2
end
local targets = self.get_targets["杀"](self, t)
helper.remove(targets, t.targets)
if n > #targets then
n = #targets
end
if n > 0 then
text("本次杀你可以额外指定%d名目标", n)
end
for _ = 1, n, 1 do
if not next(targets) then
break
end
if not query["二选一"]("是否继续指定杀的目标") then
break
end
local target = query["选择一名玩家"](targets, "杀")
helper.remove(targets, target)
helper.insert(t.targets, target)
end
self:kill_set_args(t)
end
function Player:kill_set_args(t)
for _, target in ipairs(t.targets) do
if target:has_skill("流离") then
local new_target = target.skill["流离"](target, self)
if new_target then
helper.remove(t.targets, target)
helper.insert(t.targets, new_target)
end
break
end
end
if #t.targets > 1 then
t.targets = adjust_kill_targets_order(self, t.targets)
end
t.need_dodge = {}
for _, target in ipairs(t.targets) do
t.need_dodge[target] = 1
if self:has_skill("无双") then
t.need_dodge[target] = t.need_dodge[target] + 1
end
end
t.can_dodge = {}
for _, target in ipairs(t.targets) do
t.can_dodge[target] = true
if self:has_skill("烈弓") and #self.hand_cards >= #target.hand_cards then
t.can_dodge[target] = false
end
end
t.damage = {}
for _, target in ipairs(t.targets) do
t.damage[target] = 1
if self:has_flag("裸衣") then
t.damage[target] = t.damage[target] + 1
end
if self:has_skill("烈弓") and self.life <= target.life then
t.damage[target] = t.damage[target] + 1
end
end
local not_duplicate_targets = {}
local last_target
for _, target in ipairs(t.targets) do
if target ~= last_target then
helper.insert(not_duplicate_targets, target)
last_target = target
end
end
for _, target in ipairs(not_duplicate_targets) do
self.skill["杀-指定目标后"](self, target, t)
end
t.invalid = {}
for _, target in ipairs(not_duplicate_targets) do
target.skill["杀-成为目标后"](target, self, t)
end
for _, target in ipairs(t.targets) do
if not self:has_skill("青釭剑") then
if target:has_skill("仁王盾") and self:get_kill_color(t) == macro.color.black then
t.invalid[target] = true
end
end
end
for _, target in ipairs(t.targets) do
target.respond["杀"](target, self, t)
end
end
Player.respond["杀"] = function (self, causer, t)
if t.invalid[self] then
return
end
if not t.can_dodge[self] then
self:sub_life({causer = causer, type = macro.sub_life_type.damage, name = "杀", card_id = t.id, n = t.damage[self]})
return
end
if not causer:has_skill("青釭剑") then
local skill_name
if self:has_skill("八卦阵") then
skill_name = "八卦阵"
elseif self:has_skill("八阵") then
skill_name = "八阵"
end
if skill_name then
while t.need_dodge[self] > 0 do
if self.skill[skill_name](self) then
if self:has_skill("雷击") then
self.skill["雷击"](self)
end
if game.finish then
return
end
t.need_dodge[self] = t.need_dodge[self] - 1
else
break
end
end
end
end
while t.need_dodge[self] > 0 do
local func = function (id) return resmng[id].name == "闪" end
local dodges = self:get_cards(func, true)
local skills = self:get_skills_can_be_card("闪")
if next(dodges) or next(skills) then
local id = query["询问出牌"](dodges, skills, "闪")
if resmng.check_card(id) then
helper.remove(self.hand_cards, id)
game.skill["失去手牌"](game, self, self, "使用")
helper.insert(deck.discard_pile, id)
if self:has_skill("雷击") then
self.skill["雷击"](self)
end
if game.finish then
return
end
t.need_dodge[self] = t.need_dodge[self] - 1
elseif resmng.check_skill(id) then
self.skill["闪"](self, id, "被杀")
t.need_dodge[self] = t.need_dodge[self] - 1
else
break
end
else
break
end
end
if t.need_dodge[self] == 0 then
if causer:check_alive() then
if causer:has_skill("贯石斧") then
causer.skill["贯石斧"](causer, self, t)
elseif causer:has_skill("青龙偃月刀") then
causer.skill["青龙偃月刀"](causer, self)
end
end
else
self:sub_life({causer = causer, type = macro.sub_life_type.damage, name = "杀", card_id = t.id, n = t.damage[self]})
end
end
function Player:get_kill_color(t)
local color
if t.is_transfer then
if t.transfer_type == "丈八蛇矛" then
local color1 = self:get_color(t.id[1])
local color2 = self:get_color(t.id[2])
if color1 == color2 then
color = color1
end
elseif t.transfer_type == "神速" then
color = nil
end
else
color = self:get_color(t.id)
end
return color
end
Player.skill["杀-指定目标后"] = function (self, target, t)
if self:has_skill("雌雄双股剑") then
self.skill["雌雄双股剑"](self, target)
end
end
Player.skill["杀-成为目标后"] = function (target, self, t)
end
Player.skill["决斗-指定目标后"] = function (self, id)
end
Player.skill["决斗-成为目标后"] = function (self, causer, id)
end
Player.use["桃"] = function (self, target)
target:add_life(1)
end
Player.skill["八卦阵"] = function (self)
if not query["询问发动技能"]("八卦阵") then
return false
end
local id = game:judge(self, "八卦阵")
if not (self:has_skill("天妒") and self.skill["天妒"](self, id)) then
helper.insert(deck.discard_pile, id)
end
return self:get_color(id) == macro.color.red and true or false
end
Player.check_skill["丈八蛇矛"] = function (self)
if not self:check_can_kill() then
return false
end
if #self.hand_cards < 2 then
return false
end
return true
end
Player.skill["丈八蛇矛"] = function (self, reason, ...)
local id1 = query["选择一张牌"](self.hand_cards, "丈八蛇矛")
helper.remove(self.hand_cards, id1)
local id2 = query["选择一张牌"](self.hand_cards, "丈八蛇矛")
helper.remove(self.hand_cards, id2)
local ids = {id1, id2}
game.skill["失去手牌"](game, self, self, "使用")
if not reason then
reason = "正常出杀"
end
if reason == "南蛮入侵" or reason == "决斗" then
helper.insert(deck.discard_pile, ids)
else
self:before_settle(ids)
self.use["杀"](self, {is_transfer = true, transfer_type = "丈八蛇矛", id = ids}, reason, ...)
self:after_settle(ids)
end
end
Player.skill["雌雄双股剑"] = function (self, target, t)
if self.sex == target.sex then
return
end
if not query["询问发动技能"]("雌雄双股剑") then
return
end
local hand_cards = target.hand_cards
if #hand_cards == 0 then
helper.insert(self.hand_cards, deck:draw(1))
else
if query["二选一"]("雌雄双股剑") then
opt["弃置一张牌"](target, target, "雌雄双股剑", true)
else
helper.insert(self.hand_cards, deck:draw(1))
end
end
end
Player.skill["贯石斧"] = function (self, target, t)
local func = function (id) return resmng[id].name ~= "贯石斧" end
if #self:get_cards(func, true, true) < 2 then
return
end
if not query["询问发动技能"]("贯石斧") then
return
end
opt["弃置n张牌"](self, self, "贯石斧", true, true, 2, func)
target:sub_life({causer = self, type = macro.sub_life_type.damage, name = "杀", card_id = t.id, n = t.damage[target]})
end
Player.skill["青龙偃月刀"] = function (self, target)
local func = function (id) return resmng[id].name == "杀" end
local kills = self:get_cards(func, true)
local skills = self:get_skills_can_be_card("杀")
if not next(kills) and not next(skills) then
return
end
if not query["询问发动技能"]("青龙偃月刀") then
return
end
local id = query["询问出牌"](kills, skills, "杀")
if resmng.check_card(id) then
helper.remove(self.hand_cards, id)
game.skill["失去手牌"](game, self, self, "使用")
self:before_settle(id)
self.use["杀"](self, {id = id}, "青龙偃月刀", target)
self:after_settle(id)
elseif resmng.check_skill(id) then
self.skill["杀"](self, id, "青龙偃月刀", target)
end
end
Player.skill["寒冰剑"] = function (self, causer, target, t)
if self ~= causer then
return
end
local cards = target:get_cards(nil, true, true)
if not next(cards) then
return
end
if not query["询问发动技能"]("寒冰剑") then
return
end
opt["弃置一张牌"](self, target, "寒冰剑", true, true)
if next(target:get_cards(nil, true, true)) then
opt["弃置一张牌"](self, target, "寒冰剑", true, true)
end
t.settle_finish = true
end
Player.skill["麒麟弓"] = function (self, causer, target, t)
if self ~= causer then
return
end
if t.name ~= "杀" then
return
end
local func = function (id) return resmng[id].type == "add_horse" or resmng[id].type == "sub_horse" end
if not next(target:get_cards(func, false, true)) then
return
end
if not query["询问发动技能"]("麒麟弓") then
return
end
opt["弃置一张牌"](self, target, "麒麟弓", false, true, false, func)
end
function Player:add_life(n)
if self.life + n > self.life_limit then
self.life = self.life_limit
else
self.life = self.life + n
end
end
-- t包含casuer, type, name, card_id(牌), n, settle_finish
function Player:sub_life(t)
-- 体力流失
if t.type == macro.sub_life_type.life_loss then
self.life = self.life - t.n
text("%s因%s流失%d点体力", self.name, t.name, t.n)
if self.life <= 0 then
self:dying(t)
end
-- 受到伤害