--Регистрация function CreatTitanRoleObj(RoleID) if Titan_Role[RoleID] == nil then local Target_MapID, Target_InstanceID = role.GetRoleMapID(RoleID) local rolelevel = role.GetRoleLevel(Target_MapID, Target_InstanceID, RoleID) if rolelevel >= 100 then Titan_Roletotal = Titan_Roletotal + 1 Titan_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 Titan_Role[RoleID].Guild = Guild else Titan_Role[RoleID].Guild = 0 end if FamilyID ~= nil and FamilyID ~= 4294967295 then Titan_Role[RoleID].FamilyID = FamilyID else Titan_Role[RoleID].FamilyID = 0 end Titan_Role[RoleID].ShowTitanTime = ShowTitanTime Titan_Role[RoleID].GetAttBuff_Titan = GetAttBuff_Titan Titan_Role[RoleID].WuDi_Titan = WuDi_Titan Titan_Role[RoleID].SetColor_Titan = SetColor_Titan Titan_Role[RoleID].SendInfo_Titan = SendInfo_Titan Titan_Role[RoleID].PlayerLeaveTitan = PlayerLeaveTitan Titan_Role[RoleID].PlayerEnterTitan = PlayerEnterTitan Titan_Role[RoleID].GetKillExp_Titan = GetKillExp_Titan end end end --Создание групп function CreatTitanSideObj() local k = #Titan_Side + 1 Titan_Side[k] = {Player={},InSidePlayer={},Num = 0,Point = 0} if k%2 == 1 then Titan_Side[k].Side = "Red" else Titan_Side[k].Side = "Blue" end Titan_Side[k].PlayerJoinTitanSide = PlayerJoinTitanSide return Titan_Side[k] end --Присоединение к группе function PlayerJoinTitanSide(Obj,PlayerID) table.insert(Obj.Player,PlayerID) Titan_Role[PlayerID].Side = Obj.Side end --Создание поля боя function CreatTitannBattleObj(RedPlayer,BluePlayer) local k = #Titan_Battle + 1 map.CreateInstance(n6_MapID, k) Titan_Battle[k] = {RedPlayer = RedPlayer,BluePlayer = BluePlayer,InstanceID=k} for k1,v in pairs(RedPlayer.Player) do Titan_Role[v].InstanceID = k end for k1,v in pairs(BluePlayer.Player) do Titan_Role[v].InstanceID = k end Titan_Battle[k].SendAllInfo_Titan = SendAllInfo_Titan Titan_Battle[k].SetPlayerPoint_Titan = SetPlayerPoint_Titan Titan_Battle[k].SetPlayerFinalPoint_Titan = SetPlayerFinalPoint_Titan Titan_Battle[k].ResetInSidePlayer_Titan = ResetInSidePlayer_Titan end --Получение игроков поля боя function GetTitanRoleObj(RoleID) return Titan_Role[RoleID] end --Выбор стороны function Titan_ChooseSide() if Titan_Roletotal > 159 then local k = math.floor(Titan_Roletotal/80) local av_player = math.floor(Titan_Roletotal/k) local num = {} for i = 1,k do if i ~= k then num[i] = av_player else num[i] = Titan_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(Titan_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 = CreatTitanSideObj() local BlueSideObj = CreatTitanSideObj() local red = 0 local times = 0 while red < num[i]/2 do RedSideObj:PlayerJoinTitanSide(Player[i][1]) local Player1Obj = GetTitanRoleObj(Player[i][1]) red = red + 1 for k1,v in pairs(Player[i]) do local PlayerObj = GetTitanRoleObj(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:PlayerJoinTitanSide(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:PlayerJoinTitanSide(v) -- BlueSideObj.Num = BlueSideObj.Num + 1 end CreatTitannBattleObj(RedSideObj,BlueSideObj) end else local Player = {} for k,v in pairs(Titan_Role) do table.insert(Player,k) --v.InstanceID = 1 end local RedSideObj = CreatTitanSideObj() local BlueSideObj = CreatTitanSideObj() local red = 0 local times = 0 while red < Titan_Roletotal/2 do RedSideObj:PlayerJoinTitanSide(Player[1]) local Player1Obj = GetTitanRoleObj(Player[1]) red = red + 1 for k1,v in pairs(Player) do local PlayerObj = GetTitanRoleObj(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:PlayerJoinTitanSide(v) red = red + 1 table.remove(Player,k1) if red >= Titan_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:PlayerJoinTitanSide(v) -- BlueSideObj.Num = BlueSideObj.Num + 1 end CreatTitannBattleObj(RedSideObj,BlueSideObj) end end --время боя function ShowTitanTime(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_Titan(RoleObj) local rolelevel = role.GetRoleLevel(n6_MapID, RoleObj.InstanceID, RoleObj.RoleID) if rolelevel > 100 then rolelevel = 100 end if rolelevel >= 40 then local index = math.floor((rolelevel-50)/5) + 1 unit.AddBuff(n6_MapID, RoleObj.InstanceID, RoleObj.RoleID, index*100+6107001, RoleObj.RoleID) end end --Получение опыта за убийство function GetKillExp_Titan(RoleObj) local rolelevel = role.GetRoleLevel(n6_MapID, RoleObj.InstanceID, RoleObj.RoleID) if rolelevel < 45 then rolelevel = 45 elseif rolelevel > 100 then rolelevel = 100 end RoleObj.Kill = RoleObj.Kill + 1 local exp1 = math.floor(Titan_Exp[rolelevel] / 10) if RoleObj.Kill > 30 then exp1 = 0 else role.AddRoleExp(n6_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_Titan(RoleObj) unit.AddBuff(n6_MapID, RoleObj.InstanceID, RoleObj.RoleID, 6109401, RoleObj.RoleID) end --Цвет команд function SetColor_Titan(RoleObj) if RoleObj.Side == "Red" then unit.SetState(n6_MapID, RoleObj.InstanceID, RoleObj.RoleID, 10) else unit.SetState(n6_MapID, RoleObj.InstanceID, RoleObj.RoleID, 11) end end --Отправка информации function SendInfo_Titan(RoleObj) local redpoint = Titan_Battle[RoleObj.InstanceID].RedPlayer.Point local rednum = Titan_Battle[RoleObj.InstanceID].RedPlayer.Num local bluepoint = Titan_Battle[RoleObj.InstanceID].BluePlayer.Point local bluenum = Titan_Battle[RoleObj.InstanceID].BluePlayer.Num local char = redpoint..","..rednum..","..bluepoint..","..bluenum role.DotaSendMsg(n6_MapID, RoleObj.InstanceID, RoleObj.RoleID, 1, char) end --Вход игроков на поле плюсование function PlayerEnterTitan(RoleObj) RoleObj.State = "InSide" local tbl = {} if RoleObj.Side == "Red" then Titan_Battle[RoleObj.InstanceID].RedPlayer.Num = Titan_Battle[RoleObj.InstanceID].RedPlayer.Num + 1 tbl = Titan_Battle[RoleObj.InstanceID].RedPlayer.InSidePlayer elseif RoleObj.Side == "Blue" then Titan_Battle[RoleObj.InstanceID].BluePlayer.Num = Titan_Battle[RoleObj.InstanceID].BluePlayer.Num + 1 tbl = Titan_Battle[RoleObj.InstanceID].BluePlayer.InSidePlayer end table.insert(tbl,RoleObj.RoleID) end --покидает поле боя отнимание function PlayerLeaveTitan(RoleObj) RoleObj.State = "OutSide" local tbl = {} if RoleObj.Side == "Red" then Titan_Battle[RoleObj.InstanceID].RedPlayer.Num = Titan_Battle[RoleObj.InstanceID].RedPlayer.Num - 1 tbl = Titan_Battle[RoleObj.InstanceID].RedPlayer.InSidePlayer elseif RoleObj.Side == "Blue" then Titan_Battle[RoleObj.InstanceID].BluePlayer.Num = Titan_Battle[RoleObj.InstanceID].BluePlayer.Num - 1 tbl = Titan_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_Titan(BattleObj) for k,v in pairs(BattleObj.RedPlayer.Player) do local RoleObj = GetTitanRoleObj(v) local Target_MapID, Target_InstanceID = role.GetRoleMapID(RoleObj.RoleID) if Target_MapID ~= nil and Target_InstanceID ~= nil and Target_MapID == n6_MapID and RoleObj.InstanceID == Target_InstanceID then RoleObj:SendInfo_Titan() end end for k,v in pairs(BattleObj.BluePlayer.Player) do local RoleObj = GetTitanRoleObj(v) local Target_MapID, Target_InstanceID = role.GetRoleMapID(RoleObj.RoleID) if Target_MapID ~= nil and Target_InstanceID ~= nil and Target_MapID == n6_MapID and RoleObj.InstanceID == Target_InstanceID then RoleObj:SendInfo_Titan() end end end --очки персонажа function SetPlayerPoint_Titan(BattleObj) local RedSideObj = BattleObj.RedPlayer local BlueSideObj = BattleObj.BluePlayer for k,v in pairs(RedSideObj.Player) do local RoleObj = Titan_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["Titan_Point"], role.GetRoleScriptData(RoleObj.RoleID, 1, RoleDataType["Titan_Point"])+1) end end end end for k,v in pairs(BlueSideObj.Player) do local RoleObj = Titan_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["Titan_Point"], role.GetRoleScriptData(RoleObj.RoleID, 1, RoleDataType["Titan_Point"])+1) end end end end end --Очки за выйграш function SetPlayerFinalPoint_Titan(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 = Titan_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["Titan_win"], 1) local MsgID = msg.BeginMsgEvent() msg.AddMsgEvent(MsgID, 102, 900246) msg.AddMsgEvent(MsgID, 5, TargetTypeID) msg.DispatchWorldMsgEvent(MsgID) end end end end end if RedSideObj.Point <= BlueSideObj.Point then for k,v in pairs(BlueSideObj.Player) do local RoleObj = Titan_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["Titan_win"], 1) local MsgID = msg.BeginMsgEvent() msg.AddMsgEvent(MsgID, 102, 900247) msg.AddMsgEvent(MsgID, 5, TargetTypeID) msg.DispatchWorldMsgEvent(MsgID) end end end end if RedSideObj.Point == BlueSideObj.Point then for k,v in pairs(BlueSideObj.Player) do local RoleObj = Titan_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["Titan_win"], 2) local MsgID = msg.BeginMsgEvent() msg.AddMsgEvent(MsgID, 102, 900248) msg.AddMsgEvent(MsgID, 5, TargetTypeID) msg.DispatchWorldMsgEvent(MsgID) end end end end end end end --обновление игроков function ResetInSidePlayer_Titan(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