freeslot("sfx_lotede")

enemyList["georeaper"] = {
		name = "Orbal Reaper",
		skillchance = 100,	-- /100, probability of using a skill
		level = 100,
		hp = 10000,
		sp = 8888,
		strength = 85,
		magic = 85,
		endurance = 99,
		luck = 90,
		agility = 85,
		melee_natk = "strike_1",	-- enemies don't have crit anims for their attacks.
		thinker = generalEnemyThinker,
		boss = true,
		endboss = true,
		turns = 2,
		scale = FRACUNIT*3/2,

		r_exp = 75000,
		anim_stand = 		{SPR_REAP, A, B, C, D, E, F, G, H, I, J, 4},
		anim_stand_hurt = 	{SPR_REAP, A, B, C, D, E, F, G, H, I, J, 4},
		anim_move =			{SPR_REAP, A, B, C, D, E, F, G, H, I, J, 4},
		anim_run =			{SPR_REAP, A, B, C, D, E, F, G, H, I, J, 4},
		anim_hurt =			{SPR_REAP, A, 10},
		anim_getdown =		{SPR_REAP, A, 1},
		anim_downloop =		{SPR_REAP, A, 1},
		anim_getup =		{SPR_REAP, A, 1},		-- enemies don't need special standing, death or revive anims.
													-- they explode on death, and cannot be revived.
													-- unless it's specified like for players.
													
		hudcutin = "REAP_A",	-- cut in
		color = SKINCOLOR_WHITE,
													
													
		skills = {"reapermusicthing", "megidolaon", "power charge", "mind charge", "megaton raid", "vicious strike", "heat riser",
					"orbal_down", "chrono_down", "phantom_pain", "lord_inferno", "cocytus",
					"NoTeamaero_storm", "golden halo", "ragna_dorian", "zeruel_cannon", "lost_eden", "adamantine_guard", "a_reflex",
					"dekaja", "innocence_arc", "death_scream", "ragna_vortex", 
					"seventh caliber", "psycho force", "abyss_fall", "diamond_nova", "crimson_ray", "judgement_bolt", "void boost 7"},
}

