-- 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 MonsterWave = require('MonsterWave')

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

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

local map_4_11 = Map.Create().WithMapId(5301).SetMapCoordinates(4, 11).WithTask(
    TimeSpaceTask.Create(TimeSpaceTaskType.None)
) -- start
local map_4_10 = Map.Create().WithMapId(5302).SetMapCoordinates(4, 10).WithTask(
    TimeSpaceTask.Create(TimeSpaceTaskType.None).WithOnStartShout("TS_35_TEXT_0")
)
local map_4_9 = Map.Create().WithMapId(5302).SetMapCoordinates(4, 9).WithTask(
    TimeSpaceTask.Create(TimeSpaceTaskType.KillAllMonsters).WithTaskText("TS_35_TEXT_1").WithOnStartDialog(6145).WithOnFinishShout("TS_35_TEXT_2")
)
local map_4_8 = Map.Create().WithMapId(5301).SetMapCoordinates(4, 8).WithTask(
    TimeSpaceTask.Create(TimeSpaceTaskType.None)
)
local map_3_8 = Map.Create().WithMapId(5307).SetMapCoordinates(3, 8).WithTask(
    TimeSpaceTask.Create(TimeSpaceTaskType.KillAllMonsters).WithTaskText("TS_35_TEXT_3").WithOnStartDialog(6146).WithOnFinishShout("TS_35_TEXT_2")
)
local map_4_7 = Map.Create().WithMapId(5302).SetMapCoordinates(4, 7).WithTask(
    TimeSpaceTask.Create(TimeSpaceTaskType.KillAllMonsters).WithTaskText("TS_35_TEXT_3").WithOnStartDialog(6147).WithOnFinishShout("TS_35_TEXT_2")
)
local map_4_6 = Map.Create().WithMapId(5303).SetMapCoordinates(4, 6).WithTask(
    TimeSpaceTask.Create(TimeSpaceTaskType.None)
)
local map_5_6 = Map.Create().WithMapId(5304).SetMapCoordinates(5, 6).WithTask(
    TimeSpaceTask.Create(TimeSpaceTaskType.KillAllMonsters).WithTaskText("TS_35_TEXT_3").WithOnStartDialog(6148).WithOnFinishShout("TS_35_TEXT_5")
)
local map_5_5 = Map.Create().WithMapId(5302).SetMapCoordinates(5, 5).WithTask(
    TimeSpaceTask.Create(TimeSpaceTaskType.None)
)
local map_5_4 = Map.Create().WithMapId(5303).SetMapCoordinates(5, 4).WithTask(
    TimeSpaceTask.Create(TimeSpaceTaskType.Survive, 30).WithTaskText("TS_35_TEXT_4").WithOnFinishDialog(6149)
)
local map_6_4 = Map.Create().WithMapId(5306).SetMapCoordinates(6, 4).WithTask(
    TimeSpaceTask.Create(TimeSpaceTaskType.None).WithOnStartDialog(6150)
)
local map_5_8 = Map.Create().WithMapId(5307).SetMapCoordinates(5, 8).WithTask(
    TimeSpaceTask.Create(TimeSpaceTaskType.KillAllMonsters).WithTaskText("TS_35_TEXT_3").WithOnStartDialog(6145).WithOnFinishShout("TS_35_TEXT_5")
)

