魔力宝贝

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz

[GP] WatchBattle.lua--观战

[复制链接]
发表于 3 天前 | 显示全部楼层 |阅读模式
local GetWatchIndexWord = "/7" --获取自己观战码指令
local CancelWatchIndexWord = "/nowb" --取消自己的观战状态
local GetWatchGold = 1000 --获取观战码花费的魔币数量
local UseWatchIndexWord = "/wb " --观战指令 /wb xxx
local WatchBattleAnn = "正在邀请所有人对他观战,"

local WatchBattle_NPCxq = {14522,"观战",6,1000,234,116} --NPC详情

-------------------------------------
Global_Reg.RegInit("WatchBattle_zhuce");--注册
Global_Reg.RegLoginEvent("WatchBattleLoginEvent");
Global_Reg.RegLogoutEvent("WatchBattleOutEvent");
Global_Reg.RegTalkEvent("TalkEvent_WatchBattle");

WatchPlayerTable = WatchPlayerTable or {}
WatchBattleCheck = WatchBattleCheck or {}

function WatchBattleOutEvent(player)
        if WatchPlayerTable[player] ~= nil        then
        WatchPlayerTable[player] = nil
        end
end

function TalkEvent_WatchBattle(player, msg, color, range, size)
        if(string.sub(msg,1,4)=="P|"..GetWatchIndexWord)then
                if Char.GetData(player,53) >= GetWatchGold then
                        Char.SetData(player,53,Char.GetData(player,53)-1000)
                        NLG.UpChar(player)
                        WatchPlayerTable[player] = 1
                        NLG.SystemMessage(-1,Char.GetData(player,2000)..WatchBattleAnn.."所有人可以输入【"..UseWatchIndexWord..player.."】或前往法兰城老银行前("..WatchBattle_NPCxq[5]..","..WatchBattle_NPCxq[6]..")的"..WatchBattle_NPCxq[2].."处点击他的名字观战。")
                        NLG.SystemMessage(player,"你的观战码为"..player..",你可以邀请你的朋友们输入【"..UseWatchIndexWord..player.."】对你进行观战。或前往法兰城老银行前("..WatchBattle_NPCxq[5]..","..WatchBattle_NPCxq[6]..")的"..WatchBattle_NPCxq[2].."处点击你的名字观战。观战码及Npc观战登记在本次登录内有效,登出或掉线后失效。您也可以输入"..CancelWatchIndexWord.."手动取消观战状态。")
                else
                        NLG.SystemMessage(player,"获取观战码指令并公告全服需要"..GetWatchGold.."魔币。")
                end
        elseif (string.sub(msg,1,7) == "P|"..CancelWatchIndexWord) then
                WatchPlayerTable[player] = nil
                NLG.SystemMessage(player,"取消了观战状态。")
        elseif string.sub(msg,1,6) == "P|"..UseWatchIndexWord then
                local watchindex = tonumber(string.sub(msg,string.len(UseWatchIndexWord)+3,string.len(msg)))
                if watchindex then
                        if WatchPlayerTable[watchindex] then
                                if Char.GetData(watchindex,(0)) == (1) then
                                       
                                        --NLG.SystemMessage(-1,"[屏蔽血条]被观战的index是"..watchindex)
                                        NLG.SystemMessage(player,"如未成功观战,则说明该玩家目前不在战斗中。")
                                        Char.SendHideHpMp(player,0)
                                        --NLG.SystemMessage(-1,"1就是成功,返回值是:"..a)
                                        if BattleIndex_save_tbl[watchindex] then
                                                Char.SendHideHpMp(player,1)
                                        end
                                        NLG.WatchEntry(player,watchindex)
                                else
                                        NLG.SystemMessage(player,"请输入正确的观战码。")
                                end
                        else
                                NLG.SystemMessage(player,"该玩家未登记观战或已下线。")
                        end
                else
                        NLG.SystemMessage(player,"请输入正确的观战格式:"..UseWatchIndexWord.."xxx 。")
                end
--        elseif msg =="P|测试" then
--        local hp = Char.GetData(player,158)
--                NLG.SystemMessage(player,"hp:"..hp)
        end
end

function WatchBattleLoginEvent(player)
        WatchPlayerTable[player] = nil
        WatchBattleCheck[player] = nil
end

function WatchBattle_zhuce()
--        Protocol.RegProtocolRecv(nil,"WatchBattle_fabao")
        WatchBattle_NPC()
        return 0
        end


function WatchBattle_NPC(WatchBattle_npcindex)
        if WatchBattle_npcindex == nil  then
        WatchBattle_npcindex = NL.CreateNpc(nil,"WatchBattle_NPCzhizuo")
        end       
        Char.SetData(WatchBattle_npcindex,1,WatchBattle_NPCxq[1])
        Char.SetData(WatchBattle_npcindex,2,WatchBattle_NPCxq[1])
        Char.SetData(WatchBattle_npcindex,2000,WatchBattle_NPCxq[2])
        Char.SetData(WatchBattle_npcindex,7,WatchBattle_NPCxq[3])
        Char.SetData(WatchBattle_npcindex,4,WatchBattle_NPCxq[4])
        Char.SetData(WatchBattle_npcindex,5,WatchBattle_NPCxq[5])
        Char.SetData(WatchBattle_npcindex,6,WatchBattle_NPCxq[6])
        LuaNpcIndex["WatchBattle_npcindex"]=WatchBattle_npcindex;
        InstallNpc("WatchBattle_npcindex",WatchBattle_npcindex);
        NLG.UpChar(WatchBattle_npcindex)
        Char.SetTalkedEvent(nil,"WatchBattle_chuangkou",WatchBattle_npcindex)
        Char.SetWindowTalkedEvent(nil,"WatchBattle_gongneng",WatchBattle_npcindex)
        return true
