-- TimeSpace Script generated by friends111's python script. Replace all %TODO% values accordingly, check for errors (packet-generation isn't perfect), and modify things if needed.
local Map = require('Map')
local Monster = require('Monster')
local Event = require('Event')
local MapObject = require('MapObject')
local MapNpc = require('MapNpc')
local Portal = require('Portal')
local Location = require('Location')
local TimeSpace = require('TimeSpace')
local PortalType = require("PortalType")
local PortalMinimapOrientation = require('PortalMinimapOrientation')
local TimeSpaceObjective = require('TimeSpaceObjective')
local TimeSpaceTaskType = require('TimeSpaceTaskType')
local TimeSpaceTask = require('TimeSpaceTask')

local objectives = TimeSpaceObjective.Create()
    .WithGoToExit()
    .WithProtectNPC()

-- Grid min:(0, 8) ~ max:(5, 9) (width: 5, height: 1)
--     [ 0][ 1][ 2][ 3][ 4][ 5][ 6][ 7][ 8][ 9][10]
-- [ 0][  ][  ][  ][  ][  ][  ][  ][  ][  ][  ][  ]
-- [ 1][  ][  ][  ][  ][  ][  ][  ][  ][  ][  ][  ]
-- [ 2][  ][  ][  ][  ][  ][  ][  ][  ][  ][  ][  ]
-- [ 3][  ][  ][  ][  ][  ][  ][  ][  ][  ][  ][  ]
-- [ 4][  ][  ][  ][  ][  ][  ][  ][  ][  ][  ][  ]
-- [ 5][  ][  ][  ][  ][  ][  ][  ][  ][  ][  ][  ]
-- [ 6][  ][  ][  ][  ][  ][  ][  ][  ][  ][  ][  ]
-- [ 7][  ][  ][  ][  ][  ][  ][  ][  ][  ][  ][  ]
-- [ 8][OO][XX][XX][  ][  ][  ][  ][  ][  ][  ][  ]
-- [ 9][  ][  ][XX][XX][XX][XX][  ][  ][  ][  ][  ]
-- [10][  ][  ][  ][  ][  ][  ][  ][  ][  ][  ][  ]

local map_0_8 = Map.Create().WithMapId(4202).SetMapCoordinates(0, 8).WithTask(
    TimeSpaceTask.Create(TimeSpaceTaskType.None)
) -- start
local map_1_8 = Map.Create().WithMapId(4205).SetMapCoordinates(1, 8).WithTask(
    TimeSpaceTask.Create(TimeSpaceTaskType.KillAllMonsters).WithTaskText("TS_31_TEXT_0").WithOnFinishDialog(6139)
)
local map_2_8 = Map.Create().WithMapId(4209).SetMapCoordinates(2, 8).WithTask(
    TimeSpaceTask.Create(TimeSpaceTaskType.KillAllMonsters).WithTaskText("TS_GENERIC_TEXT_KILL_ALL_ENEMIES").WithOnStartDialog(6140)
)
local map_2_9 = Map.Create().WithMapId(4207).SetMapCoordinates(2, 9).WithTask(
    TimeSpaceTask.Create(TimeSpaceTaskType.KillAllMonsters).WithTaskText("TS_GENERIC_TEXT_KILL_ALL_ENEMIES").WithOnStartDialog(6141)
)
local map_3_9 = Map.Create().WithMapId(4205).SetMapCoordinates(3, 9).WithTask(
    TimeSpaceTask.Create(TimeSpaceTaskType.KillAllMonsters).WithTaskText("TS_31_TEXT_1")
)
local map_4_9 = Map.Create().WithMapId(4205).SetMapCoordinates(4, 9).WithTask(
    TimeSpaceTask.Create(TimeSpaceTaskType.KillAllMonsters).WithTaskText("TS_31_TEXT_2").WithOnFinishDialog(6142)
)
local map_5_9 = Map.Create().WithMapId(4205).SetMapCoordinates(5, 9).WithTask(
    TimeSpaceTask.Create(TimeSpaceTaskType.KillAllMonsters).WithTaskText("TS_31_TEXT_3").WithOnStartDialog(6143).WithOnFinishDialog(6144)
)