local portal_4_11_to_4_10 = Portal.Create(PortalType.TsNormal).From(map_4_11, 14, 1).To(map_4_10, 15, 28).MinimapOrientation(PortalMinimapOrientation.North)
local portal_4_10_to_4_9 = Portal.Create(PortalType.TsNormal).From(map_4_10, 15, 2).To(map_4_9, 15, 28).MinimapOrientation(PortalMinimapOrientation.North)
local portal_4_10_to_4_11 = Portal.Create(PortalType.TsNormal).From(map_4_10, 15, 28).To(map_4_11, 14, 1).MinimapOrientation(PortalMinimapOrientation.South)
local portal_4_9_to_4_8 = Portal.Create(PortalType.Locked).From(map_4_9, 15, 2).To(map_4_8, 14, 28).MinimapOrientation(PortalMinimapOrientation.North)
local portal_4_9_to_4_10 = Portal.Create(PortalType.Locked).From(map_4_9, 15, 28).To(map_4_10, 15, 2).MinimapOrientation(PortalMinimapOrientation.South)
local portal_4_8_to_4_7 = Portal.Create(PortalType.Locked).From(map_4_8, 14, 1).To(map_4_7, 15, 28).MinimapOrientation(PortalMinimapOrientation.North)
local portal_4_8_to_5_8 = Portal.Create(PortalType.TsNormal).From(map_4_8, 28, 15).To(map_5_8, 2, 16).MinimapOrientation(PortalMinimapOrientation.East)
local portal_4_8_to_4_9 = Portal.Create(PortalType.TsNormal).From(map_4_8, 14, 28).To(map_4_9, 15, 2).MinimapOrientation(PortalMinimapOrientation.South)
local portal_4_8_to_3_8 = Portal.Create(PortalType.TsNormal).From(map_4_8, 1, 15).To(map_3_8, 28, 16).MinimapOrientation(PortalMinimapOrientation.West)
local portal_3_8_to_4_8 = Portal.Create(PortalType.Locked).From(map_3_8, 28, 16).To(map_4_8, 1, 15).MinimapOrientation(PortalMinimapOrientation.East)
local portal_5_8_to_4_8 = Portal.Create(PortalType.Locked).From(map_5_8, 2, 16).To(map_4_8, 28, 15).MinimapOrientation(PortalMinimapOrientation.West)
local portal_4_7_to_4_6 = Portal.Create(PortalType.Locked).From(map_4_7, 15, 2).To(map_4_6, 14, 28).MinimapOrientation(PortalMinimapOrientation.North)
local portal_4_7_to_4_8 = Portal.Create(PortalType.Locked).From(map_4_7, 15, 28).To(map_4_8, 14, 1).MinimapOrientation(PortalMinimapOrientation.South)
local portal_4_6_to_5_6 = Portal.Create(PortalType.TsNormal).From(map_4_6, 28, 15).To(map_5_6, 1, 15).MinimapOrientation(PortalMinimapOrientation.East)
local portal_4_6_to_4_7 = Portal.Create(PortalType.TsNormal).From(map_4_6, 14, 28).To(map_4_7, 15, 2).MinimapOrientation(PortalMinimapOrientation.South)
local portal_5_6_to_5_5 = Portal.Create(PortalType.Locked).From(map_5_6, 14, 1).To(map_5_5, 15, 28).MinimapOrientation(PortalMinimapOrientation.North)
local portal_5_6_to_4_6 = Portal.Create(PortalType.Locked).From(map_5_6, 1, 15).To(map_4_6, 28, 15).MinimapOrientation(PortalMinimapOrientation.West)
local portal_5_5_to_5_4 = Portal.Create(PortalType.TsNormal).From(map_5_5, 15, 2).To(map_5_4, 14, 28).MinimapOrientation(PortalMinimapOrientation.North)
local portal_5_5_to_5_6 = Portal.Create(PortalType.TsNormal).From(map_5_5, 15, 28).To(map_5_6, 14, 1).MinimapOrientation(PortalMinimapOrientation.South)
local portal_5_4_to_6_4 = Portal.Create(PortalType.Locked).From(map_5_4, 28, 15).To(map_6_4, 2, 16).MinimapOrientation(PortalMinimapOrientation.East)
local portal_5_4_to_5_5 = Portal.Create(PortalType.Locked).From(map_5_4, 14, 28).To(map_5_5, 15, 2).MinimapOrientation(PortalMinimapOrientation.South)
local portal_6_4_to_UNKNOWN = Portal.Create(PortalType.TSEnd).From(map_6_4, 15, 28).To(map_6_4, 15, 28).MinimapOrientation(PortalMinimapOrientation.South)
local portal_6_4_to_5_4 = Portal.Create(PortalType.TsNormal).From(map_6_4, 2, 16).To(map_5_4, 28, 15).MinimapOrientation(PortalMinimapOrientation.West)

