|
|
|
|
@@ -36,8 +36,8 @@ type Impl_Constructor = {
|
|
|
|
|
__index: Impl_Constructor,
|
|
|
|
|
constructor: Constructor_Fun,
|
|
|
|
|
--Class functions
|
|
|
|
|
__RequestFloor: (self: ClassConstructor, Level: number, RequestedLevel: number, GoingUp: boolean) -> (),
|
|
|
|
|
RequestLevel: (self: ClassConstructor, RequestedLevel: number) -> ()
|
|
|
|
|
__GoToFloor: (self: ClassConstructor, Level: number, GoingUp: boolean) -> (),
|
|
|
|
|
RequestLevelAsync: (self: ClassConstructor, RequestedLevel: number) -> boolean
|
|
|
|
|
} & Impl_Static_Props
|
|
|
|
|
|
|
|
|
|
type Impl_Static_Props = {
|
|
|
|
|
@@ -47,6 +47,7 @@ type Impl_Static_Props = {
|
|
|
|
|
FloorLevelingDistance: number,
|
|
|
|
|
DoorOpeningDistance: number,
|
|
|
|
|
LeveledDistance: number,
|
|
|
|
|
QueueWaitTime: number,
|
|
|
|
|
|
|
|
|
|
Sounds: {
|
|
|
|
|
LanternChimeDirection: SoundEnums.Otis1960LanternChimeDirection,
|
|
|
|
|
@@ -59,10 +60,10 @@ type Impl_Static_Props = {
|
|
|
|
|
LanternDisplayOff: Color3,
|
|
|
|
|
},
|
|
|
|
|
Attributes: {
|
|
|
|
|
PassingFloor: IntValue,
|
|
|
|
|
CurrentFloor: IntValue,
|
|
|
|
|
GoalFloor: IntValue,
|
|
|
|
|
Moving: BoolValue,
|
|
|
|
|
GoingUp: BoolValue
|
|
|
|
|
GoingUp: BoolValue
|
|
|
|
|
},
|
|
|
|
|
Events: {
|
|
|
|
|
ButtonActivated: BindableEvent
|
|
|
|
|
@@ -92,6 +93,7 @@ type Constructor_Return_Props = {
|
|
|
|
|
PieplatePulley: UnionOperation,
|
|
|
|
|
MachineRoom: MovingObjects.MachineRoom,
|
|
|
|
|
HallDisplays: {Instance},
|
|
|
|
|
ButtonsConstructor: Buttons.ButtonsConstructor,
|
|
|
|
|
__MovingConnection: RBXScriptConnection?,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -106,6 +108,7 @@ Otis1960.DoorOpeningDistance = Otis1960.FloorLevelingDistance/2.8
|
|
|
|
|
Otis1960.LeveledDistance = 0.5
|
|
|
|
|
Otis1960.Responsiveness = 50
|
|
|
|
|
Otis1960.MaxVelocity = 10
|
|
|
|
|
Otis1960.QueueWaitTime = 5
|
|
|
|
|
|
|
|
|
|
Otis1960.Sounds = {
|
|
|
|
|
LanternChimeDirection = SoundEnums.Otis1960.LanternChimeDirection,
|
|
|
|
|
@@ -120,8 +123,8 @@ Otis1960.Colors = {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Otis1960.Attributes = {
|
|
|
|
|
PassingFloor = Instance.new("IntValue") :: IntValue,
|
|
|
|
|
CurrentFloor = Instance.new("IntValue") :: IntValue,
|
|
|
|
|
GoalFloor = Instance.new("IntValue") :: IntValue,
|
|
|
|
|
Moving = Instance.new("BoolValue") :: BoolValue,
|
|
|
|
|
GoingUp = Instance.new("BoolValue") :: BoolValue
|
|
|
|
|
}
|
|
|
|
|
@@ -130,8 +133,8 @@ Otis1960.Events = {
|
|
|
|
|
ButtonActivated = Instance.new("BindableEvent") :: BindableEvent
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Otis1960.Attributes.PassingFloor.Value = 1
|
|
|
|
|
Otis1960.Attributes.CurrentFloor.Value = 1
|
|
|
|
|
Otis1960.Attributes.GoalFloor.Value = 1
|
|
|
|
|
Otis1960.Attributes.Moving.Value = false
|
|
|
|
|
Otis1960.Attributes.GoingUp.Value = false
|
|
|
|
|
|
|
|
|
|
@@ -142,16 +145,30 @@ local function ElevatorGoingUpDirection(Floor: number, RequestedFloor: number):
|
|
|
|
|
return -(Floor-RequestedFloor)>0
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local ButtonsConstructor = Buttons.constructor(Otis1960.Attributes, Otis1960.Events, Otis1960.Colors)
|
|
|
|
|
local function _ActivatedFloorButton(self: ClassConstructor, ButtonFloor: number, ButtonInst: BasePart)
|
|
|
|
|
local Some = self:RequestLevelAsync(ButtonFloor)
|
|
|
|
|
|
|
|
|
|
local function HookButtons(self: ClassConstructor, ButtonNameType: Enums.ButtonTreeValues, ButtonName: string, ButtonTree)
|
|
|
|
|
if Some then
|
|
|
|
|
local FloorTracker: RBXScriptConnection
|
|
|
|
|
|
|
|
|
|
FloorTracker = Attributes.CurrentFloor:GetPropertyChangedSignal("Value"):Connect(function()
|
|
|
|
|
if Attributes.CurrentFloor.Value == ButtonFloor and Attributes.GoalFloor.Value == ButtonFloor then
|
|
|
|
|
FloorTracker:Disconnect()
|
|
|
|
|
|
|
|
|
|
self.ButtonsConstructor:__DeactivateButton(ButtonInst, ButtonInst:FindFirstChild("Glass") :: BasePart?)
|
|
|
|
|
end
|
|
|
|
|
end)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local function HookButtons(self: ClassConstructor, ButtonNameType: Enums.ButtonTreeValues, ButtonName: string, ButtonTree: Tags.ButtonProperties)
|
|
|
|
|
if ButtonNameType == Enums.ButtonTree.Car then
|
|
|
|
|
ButtonsConstructor:CarButton(ButtonName, ButtonTree, function(Floor: number)
|
|
|
|
|
self:RequestLevel(Floor)
|
|
|
|
|
self.ButtonsConstructor:CarButton(ButtonName, ButtonTree, function(ButtonFloor: number)
|
|
|
|
|
_ActivatedFloorButton(self, ButtonFloor, ButtonTree.Inst :: BasePart)
|
|
|
|
|
end)
|
|
|
|
|
elseif ButtonNameType == Enums.ButtonTree.Landing then
|
|
|
|
|
ButtonsConstructor:LandingButton(ButtonName, ButtonTree, function(Floor: number)
|
|
|
|
|
self:RequestLevel(Floor)
|
|
|
|
|
self.ButtonsConstructor:LandingButton(ButtonName, ButtonTree, function(ButtonFloor: number)
|
|
|
|
|
_ActivatedFloorButton(self, ButtonFloor, ButtonTree.Inst :: BasePart)
|
|
|
|
|
end)
|
|
|
|
|
elseif ButtonNameType == Enums.ButtonTree.Special then
|
|
|
|
|
|
|
|
|
|
@@ -164,8 +181,8 @@ local function HookButtons(self: ClassConstructor, ButtonNameType: Enums.ButtonT
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local function IterateButtons(self: ClassConstructor, ButtonsConstructor: ButtonTags.ButtonsConstructor)
|
|
|
|
|
for ButtonNameType, ButtonList in ButtonsConstructor.Buttons do
|
|
|
|
|
local function IterateButtons(self: ClassConstructor, ButtonsTagsConstructor: ButtonTags.ButtonsTagsConstructor)
|
|
|
|
|
for ButtonNameType, ButtonList in ButtonsTagsConstructor.Buttons do
|
|
|
|
|
for ButtonName, ButtonTree in ButtonList do
|
|
|
|
|
if ButtonTree.Prompt then
|
|
|
|
|
if ButtonTree.Inst then
|
|
|
|
|
@@ -211,8 +228,10 @@ function Otis1960.constructor(TagsConstructor, ButtonsTags, LanternsTags, Landin
|
|
|
|
|
|
|
|
|
|
self.LanternsConstructor = Lanterns.constructor(LanternDisplay, LanternsTags, Otis1960.Sounds, Otis1960.Colors)
|
|
|
|
|
|
|
|
|
|
local ButtonsConstructor = ButtonTags.constructor(TagsConstructor, ButtonsTags)
|
|
|
|
|
local Otis1960_Buttons = ButtonsConstructor:CreatePromptButtons()
|
|
|
|
|
local ButtonsTagsConstructor = ButtonTags.constructor(TagsConstructor, ButtonsTags)
|
|
|
|
|
local Otis1960_Buttons = ButtonsTagsConstructor:CreatePromptButtons()
|
|
|
|
|
|
|
|
|
|
self.ButtonsConstructor = Buttons.constructor(Otis1960.Attributes, Otis1960.Events, Otis1960.Colors)
|
|
|
|
|
|
|
|
|
|
self.HallDisplaysConstructor:BindHallDisplays()
|
|
|
|
|
|
|
|
|
|
@@ -221,7 +240,7 @@ function Otis1960.constructor(TagsConstructor, ButtonsTags, LanternsTags, Landin
|
|
|
|
|
self.BoxAlignOrientation = ElevatorMover(self.ElevatorBox_1960, self.ElevatorBox_1960.Position, Otis1960.Responsiveness, Otis1960.MaxVelocity)
|
|
|
|
|
|
|
|
|
|
local ClassConstructor = setmetatable(self, Otis1960)
|
|
|
|
|
IterateButtons(ClassConstructor, ButtonsConstructor)
|
|
|
|
|
IterateButtons(ClassConstructor, ButtonsTagsConstructor)
|
|
|
|
|
|
|
|
|
|
--Open the elevator doors on server start
|
|
|
|
|
task.spawn(function()
|
|
|
|
|
@@ -234,10 +253,27 @@ function Otis1960.constructor(TagsConstructor, ButtonsTags, LanternsTags, Landin
|
|
|
|
|
return ClassConstructor
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local FloorQueue = {}
|
|
|
|
|
local FloorQueue: {number} = {}
|
|
|
|
|
|
|
|
|
|
local function CheckQueue()
|
|
|
|
|
local function CheckQueue(self: ClassConstructor)
|
|
|
|
|
table.remove(FloorQueue, 1)
|
|
|
|
|
|
|
|
|
|
if #FloorQueue>0 then
|
|
|
|
|
--table.sort
|
|
|
|
|
self:__GoToFloor(Leveling[FloorQueue[1]], ElevatorGoingUpDirection(Attributes.CurrentFloor.Value, FloorQueue[1]))
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local function FloorLeveled(self: ClassConstructor, RequestedLevel: number)
|
|
|
|
|
(self.__MovingConnection :: RBXScriptConnection):Disconnect()
|
|
|
|
|
Attributes.Moving.Value = false
|
|
|
|
|
Attributes.CurrentFloor.Value = RequestedLevel
|
|
|
|
|
self.BoxAlignPosition.MaxVelocity = Otis1960.MaxVelocity
|
|
|
|
|
|
|
|
|
|
self.LanternsConstructor:Reset(Attributes.CurrentFloor.Value)
|
|
|
|
|
|
|
|
|
|
task.wait(Otis1960.QueueWaitTime)
|
|
|
|
|
CheckQueue(self)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local function FloorLeveling(self: ClassConstructor, RequestedLevel: number)
|
|
|
|
|
@@ -245,22 +281,8 @@ local function FloorLeveling(self: ClassConstructor, RequestedLevel: number)
|
|
|
|
|
self.LanternsConstructor:Toggle(true, RequestedLevel)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local function FloorLeveled(self: ClassConstructor, RequestedLevel: number)
|
|
|
|
|
(self.__MovingConnection :: RBXScriptConnection):Disconnect()
|
|
|
|
|
|
|
|
|
|
Attributes.Moving.Value = false
|
|
|
|
|
Attributes.CurrentFloor.Value = RequestedLevel
|
|
|
|
|
self.BoxAlignPosition.MaxVelocity = Otis1960.MaxVelocity
|
|
|
|
|
|
|
|
|
|
self.LanternsConstructor:Reset(Attributes.CurrentFloor.Value)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
local function FloorPassingUp(self: ClassConstructor, ElevatorPositionY: number, RequestedLevel: number)
|
|
|
|
|
local CF = Attributes.CurrentFloor.Value
|
|
|
|
|
|
|
|
|
|
if ElevatorPositionY>=Leveling[CF+1] then
|
|
|
|
|
if ElevatorPositionY>=Leveling[Attributes.CurrentFloor.Value+1] then
|
|
|
|
|
Attributes.CurrentFloor.Value+=1
|
|
|
|
|
|
|
|
|
|
self.LanternsConstructor:Toggle(true, Attributes.CurrentFloor.Value)
|
|
|
|
|
@@ -277,8 +299,10 @@ local function FloorPassingDown(self: ClassConstructor, ElevatorPositionY: numbe
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function Otis1960:__RequestFloor(GoalLevelVEC, RequestedLevel, GoingUp)
|
|
|
|
|
self.ElevatorDoorsConstructor:ToggleElevatorDoors(false, Attributes.CurrentFloor.Value)
|
|
|
|
|
function Otis1960:__GoToFloor(GoalLevelVEC, GoingUp)
|
|
|
|
|
if Doors.Attributes.DoorsOpen.Value then
|
|
|
|
|
self.ElevatorDoorsConstructor:ToggleElevatorDoors(false, Attributes.CurrentFloor.Value)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if self.__MovingConnection and self.__MovingConnection.Connected then
|
|
|
|
|
self.__MovingConnection:Disconnect()
|
|
|
|
|
@@ -298,8 +322,11 @@ function Otis1960:__RequestFloor(GoalLevelVEC, RequestedLevel, GoingUp)
|
|
|
|
|
--Otis1960_ShaftGovernor
|
|
|
|
|
self.__MovingConnection = RS.Heartbeat:Connect(function(_dt)
|
|
|
|
|
Delta+=1
|
|
|
|
|
local FloorGoal: number = FloorQueue[1]
|
|
|
|
|
|
|
|
|
|
Attributes.Moving.Value = true
|
|
|
|
|
|
|
|
|
|
Attributes.GoalFloor.Value = FloorGoal
|
|
|
|
|
|
|
|
|
|
local ElevatorPosition: Vector3 = self.ElevatorBox_1960.Position
|
|
|
|
|
local ElevatorPositionY: number = ElevatorPosition.Y
|
|
|
|
|
local BoxAlignY: number = self.BoxAlignPosition.Position.Y
|
|
|
|
|
@@ -310,34 +337,34 @@ function Otis1960:__RequestFloor(GoalLevelVEC, RequestedLevel, GoingUp)
|
|
|
|
|
|
|
|
|
|
--Kill the connection
|
|
|
|
|
if GoingUp then
|
|
|
|
|
FloorPassingUp(self, ElevatorPositionY, RequestedLevel)
|
|
|
|
|
FloorPassingUp(self, ElevatorPositionY, FloorGoal)
|
|
|
|
|
|
|
|
|
|
if ElevatorPositionY>=BoxAlignY-Otis1960.FloorLevelingDistance then
|
|
|
|
|
FloorLeveling(self, RequestedLevel)
|
|
|
|
|
FloorLeveling(self, FloorGoal)
|
|
|
|
|
|
|
|
|
|
if not DoorsOpeningEvent and ElevatorPositionY>=BoxAlignY-Otis1960.DoorOpeningDistance then
|
|
|
|
|
DoorsOpeningEvent = true
|
|
|
|
|
self.ElevatorDoorsConstructor:ToggleElevatorDoors(true, RequestedLevel)
|
|
|
|
|
self.ElevatorDoorsConstructor:ToggleElevatorDoors(true, FloorGoal)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if ElevatorPositionY>=BoxAlignY-Otis1960.LeveledDistance then
|
|
|
|
|
FloorLeveled(self, RequestedLevel)
|
|
|
|
|
FloorLeveled(self, FloorGoal)
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
FloorPassingDown(self, ElevatorPositionY, RequestedLevel)
|
|
|
|
|
FloorPassingDown(self, ElevatorPositionY, FloorGoal)
|
|
|
|
|
|
|
|
|
|
if ElevatorPositionY<=BoxAlignY+Otis1960.FloorLevelingDistance then
|
|
|
|
|
FloorLeveling(self, RequestedLevel)
|
|
|
|
|
FloorLeveling(self, FloorGoal)
|
|
|
|
|
|
|
|
|
|
if not DoorsOpeningEvent and ElevatorPositionY>=BoxAlignY-Otis1960.DoorOpeningDistance then
|
|
|
|
|
DoorsOpeningEvent = true
|
|
|
|
|
self.ElevatorDoorsConstructor:ToggleElevatorDoors(true, RequestedLevel)
|
|
|
|
|
self.ElevatorDoorsConstructor:ToggleElevatorDoors(true, FloorGoal)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if ElevatorPositionY<=BoxAlignY+Otis1960.LeveledDistance then
|
|
|
|
|
FloorLeveled(self, RequestedLevel)
|
|
|
|
|
FloorLeveled(self, FloorGoal)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end)
|
|
|
|
|
@@ -345,21 +372,48 @@ function Otis1960:__RequestFloor(GoalLevelVEC, RequestedLevel, GoingUp)
|
|
|
|
|
self.BoxAlignPosition.Position = Vector3.new(ElevatorBoxCurrentPos.X, GoalLevelVEC, ElevatorBoxCurrentPos.Z)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function Otis1960:RequestLevel(RequestedLevel)
|
|
|
|
|
function Otis1960:RequestLevelAsync(RequestedLevel)
|
|
|
|
|
local GoalLevelVEC: number = Leveling[RequestedLevel]
|
|
|
|
|
|
|
|
|
|
if GoalLevelVEC and GoalLevelVEC ~= Attributes.CurrentFloor.Value then
|
|
|
|
|
local GoingUp = ElevatorGoingUpDirection(Attributes.CurrentFloor.Value, RequestedLevel)
|
|
|
|
|
|
|
|
|
|
if Attributes.Moving.Value then
|
|
|
|
|
local ElevatorBoxCurrentPos = self.ElevatorBox_1960.Position
|
|
|
|
|
|
|
|
|
|
if Attributes.GoingUp.Value then
|
|
|
|
|
if GoingUp then
|
|
|
|
|
table.insert(FloorQueue, 1, RequestedLevel)
|
|
|
|
|
|
|
|
|
|
if not Doors.Attributes.DoorsOpen.Value then
|
|
|
|
|
self.BoxAlignPosition.Position = Vector3.new(ElevatorBoxCurrentPos.X, GoalLevelVEC, ElevatorBoxCurrentPos.Z)
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
table.insert(FloorQueue, RequestedLevel)
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
if not GoingUp then
|
|
|
|
|
table.insert(FloorQueue, 1, RequestedLevel)
|
|
|
|
|
|
|
|
|
|
if not Doors.Attributes.DoorsOpen.Value then
|
|
|
|
|
self.BoxAlignPosition.Position = Vector3.new(ElevatorBoxCurrentPos.X, GoalLevelVEC, ElevatorBoxCurrentPos.Z)
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
table.insert(FloorQueue, RequestedLevel)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
Attributes.GoingUp.Value = GoingUp
|
|
|
|
|
self:__RequestFloor(GoalLevelVEC, RequestedLevel, GoingUp)
|
|
|
|
|
|
|
|
|
|
table.insert(FloorQueue, 1, RequestedLevel)
|
|
|
|
|
self:__GoToFloor(GoalLevelVEC, GoingUp)
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
warn(`[{Otis1960.Name}]: landing out of range or equals the same range as the goal, requested landing: {tostring(RequestedLevel)}`)
|
|
|
|
|
return false
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
return true
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
return Otis1960
|