local portal_0_8_to_1_8 = Portal.Create(PortalType.TsNormal).From(map_0_8, 28, 15).To(map_1_8, 1, 15).MinimapOrientation(PortalMinimapOrientation.East)
local portal_1_8_to_2_8 = Portal.Create(PortalType.Locked).From(map_1_8, 28, 15).To(map_2_8, 1, 15).MinimapOrientation(PortalMinimapOrientation.East)
local portal_1_8_to_0_8 = Portal.Create(PortalType.Locked).From(map_1_8, 1, 15).To(map_0_8, 28, 15).MinimapOrientation(PortalMinimapOrientation.West)
local portal_2_8_to_2_9 = Portal.Create(PortalType.Locked).From(map_2_8, 14, 28).To(map_2_9, 14, 1).MinimapOrientation(PortalMinimapOrientation.South)
local portal_2_8_to_1_8 = Portal.Create(PortalType.Locked).From(map_2_8, 1, 15).To(map_1_8, 28, 15).MinimapOrientation(PortalMinimapOrientation.West)
local portal_2_9_to_2_8 = Portal.Create(PortalType.Locked).From(map_2_9, 14, 1).To(map_2_8, 14, 28).MinimapOrientation(PortalMinimapOrientation.North)
local portal_2_9_to_3_9 = Portal.Create(PortalType.Locked).From(map_2_9, 28, 15).To(map_3_9, 1, 15).MinimapOrientation(PortalMinimapOrientation.East)
local portal_3_9_to_4_9 = Portal.Create(PortalType.Locked).From(map_3_9, 28, 15).To(map_4_9, 1, 15).MinimapOrientation(PortalMinimapOrientation.East)
local portal_3_9_to_2_9 = Portal.Create(PortalType.Locked).From(map_3_9, 1, 15).To(map_2_9, 28, 15).MinimapOrientation(PortalMinimapOrientation.West)
local portal_4_9_to_5_9 = Portal.Create(PortalType.Locked).From(map_4_9, 28, 15).To(map_5_9, 1, 15).MinimapOrientation(PortalMinimapOrientation.East)
local portal_4_9_to_3_9 = Portal.Create(PortalType.Locked).From(map_4_9, 1, 15).To(map_3_9, 28, 15).MinimapOrientation(PortalMinimapOrientation.West)
local portal_5_9_to_UNKNOWN = Portal.Create(PortalType.TSEndClosed).From(map_5_9, 28, 15).To(map_5_9, 28, 15).MinimapOrientation(PortalMinimapOrientation.East)
local portal_5_9_to_4_9 = Portal.Create(PortalType.Locked).From(map_5_9, 1, 15).To(map_4_9, 28, 15).MinimapOrientation(PortalMinimapOrientation.West)

map_0_8.AddPortal(portal_0_8_to_1_8)
map_1_8.AddPortal(portal_1_8_to_2_8)
map_1_8.AddPortal(portal_1_8_to_0_8)
map_2_8.AddPortal(portal_2_8_to_2_9)
map_2_8.AddPortal(portal_2_8_to_1_8)
map_2_9.AddPortal(portal_2_9_to_2_8)
map_2_9.AddPortal(portal_2_9_to_3_9)
map_3_9.AddPortal(portal_3_9_to_4_9)
map_3_9.AddPortal(portal_3_9_to_2_9)
map_4_9.AddPortal(portal_4_9_to_5_9)
map_4_9.AddPortal(portal_4_9_to_3_9)
map_5_9.AddPortal(portal_5_9_to_UNKNOWN)
map_5_9.AddPortal(portal_5_9_to_4_9)

--- Map 0_8
map_0_8.OnMapJoin({
    Event.TryStartTaskForMap(map_0_8),
})
---

