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

-- Trigger变量
local defs = {
	duration = 18,
	group_id = 133103554
}

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

-- 怪物
monsters = {
}

-- NPC
npcs = {
}

-- 装置
gadgets = {
	{ config_id = 554001, gadget_id = 70211111, pos = { x = 938.565, y = 329.254, z = 1651.852 }, rot = { x = 0.000, y = 288.540, z = 0.000 }, level = 21, drop_tag = "解谜中级璃月", isOneoff = true, persistent = true, oneoff_reset_version = 2, explore = { name = "chest", exp = 1 }, area_id = 6 },
	{ config_id = 554002, gadget_id = 70350083, pos = { x = 881.579, y = 323.350, z = 1515.352 }, rot = { x = 0.000, y = 0.000, z = 0.000 }, level = 24, persistent = true, area_id = 6 },
	{ config_id = 554003, gadget_id = 70360001, pos = { x = 880.680, y = 324.315, z = 1517.976 }, rot = { x = 0.000, y = 0.000, z = 0.000 }, level = 24, persistent = true, area_id = 6 },
	{ config_id = 554004, gadget_id = 70690001, pos = { x = 888.436, y = 323.336, z = 1522.753 }, rot = { x = 10.000, y = 40.000, z = 0.000 }, level = 24, area_id = 6 },
	{ config_id = 554011, gadget_id = 70690001, pos = { x = 898.080, y = 320.913, z = 1532.853 }, rot = { x = 10.000, y = 40.000, z = 0.000 }, level = 24, area_id = 6 },
	{ config_id = 554012, gadget_id = 70690001, pos = { x = 905.609, y = 318.947, z = 1540.565 }, rot = { x = 10.000, y = 40.000, z = 0.000 }, level = 24, area_id = 6 },
	{ config_id = 554013, gadget_id = 70690001, pos = { x = 910.326, y = 317.714, z = 1545.095 }, rot = { x = 0.000, y = 77.260, z = 0.000 }, level = 24, area_id = 6 },
	{ config_id = 554014, gadget_id = 70690001, pos = { x = 917.219, y = 318.334, z = 1548.185 }, rot = { x = 350.000, y = 86.201, z = 0.000 }, level = 24, area_id = 6 },
	{ config_id = 554015, gadget_id = 70690001, pos = { x = 928.276, y = 319.324, z = 1548.974 }, rot = { x = 350.000, y = 85.684, z = 0.000 }, level = 24, area_id = 6 },
	{ config_id = 554016, gadget_id = 70690001, pos = { x = 939.116, y = 320.297, z = 1549.917 }, rot = { x = 350.000, y = 85.401, z = 0.000 }, level = 24, area_id = 6 },
	{ config_id = 554017, gadget_id = 70690001, pos = { x = 951.247, y = 321.384, z = 1550.792 }, rot = { x = 350.000, y = 84.280, z = 0.000 }, level = 24, area_id = 6 },
	{ config_id = 554018, gadget_id = 70690001, pos = { x = 957.257, y = 322.190, z = 1551.051 }, rot = { x = 0.000, y = 29.346, z = 0.000 }, level = 24, area_id = 6 },
	{ config_id = 554019, gadget_id = 70690001, pos = { x = 960.388, y = 322.433, z = 1557.513 }, rot = { x = 355.000, y = 10.434, z = 0.000 }, level = 24, area_id = 6 },
	{ config_id = 554020, gadget_id = 70690001, pos = { x = 962.605, y = 323.255, z = 1568.578 }, rot = { x = 355.000, y = 10.485, z = 0.000 }, level = 24, area_id = 6 },
	{ config_id = 554021, gadget_id = 70690001, pos = { x = 966.069, y = 325.072, z = 1585.453 }, rot = { x = 355.000, y = 10.897, z = 0.000 }, level = 24, area_id = 6 },
	{ config_id = 554022, gadget_id = 70690001, pos = { x = 968.058, y = 326.578, z = 1595.694 }, rot = { x = 355.000, y = 340.786, z = 4.998 }, level = 24, area_id = 6 },
	{ config_id = 554023, gadget_id = 70690001, pos = { x = 966.269, y = 327.266, z = 1600.346 }, rot = { x = 355.000, y = 303.417, z = 0.000 }, level = 24, area_id = 6 },
	{ config_id = 554024, gadget_id = 70690001, pos = { x = 959.597, y = 328.120, z = 1604.748 }, rot = { x = 355.000, y = 303.417, z = 0.000 }, level = 24, area_id = 6 },
	{ config_id = 554025, gadget_id = 70690001, pos = { x = 952.188, y = 328.837, z = 1609.637 }, rot = { x = 355.000, y = 303.417, z = 0.000 }, level = 24, area_id = 6 },
	{ config_id = 554026, gadget_id = 70690001, pos = { x = 942.752, y = 329.757, z = 1615.863 }, rot = { x = 355.000, y = 303.417, z = 0.000 }, level = 24, area_id = 6 },
	{ config_id = 554027, gadget_id = 70690001, pos = { x = 932.433, y = 331.053, z = 1639.018 }, rot = { x = 0.000, y = 16.752, z = 0.000 }, level = 24, area_id = 6 },
	{ config_id = 554028, gadget_id = 70690001, pos = { x = 931.417, y = 330.575, z = 1623.463 }, rot = { x = 355.000, y = 355.624, z = 0.000 }, level = 24, area_id = 6 },
	{ config_id = 554029, gadget_id = 70690001, pos = { x = 929.661, y = 330.988, z = 1629.806 }, rot = { x = 0.000, y = 16.752, z = 0.000 }, level = 24, area_id = 6 },
	{ config_id = 554030, gadget_id = 70900201, pos = { x = 937.465, y = 329.332, z = 1652.306 }, rot = { x = 0.000, y = 36.764, z = 0.000 }, level = 1, area_id = 6 }
}

