--Регистрация function CreatPoboisheRoleObj(RoleID) if Poboishe_Role[RoleID] == nil then local Target_MapID, Target_InstanceID = role.GetRoleMapID(RoleID) local rolelevel = role.GetRoleLevel(Target_MapID, Target_InstanceID, RoleID) if rolelevel >= 80 then Poboishe_Roletotal = Poboishe_Roletotal + 1 Poboishe_Role[RoleID] = {RoleID = RoleID, Time = 0, Side = "None", InstanceID = 1,State = "OutSide",Kill = 0} local Guild = guild.GetRoleGuildID(RoleID) local FamilyID = role.GetRoleFamilyID(Target_MapID, Target_InstanceID, RoleID) if Guild ~= nil and Guild ~= 4294967295 then Poboishe_Role[RoleID].Guild = Guild else Poboishe_Role[RoleID].Guild = 0 end if FamilyID ~= nil and FamilyID ~= 4294967295 then Poboishe_Role[RoleID].FamilyID = FamilyID else Poboishe_Role[RoleID].FamilyID = 0 end Poboishe_Role[RoleID].ShowPoboisheTime = ShowPoboisheTime Poboishe_Role[RoleID].GetAttBuff_Poboishe = GetAttBuff_Poboishe Poboishe_Role[RoleID].WuDi_Poboishe = WuDi_Poboishe Poboishe_Role[RoleID].SetColor_Poboishe = SetColor_Poboishe Poboishe_Role[RoleID].SendInfo_Poboishe = SendInfo_Poboishe Poboishe_Role[RoleID].PlayerLeavePoboishe = PlayerLeavePoboishe Poboishe_Role[RoleID].PlayerEnterPoboishe = PlayerEnterPoboishe Poboishe_Role[RoleID].GetKillExp_Poboishe = GetKillExp_Poboishe end end end --Создание групп function CreatPoboisheSideObj() local k = #Poboishe_Side + 1 Poboishe_Side[k] = {Player={},InSidePlayer={},Num = 0,Point = 0} if k%2 == 1 then Poboishe_Side[k].Side = "Red" else Poboishe_Side[k].Side = "Blue" end Poboishe_Side[k].PlayerJoinPoboisheSide = PlayerJoinPoboisheSide return Poboishe_Side[k] end --Присоединение к группе function PlayerJoinPoboisheSide(Obj,PlayerID) table.insert(Obj.Player,PlayerID) Poboishe_Role[PlayerID].Side = Obj.Side end --Создание поля боя function CreatPoboishenBattleObj(RedPlayer,BluePlayer) local k = #Poboishe_Battle + 1 map.CreateInstance(S66_1_MapID, k) Poboishe_Battle[k] = {RedPlayer = RedPlayer,BluePlayer = BluePlayer,InstanceID=k} for k1,v in pairs(RedPlayer.Player) do Poboishe_Role[v].InstanceID = k end for k1,v in pairs(BluePlayer.Player) do Poboishe_Role[v].InstanceID = k end Poboishe_Battle[k].SendAllInfo_Poboishe = SendAllInfo_Poboishe Poboishe_Battle[k].SetPlayerPoint_Poboishe = SetPlayerPoint_Poboishe Poboishe_Battle[k].SetPlayerFinalPoint_Poboishe = SetPlayerFinalPoint_Poboishe Poboishe_Battle[k].ResetInSidePlayer_Poboishe = ResetInSidePlayer_Poboishe end --Получение игроков поля боя function GetPoboisheRoleObj(RoleID) return Poboishe_Role[RoleID] end --Выбор стороны function Poboishe_ChooseSide() if Poboishe_Roletotal > 159 then local k = math.floor(Poboishe_Roletotal/80) local av_player = math.floor(Poboishe_Roletotal/k) local num = {} for i = 1,k do if i ~= k then num[i] = av_player else num[i] = Poboishe_Roletotal - av_player*(k-1) end end local Player = {} local Playertotal = 0 local function GetIndex(Playertotal) local total = 0 for i = 1,k do total = total + num[i] if total >= Playertotal then return i end end end for k1,v in pairs(Poboishe_Role) do Playertotal = Playertotal + 1 local index = GetIndex(Playertotal) --v.InstanceID = index if Player[index] == nil then Player[index] = {} end table.insert(Player[index],k1) end for i = 1,k do local RedSideObj = CreatPoboisheSideObj() local BlueSideObj = CreatPoboisheSideObj() local red = 0 local times = 0 while red < num[i]/2 do RedSideObj:PlayerJoinPoboisheSide(Player[i][1]) local Player1Obj = GetPoboisheRoleObj(Player[i][1]) red = red + 1 for k1,v in pairs(Player[i]) do local PlayerObj = GetPoboisheRoleObj(v) if PlayerObj.RoleID ~= v and ((PlayerObj.Guild ~= 0 and PlayerObj.Guild == Player1Obj.Guild) or (PlayerObj.FamilyID ~= 0 and PlayerObj.FamilyID == Player1Obj.FamilyID)) then RedSideObj:PlayerJoinPoboisheSide(v) red = red + 1 table.remove(Player[i],k1) if red >= num[i]/2 then break end end end table.remove(Player[i],1) times = times + 1 if times > 160 then break end end --RedSideObj.Num = red for k1,v in pairs(Player[i]) do BlueSideObj:PlayerJoinPoboisheSide(v) -- BlueSideObj.Num = BlueSideObj.Num + 1 end CreatPoboishenBattleObj(RedSideObj,BlueSideObj) end else local Player = {} for k,v in pairs(Poboishe_Role) do table.insert(Player,k) --v.InstanceID = 1 end local RedSideObj = CreatPoboisheSideObj() local BlueSideObj = CreatPoboisheSideObj() local red = 0 local times = 0 while red < Poboishe_Roletotal/2 do RedSideObj:PlayerJoinPoboisheSide(Player[1]) local Player1Obj = GetPoboisheRoleObj(Player[1]) red = red + 1 for k1,v in pairs(Player) do local PlayerObj = GetPoboisheRoleObj(v) if PlayerObj.RoleID ~= v and ((PlayerObj.Guild ~= 0 and PlayerObj.Guild == Player1Obj.Guild) or (PlayerObj.FamilyID ~= 0 and PlayerObj.FamilyID == Player1Obj.FamilyID)) then RedSideObj:PlayerJoinPoboisheSide(v) red = red + 1 table.remove(Player,k1) if red >= Poboishe_Roletotal/2 then break end end end table.remove(Player,1) times = times + 1 if times > 160 then break end end --RedSideObj.Num = red for k1,v in pairs(Player) do BlueSideObj:PlayerJoinPoboisheSide(v) -- BlueSideObj.Num = BlueSideObj.Num + 1 end CreatPoboishenBattleObj(RedSideObj,BlueSideObj) end end --время боя function ShowPoboisheTime(RoleObj) local leftSec = 3600 local Min = tonumber(os.date("%M")) local Second = tonumber(os.date("%S")) leftSec = leftSec - Min*60 - Second local MsgID = msg.BeginMsgEvent() msg.AddMsgEvent(MsgID, 16, 28) msg.AddMsgEvent(MsgID, 16, leftSec) msg.DispatchRoleMsgEvent(RoleObj.RoleID, MsgID) end --Бафф function GetAttBuff_Poboishe(RoleObj) local rolelevel = role.GetRoleLevel(S66_1_MapID, RoleObj.InstanceID, RoleObj.RoleID) if rolelevel > 100 then rolelevel = 100 end if rolelevel >= 50 then local index = math.floor((rolelevel-50)/5) + 1 unit.AddBuff(S66_1_MapID, RoleObj.InstanceID, RoleObj.RoleID, index*100+6107001, RoleObj.RoleID) end end --Получение опыта за убийство function GetKillExp_Poboishe(RoleObj) local rolelevel = role.GetRoleLevel(S66_1_MapID, RoleObj.InstanceID, RoleObj.RoleID) if rolelevel < 80 then rolelevel = 80 elseif rolelevel > 100 then rolelevel = 100 end RoleObj.Kill = RoleObj.Kill + 1 local exp1 = math.floor(Poboishe_Exp[rolelevel] / 10) if RoleObj.Kill > 30 then exp1 = 0 else role.AddRoleExp(S66_1_MapID, RoleObj.InstanceID, RoleObj.RoleID, exp1) end local MsgID = msg.BeginMsgEvent() msg.AddMsgEvent(MsgID, 13, 0) msg.AddMsgEvent(MsgID, 1, 206731) --Убито: <p1>, получено <p2> очков опыта. (Максимум можно получить 30-ти кратный опыт) msg.AddMsgEvent(MsgID, 9, RoleObj.Kill) msg.AddMsgEvent(MsgID, 9, exp1) msg.DispatchRoleMsgEvent(RoleObj.RoleID, MsgID) end --Баф при начале боя или смерти на 15 секунд function WuDi_Poboishe(RoleObj) unit.AddBuff(S66_1_MapID, RoleObj.InstanceID, RoleObj.RoleID, 6109401, RoleObj.RoleID) end --Цвет команд function SetColor_Poboishe(RoleObj) if RoleObj.Side == "Red" then unit.SetState(S66_1_MapID, RoleObj.InstanceID, RoleObj.RoleID, 10) else unit.SetState(S66_1_MapID, RoleObj.InstanceID, RoleObj.RoleID, 11) end end --Отправка информации function SendInfo_Poboishe(RoleObj) local redpoint = Poboishe_Battle[RoleObj.InstanceID].RedPlayer.Point local rednum = Poboishe_Battle[RoleObj.InstanceID].RedPlayer.Num local bluepoint = Poboishe_Battle[RoleObj.InstanceID].BluePlayer.Point local bluenum = Poboishe_Battle[RoleObj.InstanceID].BluePlayer.Num local char = redpoint..","..rednum..","..bluepoint..","..bluenum role.DotaSendMsg(S66_1_MapID, RoleObj.InstanceID, RoleObj.RoleID, 1, char) end --Вход игроков на поле плюсование function PlayerEnterPoboishe(RoleObj) RoleObj.State = "InSide" local tbl = {} if RoleObj.Side == "Red" then Poboishe_Battle[RoleObj.InstanceID].RedPlayer.Num = Poboishe_Battle[RoleObj.InstanceID].RedPlayer.Num + 1 tbl = Poboishe_Battle[RoleObj.InstanceID].RedPlayer.InSidePlayer elseif RoleObj.Side == "Blue" then Poboishe_Battle[RoleObj.InstanceID].BluePlayer.Num = Poboishe_Battle[RoleObj.InstanceID].BluePlayer.Num + 1 tbl = Poboishe_Battle[RoleObj.InstanceID].BluePlayer.InSidePlayer end table.insert(tbl,RoleObj.RoleID) end --покидает поле боя отнимание function PlayerLeavePoboishe(RoleObj) RoleObj.State = "OutSide" local tbl = {} if RoleObj.Side == "Red" then Poboishe_Battle[RoleObj.InstanceID].RedPlayer.Num = Poboishe_Battle[RoleObj.InstanceID].RedPlayer.Num - 1 tbl = Poboishe_Battle[RoleObj.InstanceID].RedPlayer.InSidePlayer elseif RoleObj.Side == "Blue" then Poboishe_Battle[RoleObj.InstanceID].BluePlayer.Num = Poboishe_Battle[RoleObj.InstanceID].BluePlayer.Num - 1 tbl = Poboishe_Battle[RoleObj.InstanceID].BluePlayer.InSidePlayer end for k,v in pairs(tbl) do if v == RoleObj.RoleID then table.remove(tbl,k) end end end --Информация за обе команды function SendAllInfo_Poboishe(BattleObj) for k,v in pairs(BattleObj.RedPlayer.Player) do local RoleObj = GetPoboisheRoleObj(v) local Target_MapID, Target_InstanceID = role.GetRoleMapID(RoleObj.RoleID) if Target_MapID ~= nil and Target_InstanceID ~= nil and Target_MapID == S66_1_MapID and RoleObj.InstanceID == Target_InstanceID then RoleObj:SendInfo_Poboishe() end end for k,v in pairs(BattleObj.BluePlayer.Player) do local RoleObj = GetPoboisheRoleObj(v) local Target_MapID, Target_InstanceID = role.GetRoleMapID(RoleObj.RoleID) if Target_MapID ~= nil and Target_InstanceID ~= nil and Target_MapID == S66_1_MapID and RoleObj.InstanceID == Target_InstanceID then RoleObj:SendInfo_Poboishe() end end end --очки персонажа function SetPlayerPoint_Poboishe(BattleObj) local RedSideObj = BattleObj.RedPlayer local BlueSideObj = BattleObj.BluePlayer for k,v in pairs(RedSideObj.Player) do local RoleObj = Poboishe_Role[v] if RoleObj.State == "InSide" then local Target_MapID, Target_InstanceID = role.GetRoleMapID(RoleObj.RoleID) if Target_MapID ~= nil then if not unit.IsDead(Target_MapID, Target_InstanceID, RoleObj.RoleID) then role.SetRoleScriptData(RoleObj.RoleID, 1, RoleDataType["Poboishe_Point"], role.GetRoleScriptData(RoleObj.RoleID, 1, RoleDataType["Poboishe_Point"])+1) end end end end for k,v in pairs(BlueSideObj.Player) do local RoleObj = Poboishe_Role[v] if RoleObj.State == "InSide" then local Target_MapID, Target_InstanceID = role.GetRoleMapID(RoleObj.RoleID) if Target_MapID ~= nil then if not unit.IsDead(Target_MapID, Target_InstanceID, RoleObj.RoleID) then role.SetRoleScriptData(RoleObj.RoleID, 1, RoleDataType["Poboishe_Point"], role.GetRoleScriptData(RoleObj.RoleID, 1, RoleDataType["Poboishe_Point"])+1) end end end end end --Очки за выйграш function SetPlayerFinalPoint_Poboishe(BattleObj) local RedSideObj = BattleObj.RedPlayer local BlueSideObj = BattleObj.BluePlayer if RedSideObj.Point >= BlueSideObj.Point then for k,v in pairs(RedSideObj.Player) do local RoleObj = Poboishe_Role[v] if RoleObj.State == "InSide" then local Target_MapID, Target_InstanceID = role.GetRoleMapID(RoleObj.RoleID) if Target_MapID ~= nil then if not unit.IsDead(Target_MapID, Target_InstanceID, RoleObj.RoleID) then role.SetRoleScriptData(RoleObj.RoleID, 1, RoleDataType["Poboishe_win"], 1) end end end end end if RedSideObj.Point <= BlueSideObj.Point then for k,v in pairs(BlueSideObj.Player) do local RoleObj = Poboishe_Role[v] if RoleObj.State == "InSide" then local Target_MapID, Target_InstanceID = role.GetRoleMapID(RoleObj.RoleID) if Target_MapID ~= nil then if not unit.IsDead(Target_MapID, Target_InstanceID, RoleObj.RoleID) then role.SetRoleScriptData(RoleObj.RoleID, 1, RoleDataType["Poboishe_win"], 1) end end end end end end --обновление игроков function ResetInSidePlayer_Poboishe(BattleObj) local function reset(tbl) local tbl_new = {} if #tbl > 0 then for i = 1,#tbl do local index = math.random(#tbl) table.insert(tbl_new,tbl[index]) table.remove(tbl,index) end end return tbl_new end BattleObj.BluePlayer.InSidePlayer = reset(BattleObj.BluePlayer.InSidePlayer) BattleObj.RedPlayer.InSidePlayer = reset(BattleObj.RedPlayer.InSidePlayer) end