-- 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()
    .WithKillMob(318, 1)

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

local map_3_11 = Map.Create().WithMapId(5100).SetMapCoordinates(3, 11).WithTask(
    TimeSpaceTask.Create(TimeSpaceTaskType.None)
) -- start
local map_3_10 = Map.Create().WithMapId(5100).SetMapCoordinates(3, 10).WithTask(
    TimeSpaceTask.Create(TimeSpaceTaskType.None).WithOnStartDialog(6111)
)
local map_3_9 = Map.Create().WithMapId(5100).SetMapCoordinates(3, 9).WithTask(
    TimeSpaceTask.Create(TimeSpaceTaskType.None)
)
local map_3_8 = Map.Create().WithMapId(5100).SetMapCoordinates(3, 8).WithTask(
    TimeSpaceTask.Create(TimeSpaceTaskType.None)
)
local map_3_7 = Map.Create().WithMapId(5100).SetMapCoordinates(3, 7).WithTask(
    TimeSpaceTask.Create(TimeSpaceTaskType.None)
)
local map_3_6 = Map.Create().WithMapId(5100).SetMapCoordinates(3, 6).WithTask(
    TimeSpaceTask.Create(TimeSpaceTaskType.KillAllMonsters).WithOnStartDialog(6112).WithOnFinishDialog(6113)
)

local portal_3_11_to_3_10 = Portal.Create(PortalType.TsNormal).From(map_3_11, 14, 1).To(map_3_10, 14, 28).MinimapOrientation(PortalMinimapOrientation.North)
local portal_3_10_to_3_9 = Portal.Create(PortalType.TsNormal).From(map_3_10, 14, 1).To(map_3_9, 14, 28).MinimapOrientation(PortalMinimapOrientation.North)
local portal_3_10_to_3_11 = Portal.Create(PortalType.TsNormal).From(map_3_10, 14, 28).To(map_3_11, 14, 1).MinimapOrientation(PortalMinimapOrientation.South)
local portal_3_9_to_3_8 = Portal.Create(PortalType.Locked).From(map_3_9, 14, 1).To(map_3_8, 14, 28).MinimapOrientation(PortalMinimapOrientation.North)
local portal_3_9_to_3_10 = Portal.Create(PortalType.TsNormal).From(map_3_9, 14, 28).To(map_3_10, 14, 1).MinimapOrientation(PortalMinimapOrientation.South)
local portal_3_8_to_3_7 = Portal.Create(PortalType.Locked).From(map_3_8, 14, 1).To(map_3_7, 14, 28).MinimapOrientation(PortalMinimapOrientation.North)
local portal_3_8_to_3_9 = Portal.Create(PortalType.TsNormal).From(map_3_8, 14, 28).To(map_3_9, 14, 1).MinimapOrientation(PortalMinimapOrientation.South)
local portal_3_7_to_3_6 = Portal.Create(PortalType.Locked).From(map_3_7, 14, 1).To(map_3_6, 14, 28).MinimapOrientation(PortalMinimapOrientation.North)
local portal_3_7_to_3_8 = Portal.Create(PortalType.TsNormal).From(map_3_7, 14, 28).To(map_3_8, 14, 1).MinimapOrientation(PortalMinimapOrientation.South)
local portal_3_6_to_UNKNOWN = Portal.Create(PortalType.TSEnd).From(map_3_6, 14, 1).To(map_3_6, 14, 1).MinimapOrientation(PortalMinimapOrientation.North)
local portal_3_6_to_3_7 = Portal.Create(PortalType.Locked).From(map_3_6, 14, 28).To(map_3_7, 14, 1).MinimapOrientation(PortalMinimapOrientation.South)

map_3_11.AddPortal(portal_3_11_to_3_10)
map_3_10.AddPortal(portal_3_10_to_3_9)
map_3_10.AddPortal(portal_3_10_to_3_11)
map_3_9.AddPortal(portal_3_9_to_3_8)
map_3_9.AddPortal(portal_3_9_to_3_10)
map_3_8.AddPortal(portal_3_8_to_3_7)
map_3_8.AddPortal(portal_3_8_to_3_9)
map_3_7.AddPortal(portal_3_7_to_3_6)
map_3_7.AddPortal(portal_3_7_to_3_8)
map_3_6.AddPortal(portal_3_6_to_UNKNOWN)
map_3_6.AddPortal(portal_3_6_to_3_7)

--- Map 3_11
map_3_11.OnMapJoin({
    Event.TryStartTaskForMap(map_3_11),
})
---

--- Map 3_10
map_3_10.OnMapJoin({
    Event.TryStartTaskForMap(map_3_10),
})
---

