BulletHaloOneShot = class(Room, function(o, x, y, world, ...)
	local arg = {...}
	if arg[1] == nil then
		options = {}
	else
		options = arg[1]
	end
	o.settingName = options.settingName or 'halo_one_shot_'
	o.prefix = options.prefix or '1star'
	o.shotType = options.shotType or Bullet
	o.typecount = 1
	local svgName = options.svgName or "halo_room_" .. player.currentWorld.id
	o.health = game_settings[o.settingName .. "heath"] or 1
	Room.init(o, x, y, world, ...)

	o.numShots = game_settings[o.settingName .. "num_shots"] or 10
	o.damage = game_settings[o.settingName .. "damage"] or 1
	o.health = game_settings[o.settingName .. "heath"] or 1
	o.shootRate = o.shootRate*4
	o.drawType = 'svg'
	o.svg = SvgLoader(svg_root .. "defence/" .. svgName .. ".svg", true)
	o.svg:setPosition(x, y)
	Room.setHealth(o, game_settings[o.settingName .. "health"], game_settings[o.settingName .. "health"])
end)
BulletHaloOneShot.rtype = BulletHaloOneShot
function BulletHaloOneShot:pulse()
	-- explode self, shoot out a halo of bullets
	Room.pulse(self)
	Room.kill(self)
	mainState.particles:addRecycle(Flash())
	if not self.world.bullets then
		self.world.bullets = self.world:add(Group())
	end

	local numShots = self.numShots
	for i=0,numShots-1 do
		local angle = 360*i/numShots
		local direction = Vec2(0,1)
		direction:normalize()
		direction:rotate(math.rad(angle))
		direction:mult(100)
		local b;
		if self.shotType == MiniMine then
			b = self.world.bullets:addRecycle(MiniMine(self:center().x, self:center().y, self.world, game_settings[self.settingName .. "fuse_start"], game_settings[self.settingName .. "fuse_end"], game_settings[self.settingName .. "radius"], game_settings[self.settingName .. "power"]))
		else
			b = self.world.bullets:addRecycle(self.shotType(self:center().x, self:center().y, nil, self.damage))
		end
		b.velocity = direction
		b.velocity:mult(r_scale)
		if b.updateRotation then b:updateRotation() end
	end
end

BulletHaloOneShot.rtype = BulletHaloOneShot
BulletHaloOneShot.cost = 200
BulletHaloOneShot.color = {r=255, g=255, b=255, a=255, rtype=BulletHaloOneShot, typecount=1}
BulletHaloOneShot.settingName = "halo_one_shot_"

BulletHaloOneShot2 = class(BulletHaloOneShot, function(o, x, y, world, ...)
	local arg = {...}
	if arg[1] == nil then
		options = {}
	else
		options = arg[1]
	end
	mergeTable(options, {settingName='halo_one_shot_2_', shotType=MiniMine, svgName='halo_room_mine_' .. player.currentWorld.id})
	BulletHaloOneShot.init(o, x, y, world, options)
end)
BulletHaloOneShot2.rtype = BulletHaloOneShot2

BulletHaloOneShot3 = class(BulletHaloOneShot, function(o, x, y, world, ...)
	local arg = {...}
	if arg[1] == nil then
		options = {}
	else
		options = arg[1]
	end
	mergeTable(options, {settingName='halo_one_shot_3_', shotType=MiniMine, svgName='missile_room_' .. player.currentWorld.id})
	BulletHaloOneShot.init(o, x, y, world, options)
end)
BulletHaloOneShot3.rtype = BulletHaloOneShot3

function BulletHaloOneShot3:pulse()
	if self.world.enemies:countLiving() > 0 then
		-- explode self, shoot out a halo of bullets
		Room.pulse(self)
		Room.kill(self)
		mainState.particles:addRecycle(Flash())
		if not self.world.bullets then
			self.world.bullets = self.world:add(Group())
		end

		local numShots = self.numShots
		-- get the list of targets so that we can take them out one by one
		self.targets = findOrderDistance(self.world.enemies.members, self:center())

		for i=0,numShots-1 do
			local angle = 360*i/numShots
			local direction = Vec2(0,1)
			direction:normalize()
			direction:rotate(math.rad(angle))
			direction:mult(100)
			local b;
			b = self.world.bullets:addRecycle(HomingBullet(self:center().x, self:center().y, self.targets[math.random(1, math.min(#self.targets, 3))][1], self.damage))
			b.velocity = direction
			b.velocity:mult(r_scale)
			if b.updateRotation then b:updateRotation() end
		end
	end
end

BulletHaloOneShot4 = class(BulletHaloOneShot, function(o, x, y, world, ...)
	local arg = {...}
	if arg[1] == nil then
		options = {}
	else
		options = arg[1]
	end
	mergeTable(options, {settingName='halo_one_shot_4_', shotType=Bullet, svgName='halo_room_2_' .. player.currentWorld.id})
	BulletHaloOneShot.init(o, x, y, world, options)
end)
BulletHaloOneShot4.rtype = BulletHaloOneShot4