local dng = {
	
	name = "Geofront Sector A",											-- The Dungeon's name
	description = "Explore the Geofront during the Dark Hour",	
	gensize = 5,															-- 1-6 sets how big the generation can get.
	floors = 20,															-- # of floors.
	level = 70,																-- Starting level
	levelcap = 99,															-- Max level
	
	weapon_addpow = 800,													-- power added to the stock equipped weapon (10:1)
	armour_adddef = 500,													-- defence added to the stock equipped wardring (10:1)
	
	dungeonmusic = "AOGEO",												-- Music to play inside the dungeon
	
	floortextures = "ERZBG4",												-- Prefix of the floor texture
	ceilingtexture = "ERZBG1",												-- Ceiling texture
	useautotile = false,													-- wether to change the floor texture based on surrounding tiles. leave to off to only use a single floor texture accross the entire floor
	startwalltexture = "ERZGREY3",											-- 1st wall texture
	texturerange = 0,														-- Texture range: How far from the startwalltexture can we randomize?
	brightness = 200,
	skynum = 9,
	maxep = 6,
	
	allowinterference = true,												-- Chooses to allow generation interference (dark floors, dread floors... etc)
	
	shufflelevel = 9,														-- Maximum shuffle time levels
	shufflepersonas = {
		"trumpeter",
		"lilith",
		"archangel",
		"raphael",
		"sati",
		"loki",
		"alice",
		"daisoujou",
		"anubis",
		"kinki",
		"quezacoatl",
		"belphegor",
		"siegfried",
		"matador",
		"hell biker",
		"byakko",
		"seiryuu",
		"mara",
		"zeit",
		"kea",
		"guy",
		"noel",
		"wazy",
		"renne",
		"earcus",
		
		},
		
		-- List of Sub-Personas.
	
	shop = "tiotrailsshop",												-- Name of the custom shop. Defaults to the regular Velvet Shop
	
	-- Item drop tables:
	itemdrops = {
		{"snuffsoul", 17},
		{"chewing soul", 10},
		{"silverring", 25},
		{"silvercombiring", 10},
		{"hypercombiring", 8},
		{"homunculus", 7},
		{"me patra gem", 10},
		{"megidola gem", 3},
		{"megidolaon gem", 2},
		{"agidyne gem", 5},
		{"bufudyne gem", 5},
		{"ziodyne gem", 5},
		{"garudyne gem", 5},
		{"psiodyne gem", 5},
		{"freidyne gem", 5},
		{"hell magatama", 2},
		{"cyclone magatama", 2},
		{"storm magatama", 2},
		{"frost magatama", 2},
		{"megidolaon gem", 2},
		{"blow bouncer", 9},
		{"magic mirror", 9},
		{"dekaja gem", 15},
		{"dekunda gem", 15},
		{"1up", 10},
		{"super1up", 5},
		{"chaos drive 2", 10},
		{"chaos drive 3", 7},
		{"hyperring", 10},
		{"diamond", 15},
		{"ruby", 13},
		{"painite", 9},
		{"tearalbalm", 10},
		{"spcharge", 16},
		{"spcharge2", 8},
		{"spcharge3", 8},
		{"revbalm", 8},
		{"celbalm", 4},
		{"zerpow", 2},
		{"antidote", 3},
		{"relaxant", 4},
		{"tape", 3},
		{"spray", 4},
		{"warmer", 3},
		{"eye", 3},
		{"mint", 3},
		{"salts", 3},
		{"curiabalm", 4},
		{"stablet", 7},
		{"recuriabalm", 4},
		{"battlescope", 7},
		
		
		{{"series", "novel"}, 12},
		{{"series", "v2-alter"}, 12},
		{{"series", "v2-vitalis"}, 9},
		{{"series", "v2-spirita"}, 9},
		{{"series", "awake"}, 8},
		{{"series", "obliance"}, 7},			
		{{"series", "freifi"}, 5},
		{{"series", "buhn"}, 1},
		{{"ring", "novel rings"}, 10},
		{{"ring", "vitalis rings"}, 5},
		{{"ring", "spirita rings"}, 5},
		{{"ring", "awake rings"}, 5},
		{{"ring", "freifi rings"}, 2},
	},
	
	-- Floor data table:
	floordata = {
		
		-- Floor 1
		[1] = {
			noreaper = nil,
			map = nil,	-- Nil map means that we let the game generate it randomly.
		},
		
		-- Floors 2, 3, and 4 will use the same data as floor 1's!
		
		-- Floor 5
		[7] = {
			map = BOSSFLOOR,
			noreaper = true,
			eventdir = 270,		-- Angle of the in-map enemy spawn
			spawndir = 90,		-- Player spawn angle
			shopdir = 0,		-- This is a boss floor.
		},

		-- Floor 6, go back to normal random floors!
		[8] = {
			noreaper = nil,
			map = nil,	-- Nil map means that we let the game generate it randomly.
		},

		[12] = {
			map = BOSSFLOOR,
			noreaper = true,
			eventdir = 270,		-- Angle of the in-map enemy spawn
			spawndir = 90,		-- Player spawn angle
			shopdir = 0,		-- This is a boss floor.
		},
		
		[13] = {
			map = BOSSFLOOR,
			noreaper = true,
			eventdir = 270,		-- Angle of the in-map enemy spawn
			spawndir = 90,		-- Player spawn angle
			shopdir = 0,		-- This is a boss floor.
		},
		
		
		[14] = {
			noreaper = nil,
			map = nil,	-- Nil map means that we let the game generate it randomly.
		},
		
		-- Floor 10, our final floor, go back to being a boss floor for our final boss
		[17] = {
			map = BOSSFLOOR,
			noreaper = true,
			eventdir = 270,
			spawndir = 90,
			shopdir = 0,		-- This is a boss floor.
		},
		
		[18] = {
			noreaper = nil,
			map = nil,	-- Nil map means that we let the game generate it randomly.
		},
		
		[20] = {
			map = BOSSFLOOR,
			noreaper = true,
			eventdir = 270,
			spawndir = 90,
			shopdir = 0,		-- This is a boss floor.
		},
		
	},
	
	-- Finally, our enemies.
	-- This is a small example, your tables can get a lot bigger than these but I want to keep simple and comprehensive!
	
	enemies = {
		
		-- Enemies from floor 1 onwards:
		[1] = {
			
			-- Enemy waves in floor 1
		{
			"idol_adamah",
			"nyogo_adamah",
			"idol_adamah",
		},

		{
			"giant_adamah",
			"turret_adamah",
			"turret_adamah",
			"twins_adamah",
		},

		{
			"balance_adamah",
			"giant_adamah",
			"balance_adamah",
		},

		{
			"gene_adamah",
			"knight_adamah",
			"gene_adamah",
		},

		{
			"castle_adamah",
			"turret_adamah",
			"turret_adamah",
			"castle_adamah",
		},

		{
			"minotaur_adamah",
			"dice_adamah",
			"minotaur_adamah",
		},

		{
			"dice_adamah",
			"dice_adamah",
			"nyogo_adamah",
			"dice_adamah",
			"dice_adamah",
		},

		{
			"giant_adamah",
			"giant_adamah",
			"giant_adamah",
		},

		{
			"snake_adamah",
			"phantom_adamah",
			"panzer_adamah",
			"phantom_adamah",
		},

		{
			"dice_adamah",
			"nyogo_adamah",
			"phantom_adamah",
			"dice_adamah",
		},

		{
			"sand_adamah",
			"beetle_adamah",
			"drive_adamah",
			"sand_adamah",
		},

		{
			"gene_adamah",
			"hand_adamah",
			"hand_adamah",
			"gene_adamah",
		},

		{
			"idol_adamah",
			"hand_adamah",
			"hand_adamah",
			"idol_adamah",
		},

		{
			"balance_adamah",
			"panzer_adamah",
			"balance_adamah",
		},
		
		{
			"pesce_adamah",
			"nyogo_adamah",
			"pesce_adamah",
		},

		{
			"gigas_adamah",
			"sand_adamah",
			"maya_adamah",
			"gigas_adamah",
		},

		{
			"idol_adamah",
			"idol_adamah",
			"minotaur_adamah",
			"idol_adamah",
		},

		{
			"idol_adamah",
			"hand_adamah",
			"maya_adamah",
			"idol_adamah",
		},

		{
			"minotaur_adamah",
			"minotaur_adamah",
		},

		{
			"snake_adamah",
			"panzer_adamah",
			"snake_adamah",
		},

		{
			"idol_adamah",
			"minotaur_adamah",
			"idol_adamah",
		},

		{
			"snake_adamah",
			"knight_adamah",
			"snake_adamah",
		},

		{
			"drive_adamah",
			"giant_adamah",
			"nyogo_adamah",
		},

		{
			"idol_adamah",
			"idol_adamah",
			"idol_adamah",
			"dice_adamah",
		},
		
			
		},
		
		
		-- Remember? We set floor 5 to be a boss floor above, so let's make the enemies that spawn here bosses!
		-- Mecha Sonichough the game never uses it, you can have multiple waves here to have different bosses spawn!
		
		[7] = {
						
			{	
			
			"eagle_boss1_adamah",
			"eagle_boss1_adamah",
			"eagle_boss1_adamah",
					
			},
			
		},
		
		-- And here, we're back to our normal encounters from floor 6 onwards. They can be different from the encounters we had in 1F.
		[8] = {
			
			-- Enemy waves in floor 1
				{
		"maya_monad",
		"mage_monad",
		"maya_monad",
	},
	
	{
		"maya_monad",
		"hablerie_monad",
		"maya_monad",
	},	
	
	{
		"sand_monad",
		"maya_monad",
		"sand_monad",
	},	

	{
		"eagle_monad",
		"musha_monad",
		"musha_monad",
	},
	
	{
		"maya_monad",
		"tower_monad",
		"maya_monad",
		"maya_monad",
	},	
	
	{
		"musha_monad",
		"giant_monad",
		"mage_monad",
		"mage_monad",
	},		

	{
		"knight_monad",
		"hablerie_monad",
		"knight_monad",
		"maya_monad",
	},
	
	{
		"sand_monad",
		"turret_monad",
		"sand_monad",
	},
	
	{
		"turret_monad",
		"giant_monad",
		"turret_monad",
	},
	
	{
		"turret_monad",
		"tower_monad",
		"turret_monad",
	},	

			
		},
		
	
	[12] = {
						
			{
			
			"knight_boss1_adamah",
			"knight_boss1_adamah",
			"knight_boss1_adamah",
			
			},
			
		},
		
	[13] = {
	
			{
			
			"drive_boss_monad"
			
			},
			
		},
		
		[14] = {
			
	{
		"maya_monad",
		"basalt_monad",
		"maya_monad",
	},

	{
		"maya_monad",
		"machine_monad",
		"maya_monad",
	},

	{
		"maya_monad",
		"okina_monad",
		"maya_monad",
		"turret_monad",
	},
	
	{
		"sand_monad",
		"okina_monad",
		"sand_monad",
		"gigas_monad",
	},	

	{
		"eagle_monad",
		"musha_monad",
		"musha_monad",
		"turret_monad",
	},
	
	{
		"maya_monad",
		"okina_monad",
		"maya_monad",
		"maya_monad",
		"gigas_monad",
	},	
	
	{
		"musha_monad",
		"giant_monad",
		"giant_monad",
		"mage_monad",
		"mage_monad",
	},		

	{
		"knight_monad",
		"giant_monad",
		"knight_monad",
		"maya_monad",
	},
	
	{
		"sand_monad",
		"turret_monad",
		"sand_monad",
		"gigas_monad",
	},
	
	{
		"turret_monad",
		"giant_monad",
		"turret_monad",
		"giant_monad",
	},
	
	{
		"turret_monad",
		"tower_monad",
		"turret_monad",
		"gigas_monad",
		
		
	},				
	
		},	
		
		[17] = {
			
			{
				"maya_boss_monad",	
			},
			
		},
		
		[18] = {
			
	{
		"maya_monad",
		"basalt_monad",
		"maya_monad",
	},

	{
		"maya_monad",
		"machine_monad",
		"maya_monad",
	},

	{
		"maya_monad",
		"okina_monad",
		"maya_monad",
		"turret_monad",
	},
	
	{
		"sand_monad",
		"okina_monad",
		"sand_monad",
		"gigas_monad",
	},	

	{
		"eagle_monad",
		"musha_monad",
		"musha_monad",
		"turret_monad",
	},
	
	{
		"maya_monad",
		"okina_monad",
		"maya_monad",
		"maya_monad",
		"gigas_monad",
	},	
	
	{
		"musha_monad",
		"giant_monad",
		"giant_monad",
		"mage_monad",
		"mage_monad",
	},		

	{
		"knight_monad",
		"giant_monad",
		"knight_monad",
		"maya_monad",
	},
	
	{
		"sand_monad",
		"turret_monad",
		"sand_monad",
		"gigas_monad",
	},
	
	{
		"turret_monad",
		"giant_monad",
		"turret_monad",
		"giant_monad",
	},
	
	{
		"turret_monad",
		"tower_monad",
		"turret_monad",
		"gigas_monad",
		
		
	},	
		
		},	
		
		[20] = {
			
			{
				"georeaper",	-- The rampage drive has an "endboss" field.
			},		
			
		},
		
	},
}