--- Map 3_9
map_3_9.AddMonsters({
    Monster.CreateWithVnum(20).At(20, 22).Facing(2), -- Angry Mandra [16:24:34]
    Monster.CreateWithVnum(20).At(20, 13).Facing(0), -- Angry Mandra [16:24:34]
    Monster.CreateWithVnum(20).At(20, 6).Facing(1), -- Angry Mandra [16:24:34]
    Monster.CreateWithVnum(140).At(16, 10).Facing(5), -- Small Mimic [16:24:34]
    Monster.CreateWithVnum(140).At(15, 18).Facing(3), -- Small Mimic [16:24:34]
    Monster.CreateWithVnum(140).At(15, 10).Facing(7), -- Small Mimic [16:24:34]
    Monster.CreateWithVnum(140).At(12, 16).Facing(4), -- Small Mimic [16:24:34]
    Monster.CreateWithVnum(20).At(9, 21).Facing(0), -- Angry Mandra [16:24:34]
    Monster.CreateWithVnum(20).At(9, 14).Facing(0), -- Angry Mandra [16:24:34]
    Monster.CreateWithVnum(20).At(9, 6).Facing(0), -- Angry Mandra [16:24:34]
})
map_3_9.AddObjects({
    MapObject.CreateLever().At(11, 12).OnSwitch({
        Event.TogglePortal(portal_3_9_to_3_8),
    }), -- [16:24:34]
})
map_3_9.OnMapJoin({
    Event.TryStartTaskForMap(map_3_9),
})
---

--- Map 3_8
map_3_8.AddMonsters({
    Monster.CreateWithVnum(141).At(22, 17).Facing(1), -- Mimic [16:24:57]
    Monster.CreateWithVnum(20).At(22, 14).Facing(7), -- Angry Mandra [16:24:57]
    Monster.CreateWithVnum(20).At(20, 10).Facing(3), -- Angry Mandra [16:24:57]
    Monster.CreateWithVnum(141).At(18, 14).Facing(0), -- Mimic [16:24:57]
    Monster.CreateWithVnum(20).At(17, 6).Facing(7), -- Angry Mandra [16:24:57]
    Monster.CreateWithVnum(20).At(13, 5).Facing(7), -- Angry Mandra [16:24:57]
    Monster.CreateWithVnum(141).At(12, 12).Facing(2), -- Mimic [16:24:57]
    Monster.CreateWithVnum(20).At(10, 7).Facing(0), -- Angry Mandra [16:24:57]
    Monster.CreateWithVnum(141).At(9, 16).Facing(5), -- Mimic [16:24:57]
    Monster.CreateWithVnum(20).At(7, 10).Facing(2), -- Angry Mandra [16:24:57]
    Monster.CreateWithVnum(20).At(6, 13).Facing(3), -- Angry Mandra [16:24:57]
})
map_3_8.AddObjects({
    MapObject.CreateLever().At(11, 14).OnSwitch({
        Event.TogglePortal(portal_3_8_to_3_7),
    }), -- [16:24:57]
    MapObject.CreateOldBox().At(14, 18), -- [16:24:57]
})
map_3_8.OnMapJoin({
    Event.TryStartTaskForMap(map_3_8),
})
---

--- Map 3_7
map_3_7.AddMonsters({
    Monster.CreateWithVnum(20).At(24, 17).Facing(6), -- Angry Mandra [16:25:11]
    Monster.CreateWithVnum(20).At(19, 11).Facing(7), -- Angry Mandra [16:25:11]
    Monster.CreateWithVnum(20).At(16, 6).Facing(7), -- Angry Mandra [16:25:11]
    Monster.CreateWithVnum(20).At(13, 6).Facing(0), -- Angry Mandra [16:25:11]
    Monster.CreateWithVnum(20).At(9, 11).Facing(0), -- Angry Mandra [16:25:11]
    Monster.CreateWithVnum(20).At(5, 17).Facing(6), -- Angry Mandra [16:25:11]
})
map_3_7.AddObjects({
    MapObject.CreateLever().At(14, 9).OnSwitch({
        Event.TogglePortal(portal_3_7_to_3_6),
    }), -- [16:25:11]
})
map_3_7.OnMapJoin({
    Event.TryStartTaskForMap(map_3_7),
})
---

--- Map 3_6
map_3_6.AddMonsters({
    Monster.CreateWithVnum(4).At(18, 13).Facing(5), -- Dusi-Fox [16:25:23]
    Monster.CreateWithVnum(4).At(14, 10).Facing(5), -- Dusi-Fox [16:25:23]
    Monster.CreateWithVnum(4).At(10, 13).Facing(2), -- Dusi-Fox [16:25:23]
    Monster.CreateWithVnum(318).At(8, 22).Facing(2).AsTarget(), -- Tom [16:25:23]
})
map_3_6.OnMapJoin({
    Event.TryStartTaskForMap(map_3_6),
})
map_3_6.OnAllTargetMobsDead({
    Event.DespawnAllMobsInRoom(map_3_6),
})
---
local ts = TimeSpace.Create(21)  -- TimeSpace ID
    .SetMaps({map_3_11, map_3_10, map_3_9, map_3_8, map_3_7, map_3_6})
    .SetSpawn(Location.InMap(map_3_11).At(8, 10))
    .SetLives(1)
    .SetObjectives(objectives)
    .SetDurationInSeconds(200)
    .SetBonusPointItemDropChance(5000)
return ts
