Ai
1 Star 0 Fork 3

该账号已注销/Lang

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
EndLessPractice.lua 40.92 KB
一键复制 编辑 原始数据 按行查看 历史
wxj 提交于 2024-10-31 15:11 +08:00 . 2
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181
-- SPDX-License-Identifier: GPL-3.0-or-later
---@class EndLessPractice: Object
---@field public reward_cfg table<string, number>
---@field public pdl_tmpskills string
---@field public panduola_call number
local EndLessPractice = class("EndLessPractice")
local ShopMgr = require "packages/lang/ShopMgr"
function EndLessPractice:initialize()
--白名单武将池
self.camps = {lord = 1,loyalist = 1,rebel = 2}
self.room = Fk:currentRoom()
ShopMgr:preLoadShopSkills()
end
function EndLessPractice:initData(player,data) --初始化数据
self.layowner = player
self.room = player.room
self.layer = data.i_layer
self.totallayer = data.t_layer
self.maxctiwin = data.maxctiwin
self.laygetskill_n = data.laygetskill_n --层主每过几关获得技能
self.lordsperup = data.lordsperup
self.lordslayer = data.lordslayer
self.goldpower = data.goldpower
self.meetpuyuandata = data.meetpuyuan
self.layownskills = data.layownskills
self.rewd_intval = data.rewd_intval
self.godboss = data.godboss or false
self.defbossstep = data.defbossstep or 10
self.rulename = data.rulename
self.reward_cfg = {} --过关奖励选项列表
self.pdl_tmpskills = {} --潘多拉临时技能
self.panduola_call = 0 --潘多拉开启次数
self.curctiwin = 0 --连胜次数
self.meetpyrate = 0
self.meetpylayer = 0
self.getpdlskillnum = 0
self.initshopskills = data.initshopskills
self.curboss = nil
self.shop_items = {}
self:initOplayerData(data)
self:initSkills()
self:initLayer()
self:upShopItems(true)
end
function EndLessPractice:relifeHumans()
for _,pr in ipairs(self.room.players) do
if pr.id > 0 and pr.dead then
self:relifePlayer(pr.general)
end
end
end
function EndLessPractice:relifeAIRebels()
local deadrebels,aliverebels = {},{}
for _,pr in ipairs(self.room.players) do
if pr.id < 0 and pr.dead and pr.role == "rebel" then
table.insert(deadrebels,pr)
end
if pr.id < 0 and not pr.dead and pr.role == "rebel" then
table.insert(aliverebels,pr)
end
end
if #deadrebels > 0 then
local randai = table.random(deadrebels)
self:relifePlayer(randai.general)
else
local randai = table.random(aliverebels)
self:upAiFriends(randai)
end
end
function EndLessPractice:getLayerOwner()
return self.layowner
end
function EndLessPractice:getLayerSkillnum()
return self.laygetskill_n
end
function EndLessPractice:getExtraFriendByLayers()
return self.lordslayer
end
-- function EndLessPractice:upMaxShopSkills(num)
-- table.removeOne(self.shop_items,"Exist")
-- local shopitems = ShopMgr:getShopItems()
-- end
function EndLessPractice:upShopItems(isinit,refreskills)
local shopitems = ShopMgr:getShopItems()
if not isinit then
for _,medics in ipairs(shopitems[1]) do --药水重新刷新
if not table.contains(self.shop_items,medics) then
table.insert(self.shop_items,1,medics)
end
end
for _,cds in ipairs(shopitems[5]) do --卡包重新刷新
if not table.contains(self.shop_items,cds) then
table.insert(self.shop_items,#self.shop_items-1,cds)
end
end
local atkskills,defskills = table.clone(shopitems[3]),table.clone(shopitems[4])
local point = 0
local changelist = {}
local atkchar,defchar = "skt_","skd_"
while point < #self.shop_items do
point = point + 1
if string.startsWith(self.shop_items[point],atkchar) then
self.shop_items[point] = table.remove(atkskills,math.random(1,#atkskills))
end
if string.startsWith(self.shop_items[point],defchar) then
self.shop_items[point] = table.remove(defskills,math.random(1,#defskills))
end
end
if refreskills then
local initrefstr,refstr = shopitems[6][1],"rfe_skills" --检测刷新商店技能
local hasinitref,pos
-- local hasinitref = table.find(self.shop_items,function(c) return string.find(c,refstr) end)
for i,chc in ipairs(self.shop_items) do
if string.find(chc,refstr) then
hasinitref = chc
pos = i
end
end
if not hasinitref then
table.insert(self.shop_items,#self.shop_items-1,initrefstr)
else
if hasinitref ~= initrefstr then
self.shop_items[pos] = initrefstr
end
end
end
else
table.insertTable(self.shop_items,shopitems[1])
table.insertTable(self.shop_items,shopitems[2])
table.insertTable(self.shop_items,table.random(shopitems[3],self.initshopskills))
table.insertTable(self.shop_items,table.random(shopitems[4],self.initshopskills))
table.insertTable(self.shop_items,shopitems[5])
table.insert(self.shop_items,"Exist")
end
end
function EndLessPractice:gainRandGold()
local room = self.room
local layer = self.layer
local value = self.goldpower
table.forEach(self.otherplayers,function (op)
if op.id < 0 then return end
local min = math.ceil(layer/10)
local max = math.floor(math.random(min,min+4)*value+0.5)
-- local randgold = math.floor(math.random(min,max)+0.5)
local randgold = max
room:addPlayerMark(op,"@gold_num",randgold)
room:doBroadcastNotify("ShowToast",Fk:translate(op.general).."金币+"..randgold)
end)
end
--购买商店装备
function EndLessPractice:getShopEquips(equip,from)
local room = self.room
local geteid
local name = string.sub(equip,4)
for _, id in ipairs(Fk:getAllCardIds()) do
local card = Fk:getCardById(id, true)
if card.trueName == name then
geteid = id
break
end
end
if geteid then
room:obtainCard(from,geteid,true,fk.ReasonJustMove)
return true
else
room:doBroadcastNotify("ShowToast", "买不到?似乎没开装备对应扩展包?")
end
return false
end
--喝药水
function EndLessPractice:drankPotion(name,who)
local room = who.room
if name == "sp_redpotion" or name == "sp_bluepotion" then
local mark = name == "sp_redpotion" and "@slash_dmg" or "@trick_dmg"
room:setPlayerMark(who,mark,who:getMark(mark) * 2)
elseif name == "sp_recoverpotion" then
if who:isWounded() then
room:recover({who = who,num = math.ceil(who:getLostHp()/2),recoverBy = who,skillName = self.rulename})
end
elseif name == "sp_drawpotion" then
room:drawCards(who, 5,self.rulename)
end
return true
end
function EndLessPractice:getCardsToDis(cards)
-- local printids = {}
local room = self.room
-- for i=1,300 do
-- table.insert(printids,room.draw_pile[i])
-- end
-- local player = table.find(room.players,function(pr) return pr.id >0 end)
-- room:obtainCard(player,printids,false,fk.ReasonJustMove)
for cname,info in pairs(cards) do
for i=1,info[1] do
local suit = math.random(info[2][1],info[2][2])
local number = math.random(1,13)
local cd = Fk:cloneCard(cname, suit, number)
Fk:_addPrintedCard(cd)
table.insert(room.discard_pile,cd.id)
room:setCardArea(cd.id, Card.DiscardPile, nil)
room:doBroadcastNotify("PrintCard", json.encode{ cname, suit, number })
end
end
-- room:doBroadcastNotify("UpdateDrawPile", #room.discard_pile)
end
--补充扩展牌
function EndLessPractice:addCards(name)
if name == "spk_basecards" then
local basecards = {slash={5,{1,4}},thunder__slash={5,{1,2}},fire__slash={5,{3,4}},jink={15,{3,4}},peach={10,{3,4}},analeptic={10,{1,4}}}
self:getCardsToDis(basecards)
elseif name == "spk_trickcards" then
local trickcards = {ex_nihilo={5,{3,4}},snatch={5,{1,4}},duel={5,{1,4}},dismantlement={5,{1,4}},nullification={5,{1,4}},indulgence={3,{1,4}},supply_shortage={3,{1,2}},collateral={3,{1,2}},
amazing_grace = {4,{3,4}},savage_assault = {4,{1,2}},archery_attack = {4,{3,4}},god_salvation = {4,{3,4}}}
self:getCardsToDis(trickcards)
end
return true
end
--购买技能
function EndLessPractice:getShopSkills(skill,from)
local room = self.room
local name = string.sub(skill,5)
if table.find(from.player_skills,function(s) return s.trueName==name end) then return false end
room:handleAddLoseSkills(from, name, nil, false)
return true
end
--刷新商店技能
function EndLessPractice:refreShopSkills(item_name,player)
local curref,pos = item_name,nil
for i,chc in ipairs(self.shop_items) do
if string.find(chc,curref) then
pos = i
break
end
end
local num = tonumber(string.sub(curref,#curref))
local shopitems = ShopMgr:getShopItems()
if num >= #shopitems[6] then
-- table.remove(self.shop_items,pos)
self:upShopItems()
return true
end
local nextpos
for j,upstr in ipairs(shopitems[6]) do
if string.find(upstr,curref) then
nextpos = j + 1
break
end
end
self.shop_items[pos] = shopitems[6][nextpos]
self:upShopItems()
self.refreshop = true
return true
end
function EndLessPractice:buyShopItem(who,chs,price,goldnum,item_name)
local room = self.room
local item_str = string.sub(item_name,1,3)
local trans = Fk:translate(item_name)
trans = string.gsub(trans,"(%arg金币)","")
if goldnum - price >= 0 then
local ret
if item_str == "sp_" then
ret = self:drankPotion(item_name,who)
elseif item_str == "st_" then
ret = self:getShopEquips(item_name,who)
elseif item_str == "skt" or item_str == "skd" then
ret = self:getShopSkills(item_name,who)
elseif item_str == "spk" then
ret = self:addCards(item_name)
elseif item_str == "rfe" then
ret = self:refreShopSkills(item_name,who)
end
if ret then
room:setPlayerMark(who,"@gold_num",goldnum - price)
room:doBroadcastNotify("ShowToast", Fk:translate(who.general) .."购买"..trans)
table.removeOne(self.shop_items,item_name..":::"..price)
else
room:doBroadcastNotify("ShowToast", Fk:translate(who.general) .."购买失败")
end
else
room:doBroadcastNotify("ShowToast", Fk:translate(who.general) .."买不起"..trans)
end
end
function EndLessPractice:cellSelfSkills(player)
local room = self.room
local pdlskills = self.pdl_tmpskills[tostring(player.id)]
local equipskills = {}
local cellskills = {}
if #player.player_cards[Player.Equip] > 0 then
for _,eid in ipairs(player.player_cards[Player.Equip]) do
local card = Fk:getCardById(eid)
if card and card.equip_skill then table.insert(equipskills,card.equip_skill.name) end
if card.name == "yx_yvxi" then table.insert(equipskills,"l_feiyang") table.insert(equipskills,"l_bahu") end
end
end
local dera_skills = {zhengnan = {"wusheng","dangxian","zhiman"},baobian = {"tiaoxin","paoxiao","shensu"},l_zhenfan = {"wusheng"},
lingren = {"jianxiong","xingshang"},lianhua = {"yingzi","guanxing","zhiyan","gongxin"},baichu={"qice"}}
local except_skills
for _,s in ipairs(player.player_skills) do
if dera_skills[s.trueName] then
except_skills = dera_skills[s.trueName]
end
if s.frequency < Skill.Limited and not string.find(pdlskills,s.name) and not table.contains(equipskills,s.name) and (not except_skills and true or not table.contains(except_skills,s.trueName)) then
table.insert(cellskills,s.name)
end
end
if #cellskills == 0 then room:doBroadcastNotify("ShowToast", "无可售技能") return end
if #cellskills > 0 then
table.insert(cellskills,"Exist")
while #cellskills > 1 do
local chs = room:askForChoice(player, cellskills, "#puyuanShop-cellskills", "#puyuanShop-cellskills")
if chs == "Exist" then return end
local getgold = math.floor(math.random(20,30)+0.5)
room:addPlayerMark(player,"@gold_num",getgold)
room:doBroadcastNotify("ShowToast", Fk:translate(player.general).."售卖了"..Fk:translate(chs).."。获得"..getgold.."金币")
room:handleAddLoseSkills(player, "-"..chs, nil, false)
table.removeOne(cellskills,chs)
end
end
end
function EndLessPractice:enterPYShop(player)
local room = self.room
if #self.shop_items < 2 then room:doBroadcastNotify("ShowToast", "铁匠铺东西卖光了") return end
while #self.shop_items > 1 do
local chs = room:askForChoice(player, self.shop_items, "#puyuanShop-buyeuips", "#puyuanShop-buyeuips")
if chs == "Exist" then return end
local goldnum = player:getMark("@gold_num")
local price_pos = string.find(chs,":%d")
local name_pos = string.find(chs,":")
local price = tonumber(string.sub(chs,price_pos+1))
local name = string.sub(chs,1,name_pos-1)
-- print(goldnum,price_pos,price,name)
-- dbg()
self:buyShopItem(player,chs,price,goldnum,name)
if #self.shop_items < 2 then room:doBroadcastNotify("ShowToast", "铁匠铺东西卖光了") return end
end
if self.refreshop then
self:enterPYShop(who)
end
end
function EndLessPractice:meetPuYuan()
local room = self.room
local meetcfg = self.meetpuyuandata
if self.layer % meetcfg.meet[2] == 0 then
self.meetpylayer = 0 --每meetcfg.meet[2]层最多能遇见meetcfg.meet[1]次浦沅
end
self.meetpyrate = self.meetpyrate + meetcfg.rate
-- self.meetpyrate = 1 --测试
if math.random() < self.meetpyrate and self.meetpylayer < meetcfg.meet[1] then
self.meetpyrate = 0
self.meetpylayer = self.meetpylayer + 1
self.refreshop = false
self:upShopItems(false,true)
local chc = {"Exist","pyshop_buyitems","pyshop_cellskills"}
if #chc > 1 then
table.forEach(self.otherplayers,function (op)
if op.id < 0 then return end
while #chc > 1 do
local chs = self.room:askForChoice(op, chc, "#puyuanShop-choice", "#puyuanShop-choice")
if chs == "Exist" then break end
if chs == "pyshop_buyitems" then
self:enterPYShop(op)
end
if chs == "pyshop_cellskills" then
self:cellSelfSkills(op)
end
end
end)
end
end
end
function EndLessPractice:getOPlayers(who)
local room = self.room
local nocamps = {}
local layerfriends = {}
for _, player in ipairs(room.alive_players) do
if player.id ~= who.id then
if self.camps[player.role] ~= self.camps[who.role] then
table.insert(nocamps,player)
else
table.insert(layerfriends,player)
end
end
end
if not self.layowner or self.camps[self.layowner.role] == self.camps[who.role] then
self.otherplayers = nocamps
self.layerfriends = layerfriends
end
return nocamps
end
function EndLessPractice:getAliveHumans()
local alivehumans = {}
for _, player in ipairs(self.room.alive_players) do
if player.id > 0 and player.role == "rebel" then
table.insert(alivehumans,player.id)
end
end
return alivehumans
end
function EndLessPractice:getDiePlayers()
local dead_t = {}
for _, player in ipairs(self.room.players) do
if player.dead and player.role == "rebel" then
table.insert(dead_t,player.general)
end
end
return dead_t
end
function EndLessPractice:getPyGodWeapon()
local puyuan_weapons = {"red_spear", "quenched_blade", "poisonous_dagger", "water_sword", "thunder_blade"}
local py_equips,py_weapons={},{}
for i, item in ipairs(self.shop_items) do
if string.startsWith(item,"st_") then
local name_pos = string.find(item,":")
local name = string.sub(item,4,name_pos-1)
table.insert(py_equips,name)
end
end
if #py_equips == 0 then return py_equips end
for _,pyep in ipairs(py_equips) do
if table.contains(puyuan_weapons,pyep) then
table.insert(py_weapons,pyep)
end
end
return py_weapons
end
function EndLessPractice:removePyGodWeapon(name)
local rmname
for i, ep in ipairs(self.shop_items) do
if string.startsWith(ep,name) then
rmname = ep
break
end
end
if rmname then table.removeOne(self.shop_items,rmname) end
end
function EndLessPractice:changeLayer(layer)
self.layer = self.layer + layer
end
function EndLessPractice:getLayer()
return self.layer
end
function EndLessPractice:addContiWin(n)
self.curctiwin = self.curctiwin + n
end
function EndLessPractice:handleContiWin()
local room = self.room
if self.curctiwin == self.maxctiwin-1 then
room:doBroadcastNotify("ShowToast", "层主的凝视。连胜太多越难,再连胜结束你的当前阶段")
end
if self.curboss then
room:doBroadcastNotify("ShowToast", "BOSS战,结束你的当前阶段")
end
if (self.curctiwin >= self.maxctiwin or self.curboss) and room.current.role == "rebel" then
self:endWhoPhase()
end
if self.layer >= 40 then self.maxctiwin = 4 end
end
function EndLessPractice:setContiWin(n)
self.curctiwin = n
end
function EndLessPractice:getContiWin()
return self.curctiwin
end
function EndLessPractice:addPdlCall(n)
self.panduola_call = self.panduola_call + n
end
function EndLessPractice:getPdlCall()
return self.panduola_call
end
function EndLessPractice:initOplayerData(data)
local otherplayers = self.otherplayers
for _, p in ipairs(otherplayers) do
if p.id > 0 then
self.reward_cfg[tostring(p.id)] = data.rewards
self.pdl_tmpskills[tostring(p.id)] = ""
self.room:setPlayerMark(p,"curlayerphase",1)
self.room:setPlayerMark(p,"@gold_num",data.initgold+math.floor(math.random(2,5)+0.5))
end
end
end
function EndLessPractice:initSkills()
local layowner = self.layowner
for _, p in ipairs(self.room.players) do
if p.role ~= "lord" and p.id > 0 then
self.room:handleAddLoseSkills(p, "wjsl_zhenfen", nil, false)
end
end
end
function EndLessPractice:initLayer()
self.room:setPlayerMark(self.layowner,"@wj_layer",self.layer)
end
function EndLessPractice:updateLayer(who,mark)
local layer = self.layer
self.room:setPlayerMark(who,mark,layer)
end
function EndLessPractice:removeRelateSkills(who)
local og = Fk.generals[who.general]
local to_rm = table.map(og.related_skills, Util.NameMapper)
table.insertTable(to_rm, og.related_other_skills)
self.room:handleAddLoseSkills(who, table.concat(table.map(to_rm, function(s) return "-" .. s end), "|"), nil, true)
end
function EndLessPractice:curLayerEmys(layer,isclone,isremove)
if type(self.all_generals[1]) == "string" then
local getgens = not isclone and self.all_generals or self.clone_generals
return isremove and table.remove(getgens,1) or table.random(getgens)
else
local layindex = math.ceil(layer / 10)
local gens = not isclone and self.all_generals[layindex] or self.clone_generals[layindex]
if gens then
if not isremove and math.random() < 0.2 and (self.all_generals[layindex+1] or self.clone_generals[layindex+1]) then
gens = not isclone and self.all_generals[layindex+1] or self.clone_generals[layindex+1]
end
return isremove and table.remove(gens,1) or table.random(gens)
else
if layer <= 1 then
self.room:doBroadcastNotify("ShowToast", "找不到将池,游戏结束")
self.room:gameOver("rebel")
return
end
return self:curLayerEmys(layer-1,isclone,isremove)
end
end
end
function EndLessPractice:changeGeneral(who,hasboss)
local newgeneral = Fk.generals[hasboss or self:curLayerEmys(self.layer,false,true)]
if not newgeneral then
self.room:doBroadcastNotify("ShowToast", "刷新AI的将池耗尽,游戏结束")
self.room:gameOver("rebel")
return
end
local kingdom = newgeneral.kingdom
newgeneral = newgeneral.name
self.room:changeHero(who, newgeneral, true, false, true)
self.room:revivePlayer(who, false)
self.room:setPlayerProperty(who, "kingdom", kingdom)
self.room:askForChooseKingdom({who})
return newgeneral
end
function EndLessPractice:notifyLayer(mark)
local otherplayers = self.otherplayers
local layer = self.layer
for _, pr in ipairs(otherplayers) do
self.room:setPlayerMark(pr,mark,layer)
end
end
function EndLessPractice:updateMax(who,cal_add,mes)
who.hp = who.hp + cal_add
who.maxHp = who.maxHp + cal_add
self.room:setPlayerProperty(who, "hp", who.hp)
self.room:setPlayerProperty(who, "maxHp", who.maxHp)
if mes then
self.room:doBroadcastNotify("ShowToast", mes)
end
end
function EndLessPractice:getLaySkills(who)
local layer = self.layer
for s, l in pairs(self.layownskills) do
if not who:hasSkill(s) and layer >= l then
self.room:handleAddLoseSkills(who, s, nil, false)
end
end
end
function EndLessPractice:removeOldSkills(newgeneral,who)
local layer = self.layer
local gen = Fk.generals[newgeneral]
local otherskills = gen.other_skills
local rm_skills = {}
local new_gen_skills = table.map(gen.skills,function (ski) return ski.name end)
if otherskills and #otherskills > 0 then
table.insertTableIfNeed(new_gen_skills,otherskills)
end
for _, skill in ipairs(who.player_skills) do
--过滤永久技能wjsl_zhenta|paoxiao
if not table.contains(new_gen_skills,skill.name) then
--过滤关卡技能
if not self.layownskills[skill.name] or layer < self.layownskills[skill.name] then
table.insert(rm_skills,"-"..skill.name.."|")
end
end
end
if #rm_skills > 0 then
local loseskills = table.concat(rm_skills,"")
self.room:handleAddLoseSkills(who, loseskills, nil, false)
end
end
function EndLessPractice:bury(who,exceptlist)
who:setSkillUseHistory("")
who:setCardUseHistory("")
who:throwAllCards()
if exceptlist then
for mark,v in pairs(who.mark) do
if not table.contains(exceptlist,mark) then
self.room:setPlayerMark(who, mark, 0)
end
end
else
who:throwAllMarks()
end
who:clearPiles()
who:reset()
end
function EndLessPractice:getRskiNum()
local getskill_n = math.floor(self.layer / self.laygetskill_n)
return getskill_n > 0 and getskill_n or 0
end
function EndLessPractice:getRandSkills(n,who,istmp)
local getskills_t = {}
local trans_skinames = ""
while #getskills_t < n do
-- local randg = table.random(self.clone_generals)
local randg = self:curLayerEmys(self.layer,true)
randg = Fk.generals[randg]
if not randg then
self.room:doBroadcastNotify("ShowToast", "抽技能时将池耗尽,游戏结束")
self.room:gameOver("rebel")
return
end
local skills_name = {}
for _, ski in ipairs(randg.skills) do
if ski.frequency < Skill.Limited then
table.insert(skills_name,ski.name)
end
end
if #skills_name > 0 then
local rand_skill = table.random(skills_name)
local skilltrueName = Fk.skills[rand_skill].trueName
local canget = table.every(who.player_skills,function (ski)
if ski.trueName ~= skilltrueName then
return true
end
end)
if canget then
if #trans_skinames > 0 then
trans_skinames = trans_skinames.. "、"
end
trans_skinames = trans_skinames..Fk:translate(rand_skill)
table.insert(getskills_t,rand_skill)
if istmp then
self.pdl_tmpskills[tostring(who.id)] = self.pdl_tmpskills[tostring(who.id)]..rand_skill.."|"
end
end
end
end
local skills = table.concat(getskills_t,"|")
skills = string.sub(skills,1,-1)
self.room:handleAddLoseSkills(who, skills, nil, false)
if istmp then
self.room:doBroadcastNotify("ShowToast",Fk:translate(who.general).."获得魔盒技能:"..trans_skinames)
return getskills_t[1]
else
self.room:doBroadcastNotify("ShowToast",Fk:translate(who.general).."获得技能:"..trans_skinames)
end
end
function EndLessPractice:drawByRelife(who)
local layer = self.layer
local players_hands = 0
local otherplayers = self.otherplayers
table.forEach(otherplayers,function (p)
players_hands = players_hands + #p.player_cards[Player.Hand]
end)
local layer_hands = math.ceil(layer / 10) * 2 + self.curctiwin * self.curctiwin
local extra_draw = 2 * math.ceil((#otherplayers / (#self.room.alive_players-#otherplayers))) + layer_hands + (self.curboss and layer_hands or 0)
if players_hands > #otherplayers * 8 then
extra_draw = extra_draw + math.ceil((players_hands - extra_draw) / 6)
end
self.room:drawCards(who, extra_draw,self.rulename)
--单人玩家摸牌
if #otherplayers == 1 then
local alivep = otherplayers[1]
self.room:drawCards(alivep, 3 + math.ceil(layer / 10),self.rulename)
end
end
function EndLessPractice:drawCardsByCamp(num,tars)
for _,pr in ipairs(tars) do
self.room:drawCards(pr, num,self.rulename)
end
end
function EndLessPractice:otherPlayersDraw(num)
table.forEach(self.otherplayers,function (p)
self.room:drawCards(p, num,self.rulename)
end)
end
function EndLessPractice:endWhoPhase()
local room = self.room
local who = room.current
if who.phase == Player.Play then
room:doBroadcastNotify("ShowToast", Fk:translate(who.general).."结束当前阶段")
room.logic:getCurrentEvent():findParent(GameEvent.Phase):shutdown()
end
end
function EndLessPractice:callPanduola(who,call_n)
if self.panduola_call >= call_n then
self.panduola_call = -9999
self:removeRelateSkills(who)
local whoname = "l__panduola"
self.room:changeHero(who, whoname, true, false, true)
self.room:setPlayerProperty(who, "kingdom", Fk.generals[whoname].kingdom)
self.room:askForChooseKingdom({who})
self:removeOldSkills(whoname,who)
self.room:drawCards(who,10,self.rulename)
self.room:doBroadcastNotify("ShowToast", "魔盒变得狂躁起来,张开血盆大口向你扑过来...")
end
end
--重置潘多拉技能
function EndLessPractice:resetPdlSkills(chcname)
local otherplayers = self.otherplayers
for _, p in ipairs(otherplayers) do
local mark = p:getMark("@pdlbox")
local tmpskills = self.pdl_tmpskills[tostring(p.id)]
if mark > 0 and tmpskills and #tmpskills > 0 then
local skills_t = tmpskills:split("|")
table.removeOne(skills_t,"")
table.insert(skills_t,"Cancel")
local resetskills,skillsname = {},{}
local resetskis = {["#rstskills_1"]=5,["#rstskills_2"]=7,["#rstskills_3"]=10,["#rstskills_4"]=12,["#rstskills_5"]=15}
local resetnum = 1
while resetskis["#rstskills_"..resetnum] and p:getMark("@gold_num") >= resetskis["#rstskills_"..resetnum] do
local resetstr = "#rstskills_"..resetnum
local chs = self.room:askForChoice(p, skills_t, resetstr, resetstr,true)
if chs == "Cancel" then break end
self.room:handleAddLoseSkills(p, "-"..chs, nil, false)
self.room:doBroadcastNotify("ShowToast", Fk:translate(p.general) .."失去魔盒技能:"..Fk:translate(chs))
table.removeOne(skills_t,chs)
table.removeOne(skills_t,"Cancel")
if #skills_t > 0 then
self.pdl_tmpskills[tostring(p.id)] = table.concat(skills_t,"|")
self.pdl_tmpskills[tostring(p.id)] = self.pdl_tmpskills[tostring(p.id)].."|"
else
self.pdl_tmpskills[tostring(p.id)] = ""
end
local getskill = self:getRandSkills(1,p,true)
if not getskill then break end
self.room:removePlayerMark(p,"@gold_num",resetskis["#rstskills_"..resetnum])
resetnum = resetnum + 1
table.insert(skills_t,getskill)
table.insert(skills_t,"Cancel")
end
end
end
end
--随机的奖励选项
function EndLessPractice:randRewardSel(who)
local layer,room = self.layer,self.room
--玩家奖励随机选项(按照cfg配置随机每个选项)
local reward_n_sel = function ()
for i = 1, #self.rewd_intval do
if layer < self.rewd_intval[i][1] then
return {self.rewd_intval[i][3],self.rewd_intval[i][2]}
end
end
end
local rwd_n_sel = reward_n_sel() --奖励(总共项|选择次数)
if not rwd_n_sel then return end
local sel_n = rwd_n_sel[2] --奖励可以选择次数
--寻找不重复选项
local skill_n = 0
local rand_choices = function (reward_cfg)
local choices = {}
while #choices < rwd_n_sel[1] do
local rand = math.random()
local forward = 0
for i, v in pairs(reward_cfg) do
local last = v
if rand >= forward and rand < last + forward then
-- 技能可以多个存在
if i ~= "skills" and table.contains(choices,i) then
break
end
table.insert(choices,i)
if i == "skills" then
skill_n = skill_n + 1 --列表中技能个数
end
break
end
forward = forward + last
end
end
return choices
end
local cfg = self.reward_cfg[tostring(who.id)]
--选项加工替换其中的skills
local chc = rand_choices(cfg) --选项列表(技能是skill需要被真的技能名替换)
local rand_skills = {}
local prohib_forn = 0
local shopskills = ShopMgr:getShopSkills()
while skill_n > 0 and #rand_skills < skill_n do
local randg = self:curLayerEmys(self.layer)
randg = Fk.generals[randg]
if not randg then
room:doBroadcastNotify("ShowToast", "抽技能时将池耗尽,游戏结束")
room:gameOver("rebel")
return
end
local skills_name = {}
for _, sk in ipairs(randg.skills) do
if sk.frequency < Skill.Limited then
table.insert(skills_name,sk.name)
end
end
if #skills_name > 0 then
local rand_skill = table.random(skills_name)
local tnskill = Fk.skills[rand_skill]
local tnameski = tnskill.trueName
if tnameski and not table.contains(shopskills,tnameski) and not table.find(who.player_skills,function(sk) return sk.trueName == tnameski end) then
table.insert(rand_skills,rand_skill)
end
end
--防止死循环
if prohib_forn > 300 then
room:doBroadcastNotify("ShowToast", "敌人将池过少,游戏结束")
room:gameOver("rebel")
return
end
prohib_forn = prohib_forn + 1
end
--技能名字替换skills
for i = 1, #chc do
if chc[i] == "skills" and #rand_skills > 0 then
chc[i] = table.remove(rand_skills,1)
end
end
return chc,sel_n
end
--选项(潘多拉)
function EndLessPractice:choiceByPdl(who,chs,name)
local luckyman = who
if chs == "disCard" then
self:throwHalfHands(luckyman,name)
elseif chs == "turnOver" then
self:turnOver(luckyman)
elseif chs == "tianQian" then
self:tianQian(luckyman,name)
elseif chs == "getShenQi" then
self:getShenQi(who,name)
elseif chs == "tmpSkills" then
local randmark = table.random({1,1,1,1,1,1,2,2,2,3})
self:addBoxMark(who,"@pdlbox",randmark)
end
end
--潘多拉印记技能
function EndLessPractice:addBoxMark(who,mark,num)
self.room:addPlayerMark(who,mark,num)
self:getRandSkills(num,who,true)
self.room:doBroadcastNotify("ShowToast",Fk:translate(who.general).."获得魔盒印记+"..num)
end
--丢弃一半手牌
-- function EndLessPractice:throwHalfHands(who,name)
-- local handcards = who.player_cards[Player.Hand]
-- if #handcards > 1 then
-- local dis_cs = table.random(handcards,math.floor(#handcards / 2))
-- self.room:throwCard(dis_cs, name, who, who)
-- end
-- self.room:doBroadcastNotify("ShowToast","潘多拉张开獠牙大嘴冲向了"..Fk:translate(who.general)..",他因为感到恐惧随机丢弃一半手牌...")
-- end
--天谴
-- function EndLessPractice:tianQian(who,name)
-- self.room:damage{to = who,damage = math.ceil(who.hp/2),damageType = fk.ThunderDamage,skillName = name}
-- self.room:doBroadcastNotify("ShowToast", "潘多拉打了个哈欠..顺便吟唱张角的闪电"..Fk:translate(who.general).."不小心成为天命之子...")
-- end
--翻面
-- function EndLessPractice:turnOver(who)
-- who:turnOver()
-- self.room:doBroadcastNotify("ShowToast","潘多拉喷出奇怪东西砸晕了"..Fk:translate(who.general).."仔细一看是gk的木马...")
-- end
--神器
-- function EndLessPractice:getShenQi(who,name)
-- if self.shenqi_n >= 2 then
-- self.room:doBroadcastNotify("ShowToast", "潘多拉神器空空如也~或许是被哪个窃贼偷光了...")
-- self.room:drawCards(who,2,name)
-- return
-- end
-- if math.random() < self.panduola_rate[tostring(who.id)] then
-- self.room:doBroadcastNotify("ShowToast", "潘多拉提醒你有神器。但它告诉你你今天运气不好,多回去等等,下次一定!")
-- self.room:drawCards(who,2,name)
-- return
-- end
-- for _, id in ipairs(Fk:getAllCardIds()) do
-- local card = Fk:getCardById(id)
-- if card.name == "shsfzjg" or card.name == "shttk" then
-- if self.room:getCardArea(id) == Card.Void then
-- self.room:moveCards({
-- ids = {id},
-- fromArea = Card.Void,
-- to = who.id,
-- toArea = Card.PlayerHand,
-- moveReason = fk.ReasonJustMove,
-- proposer = who.id,
-- skillName = name,
-- })
-- self.shenqi_n = self.shenqi_n + 1
-- self.room:doBroadcastNotify("ShowToast", "神器!吕布的神器!潘多拉一脸欧皇看着你...")
-- break
-- end
-- end
-- end
-- end
function EndLessPractice:removeLayerBoss(who)
if not self.godboss then return end
if self.curboss then
if #self.godboss == 0 then
self.curboss = nil
return
end
table.removeOne(self.godboss,self.curboss)
if not who or who.id == self.layowner.id then
self.curboss = nil
return
end
local bossskills = table.map(Fk.generals[self.curboss].skills,function (s)
return s.name
end)
local chs = self.room:askForChoice(who, bossskills, "#getBossSkills-choice", "#getBossSkills-choice",true)
self.room:handleAddLoseSkills(who, chs, nil, false)
self.curboss = nil
local bossgold = 40 * math.ceil(self.layer / 10)
self.room:addPlayerMark(who,"@gold_num",bossgold)
self.room:doBroadcastNotify("ShowToast",Fk:translate(who.general).."击杀神将金币+"..bossgold)
end
end
function EndLessPractice:getLayerBoss()
-- local step = math.floor(self.layer / 10)
if not self.godboss then return end
if self.curboss then return self.curboss end
local step_n = self.layer % self.defbossstep
local bossname = nil
if step_n == 0 then
if #self.godboss > 0 then
bossname = table.random(self.godboss)
if self.layer == self.defbossstep then
local clone_t = table.clone(self.godboss)
table.removeOne(clone_t,"godsunce")
bossname = table.random(clone_t)
end
if self.layer == self.totallayer then
bossname = "godjiangwei"
end
self.curboss = bossname
else
bossname = "godjiangwei"
self.curboss = bossname
end
end
return bossname
end
--复活玩家(死亡时候)
function EndLessPractice:relifePlayer(general)
for _, player in ipairs(self.room.players) do
if player.general == general and player.dead then
self.room:revivePlayer(player, false)
self.room:setPlayerMark(player, "curlayerphase",self.layer)
self.room:drawCards(player, 4 + (math.floor(self.layer/10) * 2),self.rulename)
break
end
end
end
--复活层主忠臣人机队友
function EndLessPractice:reLayerFriends(ldiefriends,relifenum,boss)
local room = self.room
for i, player in ipairs(ldiefriends) do
if i > relifenum then return end
local isdead = player.dead
local curlayer = self.layer + 1
if isdead then
curlayer = self.layer
self:bury(player)
self:removeRelateSkills(player)
local newgeneral = self:changeGeneral(player,boss and table.remove(boss))
if not newgeneral then
room:doBroadcastNotify("ShowToast", "将池耗尽")
room:gameOver("rebel")
return
end
--删除复活前技能
self:removeOldSkills(newgeneral,player)
end
--刷新最大maxhp与hp,每过n关获得随机技能
local cal_add = math.floor(curlayer / self.lordsperup)
if cal_add > 0 and (isdead or math.floor((self.layer + 1) / self.lordslayer) > math.floor(self.layer / self.lordslayer)) then
self:updateMax(player,cal_add)
self:getRandSkills(cal_add,player)
end
local ctw = self.curctiwin + 1
if isdead then
room:drawCards(player, 4 + (math.floor(self.layer/10)*2) + math.floor(ctw * 1.5),self.rulename)
end
end
end
--升级人机队友
function EndLessPractice:upAiFriends(owner)
local room = self.room
if not owner then return end
local ais = table.filter(room.players,function(p) return p.id < 0 and p.role == "rebel" end)
ais = table.map(ais,function(pr) return pr.general end)
local chs
if ais == 1 then
chs = ais[1]
else
chs = room:askForChoice(owner, ais, self.rulename, "#upAI-choice")
end
for _,pr in ipairs(room.players) do
if pr.general == chs then
self:updateMax(pr,1)
self:getRandSkills(1,pr)
room:addPlayerMark(pr,math.random() < 0.5 and "@slash_dmg" or "@trick_dmg",1)
room:addPlayerMark(pr,math.random() < 0.5 and "@shieldnum" or "@df_lingxin",1)
room:addPlayerMark(pr,"@slash_num",2)
break
end
end
end
--关卡奖励
function EndLessPractice:layerRewards(reset)
local otherplayers = self.otherplayers
local room = self.room
local humans,aifriends = {},{}
for _,pr in ipairs(otherplayers) do
if pr.id > 0 then table.insert(humans,pr) end
if pr.id < 0 and pr.role == "rebel" then table.insert(aifriends,pr.id) end
end
for _, p in ipairs(humans) do
local chc,sel_n = self:randRewardSel(p)
if not chc then break end
--守护天使
local angelmark = p:getMark("@@guardangle")
if angelmark == 0 and math.random() < 0.1 then
table.remove(chc,math.floor(math.random(1,#chc)+0.5))
table.insert(chc,"guard_angel")
end
--有死亡加入选项
local deadPlayers = self:getDiePlayers()
if #deadPlayers > 0 then
table.insert(chc,"relife")
end
local retstr,retgold = "rsetrwd",0
if reset then
sel_n = 1
else
if self.layer <= 20 then
retstr = retstr.."_1"
retgold = 20
elseif self.layer > 20 and self.layer <= 40 then
retstr = retstr.."_2"
retgold = 30
else
retstr = retstr.."_3"
retgold = 40
end
if p:getMark("@gold_num") >= retgold then
table.insert(chc,retstr)
end
end
if #aifriends > 0 then
table.insert(chc,"upAI")
end
--奖励可以多选
for i = 1, sel_n do
local sel_chs = room:askForChoice(p, chc, self.rulename, "#skills-choice", true)
if sel_chs == "maxhp" then
local randv = math.random() < 0.2 and 3 or table.random({1,2,1})
self:updateMax(p,randv,Fk:translate(p.general).."选择了最大体力值+"..randv)
elseif sel_chs == "lingxin" then
local randv = math.random() < 0.2 and 3 or table.random({1,2,1,1})
room:addPlayerMark(p,"@df_lingxin",randv)
room:doBroadcastNotify("ShowToast", Fk:translate(p.general).."选择了凌心+"..randv)
elseif sel_chs == "shieldnum" then
local randv = math.random() > 0.1 and 1 or 2
room:addPlayerMark(p,"@shieldnum",randv)
room:doBroadcastNotify("ShowToast", Fk:translate(p.general).."选择了护甲+"..randv)
elseif sel_chs == "magicbox" then
self:addPdlCall(1) -- 开启潘多拉次数+1
self:choiceByPdl(p,"tmpSkills",self.rulename)
elseif sel_chs == "extraslash_num" then
local randextra = math.random(2,4)
room:addPlayerMark(p,"@slash_num",randextra)
room:doBroadcastNotify("ShowToast", Fk:translate(p.general).."选择了杀次数额外增加"..randextra)
elseif sel_chs == "angelbless" then
if p:isWounded() then
room:recover({who = p,num = p:getLostHp(),recoverBy = p,skillName = self.rulename})
end
room:drawCards(p, p.maxHp,self.rulename)
local randmark = table.random({"@slash_dmg","@trick_dmg","@gold_num","@df_lingxin","@shieldnum","@slash_num"})
if randmark ~= "@gold_num" then
room:addPlayerMark(p,randmark,1)
room:doBroadcastNotify("ShowToast",Fk:translate(p.general).."选择了天使祝福,随机获得"..Fk:translate(randmark).."1")
else
local rand_gold = math.floor(math.random(10,20)*math.ceil(self.layer/10)+0.5)
room:addPlayerMark(p,randmark,rand_gold)
room:doBroadcastNotify("ShowToast",Fk:translate(p.general).."选择了天使祝福,随机获得"..Fk:translate(randmark)..rand_gold)
end
elseif sel_chs == "slash_dmg_sel" or sel_chs == "trick_dmg_sel" then
local strdmg = string.gsub(sel_chs,"_sel","")
room:addPlayerMark(p,"@"+strdmg,1)
local str = sel_chs == "slash_dmg_sel" and "杀造成伤害+1" or "锦囊造成伤害+1"
room:doBroadcastNotify("ShowToast", Fk:translate(p.general).."选择了"..str)
elseif sel_chs == "relife" then
if #deadPlayers == 0 then return end
local relifechs = room:askForChoice(p, deadPlayers, self.rulename, "#relife-choice")
self:relifePlayer(relifechs)
elseif sel_chs == "guard_angel" then
room:setPlayerMark(p,"@@guardangle",1)
room:doBroadcastNotify("ShowToast", Fk:translate(p.general).."选择了守护天使")
elseif sel_chs == "gaingold" then
local goldnum = math.ceil(math.random(math.ceil(self.layer/10)*2+40,self.layer < 30 and 60 or 70))
room:addPlayerMark(p,"@gold_num",goldnum)
room:doBroadcastNotify("ShowToast", Fk:translate(p.general).."获得金币+"..goldnum)
elseif sel_chs == "upAI" then
self:upAiFriends(p)
elseif string.startsWith(sel_chs,"rsetrwd") then
room:removePlayerMark(p,"@gold_num",retgold)
self:layerRewards(true)
else
room:handleAddLoseSkills(p, sel_chs, nil, false)
room:doBroadcastNotify("ShowToast", Fk:translate(p.general).."选择了技能:"..Fk:translate(sel_chs))
end
table.removeOne(chc,sel_chs)
end
end
end
return EndLessPractice
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/ssrzzy/lang.git
git@gitee.com:ssrzzy/lang.git
ssrzzy
lang
Lang
master

搜索帮助