-- 基础信息
local base_info = {
	group_id = 220158007
}

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

-- 怪物
monsters = {
	{ config_id = 7001, monster_id = 21020801, pos = { x = 243.416, y = 214.313, z = 625.454 }, rot = { x = 0.000, y = 37.433, z = 0.000 }, level = 1, affix = { 1109 } },
	{ config_id = 7002, monster_id = 21030201, pos = { x = 241.201, y = 214.306, z = 622.265 }, rot = { x = 0.000, y = 49.669, z = 0.000 }, level = 1, affix = { 1109 }, pose_id = 9012 },
	{ config_id = 7003, monster_id = 21020701, pos = { x = 247.843, y = 214.313, z = 641.543 }, rot = { x = 0.000, y = 187.667, z = 0.000 }, level = 1, affix = { 1109 }, pose_id = 401 },
	{ config_id = 7006, monster_id = 21010501, pos = { x = 247.948, y = 214.313, z = 620.283 }, rot = { x = 0.000, y = 0.000, z = 0.000 }, level = 1, affix = { 1109 } },
	{ config_id = 7007, monster_id = 20010501, pos = { x = 246.104, y = 214.313, z = 636.339 }, rot = { x = 0.000, y = 0.000, z = 0.000 }, level = 1, affix = { 1109 } },
	{ config_id = 7008, monster_id = 20010501, pos = { x = 254.684, y = 214.313, z = 633.485 }, rot = { x = 0.000, y = 0.000, z = 0.000 }, level = 1, affix = { 1109 } },
	{ config_id = 7009, monster_id = 21010501, pos = { x = 236.659, y = 214.313, z = 626.740 }, rot = { x = 0.000, y = 41.150, z = 0.000 }, level = 1, affix = { 1109 } },
	{ config_id = 7010, monster_id = 21010601, pos = { x = 249.858, y = 215.816, z = 647.013 }, rot = { x = 0.000, y = 169.113, z = 0.000 }, level = 1, affix = { 1109 } },
	{ config_id = 7011, monster_id = 21010601, pos = { x = 259.035, y = 214.527, z = 638.455 }, rot = { x = 0.000, y = 248.708, z = 0.000 }, level = 1, affix = { 1109 } }
}

-- NPC
npcs = {
}

