core:import("CoreMissionScriptElement")
ElementChangeVanSkin = ElementChangeVanSkin or class(CoreMissionScriptElement.MissionScriptElement)

function ElementChangeVanSkin:on_executed(instigator)
	if not self._values.enabled or not self._values.target_skin then
		return
	end
	local _match = false
	for skins_name, _ in pairs(tweak_data.van.skins) do
		if _match and self._values.target_skin ~= skins_name then
			self._values.target_skin = skins_name
			break
		end
		if skins_name == self._values.target_skin then
			_match = true
		end
	end
	local van_data = tweak_data.van.skins[self._values.target_skin]
	if Network:is_server() and van_data.dlc and not managers.dlc:is_dlc_unlocked(van_data.dlc) then
		return
	end
	if Network:is_server() then
		managers.blackmarket:equip_van_skin(self._values.target_skin)
	end
	for i, unit in pairs(self._units) do
		if unit:damage() and unit:damage():has_sequence(van_data.sequence_name) then
			unit:damage():run_sequence_simple(van_data.sequence_name)
		end
	end
	ElementChangeVanSkin.super.on_executed(self, instigator)
end