-- 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 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()
    .WithConversations(6)

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

local map_0_8 = Map.Create().WithMapId(5307).SetMapCoordinates(0, 8).WithTask(
    TimeSpaceTask.Create(TimeSpaceTaskType.None)
) -- start
local map_1_8 = Map.Create().WithMapId(5307).SetMapCoordinates(1, 8).WithTask(
    TimeSpaceTask.Create(TimeSpaceTaskType.None).WithOnStartDialog(6161)
)
local map_2_8 = Map.Create().WithMapId(5307).SetMapCoordinates(2, 8).WithTask(
    TimeSpaceTask.Create(TimeSpaceTaskType.None)
)
local map_3_8 = Map.Create().WithMapId(5307).SetMapCoordinates(3, 8).WithTask(
    TimeSpaceTask.Create(TimeSpaceTaskType.None)
)
local map_4_8 = Map.Create().WithMapId(5307).SetMapCoordinates(4, 8).WithTask(
    TimeSpaceTask.Create(TimeSpaceTaskType.None)
)
local map_5_8 = Map.Create().WithMapId(5308).SetMapCoordinates(5, 8).WithTask(
    TimeSpaceTask.Create(TimeSpaceTaskType.None)
)
local map_6_8 = Map.Create().WithMapId(4405).SetMapCoordinates(6, 8).WithTask(
    TimeSpaceTask.Create(TimeSpaceTaskType.None).WithOnStartDialog(6162)
)
local map_6_9 = Map.Create().WithMapId(4406).SetMapCoordinates(6, 9).WithTask(
    TimeSpaceTask.Create(TimeSpaceTaskType.KillAllMonsters).WithTaskText("TS_GENERIC_TEXT_KILL_ALL_ENEMIES").WithOnStartDialog(6163, true)
)
local map_5_9 = Map.Create().WithMapId(4408).SetMapCoordinates(5, 9).WithTask(
    TimeSpaceTask.Create(TimeSpaceTaskType.KillAllMonsters).WithTaskText("TS_GENERIC_TEXT_KILL_ALL_ENEMIES").WithOnStartDialog(6163, true)
)
local map_5_10 = Map.Create().WithMapId(4406).SetMapCoordinates(5, 10).WithTask(
    TimeSpaceTask.Create(TimeSpaceTaskType.KillAllMonsters).WithTaskText("TS_GENERIC_TEXT_KILL_ALL_ENEMIES").WithOnStartDialog(6163, true)
)
local map_4_10 = Map.Create().WithMapId(4407).SetMapCoordinates(4, 10).WithTask(
    TimeSpaceTask.Create(TimeSpaceTaskType.KillAllMonsters).WithTaskText("TS_GENERIC_TEXT_KILL_ALL_ENEMIES").WithOnStartDialog(6163, true)
)
local map_4_9 = Map.Create().WithMapId(4405).SetMapCoordinates(4, 9).WithTask(
    TimeSpaceTask.Create(TimeSpaceTaskType.KillAllMonsters).WithTaskText("TS_GENERIC_TEXT_KILL_ALL_ENEMIES").WithOnStartDialog(6163, true)
)
local map_3_9 = Map.Create().WithMapId(4408).SetMapCoordinates(3, 9).WithTask(
    TimeSpaceTask.Create(TimeSpaceTaskType.None).WithOnStartDialog(6164, true)
)