map_4_11.AddPortal(portal_4_11_to_4_10)
map_4_10.AddPortal(portal_4_10_to_4_9)
map_4_10.AddPortal(portal_4_10_to_4_11)
map_4_9.AddPortal(portal_4_9_to_4_8)
map_4_9.AddPortal(portal_4_9_to_4_10)
map_4_8.AddPortal(portal_4_8_to_4_7)
map_4_8.AddPortal(portal_4_8_to_5_8)
map_4_8.AddPortal(portal_4_8_to_4_9)
map_4_8.AddPortal(portal_4_8_to_3_8)
map_3_8.AddPortal(portal_3_8_to_4_8)
map_5_8.AddPortal(portal_5_8_to_4_8)
map_4_7.AddPortal(portal_4_7_to_4_6)
map_4_7.AddPortal(portal_4_7_to_4_8)
map_4_6.AddPortal(portal_4_6_to_5_6)
map_4_6.AddPortal(portal_4_6_to_4_7)
map_5_6.AddPortal(portal_5_6_to_5_5)
map_5_6.AddPortal(portal_5_6_to_4_6)
map_5_5.AddPortal(portal_5_5_to_5_4)
map_5_5.AddPortal(portal_5_5_to_5_6)
map_5_4.AddPortal(portal_5_4_to_6_4)
map_5_4.AddPortal(portal_5_4_to_5_5)
map_6_4.AddPortal(portal_6_4_to_UNKNOWN)
map_6_4.AddPortal(portal_6_4_to_5_4)

--- Map 4_11
map_4_11.OnMapJoin({
    Event.TryStartTaskForMap(map_4_11),
})
---

--- Map 4_10
map_4_10.OnMapJoin({
    Event.TryStartTaskForMap(map_4_10),
})
---

--- Map 4_9
map_4_9.AddMonsters({
    Monster.CreateWithVnum(83).At(18, 13).Facing(7), -- Nervous Pink Jelly [16:36:42]
    Monster.CreateWithVnum(83).At(16, 17).Facing(2), -- Nervous Pink Jelly [16:36:42]
    Monster.CreateWithVnum(83).At(11, 13).Facing(6).SpawnAfterMobsKilled(2), -- Nervous Pink Jelly [16:36:46]
    Monster.CreateWithVnum(83).At(12, 20).Facing(7).SpawnAfterMobsKilled(3), -- Nervous Pink Jelly [16:36:47]
    Monster.CreateWithVnum(83).At(22, 14).Facing(1).SpawnAfterMobsKilled(3), -- Nervous Pink Jelly [16:36:47]
})
map_4_9.OnMapJoin({
    Event.TryStartTaskForMap(map_4_9),
})
map_4_9.OnTaskFinish({
    Event.OpenPortal(portal_4_9_to_4_8),
    Event.OpenPortal(portal_4_9_to_4_10),
    Event.AddTime(150),
})
---

--- Map 4_8
map_4_8.OnMapJoin({
    Event.TryStartTaskForMap(map_4_8),
    Event.CheckForTasksCompleted({map_3_8, map_5_8}, {
        Event.OpenPortal(portal_4_8_to_4_7),
    }),
})
---

--- Map 3_8
map_3_8.AddMonsters({
    Monster.CreateWithVnum(144).At(21, 13).Facing(3), -- Angry Morning Star Mimic [16:37:00]
    Monster.CreateWithVnum(144).At(14, 8).Facing(3), -- Angry Morning Star Mimic [16:37:00]
    Monster.CreateWithVnum(144).At(17, 19).Facing(6).SpawnAfterMobsKilled(1), -- Angry Morning Star Mimic [16:37:01]
    Monster.CreateWithVnum(139).At(10, 10).Facing(1).SpawnAfterMobsKilled(2), -- Morning Star Boing [16:37:04]
    Monster.CreateWithVnum(139).At(11, 14).Facing(5).SpawnAfterMobsKilled(3), -- Morning Star Boing [16:37:05]
    Monster.CreateWithVnum(139).At(11, 19).Facing(1).SpawnAfterMobsKilled(3), -- Morning Star Boing [16:37:05]
})
map_3_8.OnMapJoin({
    Event.TryStartTaskForMap(map_3_8),
})
map_3_8.OnTaskFinish({
    Event.OpenPortal(portal_3_8_to_4_8),
    Event.AddTime(100),
})
---

