---
--- Generated by EmmyLua(https://github.com/EmmyLua)
--- Created by binghong.shen.
--- DateTime: 2022/9/21 16:33
---
--[[======================================
||	filename:       Activity_PacMan
||	owner:          binghong.shen
||	description:    3.5吃豆人活动
||	LogName:        PacMan
||	Protection:     [Protection]
=======================================]]

--[[
测试gm
dungeon 91
run_lua 251015001 function func(context) \n ScriptLib.StartGallery(context, 34001) \n end
]]


--miscs配置内容
--[[
defs.moveback_pointarray_id = 1
]]
defs.teleportPointRangeMap ={
	[1]={3,20}
}


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},
}

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})
end

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

function action_group_load(context,evt)
	ScriptLib.PrintContextLog(context,"PacMan groupLoad")

	return 0
end
function action_gadget_talk_done(context,evt)
	ScriptLib.PrintContextLog(context,"PacMan 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,"PacMan 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,"PacMan 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,"PacMan action_gallery_stop")
	--ScriptLib.RemoveEntityByConfigId(context, 0, EntityType.GADGET, defs.gadget_bricks)
	--ScriptLib.RemoveEntityByConfigId(context, 0, EntityType.GADGET, defs.gadget_airWall)

	return 0
end

function SLC_TeleportBack(context)
	ScriptLib.PrintContextLog(context,"PacMan SLC_TeleportBack "..tostring(context.uid).." "..tostring(defs.moveback_pointarray_id))
	local selectedPoint = LF_GetNearPoint(context)
	if(selectedPoint~=-1)then
		ScriptLib.PrintContextLog(context,"PacMan Move Back Point "..tostring(selectedPoint))
		ScriptLib.MoveAvatarByPointArray(context, context.uid, defs.moveback_pointarray_id or 1, {selectedPoint,2,1}, {speed=10}, "{\"MarkType\":1,\"IgnoreCollisionWhenEnter\":true}")
	end
	return 0
end

function LF_GetNearPoint(context)
	ScriptLib.PrintContextLog(context,"PacMan LF_GetNearPoint In")
	local selectedPoint = -1
	local avatarUid = context.uid
	local avatarEntity = ScriptLib.GetAvatarEntityIdByUid(context, avatarUid)
	if avatarEntity==0 then
		return selectedPoint
	end
	local avatarPoint = ScriptLib.GetPosByEntityId(context, avatarEntity)
	local pointRangeMin = defs.teleportPointRangeMap[defs.moveback_pointarray_id][1]
	local pointRangeMax = defs.teleportPointRangeMap[defs.moveback_pointarray_id][2]
	local curPointDistance = 100000
	for i = pointRangeMin, pointRangeMax do
		local arrayPointRet,arrayPointPos,arrayPointRot=ScriptLib.GetPlatformArrayInfoByPointId(context, defs.moveback_pointarray_id, i)
		if(arrayPointRet~=-1)then
			local deltaX = arrayPointPos.x - avatarPoint.x
			local deltaY = arrayPointPos.y - avatarPoint.y
			local deltaZ = arrayPointPos.z - avatarPoint.z
			local distance = deltaX*deltaX + deltaY*deltaY + deltaZ*deltaZ
			if(distance<curPointDistance)then
				selectedPoint = i
				curPointDistance = distance
			end
		end
	end

	return selectedPoint
end


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