-- 装置
gadgets = {
	{ config_id = 7013, gadget_id = 70320025, pos = { x = 240.705, y = 221.968, z = 620.952 }, rot = { x = 0.000, y = 214.227, z = 0.000 }, level = 1 },
	{ config_id = 7014, gadget_id = 70360001, pos = { x = 240.705, y = 221.968, z = 620.952 }, rot = { x = 0.000, y = 0.000, z = 0.000 }, level = 1 },
	{ config_id = 7016, gadget_id = 70800111, pos = { x = 261.740, y = 216.590, z = 630.786 }, rot = { x = 0.000, y = 35.000, z = 90.000 }, level = 1 },
	{ config_id = 7018, gadget_id = 70320078, pos = { x = 254.598, y = 216.735, z = 641.763 }, rot = { x = 0.000, y = 0.000, z = 0.000 }, level = 1 },
	{ config_id = 7020, gadget_id = 70800111, pos = { x = 258.960, y = 216.590, z = 626.676 }, rot = { x = 0.000, y = 35.000, z = 90.000 }, level = 1 },
	{ config_id = 7021, gadget_id = 70800111, pos = { x = 256.190, y = 216.590, z = 622.576 }, rot = { x = 0.000, y = 35.000, z = 90.000 }, level = 1 },
	{ config_id = 7022, gadget_id = 70800111, pos = { x = 253.500, y = 216.590, z = 618.606 }, rot = { x = 0.000, y = 35.000, z = 90.000 }, level = 1 },
	{ config_id = 7023, gadget_id = 70800111, pos = { x = 250.820, y = 216.590, z = 614.636 }, rot = { x = 0.000, y = 35.000, z = 90.000 }, level = 1 },
	{ config_id = 7024, gadget_id = 70800111, pos = { x = 241.316, y = 216.590, z = 644.258 }, rot = { x = 0.000, y = 35.000, z = 90.000 }, level = 1 },
	{ config_id = 7025, gadget_id = 70800111, pos = { x = 238.536, y = 216.590, z = 640.148 }, rot = { x = 0.000, y = 35.000, z = 90.000 }, level = 1 },
	{ config_id = 7026, gadget_id = 70800111, pos = { x = 235.766, y = 216.590, z = 636.048 }, rot = { x = 0.000, y = 35.000, z = 90.000 }, level = 1 },
	{ config_id = 7027, gadget_id = 70800111, pos = { x = 233.076, y = 216.590, z = 632.078 }, rot = { x = 0.000, y = 35.000, z = 90.000 }, level = 1 },
	{ config_id = 7028, gadget_id = 70800111, pos = { x = 230.396, y = 216.590, z = 628.108 }, rot = { x = 0.000, y = 35.000, z = 90.000 }, level = 1 },
	{ config_id = 7029, gadget_id = 70800111, pos = { x = 244.534, y = 216.590, z = 613.651 }, rot = { x = 90.000, y = 35.000, z = 0.000 }, level = 1 },
	{ config_id = 7030, gadget_id = 70800111, pos = { x = 231.817, y = 216.590, z = 622.894 }, rot = { x = 90.000, y = 35.000, z = 0.000 }, level = 1 },
	{ config_id = 7031, gadget_id = 70800111, pos = { x = 247.840, y = 216.590, z = 645.207 }, rot = { x = 90.000, y = 35.000, z = 0.000 }, level = 1 },
	{ config_id = 7032, gadget_id = 70800111, pos = { x = 251.930, y = 216.590, z = 642.437 }, rot = { x = 90.000, y = 35.000, z = 0.000 }, level = 1 },
	{ config_id = 7033, gadget_id = 70800111, pos = { x = 256.110, y = 216.590, z = 639.607 }, rot = { x = 90.000, y = 35.000, z = 0.000 }, level = 1 },
	{ config_id = 7034, gadget_id = 70800111, pos = { x = 260.220, y = 216.590, z = 636.827 }, rot = { x = 90.000, y = 35.000, z = 0.000 }, level = 1 }
}

-- 区域
regions = {
	{ config_id = 7004, shape = RegionShape.SPHERE, radius = 10, pos = { x = 247.076, y = 214.711, z = 631.028 } }
}

-- 触发器
triggers = {
	{ config_id = 1007004, name = "ENTER_REGION_7004", event = EventType.EVENT_ENTER_REGION, source = "", condition = "condition_EVENT_ENTER_REGION_7004", action = "action_EVENT_ENTER_REGION_7004", trigger_count = 0 },
	{ config_id = 1007005, name = "ANY_MONSTER_DIE_7005", event = EventType.EVENT_ANY_MONSTER_DIE, source = "", condition = "condition_EVENT_ANY_MONSTER_DIE_7005", action = "action_EVENT_ANY_MONSTER_DIE_7005" },
	{ config_id = 1007012, name = "ANY_MONSTER_DIE_7012", event = EventType.EVENT_ANY_MONSTER_DIE, source = "", condition = "condition_EVENT_ANY_MONSTER_DIE_7012", action = "action_EVENT_ANY_MONSTER_DIE_7012" },
	{ config_id = 1007015, name = "SELECT_OPTION_7015", event = EventType.EVENT_SELECT_OPTION, source = "", condition = "condition_EVENT_SELECT_OPTION_7015", action = "action_EVENT_SELECT_OPTION_7015" },
	{ config_id = 1007017, name = "QUEST_FINISH_7017", event = EventType.EVENT_QUEST_FINISH, source = "302824", condition = "", action = "action_EVENT_QUEST_FINISH_7017", trigger_count = 0 },
	{ config_id = 1007019, name = "QUEST_START_7019", event = EventType.EVENT_QUEST_START, source = "302816", condition = "", action = "action_EVENT_QUEST_START_7019", trigger_count = 0 }
}