end

function WatchBattle_NPCzhizuo(index)
        return true;
end

function WatchBattle_chuangkou(npc,player)
        if NLG.CanTalk(npc,player) or WatchBattleCheck[player] then
                WatchBattleCheck[player] = nil
                local button = 0
                local WatchPlayerTableTurn = {}
                local tempi = 1
                for k,v in pairs(WatchPlayerTable) do
                        WatchPlayerTableTurn[tempi] = k
                        tempi = tempi + 1
                end
                local msg = "2\n请选择您要观战的玩家:\n任意地点输入"..GetWatchIndexWord.."可发布远程观战"
                for i = 1,6 do
                        if WatchPlayerTableTurn[i] and Char.GetData(WatchPlayerTableTurn[i],(0)) == (1) then
                                msg = msg.."\n"..Char.GetData(WatchPlayerTableTurn[i],2000)
                                if  Char.GetData(WatchPlayerTableTurn[i],(11100)) > 0 then
                                        msg = msg.."(战斗中)"
                                else
                                        msg = msg.."(无战斗)"
                                end
                        else
                                msg = msg.."\n 无"
                        end
                end
                if #WatchPlayerTableTurn > 6 then
                        button = 34
                else
                        button = 2
                end
                NLG.ShowWindowTalked(player,2,button,0,msg,npc)
        end
end

function WatchBattle_gongneng(npc,player,_SqeNo,_select,_data)
--        print("\n _SqeNo是:"..(_SqeNo or "空").."它的类型是"..type(_SqeNo).."\n  _select是:".. (_select or "空").."它的类型是"..type(_select).."\n  _data是:"..(_data or "空").."它的类型是"..type(_data))
                if _select ~= 2 then
                        local WatchPlayerTableTurn = {}
                        local tempi = 1
                        for k,v in pairs(WatchPlayerTable) do
                                WatchPlayerTableTurn[tempi] = k
                                tempi = tempi + 1
                        end
                        if tonumber(_data) > 0 then
                                if WatchPlayerTableTurn[_SqeNo*6+tonumber(_data)]~= nil then
                                        if Char.GetData(WatchPlayerTableTurn[_SqeNo*6+tonumber(_data)],(0)) == (1) then
                                                local watchindex=WatchPlayerTableTurn[_SqeNo*6+tonumber(_data)]
                                                Char.SendHideHpMp(player,0)
                                                if BattleIndex_save_tbl[watchindex] then
                                                        Char.SendHideHpMp(player,1)
                                                end
                                                NLG.WatchEntry(player,watchindex)
                                        else
                                                NLG.SystemMessage(player,"请选择正确的玩家。")
                                        end
                                else
                                        NLG.SystemMessage(player,"非法的选项。")
                                end
                        else
                                local button = 0
                                local nextSeqno = _SqeNo
                                local msg = "2\n请选择您要观战的队伍:\n"
                                if _select == 32 then
                                        nextSeqno = _SqeNo + 1
                                elseif _select == 16 then
                                        nextSeqno = _SqeNo - 1
                                end
                                if nextSeqno >= 0 and nextSeqno < math.ceil(#WatchPlayerTableTurn/6) then
                                        for i = 1,6 do
                                                if WatchPlayerTableTurn[i+nextSeqno*6] and Char.GetData(WatchPlayerTableTurn[i+nextSeqno*6],(0)) == (1) then
                                                        msg = msg.."\n"..Char.GetData(WatchPlayerTableTurn[i+nextSeqno*6],2000)
                                                        if  Char.GetData(WatchPlayerTableTurn[i+nextSeqno*6],(11100))  > 0 then
                                                                msg = msg.."(战斗中)"
                                                        else
                                                                msg = msg.."(无战斗)"
                                                        end
                                                else
                                                        msg = msg.."\n 无"
                                                end
                                        end
                                        if #WatchPlayerTableTurn > (nextSeqno+1)*6 and nextSeqno > 0 then
                                                button = 50
                                        elseif #WatchPlayerTableTurn > (nextSeqno+1)*6 and nextSeqno == 0 then
                                                button = 34
                                        elseif #WatchPlayerTableTurn <= (nextSeqno+1)*6 and nextSeqno > 0 then
                                                button = 18
                                        elseif #WatchPlayerTableTurn <= (nextSeqno+1)*6 and nextSeqno == 0 then
                                                button = 2
                                        end
                                        NLG.ShowWindowTalked(player,2,button,nextSeqno,msg,npc)
                                else
                                        NLG.SystemMessage(player,"非法的选项。")
                                end
                        end
                        end
end

回复

使用道具 举报

Archiver|魔力研究社

GMT+8, 2025-5-13 03:39 , Processed in 0.141223 second(s), 23 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表