--================================================================
-- 
-- 配置
-- 
--================================================================

-- 怪物
monsters = {
	{ config_id = 7001, monster_id = 20011201, pos = { x = 6.1, y = -0.1, z = -5.1 }, rot = { x = 0.0, y = 346.5, z = 0.0 }, level = 1, affix = { 1221 }, isElite = true },
	{ config_id = 7002, monster_id = 20011201, pos = { x = -7.2, y = -0.1, z = -5.1 }, rot = { x = 0.0, y = 21.5, z = 0.0 }, level = 1, affix = { 1221 }, isElite = true },
	{ config_id = 7003, monster_id = 20011201, pos = { x = -6.7, y = -0.1, z = -10.0 }, rot = { x = 0.0, y = 18.6, z = 0.0 }, level = 1, affix = { 1221 }, isElite = true },
	{ config_id = 7004, monster_id = 20011201, pos = { x = -0.2, y = -0.1, z = -11.6 }, rot = { x = 0.0, y = 0.0, z = 0.0 }, level = 1, affix = { 1221 }, isElite = true },
	{ config_id = 7005, monster_id = 20011201, pos = { x = 7.7, y = -0.1, z = -11.8 }, rot = { x = 0.0, y = 343.7, z = 0.0 }, level = 1, affix = { 1221 }, isElite = true },
	{ config_id = 7006, monster_id = 20011201, pos = { x = -11.4, y = -0.1, z = -1.2 }, rot = { x = 0.0, y = 64.8, z = 0.0 }, level = 1, affix = { 1221 }, isElite = true },
	{ config_id = 7007, monster_id = 20011201, pos = { x = 11.7, y = -0.1, z = -0.9 }, rot = { x = 0.0, y = 270.1, z = 0.0 }, level = 1, affix = { 1221 }, isElite = true },
	{ config_id = 7008, monster_id = 20011201, pos = { x = 9.1, y = -0.1, z = 7.2 }, rot = { x = 0.0, y = 198.8, z = 0.0 }, level = 1, affix = { 1221 }, isElite = true },
	{ config_id = 7009, monster_id = 20011301, pos = { x = -0.1, y = -0.1, z = -8.0 }, rot = { x = 0.0, y = 0.0, z = 0.0 }, level = 1, affix = { 1221 }, isElite = true },
	{ config_id = 7010, monster_id = 20011201, pos = { x = 0.3, y = -0.1, z = 9.7 }, rot = { x = 0.0, y = 180.0, z = 0.0 }, level = 1, affix = { 1221 }, isElite = true },
	{ config_id = 7011, monster_id = 20011201, pos = { x = 10.4, y = -0.1, z = 5.7 }, rot = { x = 0.0, y = 234.1, z = 0.0 }, level = 1, affix = { 1221 }, isElite = true },
	{ config_id = 7012, monster_id = 20011201, pos = { x = 11.4, y = -0.1, z = -8.2 }, rot = { x = 0.0, y = 322.1, z = 0.0 }, level = 1, affix = { 1221 }, isElite = true },
	{ config_id = 7014, monster_id = 20011201, pos = { x = -13.1, y = -0.1, z = -5.3 }, rot = { x = 0.0, y = 50.2, z = 0.0 }, level = 1, affix = { 1221 }, isElite = true },
	{ config_id = 7015, monster_id = 20011201, pos = { x = -10.1, y = -0.1, z = 5.4 }, rot = { x = 0.0, y = 126.7, z = 0.0 }, level = 1, affix = { 1221 }, isElite = true },
	{ config_id = 7016, monster_id = 20011301, pos = { x = -0.1, y = -0.1, z = -12.9 }, rot = { x = 0.0, y = 0.0, z = 0.0 }, level = 1, affix = { 1221 }, isElite = true },
	{ config_id = 7017, monster_id = 20011301, pos = { x = -11.7, y = -0.1, z = 1.6 }, rot = { x = 0.0, y = 90.0, z = 0.0 }, level = 1, affix = { 1221 }, isElite = true },
	{ config_id = 7018, monster_id = 20011301, pos = { x = 10.8, y = -0.1, z = 1.6 }, rot = { x = 0.0, y = 270.0, z = 0.0 }, level = 1, affix = { 1221 }, isElite = true },
	{ config_id = 7019, monster_id = 20011301, pos = { x = 3.4, y = -0.1, z = 9.7 }, rot = { x = 0.0, y = 188.1, z = 0.0 }, level = 1, affix = { 1221 }, isElite = true },
	{ config_id = 7020, monster_id = 22010103, pos = { x = 0.0, y = -0.1, z = -8.1 }, rot = { x = 0.0, y = 0.0, z = 0.0 }, level = 1, affix = { 1221 }, isElite = true },
	{ config_id = 7021, monster_id = 20011201, pos = { x = -12.1, y = -0.1, z = 0.1 }, rot = { x = 0.0, y = 90.0, z = 0.0 }, level = 1, affix = { 1221 }, isElite = true },
	{ config_id = 7022, monster_id = 20011201, pos = { x = 12.2, y = -0.1, z = -0.1 }, rot = { x = 0.0, y = 270.0, z = 0.0 }, level = 1, affix = { 1221 }, isElite = true },
	{ config_id = 7024, monster_id = 20011201, pos = { x = -0.2, y = -0.1, z = -4.9 }, rot = { x = 0.0, y = 0.0, z = 0.0 }, level = 1, affix = { 1221 }, isElite = true },
	{ config_id = 7025, monster_id = 20011201, pos = { x = -7.9, y = -0.1, z = 7.5 }, rot = { x = 0.0, y = 157.4, z = 0.0 }, level = 1, affix = { 1221 }, isElite = true },
	{ config_id = 7026, monster_id = 20011301, pos = { x = -4.2, y = -0.1, z = 9.4 }, rot = { x = 0.0, y = 168.7, z = 0.0 }, level = 1, affix = { 1221 }, isElite = true }
}