-- 变量
variables = {
}

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

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

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

suites = {
	{
		-- suite_id = 1,
		-- description = ,
		monsters = { 7002, 7003, 7006, 7007, 7008, 7009 },
		gadgets = { 7013, 7014, 7018 },
		regions = { 7004 },
		triggers = { "ENTER_REGION_7004", "ANY_MONSTER_DIE_7005", "QUEST_FINISH_7017", "QUEST_START_7019" },
		rand_weight = 100
	},
	{
		-- suite_id = 2,
		-- description = ,
		monsters = { 7001, 7010, 7011 },
		gadgets = { },
		regions = { },
		triggers = { "ANY_MONSTER_DIE_7012", "SELECT_OPTION_7015" },
		rand_weight = 100
	},
	{
		-- suite_id = 3,
		-- description = ,
		monsters = { },
		gadgets = { 7016, 7020, 7021, 7022, 7023, 7024, 7025, 7026, 7027, 7028, 7029, 7030, 7031, 7032, 7033, 7034 },
		regions = { },
		triggers = { },
		rand_weight = 100
	}
}

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

-- 触发条件
function condition_EVENT_ENTER_REGION_7004(context, evt)
	if evt.param1 ~= 7004 then return false end
	
	-- 判断角色数量不少于1
	if ScriptLib.GetRegionEntityCount(context, { region_eid = evt.source_eid, entity_type = EntityType.AVATAR }) < 1 then
		return false
	end
	
	return true
end

-- 触发操作
function action_EVENT_ENTER_REGION_7004(context, evt)
	-- 删除suite3的所有内容
	    ScriptLib.RemoveExtraGroupSuite(context, 220158002, 3)
	
	return 0
end

-- 触发条件
function condition_EVENT_ANY_MONSTER_DIE_7005(context, evt)
	-- 判断指定group组剩余怪物数量是否是0 
	if ScriptLib.GetGroupMonsterCountByGroupId(context, 220158007) ~= 0 then
		return false
	end
	
	return true
end

-- 触发操作
function action_EVENT_ANY_MONSTER_DIE_7005(context, evt)
	-- 添加suite2的新内容
	    ScriptLib.AddExtraGroupSuite(context, 220158007, 2)
	
	return 0
end

-- 触发条件
function condition_EVENT_ANY_MONSTER_DIE_7012(context, evt)
	-- 判断指定group组剩余怪物数量是否是0 
	if ScriptLib.GetGroupMonsterCountByGroupId(context, 220158007) ~= 0 then
		return false
	end
	
	return true
end

-- 触发操作
function action_EVENT_ANY_MONSTER_DIE_7012(context, evt)
	-- 设置操作台选项
	if 0 ~= ScriptLib.SetWorktopOptionsByGroupId(context, 220158007, 7014, {7}) then
	  ScriptLib.PrintContextLog(context, "@@ LUA_WARNING : set_wok_options_by_configid")
		return -1
	end
	
	-- 添加suite4的新内容
	    ScriptLib.AddExtraGroupSuite(context, 220158002, 4)
	
	-- 调用提示id为 201580104 的提示UI，会显示在屏幕中央偏下位置，id索引自 ReminderData表格
	if 0 ~= ScriptLib.ShowReminder(context, 201580104) then
	  ScriptLib.PrintContextLog(context, "@@ LUA_WARNING : active_reminder_ui")
		return -1
	end
	
	return 0
end

-- 触发条件
function condition_EVENT_SELECT_OPTION_7015(context, evt)
	-- 判断是gadgetid 7014 option_id 7
	if 7014 ~= evt.param1 then
		return false	
	end
	
	if 7 ~= evt.param2 then
		return false
	end
	
	
	return true
end

