directional based cab call placement, needs tweaked a bit

This commit is contained in:
2024-05-12 00:38:36 -04:00
parent 438abcca56
commit bb17304cbf
5 changed files with 121 additions and 62 deletions

View File

@@ -13,7 +13,7 @@ local Enums = require(Storage:WaitForChild("Enums"))
local PromptModule = require(Main:WaitForChild("Map"):WaitForChild("Prompts")) local PromptModule = require(Main:WaitForChild("Map"):WaitForChild("Prompts"))
local Tags = require(Load:WaitForChild("Tags")) local Tags = require(Load:WaitForChild("Tags"))
type ButtonActivatedCallback = (Floor: number) -> () type ButtonActivatedCallback = (ButtonFloor: number) -> ()
type ClassConstructor = typeof(setmetatable({} :: Constructor_Return_Props, {} :: Impl_Constructor)) type ClassConstructor = typeof(setmetatable({} :: Constructor_Return_Props, {} :: Impl_Constructor))
type Impl_Constructor = { type Impl_Constructor = {
@@ -39,7 +39,6 @@ type Constructor_Return_Props = {
} }
type ElevatorAttributes = { type ElevatorAttributes = {
PassingFloor: IntValue,
CurrentFloor: IntValue, CurrentFloor: IntValue,
Moving: BoolValue, Moving: BoolValue,
} }
@@ -55,6 +54,8 @@ type ElevatorButtonColors = {
LanternDisplayOff: Color3, LanternDisplayOff: Color3,
} }
export type ButtonsConstructor = ClassConstructor
local ButtonFunctions = {} :: Impl_Constructor local ButtonFunctions = {} :: Impl_Constructor
ButtonFunctions.__index = ButtonFunctions ButtonFunctions.__index = ButtonFunctions
@@ -144,7 +145,7 @@ function ButtonFunctions:AestheticActivateButton(Button)
end end
Button.Position+=LookVec Button.Position+=LookVec
task.wait(.30) task.wait(ButtonFunctions.ButtonHoldDuration)
if Glass then if Glass then
Glass.Position-=LookVec Glass.Position-=LookVec

View File

@@ -161,14 +161,18 @@ function Lanterns:DirectionDown(Enabled)
end end
function Lanterns:Toggle(Enabled, Floor) function Lanterns:Toggle(Enabled, Floor)
local f = self.LanternsMap[Floor] local FloorLantern = self.LanternsMap[Floor]
if FloorLantern then
if not Enabled then if not Enabled then
f.Played = false FloorLantern.Played = false
end end
if not f.Played then if not FloorLantern.Played then
f.Played = true FloorLantern.Played = true
self:Activate(Enabled, false, f, true) self:Activate(Enabled, false, FloorLantern, true)
end
else
warn(`Floor Lantern does not exist for floor: {Floor}`, debug.traceback())
end end
end end

View File

@@ -279,15 +279,15 @@ end
function Doors:ToggleElevatorDoors(opening, floor) function Doors:ToggleElevatorDoors(opening, floor)
--short circuiting central --short circuiting central
if opening then if opening then
if Doors.Closed then if not Attributes.DoorsOpen.Value then
Doors.Closed = not Doors.Closed Attributes.DoorsOpen.Value = not Attributes.DoorsOpen.Value
else else
warn("Doors are already closed, doing nothing") warn("Doors are already closed, doing nothing")
return return
end end
else else
if not Doors.Closed then if Attributes.DoorsOpen.Value then
Doors.Closed = not Doors.Closed Attributes.DoorsOpen.Value = not Attributes.DoorsOpen.Value
else else
warn("Doors are already open, doing nothing") warn("Doors are already open, doing nothing")
return return

View File

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

View File

@@ -36,7 +36,7 @@ type Constructor_Return_Props = {
Buttons: Tags.ButtonsTree Buttons: Tags.ButtonsTree
} }
export type ButtonsConstructor = ClassConstructor export type ButtonsTagsConstructor = ClassConstructor
local ButtonsModule = {} :: Impl_Constructor local ButtonsModule = {} :: Impl_Constructor
ButtonsModule.__index = ButtonsModule ButtonsModule.__index = ButtonsModule