This repository has been archived by the owner on Jun 6, 2023. It is now read-only.
forked from Mystery333/QSanguoshaAI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnostalgia-ai.lua
948 lines (838 loc) · 33.3 KB
/
nostalgia-ai.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
sgs.weapon_range.MoonSpear = 3
sgs.ai_use_priority.MoonSpear = 2.635
nosjujian_skill = {}
nosjujian_skill.name = "nosjujian"
table.insert(sgs.ai_skills, nosjujian_skill)
nosjujian_skill.getTurnUseCard = function(self)
if self:needBear() then return end
if not self.player:hasUsed("NosJujianCard") then return sgs.Card_Parse("@NosJujianCard=.") end
end
sgs.ai_skill_use_func.NosJujianCard = function(card, use, self)
local abandon_card = {}
local index = 0
local hasPeach = (self:getCardsNum("Peach") > 0)
local to
local AssistTarget = self:AssistTarget()
if AssistTarget and self:willSkipPlayPhase(AssistTarget) then AssistTarget = nil end
local trick_num, basic_num, equip_num = 0, 0, 0
if not hasPeach and self.player:isWounded() and self.player:getCards("he"):length() >=3 then
local cards = self.player:getCards("he")
cards = sgs.QList2Table(cards)
self:sortByUseValue(cards, true)
for _, card in ipairs(cards) do
if card:getTypeId() == sgs.Card_TypeTrick and not isCard("ExNihilo", card, self.player) then trick_num = trick_num + 1
elseif card:getTypeId() == sgs.Card_TypeBasic then basic_num = basic_num + 1
elseif card:getTypeId() == sgs.Card_TypeEquip then equip_num = equip_num + 1
end
end
local result_class
if trick_num >= 3 then result_class = "TrickCard"
elseif equip_num >= 3 then result_class = "EquipCard"
elseif basic_num >= 3 then result_class = "BasicCard"
end
for _, fcard in ipairs(cards) do
if fcard:isKindOf(result_class) and not isCard("ExNihilo", fcard, self.player) then
table.insert(abandon_card, fcard:getId())
index = index + 1
if index == 3 then break end
end
end
if index == 3 then
if AssistTarget and not AssistTarget:hasSkill("manjuan") then
to = AssistTarget
else
to = self:findPlayerToDraw(false, 3)
end
if not to then return end
if use.to then use.to:append(to) end
use.card = sgs.Card_Parse("@NosJujianCard=" .. table.concat(abandon_card, "+"))
return
end
end
abandon_card = {}
local cards = self.player:getHandcards()
cards = sgs.QList2Table(cards)
self:sortByUseValue(cards, true)
local slash_num = self:getCardsNum("Slash")
local jink_num = self:getCardsNum("Jink")
index = 0
for _, card in ipairs(cards) do
if index >= 3 then break end
if card:isKindOf("TrickCard") and not card:isKindOf("Nullification") then
table.insert(abandon_card, card:getId())
index = index + 1
elseif card:isKindOf("EquipCard") then
table.insert(abandon_card, card:getId())
index = index + 1
elseif card:isKindOf("Slash") then
table.insert(abandon_card, card:getId())
index = index + 1
slash_num = slash_num - 1
elseif card:isKindOf("Jink") and jink_num > 1 then
table.insert(abandon_card, card:getId())
index = index + 1
jink_num = jink_num - 1
end
end
if index == 3 then
if AssistTarget and not AssistTarget:hasSkill("manjuan") then
to = AssistTarget
else
to = self:findPlayerToDraw(false, 3)
end
if not to then return end
if use.to then use.to:append(to) end
use.card = sgs.Card_Parse("@NosJujianCard=" .. table.concat(abandon_card, "+"))
return
end
if self:getOverflow() > 0 then
local getOverflow = math.max(self:getOverflow(), 0)
local discard = self:askForDiscard("dummyreason", math.min(getOverflow, 3), nil, false, true)
if AssistTarget and not AssistTarget:hasSkill("manjuan") and not self:needKongcheng(AssistTarget, true) then
to = AssistTarget
else
to = self:findPlayerToDraw(false, math.min(getOverflow, 3))
end
if not to then return end
use.card = sgs.Card_Parse("@NosJujianCard=" .. table.concat(discard, "+"))
if use.to then use.to:append(to) end
return
end
if index > 0 then
if AssistTarget and not AssistTarget:hasSkill("manjuan") and not self:needKongcheng(AssistTarget, true) then
to = AssistTarget
else
to = self:findPlayerToDraw(false, index)
end
if not to then return end
use.card = sgs.Card_Parse("@NosJujianCard=" .. table.concat(abandon_card, "+"))
if use.to then use.to:append(to) end
return
end
end
sgs.ai_use_priority.NosJujianCard = 0
sgs.ai_use_value.NosJujianCard = 6.7
sgs.ai_card_intention.NosJujianCard = -100
sgs.dynamic_value.benefit.NosJujianCard = true
sgs.ai_skill_cardask["@enyuanheart"] = function(self, data)
local damage = data:toDamage()
if self:needToLoseHp(self.player, damage.to, nil, true) and not self:hasSkills(sgs.masochism_skill) then return "." end
if self:isFriend(damage.to) then return end
if self:needToLoseHp() and not self:hasSkills(sgs.masochism_skill) then return "." end
local cards = self.player:getHandcards()
for _, card in sgs.qlist(cards) do
if card:getSuit() == sgs.Card_Heart and not isCard("Peach", card, self.player) and not isCard("ExNihilo", card, self.player) then
return card:getEffectiveId()
end
end
return "."
end
function sgs.ai_slash_prohibit.nosenyuan(self, from, to, card)
if from:hasSkill("jueqing") then return false end
if from:hasSkill("nosqianxi") and from:distanceTo(to) == 1 then return false end
if from:hasFlag("NosJiefanUsed") then return false end
if self:needToLoseHp(from) and not self:hasSkills(sgs.masochism_skill, from) then return false end
if from:getHp() > 3 then return false end
local role = from:objectName() == self.player:objectName() and from:getRole() or sgs.ai_role[from:objectName()]
if (role == "loyalist" or role == "lord") and sgs.current_mode_players.rebel + sgs.current_mode_players.renegade == 1
and to:getHp() == 1 and getCardsNum("Peach", to, self.player) < 1 and getCardsNum("Analeptic", to, self.player) < 1
and (from:getHp() > 1 or getCardsNum("Peach", from, self.player) >= 1 and getCardsNum("Analeptic", from, self.player) >= 1) then
return false
end
if role == "rebel" and isLord(to) and self:getAllPeachNum(player) < 1 and to:getHp() == 1
and (from:getHp() > 1 or getCardsNum("Peach", from, self.player) >= 1 and getCardsNum("Analeptic", from, self.player) >= 1) then
return false
end
if role == "renegade" and from:aliveCount() == 2 and to:getHp() == 1 and getCardsNum("Peach", to, self.player) < 1 and getCardsNum("Analeptic", to, self.player) < 1
and (from:getHp() > 1 or getCardsNum("Peach", from, self.player) >= 1 and getCardsNum("Analeptic", from, self.player) >= 1) then
return false
end
local n = 0
local cards = from:getHandcards()
for _, card in sgs.qlist(cards) do
if card:getSuit() == sgs.Card_Heart and not isCard("Peach", card, from) and not isCard("ExNihilo", card, from) then
if not card:isKindOf("Slash") then return false end
n = n + 1
end
end
if n < 1 then return true end
if n > 1 then return false end
if n == 1 then return card:getSuit() == sgs.Card_Heart end
return self:isWeak(from)
end
sgs.ai_need_damaged.nosenyuan = function (self, attacker, player)
if player:hasSkill("nosenyuan") and attacker and self:isEnemy(attacker, player) and self:isWeak(attacker)
and not (self:needToLoseHp(attacker) and not self:hasSkills(sgs.masochism_skill, attacker)) then
return true
end
return false
end
nosxuanhuo_skill = {}
nosxuanhuo_skill.name = "nosxuanhuo"
table.insert(sgs.ai_skills, nosxuanhuo_skill)
nosxuanhuo_skill.getTurnUseCard = function(self)
if not self.player:hasUsed("NosXuanhuoCard") then
return sgs.Card_Parse("@NosXuanhuoCard=.")
end
end
sgs.ai_skill_use_func.NosXuanhuoCard = function(card, use, self)
local cards = self.player:getHandcards()
cards = sgs.QList2Table(cards)
self:sortByKeepValue(cards)
local target
for _, friend in ipairs(self.friends_noself) do
if self:hasSkills(sgs.lose_equip_skill, friend) and not friend:getEquips():isEmpty() and not friend:hasSkill("manjuan") then
target = friend
break
end
end
if not target then
for _, enemy in ipairs(self.enemies) do
if self:getDangerousCard(enemy) then
target = enemy
break
end
end
end
if not target then
for _, friend in ipairs(self.friends_noself) do
if self:needToThrowArmor(friend) and not friend:hasSkill("manjuan") then
target = friend
break
end
end
end
if not target then
self:sort(self.enemies, "handcard")
for _, enemy in ipairs(self.enemies) do
if self:getValuableCard(enemy) then
target = enemy
break
end
if target then break end
local cards = sgs.QList2Table(enemy:getHandcards())
local flag = string.format("%s_%s_%s", "visible", self.player:objectName(), enemy:objectName())
if not enemy:isKongcheng() and not enemy:hasSkills("tuntian+zaoxian") then
for _, cc in ipairs(cards) do
if (cc:hasFlag("visible") or cc:hasFlag(flag)) and (cc:isKindOf("Peach") or cc:isKindOf("Analeptic")) then
target = enemy
break
end
end
end
if target then break end
if self:getValuableCard(enemy) then
target = enemy
break
end
if target then break end
end
end
if not target then
for _, friend in ipairs(self.friends_noself) do
if friend:hasSkills("tuntian+zaoxian") and not friend:hasSkill("manjuan") then
target = friend
break
end
end
end
if not target then
for _, enemy in ipairs(self.enemies) do
if not enemy:isNude() and enemy:hasSkill("manjuan") then
target = enemy
break
end
end
end
if target then
local willUse
if self:isFriend(target) then
for _, card in ipairs(cards) do
if card:getSuit() == sgs.Card_Heart then
willUse = card
break
end
end
else
for _, card in ipairs(cards) do
if card:getSuit() == sgs.Card_Heart and not isCard("Peach", card, target) and not isCard("Nullification", card, target) then
willUse = card
break
end
end
end
if willUse then
target:setFlags("AI_NosXuanhuoTarget")
use.card = sgs.Card_Parse("@NosXuanhuoCard=" .. willUse:getEffectiveId())
if use.to then use.to:append(target) end
end
end
end
sgs.ai_skill_playerchosen.nosxuanhuo = function(self, targets)
for _, player in sgs.qlist(targets) do
if (player:getHandcardNum() <= 2 or player:getHp() < 2) and self:isFriend(player)
and not player:hasFlag("AI_NosXuanhuoTarget") and not self:needKongcheng(player, true) and not player:hasSkill("manjuan") then
return player
end
end
for _, player in sgs.qlist(targets) do
if self:isFriend(player)
and not player:hasFlag("AI_NosXuanhuoTarget") and not self:needKongcheng(player, true) and not player:hasSkill("manjuan") then
return player
end
end
for _, player in sgs.qlist(targets) do
if player == self.player then
return player
end
end
end
sgs.nosxuanhuo_suit_value = {
heart = 3.9
}
sgs.ai_cardneed.nosxuanhuo = function(to, card)
return card:getSuit() == sgs.Card_Heart
end
sgs.ai_skill_choice.nosxuanfeng = function(self, choices)
self:sort(self.enemies, "defenseSlash")
local slash = sgs.Sanguosha:cloneCard("slash")
for _, enemy in ipairs(self.enemies) do
if self.player:distanceTo(enemy)<=1 then
return "damage"
elseif not self:slashProhibit(slash, enemy) and self:slashIsEffective(slash, enemy) and sgs.isGoodTarget(enemy, self.enemies, self) then
return "slash"
end
end
return "nothing"
end
sgs.ai_skill_playerchosen.nosxuanfeng_damage = sgs.ai_skill_playerchosen.damage
sgs.ai_skill_playerchosen.nosxuanfeng_slash = sgs.ai_skill_playerchosen.zero_card_as_slash
sgs.ai_playerchosen_intention.nosxuanfeng_damage = 80
sgs.ai_playerchosen_intention.nosxuanfeng_slash = 80
sgs.nosxuanfeng_keep_value = sgs.xiaoji_keep_value
sgs.ai_cardneed.nosxuanfeng = sgs.ai_cardneed.equip
sgs.ai_skill_invoke.nosshangshi = sgs.ai_skill_invoke.shangshi
sgs.ai_view_as.nosgongqi = function(card, player, card_place)
local suit = card:getSuitString()
local number = card:getNumberString()
local card_id = card:getEffectiveId()
if card_place ~= sgs.Player_PlaceSpecial and card:getTypeId() == sgs.Card_TypeEquip and not card:hasFlag("using") then
return ("slash:nosgongqi[%s:%s]=%d"):format(suit, number, card_id)
end
end
local nosgongqi_skill = {}
nosgongqi_skill.name = "nosgongqi"
table.insert(sgs.ai_skills, nosgongqi_skill)
nosgongqi_skill.getTurnUseCard = function(self, inclusive)
local cards = self.player:getCards("he")
cards = sgs.QList2Table(cards)
local equip_card
self:sortByUseValue(cards, true)
for _, card in ipairs(cards) do
if card:getTypeId() == sgs.Card_TypeEquip and (self:getUseValue(card) < sgs.ai_use_value.Slash or inclusive) then
equip_card = card
break
end
end
if equip_card then
local suit = equip_card:getSuitString()
local number = equip_card:getNumberString()
local card_id = equip_card:getEffectiveId()
local card_str = ("slash:nosgongqi[%s:%s]=%d"):format(suit, number, card_id)
local slash = sgs.Card_Parse(card_str)
assert(slash)
return slash
end
end
function sgs.ai_cardneed.nosgongqi(to, card, self)
return card:getTypeId() == sgs.Card_TypeEquip and getKnownCard(to, self.player, "EquipCard", true) == 0
end
function sgs.ai_cardsview_valuable.nosjiefan(self, class_name, player)
if class_name == "Peach" and not player:hasFlag("Global_NosJiefanFailed") then
local dying = player:getRoom():getCurrentDyingPlayer()
if not dying then return nil end
local current = player:getRoom():getCurrent()
if not current or current:isDead() or current:getPhase() == sgs.Player_NotActive
or current:objectName() == player:objectName() or (current:hasSkill("wansha") and player:objectName() ~= dying:objectName())
or (self:isEnemy(current) and self:findLeijiTarget(current, 50, player)) then return nil end
return "@NosJiefanCard=."
end
end
sgs.ai_card_intention.NosJiefanCard = sgs.ai_card_intention.Peach
sgs.ai_skill_cardask["nosjiefan-slash"] = function(self, data, pattern, target)
if self:isEnemy(target) and self:findLeijiTarget(target, 50, self.player) then return "." end
for _, slash in ipairs(self:getCards("Slash")) do
if self:slashIsEffective(slash, target) then
return slash:toString()
end
end
return "."
end
function sgs.ai_cardneed.nosjiefan(to, card, self)
return isCard("Slash", card, to) and getKnownCard(to, self.player,"Slash", true) == 0
end
sgs.ai_skill_invoke.nosfuhun = function(self, data)
local target = 0
for _, enemy in ipairs(self.enemies) do
if (self.player:distanceTo(enemy) <= self.player:getAttackRange()) then target = target + 1 end
end
return target > 0 and not self.player:isSkipped(sgs.Player_Play)
end
sgs.ai_skill_invoke.noszhenlie = function(self, data)
local judge = data:toJudge()
if not judge:isGood() then
return true end
return false
end
sgs.ai_skill_playerchosen.nosmiji = function(self, targets)
targets = sgs.QList2Table(targets)
self:sort(targets, "defense")
local n = self.player:getLostHp()
if self.player:getPhase() == sgs.Player_Start then
if self.player:getHandcardNum() - n < 2 and not self:needKongcheng() and not self:willSkipPlayPhase() then return self.player end
elseif self.player:getPhase() == sgs.Player_Finish then
if self.player:getHandcardNum() - n < 2 and not self:needKongcheng() then return self.player end
end
local to = self:findPlayerToDraw(true, n)
return to or self.player
end
sgs.ai_playerchosen_intention.nosmiji = function(self, from, to)
if not (self:needKongcheng(to, true) and from:getLostHp() == 1)
and not hasManjuanEffect(to) then
sgs.updateIntention(from, to, -10)
end
end
sgs.ai_skill_invoke.nosqianxi = function(self, data)
local damage = data:toDamage()
local target = damage.to
if self:isFriend(target) then return false end
if target:getLostHp() >= 2 and target:getHp() <= 1 then return false end
if target:hasSkills(sgs.masochism_skill .. "|" .. sgs.recover_skill .. "|longhun|buqu|nosbuqu") then return true end
if self:hasHeavySlashDamage(self.player, damage.card, target) then return false end
return (target:getMaxHp() - target:getHp()) < 2
end
function sgs.ai_cardneed.nosqianxi(to, card, self)
return isCard("Slash", card, to) and getKnownCard(to, self.player, "Slash", true) == 0
end
local noslijian_skill = {}
noslijian_skill.name = "noslijian"
table.insert(sgs.ai_skills, noslijian_skill)
noslijian_skill.getTurnUseCard = function(self)
if self.player:hasUsed("NosLijianCard") or self.player:isNude() then
return
end
local card_id = self:getLijianCard()
if card_id then return sgs.Card_Parse("@NosLijianCard=" .. card_id) end
end
sgs.ai_skill_use_func.NosLijianCard = function(card, use, self)
local first, second = self:findLijianTarget("NosLijianCard", use)
if first and second then
use.card = card
if use.to then
use.to:append(first)
use.to:append(second)
end
end
end
sgs.ai_use_value.NosLijianCard = sgs.ai_use_value.LijianCard
sgs.ai_use_priority.NosLijianCard = sgs.ai_use_priority.LijianCard
noslijian_filter = function(self, player, carduse)
if carduse.card:isKindOf("NosLijianCard") then
sgs.ai_lijian_effect = true
end
end
table.insert(sgs.ai_choicemade_filter.cardUsed, noslijian_filter)
sgs.ai_card_intention.NosLijianCard = sgs.ai_card_intention.LijianCard
local nosrende_skill = {}
nosrende_skill.name = "nosrende"
table.insert(sgs.ai_skills, nosrende_skill)
nosrende_skill.getTurnUseCard = function(self)
if self.player:isKongcheng() then return end
local mode = string.lower(global_room:getMode())
if self.player:getMark("nosrende") > 1 and mode:find("04_1v3") then return end
if self:shouldUseRende() then
return sgs.Card_Parse("@NosRendeCard=.")
end
end
sgs.ai_skill_use_func.NosRendeCard = function(card, use, self)
local cards = sgs.QList2Table(self.player:getHandcards())
self:sortByUseValue(cards, true)
local notFound
for i = 1, self.player:getHandcardNum() do
local card, friend = self:getCardNeedPlayer(cards)
if card and friend then
cards = self:resetCards(cards, card)
else
notFound = true
break
end
if friend:objectName() == self.player:objectName() or not self.player:getHandcards():contains(card) then continue end
local canJijiang = self.player:hasLordSkill("jijiang") and friend:getKingdom() == "shu"
if card:isAvailable(self.player) and ((card:isKindOf("Slash") and not canJijiang) or card:isKindOf("Duel") or card:isKindOf("Snatch") or card:isKindOf("Dismantlement")) then
local dummy_use = { isDummy = true, to = sgs.SPlayerList() }
local cardtype = card:getTypeId()
self["use" .. sgs.ai_type_name[cardtype + 1] .. "Card"](self, card, dummy_use)
if dummy_use.card and dummy_use.to:length() > 0 then
if card:isKindOf("Slash") or card:isKindOf("Duel") then
local t1 = dummy_use.to:first()
if dummy_use.to:length() > 1 then continue
elseif t1:getHp() == 1 or sgs.card_lack[t1:objectName()]["Jink"] == 1
or t1:isCardLimited(sgs.Sanguosha:cloneCard("jink"), sgs.Card_MethodResponse) then continue
end
elseif (card:isKindOf("Snatch") or card:isKindOf("Dismantlement")) and self:getEnemyNumBySeat(self.player, friend) > 0 then
local hasDelayedTrick
for _, p in sgs.qlist(dummy_use.to) do
if self:isFriend(p) and (self:willSkipDrawPhase(p) or self:willSkipPlayPhase(p)) then hasDelayedTrick = true break end
end
if hasDelayedTrick then continue end
end
end
elseif card:isAvailable(self.player) and self:getEnemyNumBySeat(self.player, friend) > 0 and (card:isKindOf("Indulgence") or card:isKindOf("SupplyShortage")) then
local dummy_use = { isDummy = true }
self:useTrickCard(card, dummy_use)
if dummy_use.card then continue end
end
if friend:hasSkill("enyuan") and #cards >= 1 and not (self.room:getMode() == "04_1v3" and self.player:getMark("nosrende") == 1) then
use.card = sgs.Card_Parse("@NosRendeCard=" .. card:getId() .. "+" .. cards[1]:getId())
else
use.card = sgs.Card_Parse("@NosRendeCard=" .. card:getId())
end
if use.to then use.to:append(friend) end
return
end
if notFound then
local pangtong = self.room:findPlayerBySkillName("manjuan")
if not pangtong then return end
local cards = sgs.QList2Table(self.player:getHandcards())
self:sortByUseValue(cards, true)
if self.player:isWounded() and self.player:getHandcardNum() > 3 and self.player:getMark("nosrende") < 2 then
self:sortByUseValue(cards, true)
local to_give = {}
for _, card in ipairs(cards) do
if not isCard("Peach", card, self.player) and not isCard("ExNihilo", card, self.player) then table.insert(to_give, card:getId()) end
if #to_give == 2 - self.player:getMark("nosrende") then break end
end
if #to_give > 0 then
use.card = sgs.Card_Parse("@NosRendeCard=" .. table.concat(to_give, "+"))
if use.to then use.to:append(pangtong) end
end
end
end
end
sgs.ai_use_value.NosRendeCard = sgs.ai_use_value.RendeCard
sgs.ai_use_priority.NosRendeCard = sgs.ai_use_priority.RendeCard
sgs.ai_card_intention.NosRendeCard = sgs.ai_card_intention.RendeCard
sgs.dynamic_value.benefit.NosRendeCard = true
function sgs.ai_cardneed.nosjizhi(to, card)
return card:isNDTrick()
end
sgs.nosjizhi_keep_value = sgs.jizhi_keep_value
function sgs.ai_skill_invoke.nosjushou(self, data)
local sbdiaochan = self.room:findPlayerBySkillName("lihun")
if sbdiaochan and sbdiaochan:faceUp() and not self:willSkipPlayPhase(sbdiaochan)
and (self:isEnemy(sbdiaochan) or (sgs.turncount <= 1 and sgs.evaluatePlayerRole(sbdiaochan) == "neutral")) then return false end
if not self.player:faceUp() then return true end
for _, friend in ipairs(self.friends) do
if self:hasSkills("fangzhu|jilve", friend) then return true end
if friend:hasSkill("junxing") and friend:faceUp() and not self:willSkipPlayPhase(friend)
and not (friend:isKongcheng() and self:willSkipDrawPhase(friend)) then
return true
end
end
return self:isWeak()
end
sgs.ai_skill_askforag.nosbuqu = function(self, card_ids)
for i, card_id in ipairs(card_ids) do
for j, card_id2 in ipairs(card_ids) do
if i ~= j and sgs.Sanguosha:getCard(card_id):getNumber() == sgs.Sanguosha:getCard(card_id2):getNumber() then
return card_id
end
end
end
return card_ids[1]
end
function sgs.ai_skill_invoke.nosbuqu(self, data)
if #self.enemies == 1 and self.enemies[1]:hasSkill("nosguhuo") then
return false
else
local damage = data:toDamage()
if self.player:getHp() == 1 and damage.to and damage:getReason() == "duwu" and self:getSaveNum(true) >= 1 then return false end
return true
end
end
sgs.ai_skill_playerchosen.nosleiji = function(self, targets)
local mode = self.room:getMode()
if mode:find("_mini_17") or mode:find("_mini_19") or mode:find("_mini_20") or mode:find("_mini_26") then
local players = self.room:getAllPlayers()
for _, aplayer in sgs.qlist(players) do
if aplayer:getState() ~= "robot" then
return aplayer
end
end
end
self:updatePlayers()
return self:findLeijiTarget(self.player, 100, nil, -1)
end
sgs.ai_playerchosen_intention.nosleiji = sgs.ai_playerchosen_intention.leiji
function sgs.ai_slash_prohibit.nosleiji(self, from, to, card)
if self:isFriend(to, from) then return false end
if to:hasFlag("QianxiTarget") and (not self:hasEightDiagramEffect(to) or self.player:hasWeapon("QinggangSword")) then return false end
local hcard = to:getHandcardNum()
if from:hasSkill("liegong") and (hcard >= from:getHp() or hcard <= from:getAttackRange()) then return false end
if from:hasSkill("kofliegong") and hcard >= from:getHp() then return false end
if from:getRole() == "rebel" and to:isLord() then
local other_rebel
for _, player in sgs.qlist(self.room:getOtherPlayers(from)) do
if sgs.evaluatePlayerRole(player) == "rebel" or sgs.compareRoleEvaluation(player, "rebel", "loyalist") == "rebel" then
other_rebel = player
break
end
end
if not other_rebel and ((from:getHp() >= 4 and (getCardsNum("Peach", from, self.player) > 0 or from:hasSkills("ganglie|vsganglie"))) or from:hasSkill("hongyan")) then
return false
end
end
if sgs.card_lack[to:objectName()]["Jink"] == 2 then return true end
if getKnownCard(to, from, "Jink", true) >= 1 or (self:hasSuit("spade", true, to) and hcard >= 2) or hcard >= 4 then return true end
if self:hasEightDiagramEffect(to) then return true end
end
sgs.ai_cardneed.nosleiji = sgs.ai_cardneed.leiji
table.insert(sgs.ai_global_flags, "questioner")
sgs.ai_skill_choice.nosguhuo = function(self, choices)
local yuji = self.room:findPlayerBySkillName("nosguhuo")
local nosguhuoname = self.room:getTag("NosGuhuoType"):toString()
if nosguhuoname == "peach+analeptic" then nosguhuoname = "peach" end
if nosguhuoname == "normal_slash" then nosguhuoname = "slash" end
local nosguhuocard = sgs.Sanguosha:cloneCard(nosguhuoname)
local nosguhuotype = nosguhuocard:getClassName()
if nosguhuotype and self:getRestCardsNum(nosguhuotype, yuji) == 0 and self.player:getHp() > 0 then return "question" end
if nosguhuotype and nosguhuotype == "AmazingGrace" then return "noquestion" end
if nosguhuotype:match("Slash") then
if yuji:getState() ~= "robot" and math.random(1, 4) == 1 and not sgs.questioner and self:isEnemy(yuji) then return "question" end
if not self:hasCrossbowEffect(yuji) then return "noquestion" end
end
if yuji:hasFlag("NosGuhuoFailed") and math.random(1, 6) == 1 and self:isEnemy(yuji) and self.player:getHp() >= 3
and self.player:getHp() > self.player:getLostHp() then return "question" end
local players = self.room:getOtherPlayers(self.player)
players = sgs.QList2Table(players)
local x = math.random(1, 5)
self:sort(self.friends, "hp")
if self.player:getHp() < 2 and self:getCardsNum("Peach") < 1 and self.room:alivePlayerCount() > 2 then return "noquestion" end
if self:isFriend(yuji) then return "noquestion"
elseif sgs.questioner then return "noquestion"
elseif self.player:getHp() < self.friends[#self.friends]:getHp() then return "noquestion"
end
if self:needToLoseHp(self.player) and not self.player:hasSkills(sgs.masochism_skill) and x ~= 1 and self:isEnemy(yiji) then return "question" end
local questioner
for _, friend in ipairs(self.friends) do
if friend:getHp() == self.friends[#self.friends]:getHp() then
if friend:hasSkills("nosrende|rende|kuanggu|kofkuanggu|zaiqi|buqu|nosbuqu|yinghun|longhun|xueji|baobian") then
questioner = friend
break
end
end
end
if not questioner then questioner = self.friends[#self.friends] end
return self.player:objectName() == questioner:objectName() and x ~= 1 and "question" or "noquestion"
end
sgs.ai_choicemade_filter.skillChoice.nosguhuo = function(self, player, promptlist)
if promptlist[#promptlist] == "question" then
sgs.questioner = player
local yuji = self.room:findPlayerBySkillName("nosguhuo")
if not yuji then return end
local nosguhuoname = self.room:getTag("NosGuhuoType"):toString()
if nosguhuoname == "peach+analeptic" or nosguhuoname == "peach" then
sgs.updateIntention(player, yuji, 80)
return
end
if nosguhuoname == "normal_slash" then nosguhuoname = "slash" end
local nosguhuocard = sgs.Sanguosha:cloneCard(nosguhuoname)
if nosguhuocard then
local nosguhuotype = nosguhuocard:getClassName()
if nosguhuotype and self:getRestCardsNum(nosguhuotype, yuji) > 0 then
sgs.updateIntention(player, yuji, 80)
return
end
end
end
end
local nosguhuo_skill = {}
nosguhuo_skill.name = "nosguhuo"
table.insert(sgs.ai_skills, nosguhuo_skill)
nosguhuo_skill.getTurnUseCard = function(self)
if self.player:isKongcheng() then return end
local cards = sgs.QList2Table(self.player:getHandcards())
local otherSuit_str, NosGuhuoCard_str = {}, {}
for _, card in ipairs(cards) do
if card:isNDTrick() then
local dummyuse = { isDummy = true }
self:useTrickCard(card, dummyuse)
if dummyuse.card then
local cardstr = "@NosGuhuoCard=" .. card:getId() .. ":" .. card:objectName()
if card:getSuit() == sgs.Card_Heart then
table.insert(NosGuhuoCard_str, cardstr)
else
table.insert(otherSuit_str, cardstr)
end
end
end
end
local other_suit, enemy_is_weak, zgl_kongcheng = true
local can_fake_nosguhuo = sgs.turncount > 1
for _, enemy in ipairs(self.enemies) do
if enemy:getHp() > 2 then
other_suit = false
end
if enemy:getHp() > 1 then
can_fake_nosguhuo = false
end
if self:isWeak(enemy) then
enemy_is_weak = true
end
if enemy:hasSkill("kongcheng") and enemy:isKongcheng() then
zgl_kongcheng = true
end
end
if #otherSuit_str > 0 and other_suit then
table.insertTable(NosGuhuoCard_str, otherSuit_str)
end
local peach_str = self:getGuhuoCard("Peach", true, -1)
if peach_str then table.insert(NosGuhuoCard_str, peach_str) end
local fakeCards = {}
for _, card in sgs.qlist(self.player:getHandcards()) do
if (card:isKindOf("Slash") and self:getCardsNum("Slash", "h") >= 2 and not self:hasCrossbowEffect())
or (card:isKindOf("Jink") and self:getCardsNum("Jink", "h") >= 3)
or (card:isKindOf("EquipCard") and self:getSameEquip(card))
or card:isKindOf("Disaster") then
table.insert(fakeCards, card)
end
end
self:sortByUseValue(fakeCards, true)
local function fake_nosguhuo(objectName, can_fake_nosguhuo)
if #fakeCards == 0 then return end
local fakeCard
local nosguhuo = "peach|ex_nihilo|snatch|dismantlement|amazing_grace|archery_attack|savage_assault|god_salvation"
local ban = table.concat(sgs.Sanguosha:getBanPackages(), "|")
if not ban:match("maneuvering") then nosguhuo = nosguhuo .. "|fire_attack" end
local nosguhuos = nosguhuo:split("|")
for i = 1, #nosguhuos do
local forbidden = nosguhuos[i]
local forbid = sgs.Sanguosha:cloneCard(forbidden)
if self.player:isLocked(forbid) then
table.remove(nosguhuos, i)
i = i - 1
end
end
if can_fake_nosguhuo then
for i = 1, #nosguhuos do
if nosguhuos[i] == "god_salvation" then table.remove(nosguhuos, i) break end
end
end
for i = 1, 10 do
local card = fakeCards[math.random(1, #fakeCards)]
local newnosguhuo = objectName or nosguhuos[math.random(1, #nosguhuos)]
local nosguhuocard = sgs.Sanguosha:cloneCard(newnosguhuo, card:getSuit(), card:getNumber())
if self:getRestCardsNum(nosguhuocard:getClassName()) > 0 then
local dummyuse = { isDummy = true }
if newnosguhuo == "peach" then self:useBasicCard(nosguhuocard, dummyuse) else self:useTrickCard(nosguhuocard, dummyuse) end
if dummyuse.card then
fakeCard = sgs.Card_Parse("@NosGuhuoCard=" .. card:getId() .. ":" .. newnosguhuo)
break
end
end
end
return fakeCard
end
if #NosGuhuoCard_str > 0 then
local nosguhuo_str = NosGuhuoCard_str[math.random(1, #NosGuhuoCard_str)]
local str = nosguhuo_str:split("=")
str = str[2]:split(":")
local cardid, cardname = str[1], str[2]
if sgs.Sanguosha:getCard(cardid):objectName() == cardname and cardname == "ex_nihilo" then
if math.random(1, 3) == 1 then
local fake_exnihilo = fake_nosguhuo(cardname)
if fake_exnihilo then return fake_exnihilo end
end
return sgs.Card_Parse(nosguhuo_str)
elseif math.random(1, 5) == 1 then
local fake_NosGuhuoCard = fake_nosguhuo()
if fake_NosGuhuoCard then return fake_NosGuhuoCard end
else
return sgs.Card_Parse(nosguhuo_str)
end
elseif can_fake_nosguhuo and math.random(1, 4) ~= 1 then
local fake_NosGuhuoCard = fake_nosguhuo(nil, can_fake_nosguhuo)
if fake_NosGuhuoCard then return fake_NosGuhuoCard end
elseif zgl_kongcheng and #fakeCards > 0 then
return sgs.Card_Parse("@NosGuhuoCard=" .. fakeCards[1]:getEffectiveId() .. ":amazing_grace")
else
local lord = self.room:getLord()
local drawcard = false
if lord and self:isFriend(lord) and self:isWeak(lord) and not self.player:isLord() then
drawcard = true
elseif not enemy_is_weak then
if sgs.current_mode_players["loyalist"] > sgs.current_mode_players["renegade"] + sgs.current_mode_players["rebel"]
and self.role == "loyalist" and sgs.current_mode_players["rebel"] > 0 then
drawcard = true
elseif sgs.current_mode_players["rebel"] > sgs.current_mode_players["loyalist"] + sgs.current_mode_players["renegade"] + 2
and self.role == "rebel" then
drawcard = true
end
end
if drawcard and #fakeCards > 0 then
local card_objectname
local objectNames = { "ex_nihilo", "snatch", "dismantlement", "amazing_grace", "archery_attack", "savage_assault", "god_salvation", "duel" }
for _, objectName in ipairs(objectNames) do
local acard = sgs.Sanguosha:cloneCard(objectName)
if self:getRestCardsNum(acard:getClassName()) == 0 then
card_objectname = objectName
break
end
end
if card_objectname then
return sgs.Card_Parse("@NosGuhuoCard=" .. fakeCards[1]:getEffectiveId() .. ":" .. card_objectname)
end
end
end
if self:isWeak() then
local peach_str = self:getGuhuoCard("Peach", true, -1)
if peach_str then
local card = sgs.Card_Parse(peach_str)
local peach = sgs.Sanguosha:cloneCard("peach", card:getSuit(), card:getNumber())
local dummy_use = { isDummy = true }
self:useBasicCard(peach, dummy_use)
if dummy_use.card then return card end
end
end
local slash_str = self:getGuhuoCard("Slash", true, -1)
if slash_str and self:slashIsAvailable() then
local card = sgs.Card_Parse(slash_str)
local slash = sgs.Sanguosha:cloneCard("slash", card:getSuit(), card:getNumber())
local dummy_use = { isDummy = true }
self:useBasicCard(slash, dummy_use)
if dummy_use.card then return card end
end
end
sgs.ai_skill_use_func.NosGuhuoCard = function(card, use, self)
local userstring = card:toString()
userstring = (userstring:split(":"))[3]
local nosguhuocard = sgs.Sanguosha:cloneCard(userstring, card:getSuit(), card:getNumber())
nosguhuocard:setSkillName("nosguhuo")
if nosguhuocard:getTypeId() == sgs.Card_TypeBasic then
self:useBasicCard(nosguhuocard, use)
if not use.isDummy and use.card and use.card:isKindOf("Slash") and (not use.to or use.to:isEmpty()) then return end
else assert(nosguhuocard)
self:useTrickCard(nosguhuocard, use)
end
if not use.card then return end
use.card = card
end
sgs.ai_use_priority.NosGuhuoCard = 10
sgs.nosguhuo_suit_value = {
heart = 5,
}
sgs.ai_skill_choice.nosguhuo_saveself = sgs.ai_skill_choice.guhuo_saveself
sgs.ai_skill_choice.nosguhuo_slash = sgs.ai_skill_choice.guhuo_slash
function sgs.ai_cardneed.nosguhuo(to, card)
return card:getSuit() == sgs.Card_Heart and (card:isKindOf("BasicCard") or card:isNDTrick())
end