-- 触发操作
function action_EVENT_SELECT_OPTION_7015(context, evt)
	-- 删除suite4的所有内容
	    ScriptLib.RemoveExtraGroupSuite(context, 220158002, 4)
	
	-- 删除指定group： 220158007 ；指定config：7014；物件身上指定option：7；
	if 0 ~= ScriptLib.DelWorktopOptionByGroupId(context, 220158007, 7014, 7) then
	  ScriptLib.PrintContextLog(context, "@@ LUA_WARNING : del_work_options_by_group_configId")
		return -1
	end
	
	-- 通知任务系统完成条件类型"LUA通知"，复杂参数为quest_param的进度+1
	if 0 ~= ScriptLib.AddQuestProgress(context, "302815") then
		ScriptLib.PrintContextLog(context, "@@ LUA_WARNING : add_quest_progress")
	  return -1
	end
	
	-- 改变指定group组220158001中， configid为1003的gadget的state
	if 0 ~= ScriptLib.SetGroupGadgetStateByConfigId(context, 220158001, 1003, GadgetState.ChestLocked) then
	      ScriptLib.PrintContextLog(context, "@@ LUA_WARNING : set_gadget_state_by_GroupId_ConfigId")
			return -1
		end 
	
		-- 重新生成指定group，指定suite
		if 0 ~= ScriptLib.RefreshGroup(context, { group_id = 220158004, suite = 3 }) then
	    ScriptLib.PrintContextLog(context, "@@ LUA_WARNING : refresh_group_to_suite")
			return -1
		end
	
		-- 重新生成指定group，指定suite
		if 0 ~= ScriptLib.RefreshGroup(context, { group_id = 220158005, suite = 3 }) then
	    ScriptLib.PrintContextLog(context, "@@ LUA_WARNING : refresh_group_to_suite")
			return -1
		end
	
		-- 重新生成指定group，指定suite
		if 0 ~= ScriptLib.RefreshGroup(context, { group_id = 220158006, suite = 3 }) then
	    ScriptLib.PrintContextLog(context, "@@ LUA_WARNING : refresh_group_to_suite")
			return -1
		end
	
		-- 重新生成指定group，指定suite
		if 0 ~= ScriptLib.RefreshGroup(context, { group_id = 220158002, suite = 6 }) then
	    ScriptLib.PrintContextLog(context, "@@ LUA_WARNING : refresh_group_to_suite")
			return -1
		end
	
	
	-- 切三阶段scenetag
	ScriptLib.AddSceneTag(context, 20158, 1215 )
	
	ScriptLib.DelSceneTag(context, 20158, 1216 )
	
	ScriptLib.DelSceneTag(context, 20158, 1217 )
	
	ScriptLib.DelSceneTag(context, 20158, 1218 )
	
	-- 添加suite3的新内容
	    ScriptLib.AddExtraGroupSuite(context, 220158007, 3)
	
	
	return 0
end

-- 触发操作
function action_EVENT_QUEST_FINISH_7017(context, evt)
	-- 将configid为 7018 的物件更改为状态 GadgetState.GearStart
	if 0 ~= ScriptLib.SetGadgetStateByConfigId(context, 7018, GadgetState.GearStart) then
	  ScriptLib.PrintContextLog(context, "@@ LUA_WARNING : set_gadget_state_by_configId")
			return -1
		end 
	
	-- 将configid为 7013 的物件更改为状态 GadgetState.ChestLocked
	if 0 ~= ScriptLib.SetGadgetStateByConfigId(context, 7013, GadgetState.ChestLocked) then
	  ScriptLib.PrintContextLog(context, "@@ LUA_WARNING : set_gadget_state_by_configId")
			return -1
		end 
	
	-- 切换三阶段环境
	    ScriptLib.SetWeatherAreaState(context, 10157, 1)
	
	return 0
end

-- 触发操作
function action_EVENT_QUEST_START_7019(context, evt)
	-- 将configid为 7013 的物件更改为状态 GadgetState.Default
	if 0 ~= ScriptLib.SetGadgetStateByConfigId(context, 7013, GadgetState.Default) then
	  ScriptLib.PrintContextLog(context, "@@ LUA_WARNING : set_gadget_state_by_configId")
			return -1
		end 
	
	-- 切换二阶段环境
	    ScriptLib.SetWeatherAreaState(context, 10156, 1)
	
	
	return 0
end