--- Map 1_8
map_1_8.AddMonsters({
    Monster.CreateWithVnum(329).At(16, 11).Facing(7).OnThreeFourthsHp({
        Event.DespawnAllMobsInRoom(map_1_8),
    }), -- Kenel [16:16:14]
})
map_1_8.OnMapJoin({
    Event.TryStartTaskForMap(map_1_8),
})
map_1_8.OnTaskFinish({
    Event.OpenPortal(portal_1_8_to_2_8),
})
---

--- Map 2_8
map_2_8.AddMonsters({
    Monster.CreateWithVnum(315).At(16, 13).Facing(1).OnHalfHp({
        Event.DespawnAllMobsInRoom(map_2_8),
    }), -- Kenel [16:16:21]
})
map_2_8.OnMapJoin({
    Event.TryStartTaskForMap(map_2_8),
})
map_2_8.OnTaskFinish({
    Event.OpenPortal(portal_2_8_to_2_9),
})
---

--- Map 2_9
map_2_9.AddMonsters({
    Monster.CreateWithVnum(315).At(13, 15).Facing(3).OnQuarterHp({
        Event.DespawnAllMobsInRoom(map_2_9),
    }), -- Kenel [16:16:28]
})
map_2_9.OnMapJoin({
    Event.TryStartTaskForMap(map_2_9),
})
map_2_9.OnTaskFinish({
    Event.OpenPortal(portal_2_9_to_3_9),
})
---

--- Map 3_9
map_3_9.AddMonsters({
    Monster.CreateWithVnum(67).At(19, 11).Facing(7), -- Thornwalker [16:16:33]
    Monster.CreateWithVnum(67).At(15, 8).Facing(7), -- Thornwalker [16:16:33]
    Monster.CreateWithVnum(67).At(10, 12).Facing(1), -- Thornwalker [16:16:33]
    Monster.CreateWithVnum(67).At(11, 18).Facing(6).SpawnAfterMobsKilled(3), -- Thornwalker [16:16:37]
    Monster.CreateWithVnum(67).At(15, 21).Facing(4).SpawnAfterMobsKilled(3), -- Thornwalker [16:16:37]
    Monster.CreateWithVnum(67).At(18, 18).Facing(7).SpawnAfterMobsKilled(3), -- Thornwalker [16:16:37]
    Monster.CreateWithVnum(143).At(15, 10).Facing(0).SpawnAfterMobsKilled(4), -- Morning Star Mimic [16:16:39]
    Monster.CreateWithVnum(143).At(14, 14).Facing(1).SpawnAfterMobsKilled(5), -- Morning Star Mimic [16:16:41]
    Monster.CreateWithVnum(143).At(14, 19).Facing(4).SpawnAfterMobsKilled(6), -- Morning Star Mimic [16:16:42]
})
map_3_9.OnMapJoin({
    Event.TryStartTaskForMap(map_3_9),
})
map_3_9.OnTaskFinish({
    Event.OpenPortal(portal_3_9_to_4_9),
})
---

--- Map 4_9
map_4_9.AddMonsters({
    Monster.CreateWithVnum(67).At(12, 12).Facing(4), -- Thornwalker [16:16:50]
    Monster.CreateWithVnum(67).At(13, 22).Facing(7), -- Thornwalker [16:16:50]
    Monster.CreateWithVnum(67).At(12, 5).Facing(4), -- Thornwalker [16:16:50]
    Monster.CreateWithVnum(67).At(14, 8).Facing(0).SpawnAfterMobsKilled(1), -- Thornwalker [16:16:56]
    Monster.CreateWithVnum(67).At(12, 19).Facing(6).SpawnAfterMobsKilled(2), -- Thornwalker [16:16:58]
    Monster.CreateWithVnum(67).At(13, 25).Facing(1).SpawnAfterMobsKilled(3), -- Thornwalker [16:17:00]
    Monster.CreateWithVnum(84).At(19, 19).Facing(3).SpawnAfterMobsKilled(5), -- Tired Red Jelly [16:17:04]
    Monster.CreateWithVnum(84).At(21, 15).Facing(4).SpawnAfterMobsKilled(6), -- Tired Red Jelly [16:17:05]
    Monster.CreateWithVnum(84).At(18, 11).Facing(1).SpawnAfterMobsKilled(7), -- Tired Red Jelly [16:17:08]
})
map_4_9.AddObjects({
    MapObject.CreateRegularBox().At(17, 22), -- [16:16:50]
})
map_4_9.OnMapJoin({
    Event.TryStartTaskForMap(map_4_9),
})
map_4_9.OnTaskFinish({
    Event.OpenPortal(portal_4_9_to_5_9),
})
---

