x003002_g_scriptId=003002

x003002_g_IdPuTong={}
x003002_g_IdPuTong[1]={390001,390002,390003,390004,390005,390006,390007,390008,390009,390010,390011,390012,390013,390014,390015,390016,390017,390018,390019,390020,390020}    -- 第一波怪物的rolebaseid    等级自适应   后面的为高等级Id
x003002_g_IdPuTong[2]={390101,390102,390103,390104,390105,390106,390107,390108,390109,390110,390111,390112,390113,390114,390115,390116,390117,390118,390119,390120,390120}	--  同上
x003002_g_IdPuTong[3]={390201,390202,390203,390204,390205,390206,390207,390208,390209,390210,390211,390212,390213,390214,390215,390216,390217,390218,390219,390220,390220}
x003002_g_IdPuTong[4]={390301,390302,390303,390304,390305,390306,390307,390308,390309,390310,390311,390312,390313,390314,390315,390316,390317,390318,390319,390320,390320}
x003002_g_IdPuTong[5]={390401,390402,390403,390404,390405,390406,390407,390408,390409,390410,390411,390412,390413,390414,390415,390416,390417,390418,390419,390420,390420}

x003002_g_PuTongNum={}
x003002_g_PuTongNum[1]={5, 5, 5, 5, 5}     --   数量依次递增  与上面对应 坐标也是


x003002_g_MonsterPosList={}     
x003002_g_MonsterPosList[1]={{113,85,-1.24},{113,136,-1.24},{113,167,-1.55},{64,139,-1.55},{70,91,-0.22},{174,93,3.4},{157,149,4.3},{113,85,-1.24},{113,136,-1.24},{113,167,-1.55},{64,139,-1.55},{70,91,-0.22},{174,93,3.4},{157,149,4.3}}	-- 随机坐标 ，重复两次

x003002_g_BuffId = 9995	--   帮派等级自适应buff


function x003002_CreateMonster( scene,nStage)	
	local PosNum = #x003002_g_MonsterPosList[1]/2
	local item = RandomMon(1, PosNum)    
	--UpdateGuildAdaptLevel(scene)
	--print(GetGuildAdaptLevel(scene))
	local AdaptLevel = math.ceil(GetGuildAdaptLevel(scene)/5)
	for i = item, item+x003002_g_PuTongNum[1][nStage]-1 do

		local objId = CreateMonster(scene,x003002_g_IdPuTong[nStage][AdaptLevel],x003002_g_MonsterPosList[1][i][3],x003002_g_MonsterPosList[1][i][1],x003002_g_MonsterPosList[1][i][2])
		GetGuildLevel(scene, 3002, objId)
		SetMonScripts(scene, objId, 3002)
	end
end

function x003002_OnActivityStart( scene,curTime,idx)	
	--print("1111")
	UpdateGuildAdaptLevel(scene, 3002)
	--print("2222")
	SendTipsAllGuildMember(scene, 50200)
end
function x003002_OnUpdateAdaptLvl( scene)	
	SetGuildRobberStage(scene, 2)
	x003002_CreateMonster(scene, 1)
end
function x003002_OnGetGuildLevel( scene,level, parm)	
	for i = 1, level do
	--	print(parm)
	--	print(x003002_g_BuffId)
		SendImpactToUnit(scene, parm, x003002_g_BuffId)
	end
end
function x003002_CheckMissionMD(scene ,objId, type)
	local nLastData = GetMissionMD(scene, objId, 3, type)
	local nNewData = CheckRefreshTime(scene, nLastData, objId, 0)       -- 参数为0代表每天更新
	if math.floor(nLastData/100) ~= nNewData then
		SetMissionMD(scene, objId, 3, type, nNewData*100)
	end
end
function x003002_success( scene)	
	local nUserCount = GetSceneUserCount(scene)
	--for i=0,nUserCount-1 do                                                                                        --  帮助奖励（当所有BOSS奖励触发后开始触发）
	--	local nUserObjId = GetUserObjIdByIdx(scene,i)
	--	ShowBossTips(scene, nUserObjId, 2, 50007)                                 
	--end
	ResultsGuildRobber(scene, true)
	SetGuildRobberStage(scene, 1)
end
function x003002_AwardGuildRobber( scene, monId)	
	local nUserCount = GetSceneUserCount(scene)
	for i=0,nUserCount-1 do                                                                                        --  帮助奖励（当所有BOSS奖励触发后开始触发）
		local nUserObjId = GetUserObjIdByIdx(scene,i)
	--	print(monId)
	--	print(nUserObjId)
		if(IsAwardGuildRobber(scene, monId, nUserObjId)) then
			x003002_CheckMissionMD(scene, nUserObjId, 65)     
			x003002_CheckMissionMD(scene, nUserObjId, 65)

			local oldTime = GetMissionMD(scene, nUserObjId, 3, 65)
			SetMissionMD(scene, nUserObjId, 3, 65, oldTime+1)            
			if(GetMissionMD(scene, nUserObjId, 3, 65) % 100 <= 5) then
				AwardGuildRobber(scene,nUserObjId, true)
			elseif GetMissionMD(scene, nUserObjId, 3, 65) % 100 > 5 then
				AwardGuildRobber(scene,nUserObjId, false)
			end
		end
	end
end
function x003002_OnObjDie( scene,objId,rolebaseId,killerId )
	local AdaptLevel = math.ceil(GetGuildAdaptLevel(scene)/5)
	local stage1 = GetGuildRobberStage(scene)-1
	--print(AdaptLevel)
	--print(stage)
	--print(rolebaseId)
	if(rolebaseId ~= x003002_g_IdPuTong[stage1][AdaptLevel])  then
		return
	end
	local MonNum = GetHostileMonsterCount(scene)
	x003002_AwardGuildRobber(scene, objId)
	if MonNum == 0 then
		local stage = GetGuildRobberStage(scene)
		if stage == 6 then
			x003002_success(scene)
		end
		if stage ~= -1 and stage < 6 then
			SendTipsAllGuildMember(scene,50304)
			x003002_CreateMonster(scene,stage)
		end
		SetGuildRobberStage(scene, stage + 1)
	end
end