---
--- Generated by EmmyLua(https://github.com/EmmyLua)
--- Created by binghong.shen.
--- DateTime: 2022/8/8 16:33
---
--[[======================================
||	filename:       BrickBreaker
||	owner:          binghong.shen
||	description:    3.3打砖块活动
||	LogName:        BrickBreaker
||	Protection:     [Protection]
=======================================]]



-- 测试gadget 70290608

--miscs配置内容
--[[

--传送触发器物件
defs.gadget_teleport = 10001
--砖块玩法物件
defs.gadget_bricks = 10002
--空气墙
defs.gadget_airWall = 10003
--是否是地城
defs.isDungeon = 0
--地城氛围物件
defs.gadget_envLamp = 10004

defs.envWeather =
{
	[1]=10169,
	[2]=10170,
	[3]=10171,
}


--地城对应的天气配置
local DungeonWeather = {
    10039,10040,10041,10042
}

local defs = {
    group_id = 235801002,
    worktop_id = 123,   --操作台对应的操作数
    air_wall = 2005,    --场内空气墙对应的ConfigID
    minion_fever = 5,   --普通怪物死亡增加的热度值
    game_time = 360,    --挑战时间
    min_monster_count = 5, --场上最少怪物数量
    max_monster_count = 5, --场上最多怪物数量
    environment_suite = 4, --环境灯光所在的Suite
    noswitch_punishment_interval = 30, --不换人开始有惩罚的最小时间间隔
    num_killed_per_tide = {20, 20, 20, 20, 0} --每组怪物潮对应需要的杀怪数量
}

]]


local local_defs = {
	worktop_option = 30110,
	progress_key = 1,
	team_global_value = "FEVER_LEVEL",
	team_noswitch_pubishment = "NOSWITCH_PUNISHMENT",
	team_has_switch = "HAS_SWITCHED_TEAM",
	burn_effect_level = 2,
	environment_change_level = 1,
	base_upgrade_reminder = 358010102,
	team_noswitch_pubishment_reminder = 144,
	punish_inAdvance_reminder = 201
}

local Tri = {
	[1] = { name = "group_load", config_id = 8000001, event = EventType.EVENT_GROUP_LOAD, source = "", condition = "", action = "action_group_load", trigger_count = 0},
	[2] = { name = "gadget_talk_done", config_id = 8000002, event = EventType.EVENT_GADGETTALK_DONE, source = "", condition = "", action = "action_gadget_talk_done", trigger_count = 0},
	[3] = { name = "gallery_pre_start", config_id = 8000003, event = EventType.EVENT_GALLERY_PRE_START, source = "", condition = "", action = "action_gallery_pre_start", trigger_count = 0},
	[4] = { name = "dungeon_settle", config_id = 8000004, event = EventType.EVENT_DUNGEON_SETTLE, source = "", condition = "", action = "action_dungeon_settle", trigger_count = 0},
	[5] = { name = "gallery_stop", config_id = 8000005, event = EventType.EVENT_GALLERY_STOP, source = "", condition = "", action = "action_gallery_stop", trigger_count = 0},

	--[2] = { name = "select_option", config_id = 8000002, event = EventType.EVENT_SELECT_OPTION, source = "", condition = "", action = "action_select_option", trigger_count = 0},
	--[3] = { name = "time_axis_pass", config_id = 8000003, event = EventType.EVENT_TIME_AXIS_PASS, source = "", condition = "", action = "action_time_axis_pass", trigger_count = 0},
	--[4] = { name = "gallery_progress_pass", config_id = 8000004, event = EventType.EVENT_GALLERY_PROGRESS_PASS, source = "", condition = "", action = "action_gallery_progress_pass", trigger_count = 0},
	--[6] = { name = "sumo_switch_team", config_id = 8000008, event = EventType.EVENT_SUMO_SWITCH_TEAM_EVENT, source = "", condition = "", action = "action_sumo_switch_team", trigger_count = 0},
	--[7] = { name = "dungeon_all_avatar_die", config_id = 8000009, event = EventType.EVENT_DUNGEON_ALL_AVATAR_DIE, source = "", condition = "", action = "action_dungeon_all_avatar_die", trigger_count = 0},
	--[8] = { name = "enter_start_region", config_id = 8000011, event = EventType.EVENT_ENTER_REGION, source = "", condition = "", action = "action_enter_start_region", trigger_count = 0},

}

function Initialize()
	for k,v in pairs(Tri) do
		table.insert(triggers, v)
		table.insert(suites[1].triggers, v.name)
	end

	table.insert(variables,{ config_id=50000003,name = "fever_ratio", value = 1})
	--用于记录是否已经创建空气墙，防止玩家卡在空气墙外
	table.insert(variables,{ config_id=50000006,name = "is_air_wall_created", value = 0})
end

------------------------------------------------------------------

function action_group_load(context,evt)
	ScriptLib.PrintContextLog(context,"BrickBreaker groupLoad")
	SLC_SetEnvLevel(context,1)
	return 0
end
function action_gadget_talk_done(context,evt)
	ScriptLib.PrintContextLog(context,"BrickBreaker action_gadget_talk_done")

	local talkName = evt.source_name
	local talkID = evt.param2
	if talkID == 6800419 or talkName == 6800419 then
		ScriptLib.CreateGadget(context, { config_id = defs.gadget_teleport })
	end
	return 0
end

function action_gallery_pre_start(context,evt)
	ScriptLib.PrintContextLog(context,"BrickBreaker action_gallery_pre_start")

	local curGallery = evt.param1
	ScriptLib.SetGroupTempValue(context, "curGallery", curGallery, {})

	if defs then
		if defs.gadget_bricks then
			ScriptLib.CreateGadget(context, { config_id = defs.gadget_bricks })
		end
		if defs.gadget_airWall then
			ScriptLib.CreateGadget(context, { config_id = defs.gadget_airWall })
		end
	end
	return 0
end

function action_dungeon_settle(context,evt)
	ScriptLib.PrintContextLog(context,"BrickBreaker action_dungeon_settle")

	local curGallery = ScriptLib.GetGroupTempValue(context, "curGallery", {})
	ScriptLib.StopGallery(context, curGallery, true)

	return 0
end

function action_gallery_stop(context,evt)
	ScriptLib.PrintContextLog(context,"BrickBreaker action_gallery_stop")
	ScriptLib.RemoveEntityByConfigId(context, 0, EntityType.GADGET, defs.gadget_bricks)
	ScriptLib.RemoveEntityByConfigId(context, 0, EntityType.GADGET, defs.gadget_airWall)
	SLC_SetEnvLevel(context,1)

	return 0
end

function SLC_SetEnvLevel(context,value)
	ScriptLib.PrintContextLog(context,"BrickBreaker SLC_SetEnvLevel In")

	if value and defs.gadget_envLamp then
		if value == 1 then
			ScriptLib.PrintContextLog(context,"BrickBreaker SLC_SetEnvLevel 1")
			ScriptLib.SetGadgetStateByConfigId(context, defs.gadget_envLamp, 0)
		end
		if value == 2 then
			ScriptLib.PrintContextLog(context,"BrickBreaker SLC_SetEnvLevel 2")
			ScriptLib.SetGadgetStateByConfigId(context, defs.gadget_envLamp, 201)
		end
		if value == 3 then
			ScriptLib.PrintContextLog(context,"BrickBreaker SLC_SetEnvLevel 3")
			ScriptLib.SetGadgetStateByConfigId(context, defs.gadget_envLamp, 202)
		end
	end

	if value and defs.envWeather and defs.envWeather[value] then
		for _,v in pairs(defs.envWeather) do
			ScriptLib.SetWeatherAreaState(context, v, 0)
		end
		ScriptLib.PrintContextLog(context,"BrickBreaker ChangeWeather "..tostring(defs.envWeather[value]))

		ScriptLib.SetWeatherAreaState(context, defs.envWeather[value], 1)
	end
	return 0
end

------------------------------------------------------------------
Initialize()

