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 pathh_momentum-ai.lua
267 lines (237 loc) · 8.28 KB
/
h_momentum-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
function sgs.ai_skill_invoke.wangxi(self, data)
local target = data:toPlayer()
if self:isFriend(target) then
return not self:needKongcheng(target, true) and not (hasManjuanEffect(self.player) and hasManjuanEffect(target))
else
if hasManjuanEffect(self.player) then return false end
return self:needKongcheng(target, true) or hasManjuanEffect(target)
end
end
sgs.ai_choicemade_filter.skillInvoke.wangxi = function(self, player, promptlist)
local damage = self.room:getTag("CurrentDamageStruct"):toDamage()
local target = nil
if damage.from and damage.from:objectName() == player:objectName() then
target = damage.to
elseif damage.to and damage.to:objectName() == player:objectName() then
target = damage.from
end
if target and promptlist[3] == "yes" then
if self:needKongcheng(target, true) then sgs.updateIntention(player, target, 10)
elseif not hasManjuanEffect(target) and player:getState() == "robot" then sgs.updateIntention(player, target, -60)
end
end
end
function sgs.ai_skill_invoke.hengjiang(self, data)
local target = data:toPlayer()
if self:isEnemy(target) then
return true
else
if hasManjuanEffect(self.player) then return false end
if target:getPhase() > sgs.Player_Discard then return true end
if target:hasSkill("yongsi") then return false end
if target:hasSkill("keji") and not target:hasFlag("KejiSlashInPlayPhase") then return true end
return target:getHandcardNum() <= target:getMaxCards() - 2
end
end
sgs.ai_choicemade_filter.skillInvoke.hengjiang = function(self, player, promptlist)
if promptlist[3] == "yes" then
local current = self.room:getCurrent()
if current and current:getPhase() <= sgs.Player_Discard
and not (current:hasSkill("keji") and not current:hasFlag("KejiSlashInPlayPhase")) and current:getHandcardNum() > current:getMaxCards() - 2 then
sgs.updateIntention(player, current, 50)
end
end
end
sgs.ai_skill_invoke.guixiu = function(self, data)
return self:isWeak() and not self:willSkipPlayPhase()
end
sgs.ai_skill_invoke.guixiu_rec = function()
return true
end
local cunsi_skill = {}
cunsi_skill.name = "cunsi"
table.insert(sgs.ai_skills, cunsi_skill)
cunsi_skill.getTurnUseCard = function(self)
return sgs.Card_Parse("@CunsiCard=.")
end
sgs.ai_skill_use_func.CunsiCard = function(card, use, self)
if sgs.turncount <= 2 and self.player:aliveCount() > 2 and #self.friends_noself == 0 then return end
local to, manjuan
for _, friend in ipairs(self.friends_noself) do
if not hasManjuanEffect(friend) then
to = friend
break
else
manjuan = friend
end
end
if not to and manjuan then to = manjuan end
if not to then to = self.player end
if self.player:getMark("guixiu") >= 1 then
use.card = sgs.Card_Parse("@GuixiuCard=.")
return
else
use.card = card
if use.to then use.to:append(to) end
end
end
sgs.ai_skill_use_func.GuixiuCard = function(card, use, self)
use.card = card
end
sgs.ai_skill_invoke.yongjue = function(self, data)
local player = data:toPlayer()
return player and self:isFriend(player) and not (self:needKongcheng(player, true) and not self:hasCrossbowEffect(player))
end
sgs.ai_use_value.CunsiCard = 10
sgs.ai_use_priority.CunsiCard = 10.1
sgs.ai_use_priority.GuixiuCard = sgs.ai_use_priority.CunsiCard
--[[
sgs.ai_skill_invoke.fengshi = function(self, data)
local target = data:toPlayer()
if not target then return end
if target:hasSkills(sgs.lose_equip_skill) then return self:isFriend(target) end
return not self:isFriend(target)
end
sgs.ai_choicemade_filter.skillInvoke.fengshi = function(self, player, promptlist)
if promptlist[3] == "yes" then
end
end
sgs.ai_skill_invoke.chuanxin = function(self, data)
local damage = damage:toDamage()
local invoke
local to = damage.to
if to:getMark("chuanxin_" .. self.player:objectName()) == 0 then
for _, skill in sgs.qlist(to:getVisibleSkillList()) do
if string.find("benghua|shiyong", skill:objectName()) then return self:isFriend(to) end
end
invoke = true
end
if to:getEquips():length() > 0 then
if to:hasSkills(sgs.lose_equip_skill) then return self:isFriend(to) end
invoke = true
end
return invoke and not self:isFriend(to)
end
sgs.ai_choicemade_filter.skillInvoke.chuanxin = function(self, player, promptlist)
if promptlist[3] == "yes" then
end
end
sgs.ai_skill_choice.chuanxin = function(self, choices, data)
if self.player:hasSkills("benghuai|shiyong") then return "detach"
elseif self.player:hasSkills(sgs.lose_equip_skill) then return "throw"
else return ((not self:isWeak() or self:needToThrowArmor()) and "throw") or "detach"
end
end
sgs.ai_skill_choice.chuanxin_lose = function(self, choices, data)
if self.player:hasSkill("benghuai") then return "benghuai"
elseif self.player:hasSkill("shiyong") then return "shiyong"
else
choices = choices:split("+")
return choices[math.random(1, #choices)]
end
end
sgs.ai_skill_invoke.hengzheng = function(self, data)
local value = 0
for _, player in sgs.qlist(self.room:getOtherPlayers(self.player)) do
value = value + getGuixinValue(self, player)
end
return value >= 1.3
end
local duanxie_skill = {}
duanxie_skill.name = "duanxie"
table.insert(sgs.ai_skills, duanxie_skill)
duanxie_skill.getTurnUseCard = function(self)
if self.player:hasUsed("DuanxieCard") then return end
return sgs.Card_Parse("@DuanxieCard=.")
end
sgs.ai_skill_use_func.DuanxieCard = function(card, use, self)
self:sort(self.enemies, "handcard")
for _, enemy in ipairs(self.enemies) do
if not enemy:isChained() and enemy:isKongcheng() then
use.card = card
if use.to then use.to:append(enemy) end
return
end
end
for _, enemy in ipairs(self.enemies) do
if not enemy:isChained() then
use.card = card
if use.to then use.to:append(enemy) end
return
end
end
end
sgs.ai_card_intention.DuanxieCard = 50
sgs.ai_use_priority.DuanxieCard = 0
sgs.ai_skill_invoke.fenming = function(self, data)
local value = 0
local players = self.room:getAlivePlayers()
for _, p in sgs.qlist(players) do
if not p:isChained() or p:isKongcheng() then continue end
local HandcardNum = p:getHandcardNum()
local v = 1 / HandcardNum
local v1, v2 = 0, 0
if HandcardNum == 1 then
if p:hasSkill("kongcheng") then v1 = v1 - 1 end
if p:hasSkill("zhiji") and p:getMark("zhiji") == 0 then v1 = v1 - 1 end
if p:hasSkill("beifa") then
local canSlash
for _, pp in ipairs(self:getEnemies(p)) do
if pp:canSlash(friend, slash, true) then canSlash = true break end
end
v1 = canSlash and - 1 or 1
end
if p:hasSkill("hengzheng") and #self:getEnemies(p) > 2 then v1 = v1 - 1 end
end
local v2 = (self:getLeastHandcardNum(p) - HandcardNum - 1) or 0
v = v + math.max(v1, v2)
if self:isFriend(p) then value = value - v
else value = value + v
end
end
return value > 0
end
sgs.ai_skill_choice.yingyang = function(self, choices, data)
local pindian = data:toPindian()
local reason = pindian.reason
local from, to = pindian.from, pindian.to
local f_num, t_num = pindian.from_number, pindian.to_number
local amFrom = self.player:objectName() == from:objectName()
if math.abs(f_num - t_num) > 3 and not self.room:findPlayerBySkillName("fuzhuo") then return "cancel" end
if reason == "mizhao" then
if amFrom then
if self:isFriend(to) then
if self:getCardsNum("Jink") > 0 then return "down"
elseif getCardsNum("Jink", to, self.player) >= 1 then return "up"
else return self.player:getHp() >= to:getHp() and "down" or "up" end
else
return "up"
end
else
if self:isFriend(from) then
if self:getCardsNum("Jink") > 0 then return "down"
elseif getCardsNum("Jink", from, self.player) >= 1 then return "up"
else return self.player:getHp() >= to:getHp() and "down" or "up"
end
else return "up" end
end
elseif reason == "quhu" then
if amFrom and self.player:hasSkill("jieming") then
if f_num > 8 then return "up"
elseif self:getJiemingChaofeng(player) <= -6 then return "down"
end
end
return "up"
elseif reason == "xiechan" then
return not amFrom and self:getCardsNum("Slash") > getCardsNum("Slash", from, self.player) and "down" or "up"
elseif reason == "zhiba_pindian" then
return amFrom and self:isFriend(to) and "down" or "up"
elseif string.find("tianyi,shuangren,qiaoshui", reason) then
return not amFrom and self:isFriend(from) and "down" or "up"
elseif string.find("dahe,tanhu,lieren,tanlan,jueji,xianzhen,zhuikong", reason) then
return "up"
else
return "cancel"
end
end
]]