-- 区域
regions = {
}

-- 触发器
triggers = {
	{ config_id = 1554005, name = "CHALLENGE_SUCCESS_554005", event = EventType.EVENT_CHALLENGE_SUCCESS, source = "666", condition = "", action = "action_EVENT_CHALLENGE_SUCCESS_554005" },
	{ config_id = 1554006, name = "CHALLENGE_FAIL_554006", event = EventType.EVENT_CHALLENGE_FAIL, source = "666", condition = "", action = "action_EVENT_CHALLENGE_FAIL_554006", trigger_count = 0 },
	{ config_id = 1554007, name = "GADGET_STATE_CHANGE_554007", event = EventType.EVENT_GADGET_STATE_CHANGE, source = "", condition = "condition_EVENT_GADGET_STATE_CHANGE_554007", action = "action_EVENT_GADGET_STATE_CHANGE_554007", trigger_count = 0 },
	{ config_id = 1554008, name = "GADGET_STATE_CHANGE_554008", event = EventType.EVENT_GADGET_STATE_CHANGE, source = "", condition = "condition_EVENT_GADGET_STATE_CHANGE_554008", action = "", tag = "202" },
	{ config_id = 1554009, name = "GADGET_CREATE_554009", event = EventType.EVENT_GADGET_CREATE, source = "", condition = "condition_EVENT_GADGET_CREATE_554009", action = "action_EVENT_GADGET_CREATE_554009", trigger_count = 0 },
	{ config_id = 1554010, name = "SELECT_OPTION_554010", event = EventType.EVENT_SELECT_OPTION, source = "", condition = "condition_EVENT_SELECT_OPTION_554010", action = "action_EVENT_SELECT_OPTION_554010", trigger_count = 0 }
}

-- 变量
variables = {
}

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

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

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

suites = {
	{
		-- suite_id = 1,
		-- description = suite_1,
		monsters = { },
		gadgets = { 554002, 554003 },
		regions = { },
		triggers = { "CHALLENGE_SUCCESS_554005", "CHALLENGE_FAIL_554006", "GADGET_STATE_CHANGE_554007", "GADGET_STATE_CHANGE_554008", "GADGET_CREATE_554009", "SELECT_OPTION_554010" },
		rand_weight = 100
	},
	{
		-- suite_id = 2,
		-- description = suite_2,
		monsters = { },
		gadgets = { 554001, 554004, 554011, 554012, 554013, 554014, 554015, 554016, 554017, 554018, 554019, 554020, 554021, 554022, 554023, 554024, 554025, 554026, 554027, 554028, 554029, 554030 },
		regions = { },
		triggers = { },
		rand_weight = 100
	},
	{
		-- suite_id = 3,
		-- description = ,
		monsters = { },
		gadgets = { 554002 },
		regions = { },
		triggers = { },
		rand_weight = 100
	}
}

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