local portal_0_8_to_1_8 = Portal.Create(PortalType.TsNormal).From(map_0_8, 28, 16).To(map_1_8, 2, 16).MinimapOrientation(PortalMinimapOrientation.East)
local portal_1_8_to_2_8 = Portal.Create(PortalType.TsNormal).From(map_1_8, 28, 16).To(map_2_8, 2, 16).MinimapOrientation(PortalMinimapOrientation.East)
local portal_1_8_to_0_8 = Portal.Create(PortalType.TsNormal).From(map_1_8, 2, 16).To(map_0_8, 28, 16).MinimapOrientation(PortalMinimapOrientation.West)
local portal_2_8_to_3_8 = Portal.Create(PortalType.TsNormal).From(map_2_8, 28, 16).To(map_3_8, 2, 16).MinimapOrientation(PortalMinimapOrientation.East)
local portal_2_8_to_1_8 = Portal.Create(PortalType.TsNormal).From(map_2_8, 2, 16).To(map_1_8, 28, 16).MinimapOrientation(PortalMinimapOrientation.West)
local portal_3_8_to_4_8 = Portal.Create(PortalType.TsNormal).From(map_3_8, 28, 16).To(map_4_8, 2, 16).MinimapOrientation(PortalMinimapOrientation.East)
local portal_3_8_to_2_8 = Portal.Create(PortalType.TsNormal).From(map_3_8, 2, 16).To(map_2_8, 28, 16).MinimapOrientation(PortalMinimapOrientation.West)
local portal_4_8_to_5_8 = Portal.Create(PortalType.TsNormal).From(map_4_8, 28, 16).To(map_5_8, 2, 16).MinimapOrientation(PortalMinimapOrientation.East)
local portal_4_8_to_3_8 = Portal.Create(PortalType.TsNormal).From(map_4_8, 2, 16).To(map_3_8, 28, 16).MinimapOrientation(PortalMinimapOrientation.West)
local portal_5_8_to_6_8 = Portal.Create(PortalType.TsNormal).From(map_5_8, 28, 16).To(map_6_8, 1, 12).MinimapOrientation(PortalMinimapOrientation.East)
local portal_5_8_to_4_8 = Portal.Create(PortalType.TsNormal).From(map_5_8, 2, 16).To(map_4_8, 28, 16).MinimapOrientation(PortalMinimapOrientation.West)
local portal_6_8_to_6_9 = Portal.Create(PortalType.TsNormal).From(map_6_8, 12, 23).To(map_6_9, 12, 1).MinimapOrientation(PortalMinimapOrientation.South)
local portal_6_8_to_5_8 = Portal.Create(PortalType.TsNormal).From(map_6_8, 1, 12).To(map_5_8, 28, 16).MinimapOrientation(PortalMinimapOrientation.West)
local portal_6_9_to_6_8 = Portal.Create(PortalType.Locked).From(map_6_9, 12, 1).To(map_6_8, 12, 23).MinimapOrientation(PortalMinimapOrientation.North)
local portal_6_9_to_5_9 = Portal.Create(PortalType.Locked).From(map_6_9, 1, 12).To(map_5_9, 23, 12).MinimapOrientation(PortalMinimapOrientation.West)
local portal_5_9_to_6_9 = Portal.Create(PortalType.Locked).From(map_5_9, 23, 12).To(map_6_9, 1, 12).MinimapOrientation(PortalMinimapOrientation.East)
local portal_5_9_to_5_10 = Portal.Create(PortalType.Locked).From(map_5_9, 12, 23).To(map_5_10, 12, 1).MinimapOrientation(PortalMinimapOrientation.South)
local portal_5_10_to_5_9 = Portal.Create(PortalType.Locked).From(map_5_10, 12, 1).To(map_5_9, 12, 23).MinimapOrientation(PortalMinimapOrientation.North)
local portal_5_10_to_4_10 = Portal.Create(PortalType.Locked).From(map_5_10, 1, 12).To(map_4_10, 23, 12).MinimapOrientation(PortalMinimapOrientation.West)
local portal_4_10_to_4_9 = Portal.Create(PortalType.Locked).From(map_4_10, 12, 1).To(map_4_9, 12, 23).MinimapOrientation(PortalMinimapOrientation.North)
local portal_4_10_to_5_10 = Portal.Create(PortalType.Locked).From(map_4_10, 23, 12).To(map_5_10, 1, 12).MinimapOrientation(PortalMinimapOrientation.East)
local portal_4_9_to_4_10 = Portal.Create(PortalType.Locked).From(map_4_9, 12, 23).To(map_4_10, 12, 1).MinimapOrientation(PortalMinimapOrientation.South)
local portal_4_9_to_3_9 = Portal.Create(PortalType.Locked).From(map_4_9, 1, 12).To(map_3_9, 23, 12).MinimapOrientation(PortalMinimapOrientation.West)
local portal_3_9_to_4_9 = Portal.Create(PortalType.TsNormal).From(map_3_9, 23, 12).To(map_4_9, 1, 12).MinimapOrientation(PortalMinimapOrientation.East)
local portal_3_9_to_UNKNOWN = Portal.Create(PortalType.TSEnd).From(map_3_9, 12, 23).To(map_3_9, 12, 23).MinimapOrientation(PortalMinimapOrientation.South)

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_3_8)
map_2_8.AddPortal(portal_2_8_to_1_8)
map_3_8.AddPortal(portal_3_8_to_4_8)
map_3_8.AddPortal(portal_3_8_to_2_8)
map_4_8.AddPortal(portal_4_8_to_5_8)
map_4_8.AddPortal(portal_4_8_to_3_8)
map_5_8.AddPortal(portal_5_8_to_6_8)
map_5_8.AddPortal(portal_5_8_to_4_8)
map_6_8.AddPortal(portal_6_8_to_6_9)
map_6_8.AddPortal(portal_6_8_to_5_8)
map_6_9.AddPortal(portal_6_9_to_6_8)
map_6_9.AddPortal(portal_6_9_to_5_9)
map_5_9.AddPortal(portal_5_9_to_6_9)
map_5_9.AddPortal(portal_5_9_to_5_10)
map_5_10.AddPortal(portal_5_10_to_5_9)
map_5_10.AddPortal(portal_5_10_to_4_10)
map_4_10.AddPortal(portal_4_10_to_4_9)
map_4_10.AddPortal(portal_4_10_to_5_10)
map_4_9.AddPortal(portal_4_9_to_4_10)
map_4_9.AddPortal(portal_4_9_to_3_9)
map_3_9.AddPortal(portal_3_9_to_4_9)
map_3_9.AddPortal(portal_3_9_to_UNKNOWN)

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

