mirror of
https://github.com/unixtensor/Roblox-Elevator-Game.git
synced 2025-12-14 14:51:55 +00:00
a
This commit is contained in:
@@ -31,7 +31,7 @@ CrosshairModule.__index = CrosshairModule
|
||||
CrosshairModule.Icon = "rbxassetid://12643750723"
|
||||
|
||||
local Storage = game:GetService("ReplicatedStorage")
|
||||
local Easings = require(Storage:WaitForChild("Algebra"))
|
||||
local Algbera = require(Storage:WaitForChild("Algebra"))
|
||||
|
||||
function CrosshairModule.constructor(PlayerGui: PlayerGui)
|
||||
local Screen = PlayerGui:WaitForChild("Crosshair") :: ScreenGui
|
||||
@@ -57,7 +57,7 @@ end
|
||||
function CrosshairModule:Jump(RootVelocity: Vector3)
|
||||
local X, Y = RootVelocity.X, RootVelocity.Y;
|
||||
self.Icon.Position = UDim2.fromScale(
|
||||
Y>1 and Easings.Linear(.5,.5+(X/1000),.3) or .5,
|
||||
Y>1 and Algbera.Easing.Linear(.5,.5+(X/1000),.3) or .5,
|
||||
math.clamp(.4, .5-(-Y/1000), .6)
|
||||
)
|
||||
end
|
||||
|
||||
@@ -180,8 +180,8 @@ local function ElevatorDoorsAnimationAsync<T,U>(self: ClassConstructor<T,U>, ope
|
||||
self.ElevatorDoor1.CanCollide = false
|
||||
self.ElevatorDoor2.CanCollide = false
|
||||
|
||||
local ElevatorDoor1_P: Vector3 = self.ElevatorDoor1.Position
|
||||
local ElevatorDoor2_P: Vector3 = self.ElevatorDoor2.Position
|
||||
local ElevatorDoor1_P = self.ElevatorDoor1.Position
|
||||
local ElevatorDoor2_P = self.ElevatorDoor2.Position
|
||||
|
||||
local StartTime = os.clock()
|
||||
local Timing = Doors.ElevatorDoorTime-1
|
||||
@@ -189,13 +189,14 @@ local function ElevatorDoorsAnimationAsync<T,U>(self: ClassConstructor<T,U>, ope
|
||||
if opening then
|
||||
while task.wait() do
|
||||
local Time = Algebra.LinearElapse(StartTime, Timing)
|
||||
local Ease = Algebra.Easing.InOutQuad(Time)
|
||||
|
||||
local ElevatorBoxY = Vector3.new(0, self.ElevatorBox.Position.Y, 0)
|
||||
local Door1Vector = Vector3.new(ElevatorDoor1_P.X, 0, ElevatorDoor1_P.Z)
|
||||
local Door2Vector = Vector3.new(ElevatorDoor2_P.X, 0, ElevatorDoor2_P.Z)
|
||||
|
||||
self.ElevatorDoor1.Position = ElevatorBoxY+Door1Vector:Lerp(Door1Vector-Doors.Door1Stopped_X, Time)
|
||||
self.ElevatorDoor2.Position = ElevatorBoxY+Door2Vector:Lerp(Door2Vector-Doors.Door2Stopped_X, Time)
|
||||
self.ElevatorDoor1.Position = ElevatorBoxY+Door1Vector:Lerp(Door1Vector-Doors.Door1Stopped_X, Ease)
|
||||
self.ElevatorDoor2.Position = ElevatorBoxY+Door2Vector:Lerp(Door2Vector-Doors.Door2Stopped_X, Ease)
|
||||
|
||||
if Time>=1 then
|
||||
break
|
||||
@@ -204,13 +205,14 @@ local function ElevatorDoorsAnimationAsync<T,U>(self: ClassConstructor<T,U>, ope
|
||||
else
|
||||
while task.wait() do
|
||||
local Time = Algebra.LinearElapse(StartTime, Timing)
|
||||
local Ease = Algebra.Easing.InOutQuad(Time)
|
||||
|
||||
local ElevatorBoxY = Vector3.new(0, self.ElevatorBox.Position.Y, 0)
|
||||
local Door1Vector = Vector3.new(ElevatorDoor1_P.X, 0, ElevatorDoor1_P.Z)
|
||||
local Door2Vector = Vector3.new(ElevatorDoor2_P.X, 0, ElevatorDoor2_P.Z)
|
||||
|
||||
self.ElevatorDoor1.Position = ElevatorBoxY+Door1Vector:Lerp(Door1Vector+Doors.Door1Stopped_X, Time)
|
||||
self.ElevatorDoor2.Position = ElevatorBoxY+Door2Vector:Lerp(Door2Vector+Doors.Door2Stopped_X, Time)
|
||||
self.ElevatorDoor1.Position = ElevatorBoxY+Door1Vector:Lerp(Door1Vector+Doors.Door1Stopped_X, Ease)
|
||||
self.ElevatorDoor2.Position = ElevatorBoxY+Door2Vector:Lerp(Door2Vector+Doors.Door2Stopped_X, Ease)
|
||||
|
||||
if Time>=1 then
|
||||
break
|
||||
|
||||
@@ -21,7 +21,8 @@ type Impl_Constructor = {
|
||||
__index: Impl_Constructor,
|
||||
constructor: Constructor_Fun,
|
||||
--Class functions
|
||||
SetState: (self: ClassConstructor, RelayName: string, State: boolean, ActivateImmediately: boolean) -> ()
|
||||
SetState: (self: ClassConstructor, RelayName: string, State: boolean, ActivateImmediately: boolean) -> (),
|
||||
DisconnectButCabButtons: (self: ClassConstructor) -> ()
|
||||
}
|
||||
|
||||
type Constructor_Fun = (ElevatorModel: Enums.ElevatorValues, RelayTagList: Tags.RelayDictionary) -> ClassConstructor
|
||||
@@ -60,6 +61,51 @@ local function OtimLowPassSoundEffect(Model: Enums.ElevatorValues): OtimSoundEff
|
||||
}
|
||||
end
|
||||
|
||||
local function OtimSoundAndRelayConfiguration(RelayAudioActivated: Sound, RelayAudioDeActivated: Sound, SoundEffects: OtimSoundEffects, RelayProperties: Tags.RelayProperties)
|
||||
RelayAudioActivated.SoundGroup = SoundEffects.SoundGroup
|
||||
RelayAudioDeActivated.SoundGroup = SoundEffects.SoundGroup
|
||||
|
||||
if RelayProperties.Name == "240 V" or
|
||||
RelayProperties.Name == "440 V" or
|
||||
RelayProperties.Name == "UP" or
|
||||
RelayProperties.Name == "DOWN"
|
||||
then
|
||||
--Bigger relays
|
||||
RelayAudioActivated.SoundId = SoundEnums.Otis1960.BigRelayActivated
|
||||
RelayAudioDeActivated.SoundId = SoundEnums.Otis1960.BigRelayDeActivated
|
||||
RelayAudioActivated.Volume = .5
|
||||
RelayAudioDeActivated.Volume = .5
|
||||
RelayProperties.Unique = true
|
||||
else
|
||||
--High placed relays for better spatial sound
|
||||
if RelayProperties.Name == "F1C" or
|
||||
RelayProperties.Name == "F2C" or
|
||||
RelayProperties.Name == "F3C" or
|
||||
RelayProperties.Name == "F4C" or
|
||||
RelayProperties.Name == "F5C" or
|
||||
RelayProperties.Name == "F6C" or
|
||||
RelayProperties.Name == "F7C" or
|
||||
RelayProperties.Name == "F8C" or
|
||||
RelayProperties.Name == "F9C" or
|
||||
RelayProperties.Name == "F10C"
|
||||
then
|
||||
RelayAudioActivated.SoundId = SoundEnums.Otis1960.RelayHighActivated
|
||||
RelayAudioDeActivated.SoundId = SoundEnums.Otis1960.RelayDeActivated
|
||||
|
||||
if RelayProperties.Prompt and (RelayProperties.Name ~= "F1C" and RelayProperties.Name ~= "F2C") then
|
||||
RelayProperties.Prompt.MaxActivationDistance = 4
|
||||
end
|
||||
else
|
||||
--Low placed relays
|
||||
RelayAudioActivated.SoundId = SoundEnums.Otis1960.RelayLowActivated
|
||||
RelayAudioDeActivated.SoundId = SoundEnums.Otis1960.RelayDeActivated
|
||||
end
|
||||
end
|
||||
|
||||
RelayAudioActivated.RollOffMaxDistance = 130
|
||||
RelayAudioActivated.RollOffMinDistance = 5
|
||||
end
|
||||
|
||||
function PhysicalRelay.constructor(ElevatorModel, RelayTagList)
|
||||
local SoundEffects: OtimSoundEffects?
|
||||
|
||||
@@ -72,54 +118,14 @@ function PhysicalRelay.constructor(ElevatorModel, RelayTagList)
|
||||
for RelayName, RelayProperties in RelayTagList do
|
||||
if RelayProperties.Inst then
|
||||
--Audio
|
||||
|
||||
local RelayAudioActivated = Instance.new("Sound") :: Sound
|
||||
local RelayAudioDeActivated = Instance.new("Sound") :: Sound
|
||||
|
||||
if ElevatorModel == Enums.Elevator.Otis1960 then
|
||||
|
||||
RelayAudioActivated.SoundGroup = (SoundEffects :: OtimSoundEffects).SoundGroup
|
||||
RelayAudioDeActivated.SoundGroup = (SoundEffects :: OtimSoundEffects).SoundGroup
|
||||
|
||||
if RelayProperties.Name == "240 V" or
|
||||
RelayProperties.Name == "440 V" or
|
||||
RelayProperties.Name == "UP" or
|
||||
RelayProperties.Name == "DOWN"
|
||||
then
|
||||
--Bigger relays
|
||||
RelayAudioActivated.SoundId = SoundEnums.Otis1960.BigRelayActivated
|
||||
RelayAudioDeActivated.SoundId = SoundEnums.Otis1960.BigRelayDeActivated
|
||||
RelayAudioActivated.Volume = .5
|
||||
RelayAudioDeActivated.Volume = .5
|
||||
RelayProperties.Unique = true
|
||||
else
|
||||
--High placed relays for better spatial sound
|
||||
if RelayProperties.Name == "F1C" or
|
||||
RelayProperties.Name == "F2C" or
|
||||
RelayProperties.Name == "F3C" or
|
||||
RelayProperties.Name == "F4C" or
|
||||
RelayProperties.Name == "F5C" or
|
||||
RelayProperties.Name == "F6C" or
|
||||
RelayProperties.Name == "F7C" or
|
||||
RelayProperties.Name == "F8C" or
|
||||
RelayProperties.Name == "F9C" or
|
||||
RelayProperties.Name == "F10C"
|
||||
then
|
||||
RelayAudioActivated.SoundId = SoundEnums.Otis1960.RelayHighActivated
|
||||
RelayAudioDeActivated.SoundId = SoundEnums.Otis1960.RelayDeActivated
|
||||
|
||||
if RelayProperties.Prompt then
|
||||
RelayProperties.Prompt.MaxActivationDistance = 4
|
||||
end
|
||||
else
|
||||
--Low placed relays
|
||||
RelayAudioActivated.SoundId = SoundEnums.Otis1960.RelayLowActivated
|
||||
RelayAudioDeActivated.SoundId = SoundEnums.Otis1960.RelayDeActivated
|
||||
end
|
||||
if SoundEffects then
|
||||
OtimSoundAndRelayConfiguration(RelayAudioActivated, RelayAudioDeActivated, SoundEffects, RelayProperties)
|
||||
end
|
||||
|
||||
RelayAudioActivated.RollOffMaxDistance = 130
|
||||
RelayAudioActivated.RollOffMinDistance = 5
|
||||
RelayAudioActivated.Parent = RelayProperties.Inst
|
||||
RelayAudioDeActivated.Parent = RelayProperties.Inst
|
||||
end
|
||||
@@ -172,7 +178,7 @@ function PhysicalRelay:SetState(RelayName, State, ActivateImmediately)
|
||||
if ActivateImmediately then
|
||||
OtimRelayAnimation(Relay, State)
|
||||
else
|
||||
task.delay(Random.new():NextNumber(.1,.8), function()
|
||||
task.delay(Random.new():NextNumber(.1,1), function()
|
||||
OtimRelayAnimation(Relay, State)
|
||||
end)
|
||||
end
|
||||
@@ -186,4 +192,12 @@ function PhysicalRelay:SetState(RelayName, State, ActivateImmediately)
|
||||
end
|
||||
end
|
||||
|
||||
function PhysicalRelay:DisconnectButCabButtons()
|
||||
for RelayName, Relay in self.RelayTagList do
|
||||
if not RelayName:match('F%d+C') and Relay.Inst then
|
||||
OtimRelayAnimation(Relay, false)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return PhysicalRelay
|
||||
@@ -22,10 +22,8 @@ type Impl_Constructor = {
|
||||
--Class functions
|
||||
BulkConnect: (self: ClassConstructor) -> (),
|
||||
BulkDisconnect: (self: ClassConstructor) -> (),
|
||||
__Ready: (self: ClassConstructor) -> (),
|
||||
__Open: (self: ClassConstructor) -> (),
|
||||
__Goal: (self: ClassConstructor) -> (),
|
||||
__GoalYLevel: (self: ClassConstructor) -> (),
|
||||
}
|
||||
|
||||
type Constructor_Fun = (
|
||||
@@ -50,7 +48,6 @@ type Constructor_Return_Props = {
|
||||
__Connections: {
|
||||
ReadyForMoving: RBXScriptConnection?,
|
||||
Open: RBXScriptConnection?,
|
||||
GoalYLevel: RBXScriptConnection?,
|
||||
Goal: RBXScriptConnection?
|
||||
}
|
||||
}
|
||||
@@ -58,7 +55,6 @@ type Constructor_Return_Props = {
|
||||
type ElevatorAttributes = {
|
||||
Relay: {
|
||||
ReadyForMoving: BoolValue,
|
||||
GoalYLevel: NumberValue,
|
||||
Goal: IntValue
|
||||
},
|
||||
|
||||
@@ -86,40 +82,16 @@ function Relay.constructor(PhysicalRelay, RelayAlgorthm, ElevatorAttributes, Doo
|
||||
}, Relay)
|
||||
end
|
||||
|
||||
function Relay:__Ready()
|
||||
if not self.ElevatorAttributes.Relay.ReadyForMoving.Value then
|
||||
self:__GoalYLevel()
|
||||
end
|
||||
end
|
||||
|
||||
function Relay:__Open()
|
||||
self.ElevatorAttributes.Relay.ReadyForMoving.Value = not self.DoorAttributes.Relay.Open.Value
|
||||
end
|
||||
|
||||
function Relay:__GoalYLevel()
|
||||
if self.ElevatorAttributes.Relay.ReadyForMoving.Value then
|
||||
self.BoxAlignPosition.Position = Vector3.new(
|
||||
self.ElevatorBox.Position.X,
|
||||
self.ElevatorAttributes.Relay.GoalYLevel.Value,
|
||||
self.ElevatorBox.Position.Z
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
function Relay:__Goal()
|
||||
self.ElevatorAttributes.Relay.GoalYLevel.Value = self.LevelingModule.Leveling[self.ElevatorAttributes.Relay.Goal.Value] or self.LevelingModule.Leveling[1] :: number
|
||||
end
|
||||
|
||||
function Relay:BulkConnect()
|
||||
local ReadyForMovingRelay = self.ElevatorAttributes.Relay.ReadyForMoving
|
||||
local OpenRelay = self.DoorAttributes.Relay.Open
|
||||
|
||||
self.__Connections.ReadyForMoving = ReadyForMovingRelay:GetPropertyChangedSignal("Value"):Connect(function()
|
||||
self.PhysicalRelay:SetState("RD", ReadyForMovingRelay.Value, false)
|
||||
|
||||
if not self.ElevatorAttributes.Stopped.Value then
|
||||
self:__Ready()
|
||||
end
|
||||
end)
|
||||
|
||||
self.__Connections.Open = OpenRelay:GetPropertyChangedSignal("Value"):Connect(function()
|
||||
@@ -129,22 +101,6 @@ function Relay:BulkConnect()
|
||||
self:__Open()
|
||||
end
|
||||
end)
|
||||
|
||||
self.__Connections.GoalYLevel = self.ElevatorAttributes.Relay.GoalYLevel:GetPropertyChangedSignal("Value"):Connect(function()
|
||||
|
||||
|
||||
if not self.ElevatorAttributes.Stopped.Value then
|
||||
self:__GoalYLevel()
|
||||
end
|
||||
end)
|
||||
|
||||
self.__Connections.Goal = self.ElevatorAttributes.Relay.Goal:GetPropertyChangedSignal("Value"):Connect(function()
|
||||
|
||||
|
||||
if not self.ElevatorAttributes.Stopped.Value then
|
||||
self:__Goal()
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
function Relay:BulkDisconnect()
|
||||
@@ -154,12 +110,6 @@ function Relay:BulkDisconnect()
|
||||
if self.__Connections.Open and self.__Connections.Open.Connected then
|
||||
self.__Connections.Open:Disconnect()
|
||||
end
|
||||
if self.__Connections.GoalYLevel and self.__Connections.GoalYLevel.Connected then
|
||||
self.__Connections.GoalYLevel:Disconnect()
|
||||
end
|
||||
if self.__Connections.Goal and self.__Connections.Goal.Connected then
|
||||
self.__Connections.Goal:Disconnect()
|
||||
end
|
||||
end
|
||||
|
||||
return Relay
|
||||
@@ -8,7 +8,7 @@ type Impl_Constructor = {
|
||||
constructor: Constructor_Fun,
|
||||
--Class functions
|
||||
Sort: (self: ClassConstructor, ElevatorGoingUp: boolean) -> (),
|
||||
Check: (self: ClassConstructor, ElevatorGoingUp: boolean) -> (),
|
||||
Check: (self: ClassConstructor, ElevatorGoingUp: boolean) -> number?,
|
||||
RawInsert: (self: ClassConstructor, ElevatorGoingUp: boolean, RequestedLevel: number) -> (),
|
||||
AddFloor: (self: ClassConstructor, ElevatorGoingUp: boolean, RequestedLevel: number) -> boolean
|
||||
}
|
||||
@@ -69,9 +69,8 @@ function RelayAlgorithm:Sort(ElevatorGoingUp)
|
||||
table.sort(self.__FloorQueue, function(a, b): boolean
|
||||
if ElevatorGoingUp then
|
||||
return a<b
|
||||
else
|
||||
return a>b
|
||||
end
|
||||
return a>b
|
||||
end)
|
||||
self.Events.Sorted:Fire(self.__FloorQueue)
|
||||
end
|
||||
@@ -82,9 +81,9 @@ function RelayAlgorithm:Check(ElevatorGoingUp)
|
||||
end
|
||||
if #self.__FloorQueue ~= 0 then
|
||||
self:Sort(ElevatorGoingUp)
|
||||
return true
|
||||
return self.__FloorQueue[1]
|
||||
end
|
||||
return false
|
||||
return nil
|
||||
end
|
||||
|
||||
function RelayAlgorithm:RawInsert(ElevatorGoingUp, RequestedLevel)
|
||||
|
||||
@@ -62,13 +62,14 @@ type Impl_Constructor = {
|
||||
} & Impl_Static_Props
|
||||
|
||||
type Impl_Static_Props = {
|
||||
Name: Enums.ElevatorValues,
|
||||
Responsiveness: number,
|
||||
MaxVelocity: number,
|
||||
FloorLevelingDistance: number,
|
||||
DoorOpeningDistance: number,
|
||||
LeveledDistance: number,
|
||||
QueueWaitTime: number,
|
||||
Name: Enums.ElevatorValues,
|
||||
Responsiveness: number,
|
||||
MaxVelocity: number,
|
||||
FloorLevelingDistance: number,
|
||||
FloorLeveling3PhaseDistance: number,
|
||||
DoorOpeningDistance: number,
|
||||
LeveledDistance: number,
|
||||
QueueWaitTime: number,
|
||||
|
||||
Sounds: {
|
||||
LanternChimeDirection: SoundEnums.Otis1960LanternChimeDirection,
|
||||
@@ -88,7 +89,6 @@ type Impl_Static_Props = {
|
||||
|
||||
Relay: {
|
||||
Goal: IntValue,
|
||||
GoalYLevel: NumberValue,
|
||||
ReadyForMoving: BoolValue,
|
||||
}
|
||||
}
|
||||
@@ -137,13 +137,14 @@ type Constructor_Return_Props = {
|
||||
local Elevator = {} :: Impl_Constructor
|
||||
Elevator.__index = Elevator
|
||||
|
||||
Elevator.Name = Enums.Elevator.Otis1960
|
||||
Elevator.FloorLevelingDistance = 2.5
|
||||
Elevator.DoorOpeningDistance = Elevator.FloorLevelingDistance/2.8
|
||||
Elevator.LeveledDistance = 0.5
|
||||
Elevator.Responsiveness = 10
|
||||
Elevator.MaxVelocity = 8
|
||||
Elevator.QueueWaitTime = 5
|
||||
Elevator.Name = Enums.Elevator.Otis1960
|
||||
Elevator.FloorLevelingDistance = 4
|
||||
Elevator.FloorLeveling3PhaseDistance = 1.5
|
||||
Elevator.DoorOpeningDistance = Elevator.FloorLeveling3PhaseDistance/2.8
|
||||
Elevator.LeveledDistance = 0.5
|
||||
Elevator.Responsiveness = 10
|
||||
Elevator.MaxVelocity = 7
|
||||
Elevator.QueueWaitTime = 5
|
||||
|
||||
Elevator.Sounds = {
|
||||
LanternChimeDirection = SoundEnums.Otis1960.LanternChimeDirection,
|
||||
@@ -164,9 +165,8 @@ Elevator.Attributes = {
|
||||
Stopped = Instance.new("BoolValue") :: BoolValue,
|
||||
|
||||
Relay = {
|
||||
ReadyForMoving = Instance.new("BoolValue") :: BoolValue,
|
||||
Goal = Instance.new("IntValue") :: IntValue,
|
||||
GoalYLevel = Instance.new("NumberValue") :: NumberValue,
|
||||
ReadyForMoving = Instance.new("BoolValue") :: BoolValue,
|
||||
Goal = Instance.new("IntValue") :: IntValue,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -175,7 +175,6 @@ Elevator.Attributes.Moving.Value = false
|
||||
Elevator.Attributes.GoingUp.Value = false
|
||||
|
||||
Elevator.Attributes.Relay.Goal.Value = 1
|
||||
Elevator.Attributes.Relay.GoalYLevel.Value = LevelingModule.Leveling[Elevator.Attributes.CurrentFloor.Value]
|
||||
Elevator.Attributes.Relay.ReadyForMoving.Value = false
|
||||
|
||||
local Attributes = Elevator.Attributes
|
||||
@@ -212,8 +211,6 @@ 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,
|
||||
--then open the doors
|
||||
local function OpenElevatorDoorsSafe(self: ClassConstructor)
|
||||
print("Relay.Open=",Doors.Attributes.Relay.Open.Value,"Relay.ReadyForMoving=",Attributes.Relay.ReadyForMoving.Value)
|
||||
|
||||
if not Attributes.Relay.ReadyForMoving.Value then
|
||||
task.spawn(function()
|
||||
self.ElevatorDoorsConstructor:ToggleElevatorDoorsAsync(true, Attributes.CurrentFloor.Value)
|
||||
@@ -344,7 +341,7 @@ function Elevator.constructor(TagsConstructor, ButtonsTags, LanternsTags, Landin
|
||||
self.BoxAlignPosition,
|
||||
self.BoxAlignOrientation = ElevatorMover(
|
||||
self.ElevatorBox_1960,
|
||||
Vector3.new(self.ElevatorBox_1960.Position.X, Elevator.Attributes.Relay.GoalYLevel.Value, self.ElevatorBox_1960.Position.Z),
|
||||
Vector3.new(self.ElevatorBox_1960.Position.X, LevelingModule.Leveling[Attributes.Relay.Goal.Value] or LevelingModule.Leveling[1], self.ElevatorBox_1960.Position.Z),
|
||||
Elevator.Responsiveness,
|
||||
Elevator.MaxVelocity
|
||||
)
|
||||
@@ -365,8 +362,11 @@ function Elevator.constructor(TagsConstructor, ButtonsTags, LanternsTags, Landin
|
||||
self.RelayConstructor:BulkConnect()
|
||||
|
||||
self.__Connections.FloorSorted = self.RelayAlgorithmConstructor.Events.Sorted.Event:Connect(function(FloorQueue: RelayAlgorithm.FloorQueue)
|
||||
if Attributes.Moving.Value and FloorQueue[1] then
|
||||
print("Floors sorted")
|
||||
if FloorQueue[1] then
|
||||
Attributes.Relay.Goal.Value = FloorQueue[1] :: number
|
||||
else
|
||||
Attributes.Relay.Goal.Value = 1
|
||||
end
|
||||
end)
|
||||
|
||||
@@ -381,8 +381,8 @@ end
|
||||
|
||||
local function Leveled(self: ClassConstructor, RequestedLevel: number)
|
||||
(self.__Connections.Moving :: RBXScriptConnection):Disconnect()
|
||||
Attributes.Moving.Value = false
|
||||
Attributes.CurrentFloor.Value = RequestedLevel
|
||||
Attributes.Moving.Value = false
|
||||
Attributes.CurrentFloor.Value = RequestedLevel
|
||||
--self.BoxAlignPosition.MaxVelocity = 0
|
||||
|
||||
self.LanternsConstructor:Reset(Attributes.CurrentFloor.Value)
|
||||
@@ -392,12 +392,15 @@ local function Leveled(self: ClassConstructor, RequestedLevel: number)
|
||||
self.PhysicalRelays:SetState("240 V", false, false)
|
||||
|
||||
task.wait(Elevator.QueueWaitTime)
|
||||
|
||||
local ElevatorGoingUp = ElevatorGoingUpDirection(Attributes.CurrentFloor.Value, RequestedLevel)
|
||||
|
||||
if self.RelayAlgorithmConstructor:Check(ElevatorGoingUp) then
|
||||
local ElevatorGoingUp = ElevatorGoingUpDirection(Attributes.CurrentFloor.Value, Attributes.Relay.Goal.Value)
|
||||
|
||||
print("CurrentFloor=",Attributes.CurrentFloor.Value,"Goal=",Attributes.Relay.Goal.Value)
|
||||
local NextLevel = self.RelayAlgorithmConstructor:Check(ElevatorGoingUp)
|
||||
if NextLevel then
|
||||
--More floors in the queue
|
||||
self:__MoveToAsync(ElevatorGoingUp, RequestedLevel)
|
||||
print(self.RelayAlgorithmConstructor.__FloorQueue)
|
||||
--self:__MoveToAsync(ElevatorGoingUp, NextLevel)
|
||||
else
|
||||
--The elevator is at a full park now
|
||||
Attributes.Relay.ReadyForMoving.Value = false
|
||||
@@ -405,12 +408,16 @@ local function Leveled(self: ClassConstructor, RequestedLevel: number)
|
||||
end
|
||||
|
||||
local function Leveling(self: ClassConstructor, RequestedLevel: number)
|
||||
self.PhysicalRelays:SetState("440 V", false, false)
|
||||
self.PhysicalRelays:SetState("440 V", false, true)
|
||||
|
||||
self.BoxAlignPosition.MaxVelocity = 1
|
||||
self.LanternsConstructor:Toggle(true, RequestedLevel)
|
||||
end
|
||||
|
||||
local function Leveling3Phase(self: ClassConstructor, RequestedLevel: number)
|
||||
self.BoxAlignPosition.MaxVelocity = .4
|
||||
end
|
||||
|
||||
local function FloorPassingUp(self: ClassConstructor, ElevatorPositionY: number, RequestedLevel: number)
|
||||
local NextLevelBetweenFloors: number? = LevelingModule.LevelingBetween[Attributes.CurrentFloor.Value+1]
|
||||
|
||||
@@ -438,6 +445,13 @@ function Elevator:__MovingHeartbeat(GoingUp, RequestedLevel)
|
||||
self.__Connections.Moving:Disconnect()
|
||||
end
|
||||
|
||||
local GoingTo_Y_Level = LevelingModule.Leveling[RequestedLevel]
|
||||
if not GoingTo_Y_Level then
|
||||
--fail safe
|
||||
warn(`{Elevator.Name}: floor request "{RequestedLevel}" failed`)
|
||||
GoingTo_Y_Level = LevelingModule.Leveling[1]
|
||||
end
|
||||
|
||||
local Delta = 0
|
||||
local DoorsOpeningDebounce = false
|
||||
|
||||
@@ -448,18 +462,25 @@ function Elevator:__MovingHeartbeat(GoingUp, RequestedLevel)
|
||||
self.PhysicalRelays:SetState(GoingUp and "UP" or "DOWN", true, false)
|
||||
self.PhysicalRelays:SetState("240 V", true, false)
|
||||
self.PhysicalRelays:SetState("440 V", true, false)
|
||||
|
||||
self.MOConstructor:UpdateCFrame()
|
||||
|
||||
self.BoxAlignPosition.MaxVelocity = Elevator.MaxVelocity
|
||||
self.BoxAlignPosition.Position = Vector3.new(
|
||||
self.ElevatorBox_1960.Position.X,
|
||||
GoingTo_Y_Level,
|
||||
self.ElevatorBox_1960.Position.Z
|
||||
)
|
||||
|
||||
--task.wait(1)
|
||||
self.__Connections.Moving = RS.Heartbeat:Connect(function(_dt)
|
||||
Delta+=1
|
||||
|
||||
local ElevatorPosition: Vector3 = self.ElevatorBox_1960.Position
|
||||
local ElevatorPositionY: number = ElevatorPosition.Y
|
||||
local BoxAlignY: number = self.BoxAlignPosition.Position.Y
|
||||
local ElevatorVelocityY: number = self.ElevatorBox_1960:GetVelocityAtPosition(ElevatorPosition).Y
|
||||
local ElevatorPosition = self.ElevatorBox_1960.Position
|
||||
local ElevatorPositionY = ElevatorPosition.Y
|
||||
local BoxAlignY = self.BoxAlignPosition.Position.Y
|
||||
local ElevatorVelocityY = self.ElevatorBox_1960:GetVelocityAtPosition(ElevatorPosition).Y
|
||||
|
||||
self.TractionRopesConstructor:Move(27, self.ElevatorBox_1960.Position)
|
||||
self.TractionRopesConstructor:Move(27, ElevatorPosition)
|
||||
self.MOConstructor:Frame_Pullies(Delta, ElevatorVelocityY)
|
||||
|
||||
--Kill the connection
|
||||
@@ -469,9 +490,13 @@ function Elevator:__MovingHeartbeat(GoingUp, RequestedLevel)
|
||||
if ElevatorPositionY>=BoxAlignY-Elevator.FloorLevelingDistance then
|
||||
Leveling(self, Attributes.Relay.Goal.Value)
|
||||
|
||||
if not DoorsOpeningDebounce and ElevatorPositionY>=BoxAlignY-Elevator.DoorOpeningDistance then
|
||||
DoorsOpeningDebounce = true
|
||||
self.ElevatorDoorsConstructor:ToggleElevatorDoorsAsync(true, Attributes.Relay.Goal.Value)
|
||||
if ElevatorPositionY>=BoxAlignY-Elevator.FloorLeveling3PhaseDistance then
|
||||
Leveling3Phase(self, RequestedLevel)
|
||||
|
||||
if not DoorsOpeningDebounce and ElevatorPositionY>=BoxAlignY-Elevator.DoorOpeningDistance then
|
||||
DoorsOpeningDebounce = true
|
||||
self.ElevatorDoorsConstructor:ToggleElevatorDoorsAsync(true, Attributes.Relay.Goal.Value)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -484,9 +509,13 @@ function Elevator:__MovingHeartbeat(GoingUp, RequestedLevel)
|
||||
if ElevatorPositionY<=BoxAlignY+Elevator.FloorLevelingDistance then
|
||||
Leveling(self, Attributes.Relay.Goal.Value)
|
||||
|
||||
if not DoorsOpeningDebounce and ElevatorPositionY>=BoxAlignY-Elevator.DoorOpeningDistance then
|
||||
DoorsOpeningDebounce = true
|
||||
self.ElevatorDoorsConstructor:ToggleElevatorDoorsAsync(true, Attributes.Relay.Goal.Value)
|
||||
if ElevatorPositionY<=BoxAlignY+Elevator.FloorLeveling3PhaseDistance then
|
||||
Leveling3Phase(self, RequestedLevel)
|
||||
|
||||
if not DoorsOpeningDebounce and ElevatorPositionY<=BoxAlignY+Elevator.DoorOpeningDistance then
|
||||
DoorsOpeningDebounce = true
|
||||
self.ElevatorDoorsConstructor:ToggleElevatorDoorsAsync(true, Attributes.Relay.Goal.Value)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -501,6 +530,7 @@ function Elevator:__MoveToAsync(GoingUp, RequestedLevel)
|
||||
if Doors.Attributes.Relay.Open.Value then
|
||||
self.ElevatorDoorsConstructor:ToggleElevatorDoorsAsync(false, Attributes.CurrentFloor.Value)
|
||||
end
|
||||
|
||||
if GoingUp then
|
||||
self.LanternsConstructor:DirectionUp(true)
|
||||
else
|
||||
@@ -511,11 +541,11 @@ function Elevator:__MoveToAsync(GoingUp, RequestedLevel)
|
||||
end
|
||||
|
||||
function Elevator:RequestLevelAsync(RequestedLevel)
|
||||
local FloorExist: number? = LevelingModule.Leveling[RequestedLevel]
|
||||
local FloorY_Level: number? = LevelingModule.Leveling[RequestedLevel]
|
||||
|
||||
if FloorExist and RequestedLevel ~= Attributes.CurrentFloor.Value then
|
||||
if FloorY_Level and RequestedLevel ~= Attributes.CurrentFloor.Value then
|
||||
local ElevatorGoingUp = ElevatorGoingUpDirection(Attributes.CurrentFloor.Value, RequestedLevel)
|
||||
local Proceeding = self.RelayAlgorithmConstructor:AddFloor(ElevatorGoingUp, RequestedLevel)
|
||||
local Proceeding = self.RelayAlgorithmConstructor:AddFloor(ElevatorGoingUp, RequestedLevel)
|
||||
|
||||
--Mmm... temporary, cant distinguish here if this will be a cab or hall call
|
||||
self.PhysicalRelays:SetState(`F{RequestedLevel}C`, true, true)
|
||||
@@ -523,11 +553,21 @@ function Elevator:RequestLevelAsync(RequestedLevel)
|
||||
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
|
||||
|
||||
return true
|
||||
else
|
||||
warn(`[{Elevator.Name}]: landing out of range or equals the same range as the goal, requested landing: {tostring(RequestedLevel)}`)
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
|
||||
--My versions
|
||||
|
||||
type EaseFunction = (n: number) -> number
|
||||
type LinearFunction = (a: number, b: number, t: number) -> number
|
||||
type Ease = (n: number) -> number
|
||||
type Linear = (a: number, b: number, t: number) -> number
|
||||
|
||||
export type RotationMatrix = {
|
||||
Ixx: number,
|
||||
@@ -18,15 +18,22 @@ export type RotationMatrix = {
|
||||
|
||||
export type Scalar = {
|
||||
Distance: number,
|
||||
Center: Vector2,
|
||||
Center: Vector2,
|
||||
Rotation: number
|
||||
}
|
||||
|
||||
export type Easing = {
|
||||
Linear: Linear,
|
||||
InOutBack: Ease,
|
||||
OutBounce: Ease,
|
||||
InQuad: Ease,
|
||||
OutQuad: Ease,
|
||||
InOutQuad: Ease,
|
||||
InOutQuart: Ease,
|
||||
}
|
||||
|
||||
export type Math = {
|
||||
Linear: LinearFunction,
|
||||
InOutBack: EaseFunction,
|
||||
OutBounce: EaseFunction,
|
||||
InQuad: EaseFunction,
|
||||
Easing: Easing,
|
||||
IsOdd: (n: number) -> boolean,
|
||||
IsEven: (n: number) -> boolean,
|
||||
RotationMatrix: (X: number, Y: number, Z: number) -> RotationMatrix,
|
||||
@@ -36,7 +43,9 @@ export type Math = {
|
||||
minmax: (min: number, n: number, max: number) -> number
|
||||
}
|
||||
|
||||
local Math = {} :: Math
|
||||
local Math = {
|
||||
Easing = {}
|
||||
} :: Math
|
||||
|
||||
function Math.IsOdd(n)
|
||||
return bit32.btest(bit32.band(n, 1))
|
||||
@@ -81,24 +90,43 @@ function Math.LinearElapse(StartTime, Timing)
|
||||
end
|
||||
|
||||
--My versions
|
||||
function Math.Linear(a, b, t)
|
||||
function Math.Easing.Linear(a, b, t)
|
||||
return a-a*t+b*t
|
||||
end
|
||||
|
||||
local c = 2.59491
|
||||
function Math.InOutBack(n)
|
||||
function Math.Easing.InOutBack(n)
|
||||
return n<.5 and 2*n*n*(-c+2*n+2*c*n) or 3*(-1+n)*(-1+n)*(-2-c+2*n+2*c*n)
|
||||
end
|
||||
|
||||
local n1, d1 = 7.5625, 2.75
|
||||
function Math.OutBounce(n)
|
||||
function Math.Easing.OutBounce(n)
|
||||
return (n<0.363636 and n*n*n1 or
|
||||
n<0.727273 and (.75*(1.*d1-2.*n*n1)) or
|
||||
n<0.909091 and (.9375*(1.*d1-2.4*n*n1)/d1)) or (.984375*(1.*d1-2.66667*n*n1))/d1
|
||||
end
|
||||
|
||||
function Math.InQuad(n)
|
||||
function Math.Easing.InQuad(n)
|
||||
return n*n
|
||||
end
|
||||
|
||||
function Math.Easing.OutQuad(n)
|
||||
return -((-2+n)*n)
|
||||
end
|
||||
|
||||
function Math.Easing.InOutQuad(n)
|
||||
-- n<.5 and 2*n*n or -1-2*(-2+n)*n
|
||||
-- -n*math.abs(n)+n
|
||||
-- n-.5*n*math.abs(n)
|
||||
-- n-n*math.abs(n)
|
||||
|
||||
return n<.5 and 2*n*n or -1-2*(-2+n)*n
|
||||
end
|
||||
|
||||
function Math.Easing.InOutQuart(n)
|
||||
--n<.5 and 8*n*n*n*n or 1-(-2*n+2)*(-2*n+2)*(-2*n+2)*(-2*n+2)/2
|
||||
|
||||
return n<.5 and 8*n*n*n*n or 1-8*(-1+n)*(-1+n)*(-1+n)*(-1+n)
|
||||
end
|
||||
|
||||
return Math
|
||||
Reference in New Issue
Block a user