require("lib/common")

MiscDoor = {
  garissonEntrance = 28,
}

MiscPatch = {
  dungeonDoor = 2,
  pixel_vert = 9,
}

MiscAnimation = {
  riverPier = 1,
}

Dungeon = {
  Door = {
    cell = 8,
    exit = 21
  },

  Animation = {
    torch1 = 21,
    torch2 = 22,
  },

  patch = 0,

  Reveal = function(self)
    ApplyPatch(GetPatchScript(self.patch))
    Activate(GetActorScript(self.Animation.torch1))
    Activate(GetActorScript(self.Animation.torch2))
    ActivateDoorMouseSector(true, GetDoorScript(self.Door.exit))
    ActivateDoorMouseSector(true, GetDoorScript(self.Door.cell))
  end,

  Initialize = function(self)
    Deactivate(GetActorScript(self.Animation.torch1))
    Deactivate(GetActorScript(self.Animation.torch2))

    ActivateDoorMouseSector(false, GetDoorScript(self.Door.exit))
    ActivateDoorMouseSector(false, GetDoorScript(self.Door.cell))
  end
}

DungeonTower = {
  Door = {
    dungeonEntrance = 20,
  },

  Animation = {
    candles = 32,
  },

  patch = 1,

  Reveal = function(self)
    ApplyPatch(GetPatchScript(self.patch))
    Activate(GetActorScript(self.Animation.candles))
    ActivateDoorMouseSector(true, GetDoorScript(self.Door.entrance))
  end,

  Initialize = function(self)
    Deactivate(GetActorScript(self.Animation.candles))
    ActivateDoorMouseSector(false, GetDoorScript(self.Door.entrance))
  end
}

BedRoom = {
  Door = {
    balcony = 22,
    exit = 23,
  },

  patch = 7,

  Reveal = function(self)
    ApplyPatch(GetPatchScript(self.patch))
    ActivateDoorMouseSector(true, GetDoorScript(self.Door.exit))
    ActivateDoorMouseSector(false, GetDoorScript(self.Door.balcony))
  end,

  Initialize = function(self)
    ActivateDoorMouseSector(false, GetDoorScript(self.Door.exit))
  end
}

DrawBridgeRoom = {
  patch = 5,
  lever = 4,
  drawBridge = 3,

  Reveal = function(self)
    ApplyPatch(GetPatchScript(self.patch))
    Activate(GetActor("Treadwheel"))
  end,

  Initialize = function(self)
    Deactivate(GetActor("Treadwheel"))
  end,

  ActivateDrawBridge = function(self, soundLocation)
    StartSequence()
    SequencePlayAnimFreeze(GetActor("Treadwheel"), AnimationAction.sittingToStanding)
    Then()
    SequenceCall(function()
      MakeNoise(soundLocation, 1)
    end)
    EndSequence()
    ApplyPatch(GetPatchScript(self.drawBridge))
    ApplyPatch(GetPatchScript(self.lever))
  end
}

Battlement = {
  Door = {
    exit = 6,
    innerDoor = 37
  },

  Animation = {
    torch = 23
  },

  patch = 6,

  Reveal = function(self)
    ApplyPatch(GetPatchScript(self.patch))
    Activate(GetActorScript(self.Animation.torch))
    ActivateDoorMouseSector(true, GetDoorScript(self.Door.innerDoor))
    ActivateDoorMouseSector(false, GetDoorScript(self.Door.exit))
  end,

  Initialize = function(self)
    Deactivate(GetActorScript(self.Animation.torch))
    ActivateDoorMouseSector(false, GetDoorScript(self.Door.innerDoor))
  end
}

WeaponRoom = {
  Door = {
    southEntrance = 4,
    westEntrance = 5,
    innerDoor = 25
  },

  patch = 8,

  Reveal = function(self)
    ApplyPatch(GetPatchScript(self.patch))
    ActivateDoorMouseSector(true, GetDoorScript(self.Door.innerDoor))
    ActivateDoorMouseSector(false, GetDoorScript(self.Door.southEntrance))
    ActivateDoorMouseSector(false, GetDoorScript(self.Door.westEntrance))
  end,

  Initialize = function(self)
    ActivateDoorMouseSector(false, GetDoorScript(self.Door.innerDoor))
  end
}

StairCase = {
  Animation = {
    torch1 = 24,
    torch2 = 25,
  },

  patch = 10,

  Reveal = function(self)
    ApplyPatch(GetPatchScript(self.patch))
    Activate(GetActorScript(self.Animation.torch1))
    Activate(GetActorScript(self.Animation.torch2))
  end,

  Initialize = function(self)
    Deactivate(GetActorScript(self.Animation.torch1))
    Deactivate(GetActorScript(self.Animation.torch2))
  end
}

ThroneRoom = {
  Door = {
    exit = 0,
  },

  Animation = {
    chimneyFire1 = 19,
    chimneyFire2 = 20,
    candles1 = 26,
    candles2 = 27,
    bedroomCandles = 28,
    tableCandles1 = 29,
    tableCandles2 = 30,
    tableCandles3 = 31,
  },

  patch = 11,

  Reveal = function(self)
    ApplyPatch(GetPatchScript(self.patch))

    Activate(GetActorScript(self.Animation.chimneyFire1))
    Activate(GetActorScript(self.Animation.chimneyFire2))
    Activate(GetActorScript(self.Animation.candles1))
    Activate(GetActorScript(self.Animation.candles2))
    Activate(GetActorScript(self.Animation.bedroomCandles))
    Activate(GetActorScript(self.Animation.tableCandles1))
    Activate(GetActorScript(self.Animation.tableCandles2))
    Activate(GetActorScript(self.Animation.tableCandles3))

    ActivateDoorMouseSector(false, GetDoorScript(self.Door.exit))
  end,

  Initialize = function(self)
    Deactivate(GetActorScript(self.Animation.chimneyFire1))
    Deactivate(GetActorScript(self.Animation.chimneyFire2))
    Deactivate(GetActorScript(self.Animation.candles1))
    Deactivate(GetActorScript(self.Animation.candles2))
    Deactivate(GetActorScript(self.Animation.bedroomCandles))
    Deactivate(GetActorScript(self.Animation.tableCandles1))
    Deactivate(GetActorScript(self.Animation.tableCandles2))
    Deactivate(GetActorScript(self.Animation.tableCandles3))
  end
}

function InitializeLincoln()
  Dungeon:Initialize()
  DungeonTower:Initialize()
  BedRoom:Initialize()
  DrawBridgeRoom:Initialize()
  Battlement:Initialize()
  WeaponRoom:Initialize()
  StairCase:Initialize()
  ThroneRoom:Initialize()
end
