require("lib/common")

MiscDoor = {
  secretPassageOutside = 25,
  secretPassageInside = 26,
  cell = 55,
}

MiscPatch = {
  drawBridgeInside = 1,
  leverInside = 2,
  towerNorth = 7,
  pixel_vert1 = 12,
  pixel_vert2 = 15
}

MiscAnimation = {
  Animals = {
    butterfly1 = 39,
    butterfly2 = 40,
    butterfly3 = 41,
    pigs = 43,
    cow1 = 44,
    cow2 = 45,
    duck = 46,
  },
  LakeParts = {
    bubbles1 = 32,
    bubbles2 = 33,
    bubbles3 = 34,
    bubbles4 = 35,
    bubbles5 = 36,
  }
}

TowerNorth = {
  patch = 7,

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

CellTower = {
  Door = {
    cell = 55
  },

  patch = 13,
  cell = 14,

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

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

TowersEast = {
  patch = 3,
  drawBridge = 8,
  lever = 9,

  Reveal = function(self)
      ApplyPatch(GetPatchScript(self.patch))
      Activate(GetActor("Leicester_-_Mecanisme01_target_1"))
  end,

  Initialize = function(self)
      Deactivate(GetActor("Leicester_-_Mecanisme01_target_1"))
  end,

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

BedRoom = {
  Animation = {
      BedroomCandles = 29,
  },

  patch = 5,

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

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

ChimneyRoom = {
  Animation = {
      chimney = 22,
      candles = 30,
  },

  patch = 6,

  Reveal = function(self)
      ApplyPatch(GetPatchScript(self.patch))
      Activate(GetActorScript(self.Animation.chimney))
      Activate(GetActorScript(self.Animation.candles))
  end,

  Initialize = function(self)
      Deactivate(GetActorScript(self.Animation.chimney))
      Deactivate(GetActorScript(self.Animation.candles))
  end
}

Hallway = {
  Door = {
      sideRoom = 39,
  },

  Animation = {
      chandelier = 28,
  },

  patch = 0,

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

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

DrawBridgeRoomSouth = {
  Door = {
      east = 10,
      flap = 11,
      west = 12,
  },

  patch = 4,
  drawBridge = 10,
  lever = 11,

  Reveal = function(self)
      ApplyPatch(GetPatchScript(self.patch))
      ActivateDoorMouseSector(true, GetDoorScript(self.Door.flap))
      Activate(GetActor("Leicester_-_Mecanisme03_target_3"))
  end,

  Initialize = function(self)
      Deactivate(GetActor("Leicester_-_Mecanisme03_target_3"))
      ActivateDoorMouseSector(false, GetDoorScript(self.Door.flap))
  end,

  ActivateDrawBridge = function(self)
      MakeNoise(GetActorLocation(GetActor("Leicester_-_Mecanisme03_target_3")), 1)
      StartSequence()
      SequencePlayAnimFreeze(GetActor("Leicester_-_Mecanisme03_target_3"), AnimationAction.sittingToStanding)
      EndSequence()
      ApplyPatch(GetPatchScript(self.lever))
      ApplyPatch(GetPatchScript(self.drawBridge))
  end

}

function InitializeLeicester()
  CellTower:Initialize()
  Hallway:Initialize()
  DrawBridgeRoomSouth:Initialize()
  BedRoom:Initialize()
  ChimneyRoom:Initialize()

  DeactivateSherwoodSigns()
end