-- NPC
npcs = {
}

-- 装置
gadgets = {
	{ config_id = 7027, gadget_id = 70900205, pos = { x = 6.1, y = -1.3, z = 3.1 }, rot = { x = 0.0, y = 0.0, z = 0.0 }, level = 1 }
}

-- 区域
regions = {
}

-- 触发器
triggers = {
	{ name = "ANY_MONSTER_LIVE_7028", event = EventType.EVENT_ANY_MONSTER_LIVE, source = "", condition = "condition_EVENT_ANY_MONSTER_LIVE_7028", action = "action_EVENT_ANY_MONSTER_LIVE_7028" },
	{ name = "ANY_MONSTER_DIE_7029", event = EventType.EVENT_ANY_MONSTER_DIE, source = "", condition = "condition_EVENT_ANY_MONSTER_DIE_7029", action = "action_EVENT_ANY_MONSTER_DIE_7029" },
	{ name = "ANY_MONSTER_DIE_7030", event = EventType.EVENT_ANY_MONSTER_DIE, source = "", condition = "condition_EVENT_ANY_MONSTER_DIE_7030", action = "action_EVENT_ANY_MONSTER_DIE_7030" },
	{ name = "ANY_MONSTER_DIE_7031", event = EventType.EVENT_ANY_MONSTER_DIE, source = "", condition = "condition_EVENT_ANY_MONSTER_DIE_7031", action = "action_EVENT_ANY_MONSTER_DIE_7031" },
	{ name = "CHALLENGE_SUCCESS_7032", event = EventType.EVENT_CHALLENGE_SUCCESS, source = "2", condition = "", action = "action_EVENT_CHALLENGE_SUCCESS_7032" },
	{ name = "CHALLENGE_FAIL_7033", event = EventType.EVENT_CHALLENGE_FAIL, source = "2", condition = "", action = "action_EVENT_CHALLENGE_FAIL_7033" },
	{ name = "ANY_MONSTER_DIE_7034", event = EventType.EVENT_ANY_MONSTER_DIE, source = "", condition = "condition_EVENT_ANY_MONSTER_DIE_7034", action = "action_EVENT_ANY_MONSTER_DIE_7034" }
}

