-
Notifications
You must be signed in to change notification settings - Fork 1
/
thicket-ai.lua
172 lines (143 loc) · 3.8 KB
/
thicket-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
-- Menghuo's AI
local menghuo_ai = SmartAI:newSubclass "menghuo"
function menghuo_ai:askForSkillInvoke(skill_name, data)
if skill_name == "zaiqi" then
return self.player:getLostHp() >= 2
else
return super.askForSkillInvoke(self, skill_name, data)
end
end
-- Sunjian's AI
local sunjian_ai = SmartAI:newSubclass "sunjian"
sgs.ai_skill_choice.yinghun = function(self, choices)
if self:isFriend(self.yinghun) then
return "dxt1"
else
return "d1tx"
end
end
function sunjian_ai:askForUseCard(pattern, prompt)
if pattern == "@@yinghun" then
local x = self.player:getLostHp()
if x == 1 and #self.friends == 1 then
return "."
end
if #self.friends > 1 then
self:sort(self.friends, "chaofeng")
self.yinghun = self:getOneFriend()
else
self:sort(self.enemies, "chaofeng")
self.yinghun = self.enemies[1]
end
if self.yinghun then
return "@YinghunCard=.->" .. self.yinghun:objectName()
else
return "."
end
end
end
-- xingshang, allways invoke
sgs.ai_skill_invoke.xingshang = true
-- fangzhu, fangzhu
sgs.ai_skill_use["@@fangzhu"] = function(self, prompt)
self:sort(self.friends_noself)
local target
for _, friend in ipairs(self.friends_noself) do
if not friend:faceUp() then
target = friend
break
end
if friend:hasSkill("jushou") and friend:getPhase() == sgs.Player_Play then
target = friend
break
end
end
if not target then
local x = self.player:getLostHp()
if x >= 3 then
target = self:getOneFriend()
else
self:sort(self.enemies)
for _, enemy in ipairs(self.enemies) do
if enemy:faceUp() then
target = enemy
break
end
end
end
end
if target then
return "@FangzhuCard=.->" .. target:objectName()
else
return "."
end
end
local xuhuang_ai = SmartAI:newSubclass "xuhuang"
function xuhuang_ai:activate_dummy(use)
-- find black basic or equip card
local cards = self.player:getCards("he")
local to_use
for _, card in sgs.qlist(cards) do
if card:isBlack() and (card:inherits("BasicCard") or card:inherits("EquipCard")) then
to_use = card
break
end
end
if to_use then
local suit = to_use:getSuitString()
local number = to_use:getNumberString()
local card_id = to_use:getEffectiveId()
local card_name = "supply_shortage"
local skill_name = "duanliang"
local card_str = ("%s:%s[%s:%s]=%d"):format(card_name, skill_name, suit, number, card_id)
card = sgs.Card_Parse(card_str)
self:useCardSupplyShortage(card, use)
if use:isValid() then
return
end
end
super.activate(self, use)
end
sgs.ai_skill_invoke.songwei = function(self, data)
return self:isFriend(self.room:getLord())
end
-- baonue
sgs.ai_skill_invoke.baonue = function(self, data)
return self.player:getRole() == "loyalist"
end
-- haoshi
sgs.ai_skill_invoke.haoshi = function(self, data)
if self.player:getHandcardNum() <= 1 then
return true
end
local least = math.huge
local players = self.room:getOtherPlayers(self.player)
for _, player in sgs.qlist(players) do
least = math.min(player:getHandcardNum(), least)
end
self:sort(self.friends_noself)
for _, friend in ipairs(self.friends_noself) do
if friend:getHandcardNum() == least then
self.beggar = friend
return true
end
end
return false
end
sgs.ai_skill_use["@@haoshi!"] = function(self, prompt)
local beggar = self.beggar
assert(beggar)
self.beggar = nil
local cards = self.player:getHandcards()
local n = math.floor(self.player:getHandcardNum()/2)
local card_ids = {}
for i=1, n do
table.insert(card_ids, cards:at(i-1):getEffectiveId())
end
return "@HaoshiCard=" .. table.concat(card_ids, "+") .. "->" .. beggar:objectName()
end
sgs.ai_skill_invoke.lieren = function(self, data)
if self.player:getHandcardNum()>=self.player:getHp() then return true
else return false
end
end