--- Map 1_8
map_1_8.OnMapJoin({
    Event.TryStartTaskForMap(map_1_8),
})
---

--- Map 2_8
map_2_8.OnMapJoin({
    Event.TryStartTaskForMap(map_2_8),
})
---

--- Map 3_8
map_3_8.OnMapJoin({
    Event.TryStartTaskForMap(map_3_8),
})
---

--- Map 4_8
map_4_8.OnMapJoin({
    Event.TryStartTaskForMap(map_4_8),
})
---

--- Map 5_8
map_5_8.OnMapJoin({
    Event.TryStartTaskForMap(map_5_8),
})
---

--- Map 6_8
map_6_8.OnMapJoin({
    Event.TryStartTaskForMap(map_6_8),
})
---

--- Map 6_9
map_6_9.AddMonsters({
    Monster.CreateWithVnum(152).At(16, 16).Facing(1), -- Kenko Raider [16:59:49]
    Monster.CreateWithVnum(152).At(16, 12).Facing(7), -- Kenko Raider [16:59:49]
    Monster.CreateWithVnum(152).At(15, 8).Facing(6), -- Kenko Raider [16:59:49]
    Monster.CreateWithVnum(150).At(11, 13).Facing(4).SpawnAfterMobsKilled(1), -- Elite Kenko Spearman [16:59:50]
    Monster.CreateWithVnum(152).At(14, 11).Facing(3).SpawnAfterMobsKilled(2), -- Kenko Raider [16:59:51]
    Monster.CreateWithVnum(147).At(12, 7).Facing(5).SpawnAfterMobsKilled(4), -- Elite Kenko Swordsman [16:59:54]
    Monster.CreateWithVnum(147).At(12, 18).Facing(0).SpawnAfterMobsKilled(4), -- Elite Kenko Swordsman [16:59:54]
    Monster.CreateWithVnum(147).At(7, 11).Facing(5).SpawnAfterMobsKilled(5), -- Elite Kenko Swordsman [16:59:55]
})
map_6_9.OnMapJoin({
    Event.TryStartTaskForMap(map_6_9),
})
map_6_9.OnTaskFinish({
    Event.OpenPortal(portal_6_9_to_5_9),
    Event.AddTime(80),
})
---

--- Map 5_9
map_5_9.AddMonsters({
    Monster.CreateWithVnum(152).At(11, 17).Facing(0), -- Kenko Raider [17:00:05]
    Monster.CreateWithVnum(152).At(11, 12).Facing(4), -- Kenko Raider [17:00:05]
    Monster.CreateWithVnum(152).At(11, 9).Facing(5), -- Kenko Raider [17:00:05]
    Monster.CreateWithVnum(147).At(7, 17).Facing(3).SpawnAfterMobsKilled(2), -- Elite Kenko Swordsman [17:00:07]
    Monster.CreateWithVnum(147).At(8, 12).Facing(7).SpawnAfterMobsKilled(2), -- Elite Kenko Swordsman [17:00:07]
    Monster.CreateWithVnum(150).At(6, 15).Facing(5).SpawnAfterMobsKilled(4), -- Elite Kenko Spearman [17:00:10]
    Monster.CreateWithVnum(153).At(6, 13).Facing(5).SpawnAfterMobsKilled(6), -- Elite Kenko Raider [17:00:13]
})
map_5_9.OnMapJoin({
    Event.TryStartTaskForMap(map_5_9),
})
map_5_9.OnTaskFinish({
    Event.OpenPortal(portal_5_9_to_5_10),
    Event.AddTime(80),
})
---