-- 变量
variables = {
	{ name = "monster_wave", value = 0, no_refresh = false }
}

--================================================================
-- 
-- 初始化配置
-- 
--================================================================

-- 初始化时创建
init_config = {
	suite = 1,
	end_suite = 0,
	rand_suite = false
}

--================================================================
-- 
-- 小组配置
-- 
--================================================================

suites = {
	{
		-- suite_id = 1,
		-- description = ,
		monsters = { },
		gadgets = { 7027 },
		regions = { },
		triggers = { },
		rand_weight = 100
	},
	{
		-- suite_id = 2,
		-- description = suite_2,
		monsters = { 7001, 7002, 7003, 7004, 7005, 7024 },
		gadgets = { 7027 },
		regions = { },
		triggers = { "ANY_MONSTER_LIVE_7028", "ANY_MONSTER_DIE_7029", "CHALLENGE_SUCCESS_7032", "CHALLENGE_FAIL_7033" },
		rand_weight = 100
	},
	{
		-- suite_id = 3,
		-- description = suite_3,
		monsters = { 7006, 7007, 7008, 7009, 7010, 7025 },
		gadgets = { 7027 },
		regions = { },
		triggers = { "ANY_MONSTER_DIE_7030", "CHALLENGE_SUCCESS_7032", "CHALLENGE_FAIL_7033" },
		rand_weight = 100
	},
	{
		-- suite_id = 4,
		-- description = suite_4,
		monsters = { 7011, 7012, 7014, 7015, 7019, 7026 },
		gadgets = { 7027 },
		regions = { },
		triggers = { "ANY_MONSTER_DIE_7031", "CHALLENGE_SUCCESS_7032", "CHALLENGE_FAIL_7033" },
		rand_weight = 100
	},
	{
		-- suite_id = 5,
		-- description = suite_5,
		monsters = { 7016, 7017, 7018 },
		gadgets = { 7027 },
		regions = { },
		triggers = { "CHALLENGE_SUCCESS_7032", "CHALLENGE_FAIL_7033", "ANY_MONSTER_DIE_7034" },
		rand_weight = 100
	},
	{
		-- suite_id = 6,
		-- description = suite_6,
		monsters = { 7020, 7021, 7022 },
		gadgets = { 7027 },
		regions = { },
		triggers = { "CHALLENGE_SUCCESS_7032", "CHALLENGE_FAIL_7033" },
		rand_weight = 100
	}
}

--================================================================
-- 
-- 触发器
-- 
--================================================================

-- 触发条件
function condition_EVENT_ANY_MONSTER_LIVE_7028(context, evt)
	if 7001 ~= evt.param1 then
		return false
	end
	
	return true
end

-- 触发操作
function action_EVENT_ANY_MONSTER_LIVE_7028(context, evt)
	-- 创建编号为2（该挑战的识别id),挑战内容为198的区域挑战，param1必须为时间
	-- 从230900004的变量TPL_TIME中取出对应值并开启挑战
	  local tpl_time = ScriptLib.GetGroupVariableValueByGroup(context, "TPL_TIME", 230900004)
	  if tpl_time == nil or tpl_time < 0 then
	    return -1
	  elseif tpl_time < 1 then
	    tpl_time = 0
	  end
	  if 0 ~= ScriptLib.ActiveChallenge(context, 2, 198, tpl_time, 230900007, 24, 0) then
	    return -1
	  end
	
	-- 针对当前group内变量名为 "monster_wave" 的变量，进行修改，变化值为 1
	if 0 ~= ScriptLib.ChangeGroupVariableValue(context, "monster_wave", 1) then
	  return -1
	end
	
	return 0
end

-- 触发条件
function condition_EVENT_ANY_MONSTER_DIE_7029(context, evt)
	-- 判断指定group组剩余怪物数量是否是0 
	if ScriptLib.GetGroupMonsterCountByGroupId(context, 230900007) ~= 0 then
		return false
	end
	
	-- 判断变量"monster_wave"为1
	if ScriptLib.GetGroupVariableValue(context, "monster_wave") ~= 1 then
			return false
	end
	
	return true