-- 触发操作
function action_EVENT_CHALLENGE_SUCCESS_554005(context, evt)
	-- 将configid为 554002 的物件更改为状态 GadgetState.GearStop
	if 0 ~= ScriptLib.SetGadgetStateByConfigId(context, 554002, GadgetState.GearStop) then
	  ScriptLib.PrintContextLog(context, "@@ LUA_WARNING : set_gadget_state_by_configId")
			return -1
		end 
	
	    -- 杀死指定group内的gadget和monster,移除其它东西
	    ScriptLib.KillExtraGroupSuite(context, 133103554, 2)
	
	-- 运营数据埋点，匹配LD定义的规则使用
	    if 0 ~= ScriptLib.MarkPlayerAction(context, 3002, 3, 1) then
	      ScriptLib.PrintContextLog(context, "@@ LUA_WARNING : mark_playerAction")
	      return -1
	    end
	
	-- group调整group进度,只对非randSuite有效
	if 0 ~= ScriptLib.GoToGroupSuite(context, 133103554, 3) then
	  ScriptLib.PrintContextLog(context, "@@ LUA_WARNING : goto_groupSuite")
		return -1
	end
	
	return 0
end

-- 触发操作
function action_EVENT_CHALLENGE_FAIL_554006(context, evt)
	-- 删除suite2的所有内容
	    ScriptLib.RemoveExtraGroupSuite(context, 133103554, 2)
	
	-- 将configid为 554002 的物件更改为状态 GadgetState.Default
	if 0 ~= ScriptLib.SetGadgetStateByConfigId(context, 554002, GadgetState.Default) then
	  ScriptLib.PrintContextLog(context, "@@ LUA_WARNING : set_gadget_state_by_configId")
			return -1
		end 
	
	-- 创建id为554003的gadget
	if 0 ~= ScriptLib.CreateGadget(context, { config_id = 554003 }) then
	  ScriptLib.PrintContextLog(context, "@@ LUA_WARNING : create_gadget")
	  return -1
	end
	
	-- 运营数据埋点，匹配LD定义的规则使用
	    if 0 ~= ScriptLib.MarkPlayerAction(context, 3002, 4, 1) then
	      ScriptLib.PrintContextLog(context, "@@ LUA_WARNING : mark_playerAction")
	      return -1
	    end
	
	return 0
end

-- 触发条件
function condition_EVENT_GADGET_STATE_CHANGE_554007(context, evt)
	if 554002 ~= evt.param2 or GadgetState.GearStart ~= evt.param1 then
		return false
	end
	
	return true
end

-- 触发操作
function action_EVENT_GADGET_STATE_CHANGE_554007(context, evt)
	-- 202号挑战,duration内开启宝箱
	if 0 ~= ScriptLib.ActiveChallenge(context, 666, 202, defs.duration, 7, 202, 1) then
	return -1
	end
	
	-- 添加suite2的新内容
	ScriptLib.AddExtraGroupSuite(context, defs.group_id, 2)
	
	-- 运营数据埋点，匹配LD定义的规则使用
	if 0 ~= ScriptLib.MarkPlayerAction(context, 3002, 1, 1) then
	return -1
	end
	
	return 0
	
end

-- 触发条件
function condition_EVENT_GADGET_STATE_CHANGE_554008(context, evt)
	if 554001 ~= evt.param2 or GadgetState.ChestOpened ~= evt.param1 then
		return false
	end
	
	return true
end

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

-- 触发操作
function action_EVENT_GADGET_CREATE_554009(context, evt)
	-- 设置操作台选项
	if 0 ~= ScriptLib.SetWorktopOptionsByGroupId(context, 133103554, 554003, {177}) then
	  ScriptLib.PrintContextLog(context, "@@ LUA_WARNING : set_wok_options_by_configid")
		return -1
	end
	
	return 0
end

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

-- 触发操作
function action_EVENT_SELECT_OPTION_554010(context, evt)
		-- 永久关闭CongfigId的Gadget，需要和Groups的RefreshWithBlock标签搭配
		if 0 ~= ScriptLib.KillEntityByConfigId(context, { config_id = 554003 }) then
	    ScriptLib.PrintContextLog(context, "@@ LUA_WARNING : kill_entity_by_configId")
		    return -1
		end
		
	
	-- 将configid为 554002 的物件更改为状态 GadgetState.GearStart
	if 0 ~= ScriptLib.SetGadgetStateByConfigId(context, 554002, GadgetState.GearStart) then
	  ScriptLib.PrintContextLog(context, "@@ LUA_WARNING : set_gadget_state_by_configId")
			return -1
		end 
	
	return 0
end