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

View File

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

View File

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

View File

@@ -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,7 +322,10 @@ 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
@@ -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

View File

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