--- Map 4_7
map_4_7.AddMonsters({
    Monster.CreateWithVnum(143).At(23, 19).Facing(6), -- Morning Star Mimic [16:37:45]
    Monster.CreateWithVnum(143).At(16, 19).Facing(2), -- Morning Star Mimic [16:37:45]
    Monster.CreateWithVnum(143).At(9, 15).Facing(5), -- Morning Star Mimic [16:37:45]
    Monster.CreateWithVnum(7).At(11, 15).Facing(5).SpawnAfterMobsKilled(1), -- Oto-Fox [16:37:47]
    Monster.CreateWithVnum(85).At(19, 19).Facing(4).SpawnAfterMobsKilled(3), -- Red Jelly [16:37:49]
    Monster.CreateWithVnum(85).At(20, 13).Facing(0).SpawnAfterMobsKilled(3), -- Red Jelly [16:37:49]
    Monster.CreateWithVnum(7).At(9, 10).Facing(7).SpawnAfterMobsKilled(4), -- Oto-Fox [16:37:50]
    Monster.CreateWithVnum(85).At(16, 10).Facing(0).SpawnAfterMobsKilled(5), -- Red Jelly [16:37:51]
})
map_4_7.OnMapJoin({
    Event.TryStartTaskForMap(map_4_7),
})
map_4_7.OnTaskFinish({
    Event.OpenPortal(portal_4_7_to_4_6),
    Event.OpenPortal(portal_4_7_to_4_8),
    Event.AddTime(100),
})
---

--- Map 4_6
map_4_6.OnMapJoin({
    Event.TryStartTaskForMap(map_4_6),
})
---

--- Map 5_6
map_5_6.AddMonsters({
    Monster.CreateWithVnum(143).At(17, 9).Facing(2), -- Morning Star Mimic [16:38:05]
    Monster.CreateWithVnum(143).At(14, 9).Facing(2), -- Morning Star Mimic [16:38:05]
    Monster.CreateWithVnum(60).At(15, 16).Facing(5).SpawnAfterMobsKilled(2), -- Weak Devil Vampie [16:38:09]
    Monster.CreateWithVnum(60).At(21, 17).Facing(6).SpawnAfterMobsKilled(2), -- Weak Devil Vampie [16:38:09]
    Monster.CreateWithVnum(60).At(8, 15).Facing(4).SpawnAfterMobsKilled(3), -- Weak Devil Vampie [16:38:10]
    Monster.CreateWithVnum(61).At(10, 13).Facing(0).SpawnAfterMobsKilled(4), -- Devil Vampie [16:38:12]
    Monster.CreateWithVnum(61).At(20, 13).Facing(0).SpawnAfterMobsKilled(4), -- Devil Vampie [16:38:12]
})
map_5_6.AddObjects({
    MapObject.CreateRegularBox().At(26, 16), -- [16:38:05]
})
map_5_6.OnMapJoin({
    Event.TryStartTaskForMap(map_5_6),
})
map_5_6.OnTaskFinish({
    Event.OpenPortal(portal_5_6_to_5_5),
    Event.OpenPortal(portal_5_6_to_4_6),
    Event.AddTime(140),
})
---

--- Map 5_5
map_5_5.OnMapJoin({
    Event.TryStartTaskForMap(map_5_5),
})
---

