mirror of
https://github.com/unixtensor/Roblox-Elevator-Game.git
synced 2025-12-14 14:51:55 +00:00
need the floor algorithm
This commit is contained in:
@@ -40,8 +40,8 @@ type Constructor_Return_Props = {
|
|||||||
|
|
||||||
type ElevatorAttributes = {
|
type ElevatorAttributes = {
|
||||||
PassingFloor: IntValue,
|
PassingFloor: IntValue,
|
||||||
|
CurrentFloor: IntValue,
|
||||||
Moving: BoolValue,
|
Moving: BoolValue,
|
||||||
CurrentFloor: IntValue
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type ElevatorEvents = {
|
type ElevatorEvents = {
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ type Impl_Constructor = {
|
|||||||
__index: Impl_Constructor,
|
__index: Impl_Constructor,
|
||||||
constructor: Constructor_Fun,
|
constructor: Constructor_Fun,
|
||||||
--Class functions
|
--Class functions
|
||||||
__MoveFloors: (self: ClassConstructor, Level: number, RequestedLevel: number, GoingUp: boolean) -> (),
|
__RequestFloor: (self: ClassConstructor, Level: number, RequestedLevel: number, GoingUp: boolean) -> (),
|
||||||
RequestLevel: (self: ClassConstructor, RequestedLevel: number) -> ()
|
RequestLevel: (self: ClassConstructor, RequestedLevel: number) -> ()
|
||||||
} & Impl_Static_Props
|
} & Impl_Static_Props
|
||||||
|
|
||||||
@@ -129,8 +129,8 @@ Otis1960.Events = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Otis1960.Attributes.PassingFloor.Value = 1
|
Otis1960.Attributes.PassingFloor.Value = 1
|
||||||
Otis1960.Attributes.Moving.Value = false
|
|
||||||
Otis1960.Attributes.CurrentFloor.Value = 1
|
Otis1960.Attributes.CurrentFloor.Value = 1
|
||||||
|
Otis1960.Attributes.Moving.Value = false
|
||||||
|
|
||||||
local Attributes = Otis1960.Attributes
|
local Attributes = Otis1960.Attributes
|
||||||
|
|
||||||
@@ -259,7 +259,9 @@ local function FloorPassingDown(self: ClassConstructor, ElevatorPositionY: numbe
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function Otis1960:__MoveFloors(GoalLevelVEC, RequestedLevel, GoingUp)
|
local FloorQueue = {}
|
||||||
|
|
||||||
|
function Otis1960:__RequestFloor(GoalLevelVEC, RequestedLevel, GoingUp)
|
||||||
self.ElevatorDoors:ToggleElevatorDoors(false, Attributes.CurrentFloor.Value)
|
self.ElevatorDoors:ToggleElevatorDoors(false, Attributes.CurrentFloor.Value)
|
||||||
|
|
||||||
if self.__MovingConnection and self.__MovingConnection.Connected then
|
if self.__MovingConnection and self.__MovingConnection.Connected then
|
||||||
@@ -327,8 +329,6 @@ function Otis1960:__MoveFloors(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
|
||||||
|
|
||||||
local FloorAdvancer = {}
|
|
||||||
|
|
||||||
--My clever math function for determining if the elevator goal is to move upwards or not
|
--My clever math function for determining if the elevator goal is to move upwards or not
|
||||||
local function ElevatorDirectionGoingUp(Floor: number, RequestedFloor: number): boolean
|
local function ElevatorDirectionGoingUp(Floor: number, RequestedFloor: number): boolean
|
||||||
return -(Floor-RequestedFloor)>0
|
return -(Floor-RequestedFloor)>0
|
||||||
@@ -338,21 +338,10 @@ function Otis1960:RequestLevel(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
|
||||||
--My clever math function for determining if the elevator goal is to move upwards or not
|
|
||||||
local GoingUp = ElevatorDirectionGoingUp(Attributes.CurrentFloor.Value, RequestedLevel)
|
|
||||||
|
|
||||||
if Attributes.Moving.Value then
|
if Attributes.Moving.Value then
|
||||||
if GoingUp then
|
|
||||||
if Attributes.CurrentFloor.Value<=RequestedLevel then
|
|
||||||
self:__MoveFloors(GoalLevelVEC, RequestedLevel, GoingUp)
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
if Attributes.CurrentFloor.Value>=RequestedLevel then
|
self:__RequestFloor(GoalLevelVEC, RequestedLevel, ElevatorDirectionGoingUp(Attributes.CurrentFloor.Value, RequestedLevel))
|
||||||
self:__MoveFloors(GoalLevelVEC, RequestedLevel, GoingUp)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
else
|
|
||||||
self:__MoveFloors(GoalLevelVEC, RequestedLevel, 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)}`)
|
||||||
|
|||||||
Reference in New Issue
Block a user