mirror of
https://github.com/unixtensor/Roblox-Elevator-Game.git
synced 2025-12-15 21:51:55 +00:00
No work motiviation but hooked the relay algorithm to the elevator
This commit is contained in:
@@ -58,7 +58,7 @@ type Impl_Constructor = {
|
||||
FloorPassingUp: (self: ClassConstructor, ElevatorPositionY: number, RequestedLevel: number) -> (),
|
||||
FloorPassingDown: (self: ClassConstructor, ElevatorPositionY: number, RequestedLevel: number) -> (),
|
||||
RequestLevel: (self: ClassConstructor, RequestedLevel: number) -> boolean,
|
||||
__GoToFloor: (self: ClassConstructor, Level: number, GoingUp: boolean) -> (),
|
||||
__Move: (self: ClassConstructor, Level: number, GoingUp: boolean) -> (),
|
||||
__MovingHeartbeat: (self: ClassConstructor, GoingUp: boolean) -> (),
|
||||
} & Impl_Static_Props
|
||||
|
||||
@@ -83,7 +83,7 @@ type Impl_Static_Props = {
|
||||
},
|
||||
Attributes: {
|
||||
CurrentFloor: IntValue,
|
||||
GoalFloor: IntValue,
|
||||
Goal: IntValue,
|
||||
Moving: BoolValue,
|
||||
GoingUp: BoolValue,
|
||||
Stopped: BoolValue
|
||||
@@ -146,7 +146,7 @@ Elevator.Colors = {
|
||||
|
||||
Elevator.Attributes = {
|
||||
CurrentFloor = Instance.new("IntValue") :: IntValue,
|
||||
GoalFloor = Instance.new("IntValue") :: IntValue,
|
||||
Goal = Instance.new("IntValue") :: IntValue,
|
||||
Moving = Instance.new("BoolValue") :: BoolValue,
|
||||
GoingUp = Instance.new("BoolValue") :: BoolValue,
|
||||
Stopped = Instance.new("BoolValue") :: BoolValue
|
||||
@@ -157,7 +157,7 @@ Elevator.Events = {
|
||||
}
|
||||
|
||||
Elevator.Attributes.CurrentFloor.Value = 1
|
||||
Elevator.Attributes.GoalFloor.Value = 1
|
||||
Elevator.Attributes.Goal.Value = 1
|
||||
Elevator.Attributes.Moving.Value = false
|
||||
Elevator.Attributes.GoingUp.Value = false
|
||||
|
||||
@@ -176,7 +176,7 @@ local function _ActivatedFloorButton(self: ClassConstructor, ButtonFloor: number
|
||||
local FloorTracker: RBXScriptConnection
|
||||
|
||||
FloorTracker = Attributes.CurrentFloor:GetPropertyChangedSignal("Value"):Connect(function()
|
||||
if Attributes.CurrentFloor.Value == ButtonFloor and Attributes.GoalFloor.Value == ButtonFloor then
|
||||
if Attributes.CurrentFloor.Value == ButtonFloor and Attributes.Goal.Value == ButtonFloor then
|
||||
FloorTracker:Disconnect()
|
||||
|
||||
self.ButtonsConstructor:__DeactivateButton(ButtonTree.Inst :: BasePart, (ButtonTree.Inst :: BasePart):FindFirstChild("Glass") :: BasePart?)
|
||||
@@ -185,6 +185,7 @@ local function _ActivatedFloorButton(self: ClassConstructor, ButtonFloor: number
|
||||
end)
|
||||
else
|
||||
warn(`Failed to call floor: {ButtonFloor}`)
|
||||
ButtonTree.Prompt.Enabled = true
|
||||
end
|
||||
end
|
||||
|
||||
@@ -220,7 +221,7 @@ local function HookButtons(self: ClassConstructor, ButtonNameType: Enums.ButtonT
|
||||
(ButtonTree.Inst :: BasePart).Position-=Vector3.new(0,0,.05)
|
||||
|
||||
self.LanternsConstructor:Reset()
|
||||
self:__GoToFloor(Leveling[Attributes.CurrentFloor.Value], ElevatorGoingUpDirection(Attributes.CurrentFloor.Value, Attributes.GoalFloor.Value))
|
||||
self:__GoToFloor(Leveling[Attributes.CurrentFloor.Value], ElevatorGoingUpDirection(Attributes.CurrentFloor.Value, Attributes.Goal.Value))
|
||||
self.BoxAlignPosition.MaxVelocity = Elevator.MaxVelocity
|
||||
end
|
||||
end)
|
||||
@@ -318,7 +319,6 @@ function Elevator:Leveled(RequestedLevel)
|
||||
Attributes.Moving.Value = false
|
||||
Attributes.CurrentFloor.Value = RequestedLevel
|
||||
self.BoxAlignPosition.MaxVelocity = Elevator.MaxVelocity
|
||||
|
||||
self.LanternsConstructor:Reset(Attributes.CurrentFloor.Value)
|
||||
|
||||
task.wait(Elevator.QueueWaitTime)
|
||||
@@ -327,8 +327,7 @@ function Elevator:Leveled(RequestedLevel)
|
||||
|
||||
if self.RelayAlgorithmConstructor:Check(ElevatorGoingUp) then
|
||||
--More floors in the queue
|
||||
Attributes.GoingUp.Value = ElevatorGoingUp
|
||||
self:__GoToFloor(Leveling[self.RelayAlgorithmConstructor.__FloorQueue[1]], ElevatorGoingUp)
|
||||
self:__Move(Leveling[self.RelayAlgorithmConstructor.__FloorQueue[1]], ElevatorGoingUp)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -356,22 +355,21 @@ function Elevator:FloorPassingDown(ElevatorPositionY, RequestedLevel)
|
||||
end
|
||||
|
||||
function Elevator:__MovingHeartbeat(GoingUp)
|
||||
local Delta = 0
|
||||
local DoorsOpeningEvent = false
|
||||
Attributes.GoingUp.Value = GoingUp
|
||||
|
||||
if self.__MovingConnection and self.__MovingConnection.Connected then
|
||||
self.__MovingConnection:Disconnect()
|
||||
end
|
||||
|
||||
--Only used for the X and Z axis
|
||||
local ElevatorPositionInit: Vector3 = self.ElevatorBox_1960.Position
|
||||
|
||||
local Delta = 0
|
||||
local DoorsOpeningEvent = false
|
||||
|
||||
self.__MovingConnection = RS.Heartbeat:Connect(function(_dt)
|
||||
Delta+=1
|
||||
local FloorGoal: number = self.RelayAlgorithmConstructor.__FloorQueue[1]
|
||||
|
||||
Attributes.Moving.Value = true
|
||||
Attributes.GoalFloor.Value = FloorGoal
|
||||
Attributes.Goal.Value = FloorGoal
|
||||
|
||||
local ElevatorPosition: Vector3 = self.ElevatorBox_1960.Position
|
||||
local ElevatorPositionY: number = ElevatorPosition.Y
|
||||
@@ -413,16 +411,13 @@ function Elevator:__MovingHeartbeat(GoingUp)
|
||||
self:Leveled(FloorGoal)
|
||||
end
|
||||
end
|
||||
|
||||
self.BoxAlignPosition.Position = Vector3.new(ElevatorPositionInit.X, Leveling[FloorGoal], ElevatorPositionInit.Z)
|
||||
end)
|
||||
end
|
||||
|
||||
function Elevator:__GoToFloor(GoalLevelVEC, GoingUp)
|
||||
if Doors.Attributes.DoorsOpen.Value then
|
||||
function Elevator:__Move(GoalLevelVEC, GoingUp)
|
||||
if Doors.Attributes.Open.Value then
|
||||
self.ElevatorDoorsConstructor:ToggleElevatorDoorsAsync(false, Attributes.CurrentFloor.Value)
|
||||
end
|
||||
|
||||
if GoingUp then
|
||||
self.LanternsConstructor:DirectionUp(true)
|
||||
else
|
||||
@@ -431,9 +426,9 @@ function Elevator:__GoToFloor(GoalLevelVEC, GoingUp)
|
||||
|
||||
self.MOConstructor:UpdateCFrame()
|
||||
self:__MovingHeartbeat(GoingUp)
|
||||
|
||||
local ElevatorBoxCurrentPos = self.ElevatorBox_1960.Position
|
||||
self.BoxAlignPosition.Position = Vector3.new(ElevatorBoxCurrentPos.X, GoalLevelVEC, ElevatorBoxCurrentPos.Z)
|
||||
|
||||
local ElevatorPositionInit = self.ElevatorBox_1960.Position
|
||||
self.BoxAlignPosition.Position = Vector3.new(ElevatorPositionInit.X, GoalLevelVEC, ElevatorPositionInit.Z)
|
||||
end
|
||||
|
||||
function Elevator:RequestLevel(RequestedLevel)
|
||||
@@ -441,19 +436,15 @@ function Elevator:RequestLevel(RequestedLevel)
|
||||
|
||||
if GoalLevelVEC and GoalLevelVEC ~= Attributes.CurrentFloor.Value then
|
||||
local ElevatorGoingUp = ElevatorGoingUpDirection(Attributes.CurrentFloor.Value, RequestedLevel)
|
||||
local Proceeding = self.RelayAlgorithmConstructor:AddFloor(ElevatorGoingUp, RequestedLevel)
|
||||
|
||||
if Attributes.Moving.Value then
|
||||
self.RelayAlgorithmConstructor:Insert(ElevatorGoingUp, RequestedLevel)
|
||||
if Proceeding then
|
||||
self:__Move(GoalLevelVEC, ElevatorGoingUp)
|
||||
else
|
||||
if Doors.Attributes.DoorsOpen then
|
||||
Attributes.GoingUp.Value = ElevatorGoingUp
|
||||
|
||||
if Doors.Attributes.DoorsOpen and #self.RelayAlgorithmConstructor.__FloorQueue == 0 then
|
||||
self:__GoToFloor(GoalLevelVEC, ElevatorGoingUp)
|
||||
end
|
||||
self.RelayAlgorithmConstructor:Insert(ElevatorGoingUp, RequestedLevel)
|
||||
else
|
||||
self.RelayAlgorithmConstructor:Insert(ElevatorGoingUp, RequestedLevel)
|
||||
if not Doors.Attributes.Open.Value then
|
||||
local ElevatorPositionInit = self.ElevatorBox_1960.Position
|
||||
self.BoxAlignPosition.Position = Vector3.new(ElevatorPositionInit.X, Leveling[self.RelayAlgorithmConstructor.__FloorQueue[1]], ElevatorPositionInit.Z)
|
||||
print(Doors.Attributes.Open.Value)
|
||||
end
|
||||
end
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user