--- Map 5_4
map_5_4.AddMonsterWaves({
    -- wave 1
    MonsterWave.CreateWithDelay(0 * 30).WithMonsters({
        Monster.CreateWithVnum(119).At(21, 19).Facing(5), -- Elite Koaren Archer [16:38:24]
        Monster.CreateWithVnum(119).At(22, 15).Facing(6), -- Elite Koaren Archer [16:38:24]
        Monster.CreateWithVnum(119).At(21, 11).Facing(2), -- Elite Koaren Archer [16:38:24]
        Monster.CreateWithVnum(122).At(20, 8).Facing(4), -- Elite Koaren Warrior [16:38:24]
        Monster.CreateWithVnum(122).At(19, 20).Facing(4), -- Elite Koaren Warrior [16:38:24]
        Monster.CreateWithVnum(116).At(19, 17).Facing(7), -- Elite Koaren Sword Fighter [16:38:24]
        Monster.CreateWithVnum(116).At(18, 11).Facing(0), -- Elite Koaren Sword Fighter [16:38:24]
        Monster.CreateWithVnum(119).At(17, 14).Facing(1), -- Elite Koaren Archer [16:38:24]
        Monster.CreateWithVnum(116).At(15, 17).Facing(7), -- Elite Koaren Sword Fighter [16:38:24]
        Monster.CreateWithVnum(116).At(14, 11).Facing(5), -- Elite Koaren Sword Fighter [16:38:24]
        Monster.CreateWithVnum(119).At(14, 16).Facing(4), -- Elite Koaren Archer [16:38:24]
        Monster.CreateWithVnum(122).At(12, 7).Facing(0), -- Elite Koaren Warrior [16:38:24]
        Monster.CreateWithVnum(116).At(13, 17).Facing(6), -- Elite Koaren Sword Fighter [16:38:24]
        Monster.CreateWithVnum(122).At(10, 18).Facing(6), -- Elite Koaren Warrior [16:38:24]
        Monster.CreateWithVnum(116).At(10, 11).Facing(7), -- Elite Koaren Sword Fighter [16:38:24]
        Monster.CreateWithVnum(122).At(8, 10).Facing(6), -- Elite Koaren Warrior [16:38:24]
        Monster.CreateWithVnum(122).At(6, 16).Facing(4), -- Elite Koaren Warrior [16:38:24]
    }),
})
map_5_4.AddObjects({
    MapObject.CreateRegularBox().At(7, 6), -- [16:38:24]
})
map_5_4.OnMapJoin({
    Event.TryStartTaskForMap(map_5_4),
})
map_5_4.OnTaskFinish({
    Event.OpenPortal(portal_5_4_to_6_4),
    Event.OpenPortal(portal_5_4_to_5_5),
    Event.DespawnAllMobsInRoom(map_5_4),
})
---

--- Map 6_4
map_6_4.OnMapJoin({
    Event.TryStartTaskForMap(map_6_4),
})
---

--- Map 5_8
map_5_8.AddMonsters({
    Monster.CreateWithVnum(144).At(15, 18).Facing(7), -- Angry Morning Star Mimic [16:37:21]
    Monster.CreateWithVnum(144).At(12, 15).Facing(1), -- Angry Morning Star Mimic [16:37:21]
    Monster.CreateWithVnum(61).At(17, 11).Facing(4).SpawnAfterMobsKilled(2), -- Devil Vampie [16:37:25]
    Monster.CreateWithVnum(61).At(18, 16).Facing(2).SpawnAfterMobsKilled(2), -- Devil Vampie [16:37:25]
    Monster.CreateWithVnum(61).At(12, 10).Facing(1).SpawnAfterMobsKilled(3), -- Devil Vampie [16:37:26]
})
map_5_8.OnMapJoin({
    Event.TryStartTaskForMap(map_5_8),
})
map_5_8.OnTaskFinish({
    Event.OpenPortal(portal_5_8_to_4_8),
})
---

local ts = TimeSpace.Create(35)  -- TimeSpace ID
    .SetMaps({map_4_11, map_4_10, map_4_9, map_4_8, map_3_8, map_4_7, map_4_6, map_5_6, map_5_5, map_5_4, map_6_4, map_5_8})
    .SetSpawn(Location.InMap(map_4_11).At(14, 13))
    .SetLives(1)
    .SetObjectives(objectives)
    .SetDurationInSeconds(150)
    .SetBonusPointItemDropChance(5000)
return ts
