mirror of
https://github.com/unixtensor/Roblox-Elevator-Game.git
synced 2025-12-14 06:41:55 +00:00
bug with going down
This commit is contained in:
@@ -9,8 +9,7 @@ type Impl_Constructor = {
|
|||||||
--Class functions
|
--Class functions
|
||||||
Sort: (self: ClassConstructor, ElevatorGoingUp: boolean) -> (),
|
Sort: (self: ClassConstructor, ElevatorGoingUp: boolean) -> (),
|
||||||
Check: (self: ClassConstructor, ElevatorGoingUp: boolean) -> number?,
|
Check: (self: ClassConstructor, ElevatorGoingUp: boolean) -> number?,
|
||||||
RawInsert: (self: ClassConstructor, ElevatorGoingUp: boolean, RequestedLevel: number) -> (),
|
AddFloor: (self: ClassConstructor, ElevatorGoingUp: boolean, RequestedLevel: number) -> (),
|
||||||
AddFloor: (self: ClassConstructor, ElevatorGoingUp: boolean, RequestedLevel: number) -> boolean
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type Constructor_Fun = (BoxAlignPosition: AlignPosition, ElevatorAttributes: ElevatorAttributes, DoorAttributes: DoorAttributes) -> ClassConstructor
|
type Constructor_Fun = (BoxAlignPosition: AlignPosition, ElevatorAttributes: ElevatorAttributes, DoorAttributes: DoorAttributes) -> ClassConstructor
|
||||||
@@ -19,10 +18,6 @@ type Constructor_Return_Props = {
|
|||||||
ElevatorAttributes: ElevatorAttributes,
|
ElevatorAttributes: ElevatorAttributes,
|
||||||
DoorAttributes: DoorAttributes,
|
DoorAttributes: DoorAttributes,
|
||||||
__FloorQueue: FloorQueue,
|
__FloorQueue: FloorQueue,
|
||||||
|
|
||||||
Events: {
|
|
||||||
Sorted: BindableEvent
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type ElevatorAttributes = {
|
type ElevatorAttributes = {
|
||||||
@@ -52,9 +47,6 @@ RelayAlgorithm.__index = RelayAlgorithm
|
|||||||
|
|
||||||
function RelayAlgorithm.constructor(BoxAlignPosition, ElevatorAttributes, DoorAttributes)
|
function RelayAlgorithm.constructor(BoxAlignPosition, ElevatorAttributes, DoorAttributes)
|
||||||
return setmetatable({
|
return setmetatable({
|
||||||
Events = {
|
|
||||||
Sorted = Instance.new("BindableEvent")
|
|
||||||
},
|
|
||||||
BoxAlignPosition = BoxAlignPosition,
|
BoxAlignPosition = BoxAlignPosition,
|
||||||
ElevatorAttributes = ElevatorAttributes,
|
ElevatorAttributes = ElevatorAttributes,
|
||||||
DoorAttributes = DoorAttributes,
|
DoorAttributes = DoorAttributes,
|
||||||
@@ -72,7 +64,6 @@ function RelayAlgorithm:Sort(ElevatorGoingUp)
|
|||||||
end
|
end
|
||||||
return a>b
|
return a>b
|
||||||
end)
|
end)
|
||||||
self.Events.Sorted:Fire(self.__FloorQueue)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function RelayAlgorithm:Check(ElevatorGoingUp)
|
function RelayAlgorithm:Check(ElevatorGoingUp)
|
||||||
@@ -86,15 +77,9 @@ function RelayAlgorithm:Check(ElevatorGoingUp)
|
|||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
function RelayAlgorithm:RawInsert(ElevatorGoingUp, RequestedLevel)
|
function RelayAlgorithm:AddFloor(ElevatorGoingUp, RequestedLevel)
|
||||||
table.insert(self.__FloorQueue, ElevatorGoingUp == self.ElevatorAttributes.GoingUp.Value and 1 or #self.__FloorQueue+1, RequestedLevel)
|
table.insert(self.__FloorQueue, ElevatorGoingUp == self.ElevatorAttributes.GoingUp.Value and 1 or #self.__FloorQueue+1, RequestedLevel)
|
||||||
self:Sort(ElevatorGoingUp)
|
self:Sort(ElevatorGoingUp)
|
||||||
end
|
end
|
||||||
|
|
||||||
function RelayAlgorithm:AddFloor(ElevatorGoingUp, RequestedLevel)
|
|
||||||
self:RawInsert(ElevatorGoingUp, RequestedLevel)
|
|
||||||
|
|
||||||
return not self.ElevatorAttributes.Relay.ReadyForMoving.Value and self.DoorAttributes.Relay.Open.Value
|
|
||||||
end
|
|
||||||
|
|
||||||
return RelayAlgorithm
|
return RelayAlgorithm
|
||||||
@@ -56,9 +56,8 @@ type Impl_Constructor = {
|
|||||||
__index: Impl_Constructor,
|
__index: Impl_Constructor,
|
||||||
constructor: Constructor_Fun,
|
constructor: Constructor_Fun,
|
||||||
--Class functions
|
--Class functions
|
||||||
RequestLevelAsync: (self: ClassConstructor, RequestedLevel: number) -> boolean,
|
RequestLevel: (self: ClassConstructor, RequestedLevel: number) -> boolean,
|
||||||
__MoveToAsync: (self: ClassConstructor, GoingUp: boolean, RequestedLevel: number) -> (),
|
__TravelToFloor: (self: ClassConstructor, LevelInt: number, LevelVec3: number, ElevatorGoingUp: boolean) -> (),
|
||||||
__MovingHeartbeat: (self: ClassConstructor, GoingUp: boolean, RequestedLevel: number) -> (),
|
|
||||||
} & Impl_Static_Props
|
} & Impl_Static_Props
|
||||||
|
|
||||||
type Impl_Static_Props = {
|
type Impl_Static_Props = {
|
||||||
@@ -67,9 +66,9 @@ type Impl_Static_Props = {
|
|||||||
MaxVelocity: number,
|
MaxVelocity: number,
|
||||||
FloorLevelingDistance: number,
|
FloorLevelingDistance: number,
|
||||||
FloorLeveling3PhaseDistance: number,
|
FloorLeveling3PhaseDistance: number,
|
||||||
DoorOpeningDistance: number,
|
ParkedDistance: number,
|
||||||
LeveledDistance: number,
|
LevelingVelocity: number,
|
||||||
QueueWaitTime: number,
|
Phase3LevelingVelocity: number,
|
||||||
|
|
||||||
Sounds: {
|
Sounds: {
|
||||||
LanternChimeDirection: SoundEnums.Otis1960LanternChimeDirection,
|
LanternChimeDirection: SoundEnums.Otis1960LanternChimeDirection,
|
||||||
@@ -86,11 +85,14 @@ type Impl_Static_Props = {
|
|||||||
Moving: BoolValue,
|
Moving: BoolValue,
|
||||||
GoingUp: BoolValue,
|
GoingUp: BoolValue,
|
||||||
Stopped: BoolValue,
|
Stopped: BoolValue,
|
||||||
|
Goal: IntValue
|
||||||
Relay: {
|
},
|
||||||
Goal: IntValue,
|
Events: {
|
||||||
ReadyForMoving: BoolValue,
|
CabProgression: BindableEvent,
|
||||||
}
|
CabTraveling: BindableEvent,
|
||||||
|
Parked: BindableEvent,
|
||||||
|
Leveling: BindableEvent,
|
||||||
|
Leveling3Phase: BindableEvent,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -130,7 +132,6 @@ type Constructor_Return_Props = {
|
|||||||
|
|
||||||
__Connections: {
|
__Connections: {
|
||||||
Moving: RBXScriptConnection?,
|
Moving: RBXScriptConnection?,
|
||||||
FloorSorted: RBXScriptConnection?
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -140,11 +141,11 @@ Elevator.__index = Elevator
|
|||||||
Elevator.Name = Enums.Elevator.Otis1960
|
Elevator.Name = Enums.Elevator.Otis1960
|
||||||
Elevator.FloorLevelingDistance = 4
|
Elevator.FloorLevelingDistance = 4
|
||||||
Elevator.FloorLeveling3PhaseDistance = 1.5
|
Elevator.FloorLeveling3PhaseDistance = 1.5
|
||||||
Elevator.DoorOpeningDistance = Elevator.FloorLeveling3PhaseDistance/2.8
|
Elevator.ParkedDistance = 0.2
|
||||||
Elevator.LeveledDistance = 0.5
|
|
||||||
Elevator.Responsiveness = 10
|
Elevator.Responsiveness = 10
|
||||||
Elevator.MaxVelocity = 7
|
Elevator.MaxVelocity = 7
|
||||||
Elevator.QueueWaitTime = 5
|
Elevator.LevelingVelocity = 2
|
||||||
|
Elevator.Phase3LevelingVelocity = .5
|
||||||
|
|
||||||
Elevator.Sounds = {
|
Elevator.Sounds = {
|
||||||
LanternChimeDirection = SoundEnums.Otis1960.LanternChimeDirection,
|
LanternChimeDirection = SoundEnums.Otis1960.LanternChimeDirection,
|
||||||
@@ -158,139 +159,42 @@ Elevator.Colors = {
|
|||||||
LanternDisplayOff = Color3.fromRGB(55,55,55),
|
LanternDisplayOff = Color3.fromRGB(55,55,55),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Elevator.Events = {
|
||||||
|
CabProgression = Instance.new("BindableEvent") :: BindableEvent,
|
||||||
|
CabTraveling = Instance.new("BindableEvent") :: BindableEvent,
|
||||||
|
Parked = Instance.new("BindableEvent") :: BindableEvent,
|
||||||
|
Leveling = Instance.new("BindableEvent") :: BindableEvent,
|
||||||
|
Leveling3Phase = Instance.new("BindableEvent") :: BindableEvent,
|
||||||
|
}
|
||||||
|
|
||||||
Elevator.Attributes = {
|
Elevator.Attributes = {
|
||||||
CurrentFloor = Instance.new("IntValue") :: IntValue,
|
CurrentFloor = Instance.new("IntValue") :: IntValue,
|
||||||
Moving = Instance.new("BoolValue") :: BoolValue,
|
Moving = Instance.new("BoolValue") :: BoolValue,
|
||||||
GoingUp = Instance.new("BoolValue") :: BoolValue,
|
GoingUp = Instance.new("BoolValue") :: BoolValue,
|
||||||
Stopped = Instance.new("BoolValue") :: BoolValue,
|
Stopped = Instance.new("BoolValue") :: BoolValue,
|
||||||
|
|
||||||
Relay = {
|
|
||||||
ReadyForMoving = Instance.new("BoolValue") :: BoolValue,
|
|
||||||
Goal = Instance.new("IntValue") :: IntValue,
|
Goal = Instance.new("IntValue") :: IntValue,
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Elevator.Attributes.CurrentFloor.Value = 1
|
Elevator.Attributes.CurrentFloor.Value = 1
|
||||||
Elevator.Attributes.Moving.Value = false
|
Elevator.Attributes.Moving.Value = false
|
||||||
Elevator.Attributes.GoingUp.Value = false
|
Elevator.Attributes.GoingUp.Value = false
|
||||||
|
Elevator.Attributes.Goal.Value = 1
|
||||||
Elevator.Attributes.Relay.Goal.Value = 1
|
|
||||||
Elevator.Attributes.Relay.ReadyForMoving.Value = false
|
|
||||||
|
|
||||||
local Attributes = Elevator.Attributes
|
local Attributes = Elevator.Attributes
|
||||||
|
local Events = Elevator.Events
|
||||||
|
|
||||||
--Math function for determining if the elevator goal is to move upwards or not
|
|
||||||
local function ElevatorGoingUpDirection(CurrentFloor: number, RequestedFloor: number): boolean
|
local function ElevatorGoingUpDirection(CurrentFloor: number, RequestedFloor: number): boolean
|
||||||
-- -(CurrentFloor-RequestedFloor)>0
|
-- -(CurrentFloor-RequestedFloor)>0
|
||||||
-- -CurrentFloor+RequestedFloor>0
|
-- -CurrentFloor+RequestedFloor>0
|
||||||
return CurrentFloor<RequestedFloor
|
return CurrentFloor<RequestedFloor
|
||||||
end
|
end
|
||||||
|
|
||||||
local function _ActivatedFloorButton(self: ClassConstructor, ButtonFloor: number, ButtonTree: Tags.ButtonPropertiesSafe)
|
local function elevatorwarn<T...>(...: T...)
|
||||||
ButtonTree.Prompt.Enabled = false
|
warn("🛗 ["..Elevator.Name.."]:", ...)
|
||||||
local Some = self:RequestLevelAsync(ButtonFloor)
|
|
||||||
|
|
||||||
if Some then
|
|
||||||
local FloorTracker: RBXScriptConnection
|
|
||||||
|
|
||||||
FloorTracker = Attributes.CurrentFloor:GetPropertyChangedSignal("Value"):Connect(function()
|
|
||||||
if Attributes.CurrentFloor.Value == ButtonFloor and Attributes.Relay.Goal.Value == ButtonFloor then
|
|
||||||
FloorTracker:Disconnect()
|
|
||||||
|
|
||||||
self.ButtonsConstructor:__DeactivateButton(ButtonTree.Inst :: BasePart, (ButtonTree.Inst :: BasePart):FindFirstChild("Glass") :: BasePart?)
|
|
||||||
self.PhysicalRelays:SetState(`F{ButtonFloor}C`, false, true)
|
|
||||||
ButtonTree.Prompt.Enabled = true
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
else
|
|
||||||
warn(`Failed to call floor: {ButtonFloor}`)
|
|
||||||
ButtonTree.Prompt.Enabled = true
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--If the elevator is fully stopped at the floor and the hall button or the same cab button for the same floor is pressed,
|
local function elevatorprint<T...>(...: T...)
|
||||||
--then open the doors
|
print("🛗 ["..Elevator.Name.."]:", ...)
|
||||||
local function OpenElevatorDoorsSafe(self: ClassConstructor)
|
|
||||||
if not Attributes.Relay.ReadyForMoving.Value then
|
|
||||||
task.spawn(function()
|
|
||||||
self.ElevatorDoorsConstructor:ToggleElevatorDoorsAsync(true, Attributes.CurrentFloor.Value)
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
--Special cases inbound
|
|
||||||
local function HookButtons(self: ClassConstructor, ButtonNameType: Enums.ButtonTreeValues, ButtonID: string, ButtonTree: Tags.ButtonPropertiesSafe)
|
|
||||||
if ButtonNameType == Enums.ButtonTree.Car then
|
|
||||||
self.ButtonsConstructor:CarButton(ButtonID, ButtonTree, function(ButtonFloor: number)
|
|
||||||
_ActivatedFloorButton(self, ButtonFloor, ButtonTree)
|
|
||||||
end, function(_ButtonFloor: number)
|
|
||||||
OpenElevatorDoorsSafe(self)
|
|
||||||
end)
|
|
||||||
elseif ButtonNameType == Enums.ButtonTree.Landing then
|
|
||||||
self.ButtonsConstructor:LandingButton(ButtonID, ButtonTree, function(ButtonFloor: number)
|
|
||||||
_ActivatedFloorButton(self, ButtonFloor, ButtonTree)
|
|
||||||
end, function(_ButtonFloor: number)
|
|
||||||
OpenElevatorDoorsSafe(self)
|
|
||||||
end)
|
|
||||||
elseif ButtonNameType == Enums.ButtonTree.Special then
|
|
||||||
if Elevator.Name == Enums.Elevator.Otis1960 then
|
|
||||||
if ButtonTree.Name == Enums.SpecialButton.Stop then
|
|
||||||
ButtonTree.Attachment.Position-=Vector3.xAxis/10
|
|
||||||
ButtonTree.Prompt.HoldDuration = 1
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
self.ButtonsConstructor:SpecialButton(ButtonTree.Name :: Enums.SpecialButtonValues, ButtonID, ButtonTree, function(Toggled: Buttons.SpecialButtonToggle)
|
|
||||||
Attributes.Stopped.Value = Toggled
|
|
||||||
|
|
||||||
if Toggled then
|
|
||||||
(ButtonTree.Inst :: BasePart).Position+=Vector3.new(0,0,.05)
|
|
||||||
|
|
||||||
if self.__Connections.Moving and self.__Connections.Moving.Connected then
|
|
||||||
self.__Connections.Moving:Disconnect()
|
|
||||||
end
|
|
||||||
self.BoxAlignPosition.MaxVelocity = 0
|
|
||||||
else
|
|
||||||
(ButtonTree.Inst :: BasePart).Position-=Vector3.new(0,0,.05)
|
|
||||||
|
|
||||||
self.LanternsConstructor:Reset()
|
|
||||||
self:__MoveToAsync(ElevatorGoingUpDirection(Attributes.CurrentFloor.Value, Attributes.Relay.Goal.Value))
|
|
||||||
self.BoxAlignPosition.MaxVelocity = Elevator.MaxVelocity
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
elseif ButtonNameType == Enums.ButtonTree.Relays then
|
|
||||||
if Elevator.Name == Enums.Elevator.Otis1960 then
|
|
||||||
ButtonTree.Attachment.Position-=Vector3.zAxis/6
|
|
||||||
end
|
|
||||||
elseif ButtonNameType == Enums.ButtonTree.Unknown then
|
|
||||||
|
|
||||||
else
|
|
||||||
warn(`[{Elevator.Name}]: Could not iterate a button, ButtonNameType={ButtonNameType}`)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local function IterateButtons(self: ClassConstructor, ButtonsTagsConstructor: ButtonTags.ButtonsTagsConstructor)
|
|
||||||
for ButtonNameType, ButtonList in ButtonsTagsConstructor.Buttons[Elevator.Name] do
|
|
||||||
for ButtonID, ButtonTree in ButtonList do
|
|
||||||
if ButtonTree.Prompt and ButtonTree.Inst and ButtonTree.Attachment then
|
|
||||||
HookButtons(self, ButtonNameType :: Enums.ButtonTreeValues, ButtonID, ButtonTree :: Tags.ButtonPropertiesSafe)
|
|
||||||
else
|
|
||||||
warn(`{ButtonTree} is missing a field, {ButtonTree}`)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local function ElevatorInit(self: ClassConstructor)
|
|
||||||
task.spawn(function()
|
|
||||||
self.LanternsConstructor:Toggle(true, Attributes.CurrentFloor.Value)
|
|
||||||
self.HallDisplaysConstructor:SetHallDisplays(Attributes.CurrentFloor.Value)
|
|
||||||
|
|
||||||
--Open the elevator doors on server start
|
|
||||||
self.ElevatorDoorsConstructor:ToggleElevatorDoorsAsync(true, Attributes.CurrentFloor.Value)
|
|
||||||
--Some hacks
|
|
||||||
Doors.Attributes.Relay.Open.Value = true
|
|
||||||
end)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function Elevator.constructor(TagsConstructor, ButtonsTags, LanternsTags, LandingDoors)
|
function Elevator.constructor(TagsConstructor, ButtonsTags, LanternsTags, LandingDoors)
|
||||||
@@ -341,7 +245,7 @@ function Elevator.constructor(TagsConstructor, ButtonsTags, LanternsTags, Landin
|
|||||||
self.BoxAlignPosition,
|
self.BoxAlignPosition,
|
||||||
self.BoxAlignOrientation = ElevatorMover(
|
self.BoxAlignOrientation = ElevatorMover(
|
||||||
self.ElevatorBox_1960,
|
self.ElevatorBox_1960,
|
||||||
Vector3.new(self.ElevatorBox_1960.Position.X, LevelingModule.Leveling[Attributes.Relay.Goal.Value] or LevelingModule.Leveling[1], self.ElevatorBox_1960.Position.Z),
|
Vector3.new(self.ElevatorBox_1960.Position.X, LevelingModule.Leveling[Attributes.Goal.Value] or LevelingModule.Leveling[1], self.ElevatorBox_1960.Position.Z),
|
||||||
Elevator.Responsiveness,
|
Elevator.Responsiveness,
|
||||||
Elevator.MaxVelocity
|
Elevator.MaxVelocity
|
||||||
)
|
)
|
||||||
@@ -359,103 +263,128 @@ function Elevator.constructor(TagsConstructor, ButtonsTags, LanternsTags, Landin
|
|||||||
self.ElevatorBox_1960
|
self.ElevatorBox_1960
|
||||||
)
|
)
|
||||||
|
|
||||||
self.RelayConstructor:BulkConnect()
|
--self.RelayConstructor:BulkConnect()
|
||||||
|
|
||||||
self.__Connections.FloorSorted = self.RelayAlgorithmConstructor.Events.Sorted.Event:Connect(function(FloorQueue: RelayAlgorithm.FloorQueue)
|
|
||||||
print("Floors sorted")
|
|
||||||
if FloorQueue[1] then
|
|
||||||
Attributes.Relay.Goal.Value = FloorQueue[1] :: number
|
|
||||||
else
|
|
||||||
Attributes.Relay.Goal.Value = 1
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
|
|
||||||
local ClassConstructor = setmetatable(self, Elevator)
|
local ClassConstructor = setmetatable(self, Elevator)
|
||||||
IterateButtons(ClassConstructor, ButtonsTagsConstructor)
|
|
||||||
|
|
||||||
ElevatorInit(self)
|
|
||||||
print(`🔝 {Elevator.Name} initialized and ready`)
|
|
||||||
|
|
||||||
|
elevatorprint("Initialized and ready")
|
||||||
return ClassConstructor
|
return ClassConstructor
|
||||||
end
|
end
|
||||||
|
|
||||||
function Elevator:__MovingHeartbeat(GoingUp, RequestedLevel)
|
local CurrentFloor = Attributes.CurrentFloor.Value
|
||||||
|
|
||||||
|
local function CheckFloorQueue(self: ClassConstructor)
|
||||||
|
if self.RelayAlgorithmConstructor.__FloorQueue[1] ~= Attributes.CurrentFloor.Value then
|
||||||
|
elevatorwarn("The floor queue first index did not match the elevator's current floor, CurrentFloor=", Attributes.CurrentFloor.Value, "FloorQueue[1]=", self.RelayAlgorithmConstructor.__FloorQueue[1])
|
||||||
|
end
|
||||||
|
table.remove(self.RelayAlgorithmConstructor.__FloorQueue, 1)
|
||||||
|
|
||||||
local GoingTo_Y_Level = LevelingModule.Leveling[RequestedLevel]
|
local NextFloor = self.RelayAlgorithmConstructor.__FloorQueue[1]
|
||||||
if not GoingTo_Y_Level then
|
if NextFloor then
|
||||||
--fail safe
|
local ElevatorGoingUp = ElevatorGoingUpDirection(Attributes.CurrentFloor.Value, NextFloor)
|
||||||
warn(`{Elevator.Name}: floor request "{RequestedLevel}" failed`)
|
local LevelVec3 = LevelingModule.Leveling[NextFloor]
|
||||||
GoingTo_Y_Level = LevelingModule.Leveling[1]
|
|
||||||
|
self:__TravelToFloor(NextFloor, LevelVec3, ElevatorGoingUp)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local Delta = 0
|
local function CabTraveling(self: ClassConstructor, deltaTime: number, LevelVec3: number, ElevatorGoingUp: boolean)
|
||||||
|
local Elevator_Position = self.ElevatorBox_1960.Position
|
||||||
|
local Between_Levels = LevelingModule.LevelingBetween[CurrentFloor]
|
||||||
|
|
||||||
Attributes.GoingUp.Value = GoingUp
|
if ElevatorGoingUp then
|
||||||
Attributes.Relay.Goal.Value = RequestedLevel
|
--Detecting between the floors
|
||||||
Attributes.Moving.Value = true
|
if Elevator_Position.Y>=Between_Levels then
|
||||||
|
local PreviousFloor = CurrentFloor
|
||||||
|
CurrentFloor+=1
|
||||||
|
Attributes.CurrentFloor.Value = CurrentFloor
|
||||||
|
|
||||||
self.PhysicalRelays:SetState(GoingUp and "UP" or "DOWN", true, false)
|
Events.CabProgression:Fire(PreviousFloor, CurrentFloor)
|
||||||
self.PhysicalRelays:SetState("240 V", true, false)
|
end
|
||||||
self.PhysicalRelays:SetState("440 V", true, false)
|
|
||||||
|
|
||||||
self.MOConstructor:UpdateCFrame()
|
--Elevator is riding upwards towards the destination
|
||||||
|
if Elevator_Position.Y>=LevelVec3-Elevator.FloorLevelingDistance then
|
||||||
|
Events.Leveling:Fire()
|
||||||
|
self.BoxAlignPosition.MaxVelocity = Elevator.LevelingVelocity
|
||||||
|
|
||||||
self.BoxAlignPosition.MaxVelocity = Elevator.MaxVelocity
|
if Elevator_Position.Y>=LevelVec3-Elevator.FloorLeveling3PhaseDistance then
|
||||||
self.BoxAlignPosition.Position = Vector3.new(
|
Events.Leveling3Phase:Fire()
|
||||||
self.ElevatorBox_1960.Position.X,
|
self.BoxAlignPosition.MaxVelocity = Elevator.Phase3LevelingVelocity
|
||||||
GoingTo_Y_Level,
|
|
||||||
self.ElevatorBox_1960.Position.Z
|
|
||||||
)
|
|
||||||
|
|
||||||
self.__Connections.Moving = RS.Heartbeat:Connect(function(_dt)
|
if Elevator_Position.Y>=LevelVec3-Elevator.ParkedDistance then
|
||||||
Delta+=1
|
Events.Parked:Fire()
|
||||||
|
CheckFloorQueue(self);
|
||||||
|
|
||||||
|
(self.__Connections.Moving :: RBXScriptConnection):Disconnect()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
--Detecting between the floors
|
||||||
|
--leaving floor ElevatorPosition Y=62, Between_levels=75
|
||||||
|
if Elevator_Position.Y<=Between_Levels then
|
||||||
|
local PreviousFloor = CurrentFloor
|
||||||
|
CurrentFloor-=1
|
||||||
|
Attributes.CurrentFloor.Value = CurrentFloor
|
||||||
|
|
||||||
|
Events.CabProgression:Fire(PreviousFloor, CurrentFloor)
|
||||||
|
end
|
||||||
|
|
||||||
|
--Elevator is riding upwards towards the destination
|
||||||
|
if Elevator_Position.Y<=LevelVec3-Elevator.FloorLevelingDistance then
|
||||||
|
Events.Leveling:Fire()
|
||||||
|
self.BoxAlignPosition.MaxVelocity = Elevator.LevelingVelocity
|
||||||
|
|
||||||
|
if Elevator_Position.Y<=LevelVec3-Elevator.FloorLeveling3PhaseDistance then
|
||||||
|
Events.Leveling3Phase:Fire()
|
||||||
|
self.BoxAlignPosition.MaxVelocity = Elevator.Phase3LevelingVelocity
|
||||||
|
|
||||||
|
if Elevator_Position.Y<=LevelVec3-Elevator.ParkedDistance then
|
||||||
|
Events.Parked:Fire()
|
||||||
|
CheckFloorQueue(self);
|
||||||
|
|
||||||
|
(self.__Connections.Moving :: RBXScriptConnection):Disconnect()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
Events.CabTraveling:Fire(Elevator_Position)
|
||||||
|
end
|
||||||
|
|
||||||
|
function Elevator:__TravelToFloor(LevelInt, LevelVec3, ElevatorGoingUp)
|
||||||
|
if self.__Connections.Moving and self.__Connections.Moving.Connected then
|
||||||
|
self.__Connections.Moving:Disconnect()
|
||||||
|
end
|
||||||
|
|
||||||
|
Attributes.Goal.Value = LevelInt
|
||||||
|
Attributes.GoingUp.Value = ElevatorGoingUp
|
||||||
|
|
||||||
|
self.__Connections.Moving = RS.Heartbeat:Connect(function(deltaTime)
|
||||||
|
CabTraveling(self, deltaTime, LevelVec3, ElevatorGoingUp)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
--Set the elevator's AlignPosition to the floor Y vector
|
||||||
|
self.BoxAlignPosition.Position = Vector3.new(self.BoxAlignPosition.Position.X, LevelVec3, self.BoxAlignPosition.Position.Z)
|
||||||
|
--Set the elevator's max velocity to its fastest speed when moving starts
|
||||||
|
self.BoxAlignPosition.MaxVelocity = Elevator.MaxVelocity
|
||||||
end
|
end
|
||||||
|
|
||||||
function Elevator:__MoveToAsync(GoingUp, RequestedLevel)
|
function Elevator:RequestLevel(RequestedLevel)
|
||||||
if Doors.Attributes.Relay.Open.Value then
|
local LevelVec3 = LevelingModule.Leveling[RequestedLevel]
|
||||||
self.ElevatorDoorsConstructor:ToggleElevatorDoorsAsync(false, Attributes.CurrentFloor.Value)
|
|
||||||
end
|
|
||||||
|
|
||||||
if GoingUp then
|
if LevelVec3 then
|
||||||
self.LanternsConstructor:DirectionUp(true)
|
|
||||||
else
|
|
||||||
self.LanternsConstructor:DirectionDown(true)
|
|
||||||
end
|
|
||||||
|
|
||||||
self:__MovingHeartbeat(GoingUp, RequestedLevel)
|
|
||||||
end
|
|
||||||
|
|
||||||
function Elevator:RequestLevelAsync(RequestedLevel)
|
|
||||||
local FloorY_Level: number? = LevelingModule.Leveling[RequestedLevel]
|
|
||||||
|
|
||||||
if FloorY_Level and RequestedLevel ~= Attributes.CurrentFloor.Value then
|
|
||||||
local ElevatorGoingUp = ElevatorGoingUpDirection(Attributes.CurrentFloor.Value, RequestedLevel)
|
local ElevatorGoingUp = ElevatorGoingUpDirection(Attributes.CurrentFloor.Value, RequestedLevel)
|
||||||
local Proceeding = self.RelayAlgorithmConstructor:AddFloor(ElevatorGoingUp, RequestedLevel)
|
self.RelayAlgorithmConstructor:AddFloor(ElevatorGoingUp, RequestedLevel)
|
||||||
|
|
||||||
--Mmm... temporary, cant distinguish here if this will be a cab or hall call
|
if #self.RelayAlgorithmConstructor.__FloorQueue == 1 then
|
||||||
self.PhysicalRelays:SetState(`F{RequestedLevel}C`, true, true)
|
self:__TravelToFloor(RequestedLevel, LevelVec3, ElevatorGoingUp)
|
||||||
|
|
||||||
if Proceeding then
|
|
||||||
self.PhysicalRelays:SetState("RUN", true, false) --This needs to be on a timer for the generator after 60 seconds
|
|
||||||
self:__MoveToAsync(ElevatorGoingUp, RequestedLevel)
|
|
||||||
else
|
|
||||||
if ElevatorGoingUp == Attributes.GoingUp.Value then
|
|
||||||
self.BoxAlignPosition.Position = Vector3.new(
|
|
||||||
self.ElevatorBox_1960.Position.X,
|
|
||||||
LevelingModule.Leveling[self.RelayAlgorithmConstructor.__FloorQueue[1] or 1],
|
|
||||||
self.ElevatorBox_1960.Position.Z
|
|
||||||
)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return true
|
return true
|
||||||
else
|
|
||||||
warn(`[{Elevator.Name}]: landing out of range or equals the same range as the goal, requested landing: {tostring(RequestedLevel)}`)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
elevatorwarn(`Requested floor: "{RequestedLevel}" does not exist for this elevator`)
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -54,3 +54,16 @@ local Otis1960Lanterns = Lanterns[Enums.Elevator.Otis1960]
|
|||||||
local Otis1960Buttons = Buttons[Enums.Elevator.Otis1960]
|
local Otis1960Buttons = Buttons[Enums.Elevator.Otis1960]
|
||||||
local Otis1960LandingDoors = LandingDoors[Enums.Elevator.Otis1960]
|
local Otis1960LandingDoors = LandingDoors[Enums.Elevator.Otis1960]
|
||||||
local Otis1960 = Otis1960_Module.constructor(TagsConstructor, Otis1960Buttons, Otis1960Lanterns, Otis1960LandingDoors)
|
local Otis1960 = Otis1960_Module.constructor(TagsConstructor, Otis1960Buttons, Otis1960Lanterns, Otis1960LandingDoors)
|
||||||
|
|
||||||
|
task.wait(5)
|
||||||
|
Otis1960:RequestLevel(3)
|
||||||
|
|
||||||
|
Otis1960_Module.Events.Parked.Event:Connect(function()
|
||||||
|
print("Cab parked")
|
||||||
|
task.wait(3)
|
||||||
|
Otis1960:RequestLevel(1)
|
||||||
|
end)
|
||||||
|
|
||||||
|
Otis1960_Module.Events.CabProgression.Event:Connect(function(previousFloor: number?, nextFloor: number)
|
||||||
|
print("previousFloor=",previousFloor, "nextFloor=",nextFloor)
|
||||||
|
end)
|
||||||
@@ -28,7 +28,8 @@ export type InteractablesValues = typeof(Enums.InteractType.LightSwitch) |
|
|||||||
typeof(Enums.InteractType.Light) |
|
typeof(Enums.InteractType.Light) |
|
||||||
typeof(Enums.InteractType.LightSource)
|
typeof(Enums.InteractType.LightSource)
|
||||||
|
|
||||||
export type ElevatorValues = typeof(Enums.Elevator.Otis1960)
|
export type ElevatorValues = typeof(Enums.Elevator.Otis1960) |
|
||||||
|
typeof(Enums.Elevator.Haughton)
|
||||||
|
|
||||||
Enums.Button = {
|
Enums.Button = {
|
||||||
Car = "CarButton" :: "CarButton",
|
Car = "CarButton" :: "CarButton",
|
||||||
@@ -50,7 +51,8 @@ Enums.SpecialButton = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Enums.Elevator = {
|
Enums.Elevator = {
|
||||||
Otis1960 = "Otis1960" :: "Otis1960"
|
Otis1960 = "Otis1960" :: "Otis1960",
|
||||||
|
Haughton = "Haughton" :: "Haughton"
|
||||||
}
|
}
|
||||||
|
|
||||||
Enums.InteractType = {
|
Enums.InteractType = {
|
||||||
|
|||||||
Reference in New Issue
Block a user