--- Map 5_9
map_5_9.AddMonsters({
    Monster.CreateWithVnum(137).At(19, 16).Facing(1), -- Hard Boing [16:17:16]
    Monster.CreateWithVnum(137).At(17, 20).Facing(1), -- Hard Boing [16:17:16]
    Monster.CreateWithVnum(137).At(17, 11).Facing(1), -- Hard Boing [16:17:16]
    Monster.CreateWithVnum(137).At(14, 21).Facing(2), -- Hard Boing [16:17:16]
    Monster.CreateWithVnum(137).At(13, 10).Facing(4), -- Hard Boing [16:17:16]
    Monster.CreateWithVnum(137).At(9, 20).Facing(4), -- Hard Boing [16:17:16]
    Monster.CreateWithVnum(137).At(9, 11).Facing(6), -- Hard Boing [16:17:16]
    Monster.CreateWithVnum(137).At(8, 15).Facing(1), -- Hard Boing [16:17:16]
    Monster.CreateWithVnum(144).At(19, 8).Facing(7).SpawnAfterMobsKilled(3), -- Angry Morning Star Mimic [16:17:20]
    Monster.CreateWithVnum(144).At(21, 12).Facing(2).SpawnAfterMobsKilled(4), -- Angry Morning Star Mimic [16:17:22]
    Monster.CreateWithVnum(144).At(19, 22).Facing(6).SpawnAfterMobsKilled(5), -- Angry Morning Star Mimic [16:17:24]
    Monster.CreateWithVnum(144).At(20, 18).Facing(2).SpawnAfterMobsKilled(5), -- Angry Morning Star Mimic [16:17:24]
    Monster.CreateWithVnum(61).At(16, 18).Facing(4).SpawnAfterMobsKilled(10), -- Devil Vampie [16:17:31]
    Monster.CreateWithVnum(61).At(17, 14).Facing(6).SpawnAfterMobsKilled(10), -- Devil Vampie [16:17:31]
    Monster.CreateWithVnum(61).At(14, 12).Facing(7).SpawnAfterMobsKilled(11), -- Devil Vampie [16:17:32]
    Monster.CreateWithVnum(61).At(12, 17).Facing(5).SpawnAfterMobsKilled(12), -- Devil Vampie [16:17:34]
    Monster.CreateWithVnum(61).At(11, 13).Facing(7).SpawnAfterMobsKilled(14), -- Devil Vampie [16:17:37]
})
map_5_9.AddNpcs({
    MapNpc.CreateNpcWithVnum(307).At(14, 15).Facing(7).WithMustProtectAura(), -- Korrkoaren [16:17:15]
    MapNpc.CreateNpcWithVnum(315).At(7, 11).Facing(5).WithMustProtectAura(), -- Kenel [16:17:15]
})
map_5_9.OnMapJoin({
    Event.TryStartTaskForMap(map_5_9),
})
map_5_9.OnTaskFinish({
    Event.OpenPortal(portal_5_9_to_UNKNOWN),
})
---

local ts = TimeSpace.Create(31)  -- TimeSpace ID
    .SetMaps({map_0_8, map_1_8, map_2_8, map_2_9, map_3_9, map_4_9, map_5_9})
    .SetSpawn(Location.InMap(map_0_8).At(7, 10))
    .SetLives(2)
    .SetObjectives(objectives)
    .SetDurationInSeconds(300)
    .SetBonusPointItemDropChance(5000)
return ts