end

-- 触发操作
function action_EVENT_ANY_MONSTER_DIE_7029(context, evt)
	-- 添加suite3的新内容
	    ScriptLib.AddExtraGroupSuite(context, 230900007, 3)
	
	-- 针对当前group内变量名为 "monster_wave" 的变量，进行修改，变化值为 1
	if 0 ~= ScriptLib.ChangeGroupVariableValue(context, "monster_wave", 1) then
	  return -1
	end
	
	return 0
end

-- 触发条件
function condition_EVENT_ANY_MONSTER_DIE_7030(context, evt)
	-- 判断指定group组剩余怪物数量是否是0 
	if ScriptLib.GetGroupMonsterCountByGroupId(context, 230900007) ~= 0 then
		return false
	end
	
	-- 判断变量"monster_wave"为2
	if ScriptLib.GetGroupVariableValue(context, "monster_wave") ~= 2 then
			return false
	end
	
	return true
end

-- 触发操作
function action_EVENT_ANY_MONSTER_DIE_7030(context, evt)
	-- 添加suite4的新内容
	    ScriptLib.AddExtraGroupSuite(context, 230900007, 4)
	
	-- 针对当前group内变量名为 "monster_wave" 的变量，进行修改，变化值为 1
	if 0 ~= ScriptLib.ChangeGroupVariableValue(context, "monster_wave", 1) then
	  return -1
	end
	
	return 0
end

-- 触发条件
function condition_EVENT_ANY_MONSTER_DIE_7031(context, evt)
	-- 判断指定group组剩余怪物数量是否是0 
	if ScriptLib.GetGroupMonsterCountByGroupId(context, 230900007) ~= 0 then
		return false
	end
	
	-- 判断变量"monster_wave"为3
	if ScriptLib.GetGroupVariableValue(context, "monster_wave") ~= 3 then
			return false
	end
	
	return true
end

-- 触发操作
function action_EVENT_ANY_MONSTER_DIE_7031(context, evt)
	-- 添加suite5的新内容
	    ScriptLib.AddExtraGroupSuite(context, 230900007, 5)
	
	-- 针对当前group内变量名为 "monster_wave" 的变量，进行修改，变化值为 1
	if 0 ~= ScriptLib.ChangeGroupVariableValue(context, "monster_wave", 1) then
	  return -1
	end
	
	return 0
end

-- 触发条件

-- 触发操作
function action_EVENT_CHALLENGE_SUCCESS_7032(context, evt)
	-- 将本组内变量名为 "stage" 的变量设置为 2
	if 0 ~= ScriptLib.SetGroupVariableValueByGroup(context, "stage", 2, 230900004) then
	  return -1
	end
	
	return 0
end

-- 触发条件

-- 触发操作
function action_EVENT_CHALLENGE_FAIL_7033(context, evt)
		-- 重新生成指定group，指定suite
		if 0 ~= ScriptLib.RefreshGroup(context, { group_id = 230900007, suite = 1 }) then
			return -1
		end
	
	-- 地城失败结算
	if 0 ~= ScriptLib.CauseDungeonFail(context) then
		return -1
	end
	
	return 0
end

-- 触发条件
function condition_EVENT_ANY_MONSTER_DIE_7034(context, evt)
	-- 判断指定group组剩余怪物数量是否是0 
	if ScriptLib.GetGroupMonsterCountByGroupId(context, 230900007) ~= 0 then
		return false
	end
	
	-- 判断变量"monster_wave"为4
	if ScriptLib.GetGroupVariableValue(context, "monster_wave") ~= 4 then
			return false
	end
	
	return true
end

-- 触发操作
function action_EVENT_ANY_MONSTER_DIE_7034(context, evt)
	-- 添加suite6的新内容
	    ScriptLib.AddExtraGroupSuite(context, 230900007, 6)
	
	-- 针对当前group内变量名为 "monster_wave" 的变量，进行修改，变化值为 1
	if 0 ~= ScriptLib.ChangeGroupVariableValue(context, "monster_wave", 1) then
	  return -1
	end
	
	return 0
end