P_registerCustomDungeon(dng)

attackDefs["ragna_dorian"] = {
		name = "Ragna Dorian",
		type = ATK_ELEC,
		power = 350,
		accuracy = 90,
		costtype = CST_SP,
		status = COND_SHOCK,
		statuschance = 2,
		cost = 24,
		desc = "Orbal Art.\nHeavy Elec Damage to all enemies.\nMay Shock",
		target = TGT_ALLENEMIES,
		anim = function(mo, targets, hittargets, timer)
			for i = 1, #hittargets
				local target = hittargets[i]
				if timer == 20 + 10*(i-1)
					playSound(mo.battlen, sfx_elthr)
					lightningblast(target, SKINCOLOR_GREEN, FRACUNIT*3/2)
					localquake(mo.battlen, FRACUNIT*8, 8)
					damageObject(target)
				end
			end
			if timer == 60 + (10*(#hittargets-1))
				return true
			end
		end,
}

attackDefs["lost_eden"] = {
		name = "Lost Eden",
		type = ATK_PSY,
		power = 700,
		accuracy = 90,
		costtype = CST_SP,
		statuschance = 10,
		status = COND_BRAINWASH,
		cost = 60,
		desc = "Lost Art.\nSevere Psi Damage to all enemies.\nMay Brainwash",
		target = TGT_ALLENEMIES,	
		hudfunc = 	function(v, mo, timer)			
						if timer > 210
						and timer < 260
							local t = timer-210
							local p = "H_ATR"..t/2
							if v.patchExists(p)
								drawScreenwidePatch(v, v.cachePatch(p))
							end
						end
					end,
			
		anim = function(mo, targets, hittargets, timer)	
			local colors = {SKINCOLOR_RED, SKINCOLOR_YELLOW, SKINCOLOR_BLUE, SKINCOLOR_GREEN, SKINCOLOR_ORANGE, SKINCOLOR_PURPLE, SKINCOLOR_MAGENTA}
			local psiocolors = {SKINCOLOR_TEAL, SKINCOLOR_YELLOW, SKINCOLOR_PINK, SKINCOLOR_BLACK, SKINCOLOR_WHITE}
			local avgx, avgy = 0, 0
			for i = 1, #hittargets -- Get average position of targets
				avgx = $ + hittargets[i].x/FRACUNIT
				avgy = $ + hittargets[i].y/FRACUNIT
			end
			avgx = ($/#hittargets)*FRACUNIT
			avgy = ($/#hittargets)*FRACUNIT
			
			if timer == 10
				playSound(mo.battlen, sfx_lotede)
				S_StartSoundAtVolume(nil,sfx_lotede,70)
			end
			
			if timer >= 10 and timer <= 200
				for i = 1,3
					local thok = P_SpawnMobj(avgx + P_RandomRange(-120, 120)*FRACUNIT, avgy + P_RandomRange(-120, 120)*FRACUNIT, mo.z, MT_DUMMY)
					thok.flags = MF_NOBLOCKMAP
					thok.color = SKINCOLOR_WHITE
					if timer%2 then thok.color = SKINCOLOR_MAGENTA end
					thok.frame = A
					thok.tics = 35
					thok.scale = FRACUNIT*1
					thok.scalespeed = FRACUNIT/32
					thok.destscale = 1
					thok.momz = P_RandomRange(5, 7)*FRACUNIT
					thok.momx = P_RandomRange(-20, 20)*FRACUNIT
					thok.momy = P_RandomRange(-20, 20)*FRACUNIT
				end
			end
		
			local myears
			for k,v in ipairs(hittargets)
				local target = v
				local time = timer - 6*(k-1)

				if time >= 10 and time <= 90

					if leveltime%5 == 0
						local thok = P_SpawnMobj(avgx + P_RandomRange(-200, 200)*FRACUNIT, avgy + P_RandomRange(-200, 200)*FRACUNIT, mo.z + P_RandomRange(0, 200)<<FRACBITS, MT_DUMMY)
						A_OldRingExplode(thok, MT_SUPERSPARK)
						thok.flags2 = $|MF2_DONTDRAW
						if not myears
							playSound(mo.battlen, sfx_hamas1)
						end
						myears = true

						local speeds = {FRACUNIT/16, FRACUNIT/10, FRACUNIT/3, FRACUNIT/8}
						local fuses = {20, 16, 8, 16}

						for i = 1, 2
							local l = P_SpawnMobj(thok.x, thok.y, thok.z + FRACUNIT*32, MT_THOK)	-- mt_thok for auto fadeout
							l.tics = -1
							l.sprite = SPR_CARD
							l.color = colors[P_RandomRange(1, #colors)]
							l.frame = L|(i== 2 and TR_TRANS40 or TR_TRANS70)|FF_FULLBRIGHT
							l.scale = FRACUNIT/2
							l.destscale = FRACUNIT*6
							l.scalespeed = speeds[i]
							l.fuse = fuses[i]
						end
					end
					if time == 35
						for i = 1,8
							local thok = P_SpawnMobj(avgx + P_RandomRange(-40, 40)*FRACUNIT, avgy + P_RandomRange(-40, 40)*FRACUNIT, mo.z, MT_DUMMY)
							thok.state = S_SSPK1
							thok.momz = P_RandomRange(15, 30)*FRACUNIT
							thok.momx = P_RandomRange(-6, 6)*FRACUNIT
							thok.momy = P_RandomRange(-6, 6)*FRACUNIT
						end	
					end
				end
			end	
			
			if timer >= 170 and timer <= 210
			and (timer%5) == 0
				for i = 1, #hittargets
					local t = hittargets[i]
					avgx = $+ t.x/FRACUNIT
					avgy = $+ t.y/FRACUNIT
					local s = P_SpawnMobj(t.x + P_RandomRange(-128, 128)<<FRACBITS, t.y + P_RandomRange(-128, 128)<<FRACBITS, t.z + P_RandomRange(0, 192)<<FRACBITS, MT_DUMMY)
					s.color = SKINCOLOR_WHITE
					s.state = S_MEGISTAR1
					s.scale = $*2 + P_RandomRange(0, 65535)
				end	
			end		
			
			if timer >= 90 and timer <= 200
				if timer == 90
				or timer == 110
				or timer == 130
				or timer == 150
				or timer == 170
				or timer == 190
					playSound(mo.battlen, sfx_s3k74)
				end
				if not (timer%4)

					local ol = P_SpawnMobj(avgx + P_RandomRange(-200, 200)*FRACUNIT, avgy + P_RandomRange(-200, 200)*FRACUNIT, mo.z + P_RandomRange(0, 200)<<FRACBITS, MT_DUMMY)
					ol.sprite = SPR_NTHK
					ol.color = psiocolors[P_RandomRange(1, #psiocolors)]
					ol.scale = 1
					ol.destscale = FRACUNIT*32
					ol.scalespeed = FRACUNIT/5
					ol.frame = B|FF_FULLBRIGHT
					ol.tics = 20

					ol = P_SpawnMobj(avgx + P_RandomRange(-200, 200)*FRACUNIT, avgy + P_RandomRange(-200, 200)*FRACUNIT, mo.z + P_RandomRange(0, 200)<<FRACBITS, MT_DUMMY)
					ol.sprite = SPR_NTHK
					ol.color = psiocolors[P_RandomRange(1, #psiocolors)]
					ol.scale = 1
					ol.destscale = FRACUNIT*32
					ol.scalespeed = FRACUNIT
					ol.frame = B|FF_FULLBRIGHT|TR_TRANS50
					ol.tics = 8
				end
			end	
			
			if timer == 190
				for k,v in ipairs(mo.allies)
					if v and v.control and v.control.valid
						P_FlashPal(v.control, 5, 5)
					end
				end
			end	
			
			if timer >= 190 and timer <= 280
				for i = 1, 2
					local m = P_SpawnMobj(avgx + P_RandomRange(-31, 31)*FRACUNIT, avgy  + P_RandomRange(-31, 31)*FRACUNIT, mo.floorz - 100*FRACUNIT, MT_DUMMY)
					m.tics = -1
					m.color = colors[P_RandomRange(1, #colors)]
					m.frame = FF_FULLBRIGHT
					m.scale = FRACUNIT*15
					m.momz = FRACUNIT*64
					m.fuse = TICRATE
					m.sprite = SPR_THOK
				end	
			end
			
			
			if timer == 281
				playSound(mo.battlen, sfx_s3k83)
			end	
			
			if timer == 282
				for i = 1, #hittargets
					local target = hittargets[i]
					damageObject(target)
				end
			end			
			
			if timer == 300
				return true
			end
		end,			
}


attackDefs["reapermusicthing"] = {
        name = "Reaper Music Thing",
        type = ATK_PASSIVE,
        norandom = true,
        desc = "Changes the music",
        passive = PSV_STARTBATTLE,
        anim = function(mo, targets, hittargets, timer)
            server.geobosstimer = 58
            server.fuckingmusic_a = true
        end,
    }
	
attackDefs["loamusicthing"] = {
        name = "Loa Music Thing",
        type = ATK_PASSIVE,
        norandom = true,
        desc = "Changes the music",
        passive = PSV_STARTBATTLE,
        anim = function(mo, targets, hittargets, timer)
            server.geobosstimer = 58
            server.shitmusic_b = true
        end,
    }
    		
local function GeoBossThinker(mo)
    if server and server.valid
        
        if server.geobosstimer == nil then server.geobosstimer = 0 end
        
        if server.geobosstimer > 0 then 
            server.geobosstimer = $1-1 
        end
        
        if server.geobosstimer == 2  
            if server.fuckingmusic_a
                S_ChangeMusic("FORENY",true)
			elseif server.shitmusic_b
				S_ChangeMusic("GREPWR",true)
            end
        elseif server.geobosstimer == 1
            server.fuckingmusic_a = false
			server.shitmusic_b = false
        end
    end
end

addHook("ThinkFrame", GeoBossThinker)