--- Map 5_10
map_5_10.AddMonsters({
    Monster.CreateWithVnum(152).At(16, 16).Facing(2), -- Kenko Raider [17:00:18]
    Monster.CreateWithVnum(152).At(16, 12).Facing(3), -- Kenko Raider [17:00:18]
    Monster.CreateWithVnum(152).At(15, 8).Facing(5), -- Kenko Raider [17:00:18]
    Monster.CreateWithVnum(150).At(11, 13).Facing(6).SpawnAfterMobsKilled(1), -- Elite Kenko Spearman [17:00:20]
    Monster.CreateWithVnum(152).At(14, 11).Facing(2).SpawnAfterMobsKilled(2), -- Kenko Raider [17:00:21]
    Monster.CreateWithVnum(147).At(12, 7).Facing(1).SpawnAfterMobsKilled(4), -- Elite Kenko Swordsman [17:00:24]
    Monster.CreateWithVnum(147).At(12, 18).Facing(3).SpawnAfterMobsKilled(4), -- Elite Kenko Swordsman [17:00:24]
    Monster.CreateWithVnum(147).At(7, 11).Facing(6).SpawnAfterMobsKilled(5), -- Elite Kenko Swordsman [17:00:25]
})
map_5_10.OnMapJoin({
    Event.TryStartTaskForMap(map_5_10),
})
map_5_10.OnTaskFinish({
    Event.OpenPortal(portal_5_10_to_4_10),
    Event.AddTime(80),
})
---

--- Map 4_10
map_4_10.AddMonsters({
    Monster.CreateWithVnum(152).At(16, 17).Facing(0), -- Kenko Raider [17:00:33]
    Monster.CreateWithVnum(152).At(16, 15).Facing(7), -- Kenko Raider [17:00:33]
    Monster.CreateWithVnum(152).At(15, 8).Facing(7), -- Kenko Raider [17:00:33]
    Monster.CreateWithVnum(150).At(11, 13).Facing(5).SpawnAfterMobsKilled(1), -- Elite Kenko Spearman [17:00:34]
    Monster.CreateWithVnum(152).At(14, 11).Facing(3).SpawnAfterMobsKilled(2), -- Kenko Raider [17:00:35]
    Monster.CreateWithVnum(147).At(12, 7).Facing(2).SpawnAfterMobsKilled(4), -- Elite Kenko Swordsman [17:00:38]
    Monster.CreateWithVnum(147).At(12, 18).Facing(7).SpawnAfterMobsKilled(4), -- Elite Kenko Swordsman [17:00:38]
    Monster.CreateWithVnum(147).At(7, 11).Facing(5).SpawnAfterMobsKilled(5), -- Elite Kenko Swordsman [17:00:40]
    Monster.CreateWithVnum(150).At(9, 16).Facing(0).SpawnAfterMobsKilled(7), -- Elite Kenko Spearman [17:00:43]
})
map_4_10.AddObjects({
    MapObject.CreateOldBox().At(21, 18), -- [17:00:32]
    MapObject.CreateOldBox().At(17, 18), -- [17:00:32]
    MapObject.CreateOldBox().At(13, 18), -- [17:00:32]
})
map_4_10.OnMapJoin({
    Event.TryStartTaskForMap(map_4_10),
})
map_4_10.OnTaskFinish({
    Event.OpenPortal(portal_4_10_to_4_9),
    Event.AddTime(80),
})
---

--- Map 4_9
map_4_9.AddMonsters({
    Monster.CreateWithVnum(152).At(11, 17).Facing(4), -- Kenko Raider [17:00:50]
    Monster.CreateWithVnum(152).At(11, 12).Facing(0), -- Kenko Raider [17:00:50]
    Monster.CreateWithVnum(152).At(11, 9).Facing(7), -- Kenko Raider [17:00:50]
    Monster.CreateWithVnum(147).At(7, 17).Facing(1).SpawnAfterMobsKilled(2), -- Elite Kenko Swordsman [17:00:52]
    Monster.CreateWithVnum(147).At(8, 12).Facing(1).SpawnAfterMobsKilled(2), -- Elite Kenko Swordsman [17:00:52]
    Monster.CreateWithVnum(150).At(6, 15).Facing(6).SpawnAfterMobsKilled(4), -- Elite Kenko Spearman [17:00:55]
    Monster.CreateWithVnum(153).At(6, 13).Facing(2).SpawnAfterMobsKilled(6), -- Elite Kenko Raider [17:00:58]
    Monster.CreateWithVnum(153).At(11, 21).Facing(3).SpawnAfterMobsKilled(7), -- Elite Kenko Raider [17:00:59]
})
map_4_9.OnMapJoin({
    Event.TryStartTaskForMap(map_4_9),
})
map_4_9.OnTaskFinish({
    Event.OpenPortal(portal_4_9_to_3_9),
})
---

--- Map 3_9
map_3_9.OnMapJoin({
    Event.TryStartTaskForMap(map_3_9),
})
---

local ts = TimeSpace.Create(38)  -- TimeSpace ID
    .SetMaps({map_0_8, map_1_8, map_2_8, map_3_8, map_4_8, map_5_8, map_6_8, map_6_9, map_5_9, map_5_10, map_4_10, map_4_9, map_3_9})
    .SetSpawn(Location.InMap(map_0_8).At(10, 7))
    .SetLives(2)
    .SetObjectives(objectives)
    .SetDurationInSeconds(150)
    .SetBonusPointItemDropChance(5000)
return ts
