godot-psd-training/sceen/totalOfLargePassengerFlow.gd
2024-07-22 11:18:50 +08:00

437 lines
18 KiB
GDScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

extends TotalScene
class_name LargePassengerFlowScene
## 照相机名字的枚举
enum Camera_name{
#VehicleControlRoom,#车控室
SparePartsCabinet,#备品柜
PartsArea,#备品区
StationHall,#站厅
UpPlatform,#上行站台
DownPlatform,#下行站台
#APassageway,#A出入口
StationHallAExit,#站厅A出口
AEntrance,#A入口
APassage,#A口通道
#BPassageway,#B出入口
StationHallBExit,#站厅B出口
BEntrance,#B入口
BPassage,#B口通道
#CPassageway,#C出入口
StationHallCExit,#站厅C出口
CEntrance,#C入口
CPassage,#C口通道
#DPassageway,#D出入口
StationHallDExit,#站厅D出口
DEntrance,#D入口
DPassage,#D口通道
#StaionHallA,#站厅A端
ALowerStepSwitch,#A端扶梯下部开关
ATVM,#A端TVM
AInboundGate,#A端进站闸机
AExitGate,#A端出站闸机
AUpperStep,#A端扶梯上部
ALowerStep,#A端扶梯下部
AGangway,#A端站厅步梯口
#StationHallB,#站厅B端
BLowerStepSwitch,#B端扶梯下部开关
BTVM,#B端TVM
BInboundGate,#B端进站闸机
BExitGate,#B端出站闸机
BUpperStep,#B端扶梯上部
BLowerStep,#B端扶梯下部
BGangway,#B端站厅步梯口
}
@onready var cameras = $AllCamera.get_children()
var currentActiveCameraOfLarge:Camera_name = Camera_name.StationHall
##切换相机
func switchCamera (camera :Camera_name)-> void:
currentActiveCamera = cameras[camera]
currentActiveCameraOfLarge = camera
cameras[camera].make_current()
## 人运动区域的枚举
enum PlayerWalkArea3D {
entrance,#入口
passage,#通道
stationHallExit,#出口
ticketingArea, #购票区
entranceGateArea, #闸机入口区
assignArea,#选择步梯还是电梯
gangwayUpArea, #站厅步梯上
gangwayDownArea,#站厅步梯下
elevatorUpArea, #站厅电梯上
elevatorDownArea, #站厅电梯上
screenDoorWaitArea,#屏蔽门等待区域
}
const areaInfo = {
'A':{
'entrance':[Vector3(-60,9.8,43)],
'passage':Vector3(3,5.22,41),
'stationHallExit':Vector3(3,5.22,18.74),
'ticketingArea':[Vector3(-11.27,5.22,18.74)],
'entranceGateArea':[Vector3(-11.27,5.22,17.25),Vector3(36,5.22,17.25),Vector3(36,5.22,14.48)],
'assignArea':[Vector3(36,5.22,11.11),Vector3(33.9,5.22,11.11)],
'gangwayUpArea':[Vector3(33.9,5.22,7.45),Vector3(31,5.22,7.45),Vector3(22.95,3.17,7.45),Vector3(20.87,3.17,7.45)],
'gangwayDownArea': [Vector3(14.12,0.85,7.45),Vector3(11.6,0.85,7.45)],
'elevatorUpArea': [Vector3(30.22,5.22,11.11)],
'elevatorDownArea': [Vector3(14.12,0.85,11.11)],
},
'B':{
'entrance':[ Vector3(-54.8,9.8,-67.3),Vector3(-50,9.8,-64),Vector3(-30.1,9.8,-62.3)],
'passage':Vector3(1.92,5.22,-62.3),
'stationHallExit':Vector3(1.92,5.22,0),
},
'C':{'entrance':[Vector3(144.12,9.8,-60),Vector3(144.12,9.8,-68.7),Vector3(142,9.8,-68.7),Vector3(142,9.8,-60),Vector3(140,9.8,-60),Vector3(140,9.8,-67),Vector3(122.46,9.8,-66.38)],
'passage':Vector3(87.3,5.22,-66.38),
'stationHallExit':Vector3(87.3,5.22,-1.77),
},
'D':{'entrance':[Vector3(144.12,9.8,46),Vector3(144.12,9.8,36.58),Vector3(142,9.8,36.58),Vector3(142,9.8,46),Vector3(140,9.8,46),Vector3(140,9.8,38.28),Vector3(122.46,9.8,39.55)],
'passage':Vector3(93.38,5.22,39.55),
'stationHallExit':Vector3(93.38,5.22,21.04),
'ticketingArea':[Vector3(99,5.22,14.25),Vector3(99,5.22,7.86),Vector3(109.26,5.22,7.86)],
'entranceGateArea':[Vector3(109.26,5.22,6.86),Vector3(92,5.22,6.86),Vector3(92,5.22,12.98),Vector3(78.33,5.22,17.29),Vector3(56.29,5.22,17.29),Vector3(56.29,5.22,14.48)],
'gangwayUpArea':[Vector3(56,5.22,7.45),Vector3(61.46,5.22,7.45),Vector3(68.44,3.47,7.45),Vector3(68.44,3.47,7.45)],
'gangwayDownArea': [Vector3(77,0.85,7.45),Vector3(96.7,0.85,7.45)]
}
}
##区域运动(进站-连续的路径点)
func playerGoToNextArea(peopleWalkFollow:PlayerPathFollow,nextArea: PlayerWalkArea3D) -> void:
var targetAreaInfo = areaInfo[peopleWalkFollow.generateArea]
match nextArea:
PlayerWalkArea3D.entrance:
walkByPathFollow(targetAreaInfo.entrance,peopleWalkFollow)
await peopleWalkFollow.player.ArriveTargetPos
playerGoToNextArea(peopleWalkFollow,PlayerWalkArea3D.passage)
PlayerWalkArea3D.passage:
peopleWalkFollow.player.setTargetPos(targetAreaInfo.passage,0.1)
peopleWalkFollow.player.goToTarget()
await peopleWalkFollow.player.ArriveTargetPos
playerGoToNextArea(peopleWalkFollow,PlayerWalkArea3D.stationHallExit)
PlayerWalkArea3D.stationHallExit:
peopleWalkFollow.player.setTargetPos(targetAreaInfo.stationHallExit,0.1)
peopleWalkFollow.player.goToTarget()
await peopleWalkFollow.player.ArriveTargetPos
await get_tree().create_timer(1).timeout
if peopleWalkFollow.generateArea == 'A' and $AllAreaDetection/TicketingLfetAreaDetection.waitPeopleCount > 8:
peopleWalkFollow.generateArea = 'D'
walkByPathFollow([Vector3(6.66,5.22,18.74),Vector3(6.66,5.22,20.25),Vector3(85.58,5.22,20.25)],peopleWalkFollow)
await peopleWalkFollow.player.ArriveTargetPos
playerBackGoToNextArea(peopleWalkFollow,PlayerWalkArea3D.stationHallExit)
elif peopleWalkFollow.generateArea == 'B' || peopleWalkFollow.generateArea == 'C':
playerBackGoToNextArea(peopleWalkFollow,PlayerWalkArea3D.stationHallExit)
else :
playerGoToNextArea(peopleWalkFollow,PlayerWalkArea3D.ticketingArea)
PlayerWalkArea3D.ticketingArea:
walkByPathFollow(targetAreaInfo.ticketingArea,peopleWalkFollow)
await peopleWalkFollow.player.ArriveTargetPos
await get_tree().create_timer(3).timeout
playerGoToNextArea(peopleWalkFollow,PlayerWalkArea3D.entranceGateArea)
PlayerWalkArea3D.entranceGateArea:
#peopleWalkFollow.waitTimeWalkAgain = 0.5
walkByPathFollow(targetAreaInfo.entranceGateArea,peopleWalkFollow)
await peopleWalkFollow.player.ArriveTargetPos
await get_tree().create_timer(0.5).timeout
if peopleWalkFollow.generateArea == 'A' :
playerGoToNextArea(peopleWalkFollow,PlayerWalkArea3D.assignArea)
else :
playerGoToNextArea(peopleWalkFollow,PlayerWalkArea3D.gangwayUpArea)
PlayerWalkArea3D.assignArea:
walkByPathFollow(targetAreaInfo.assignArea,peopleWalkFollow)
await peopleWalkFollow.player.ArriveTargetPos
await get_tree().create_timer(0.2).timeout
var zhao = true
if zhao :
playerGoToNextArea(peopleWalkFollow,PlayerWalkArea3D.gangwayUpArea)
else :
playerGoToNextArea(peopleWalkFollow,PlayerWalkArea3D.elevatorUpArea)
PlayerWalkArea3D.gangwayUpArea:
walkByPathFollow(targetAreaInfo.gangwayUpArea,peopleWalkFollow)
await peopleWalkFollow.player.ArriveTargetPos
playerGoToNextArea(peopleWalkFollow,PlayerWalkArea3D.gangwayDownArea)
PlayerWalkArea3D.gangwayDownArea:
peopleWalkFollow.playerRotate(false)
await get_tree().create_timer(0.2).timeout
walkByPathFollow(targetAreaInfo.gangwayDownArea,peopleWalkFollow)
await peopleWalkFollow.player.ArriveTargetPos
peopleWalkFollow.queue_free()
#playerGoToNextArea(peopleWalkFollow,PlayerWalkArea3D.screenDoorWaitArea)
PlayerWalkArea3D.elevatorUpArea:
walkByPathFollow(targetAreaInfo.elevatorUpArea,peopleWalkFollow)
await peopleWalkFollow.player.ArriveTargetPos
peopleWalkFollow.playerRotate(false)
walkByPathFollow(targetAreaInfo.elevatorDownArea,peopleWalkFollow,Vector3(),"Idle")
await peopleWalkFollow.player.ArriveTargetPos
walkByPathFollow([Vector3(11.6,0.85,11.11)],peopleWalkFollow)
await peopleWalkFollow.player.ArriveTargetPos
peopleWalkFollow.playerRotate(true)
walkByPathFollow([Vector3(11.6,0.85,12.74)],peopleWalkFollow)
await peopleWalkFollow.player.ArriveTargetPos
peopleWalkFollow.queue_free()
PlayerWalkArea3D.elevatorDownArea:
walkByPathFollow(targetAreaInfo.elevatorDownArea,peopleWalkFollow)
await peopleWalkFollow.player.ArriveTargetPos
peopleWalkFollow.playerRotate(false)
walkByPathFollow(targetAreaInfo.elevatorUpArea,peopleWalkFollow,Vector3(),"Idle")
await peopleWalkFollow.player.ArriveTargetPos
peopleWalkFollow.queue_free()
PlayerWalkArea3D.screenDoorWaitArea:
goToScreenDoorAreaAndWaitTrain(peopleWalkFollow,0)
const areaBackInfo = {
'B':{
'stationHallExit':[Vector3(1.92,5.22,3.5),Vector3(5.3,5.22,3.5)],
'passage':Vector3(5.3,5.22,-66.15),
'entrance':[Vector3(-13,5.22,-66.15),Vector3(-30.1,9.8,-66.15)],
},
'C':{
'stationHallExit':[Vector3(82,5.22,6.75),Vector3(90,5.22,6.75)],
'passage':Vector3(90,5.22,-63.43),
'entrance':[Vector3(106.6,5.22,-63.43)],
},
'D':{
'stationHallExit':[Vector3(86.63,5.22,20.25)],
'passage':Vector3(86.63,5.22,42),
'entrance':[Vector3(105,5.22,42)],
},
}
##区域运动(出站)
var loopAntBEntrance = true
func playerBackGoToNextArea(peopleWalkFollow:PlayerPathFollow,nextArea: PlayerWalkArea3D) -> void:
var targetAreaInfo = areaBackInfo[peopleWalkFollow.generateArea]
match nextArea:
PlayerWalkArea3D.stationHallExit:
walkByPathFollow(targetAreaInfo.stationHallExit,peopleWalkFollow)
await peopleWalkFollow.player.ArriveTargetPos
playerBackGoToNextArea(peopleWalkFollow,PlayerWalkArea3D.passage)
PlayerWalkArea3D.passage:
peopleWalkFollow.player.setTargetPos(targetAreaInfo.passage,0.1)
peopleWalkFollow.player.goToTarget()
await peopleWalkFollow.player.ArriveTargetPos
if peopleWalkFollow.generateArea == 'B' and !loopAntBEntrance :
peopleWalkFollow.queue_free()
else :
playerBackGoToNextArea(peopleWalkFollow,PlayerWalkArea3D.entrance)
PlayerWalkArea3D.entrance:
walkByPathFollow(targetAreaInfo.entrance,peopleWalkFollow)
await peopleWalkFollow.player.ArriveTargetPos
if peopleWalkFollow.generateArea == 'C' or peopleWalkFollow.generateArea == 'D' :
peopleWalkFollow.queue_free()
playerGoToNextArea(peopleWalkFollow,PlayerWalkArea3D.entrance)
##演示排队的区域
var screenDoorAreaInfo = [
{
"areaName": "ScreenDoorWaitArea1",
"screenDoorName": 'screenDoor1',
},
{
"areaName": "ScreenDoorWaitArea2",
"screenDoorName": 'screenDoor2',
},
{
"areaName": "ScreenDoorWaitArea3",
"screenDoorName": 'screenDoor3',
},
{
"areaName": "ScreenDoorWaitArea4",
"screenDoorName": 'screenDoor4',
},
]
##进入指定屏蔽门区域并等待上车
func goToScreenDoorAreaAndWaitTrain(peopleWalkFollow:PlayerPathFollow, screenDoorAreaInfoIndex:int) -> void:
var screenDoorPos = $platform.get_node(screenDoorAreaInfo[screenDoorAreaInfoIndex].screenDoorName).get_node('dimiantishi').get_global_position()
screenDoorPos.z += 1.2
var addPoint = Vector3(screenDoorPos.x,screenDoorPos.y,screenDoorPos.z+3.2)
walkByPathFollow([addPoint,screenDoorPos],peopleWalkFollow)
await self.screenDoorOpenConfirmSignal
var trainPoint1 = Vector3(screenDoorPos.x,screenDoorPos.y,screenDoorPos.z-3.5)
var trainPoint2 = Vector3(screenDoorPos.x+3,screenDoorPos.y,screenDoorPos.z-3.5)
walkByPathFollow([trainPoint1,trainPoint2],peopleWalkFollow)
await self.screenDoorCloseConfirmSignal
peopleWalkFollow.queue_free()
const ArrayUtils = preload("res://util/ArrayUtils.gd")
func _on_screen_door_wait_area_screen_door_area_enter(curentArea: Area3D, peopleWalkFollow: PlayerPathFollow) -> void:
var waitPeopleCounts = [$AllScreenDoorWaitArea/ScreenDoorWaitArea1.waitPeopleCount,$AllScreenDoorWaitArea/ScreenDoorWaitArea2.waitPeopleCount,$AllScreenDoorWaitArea/ScreenDoorWaitArea3.waitPeopleCount,$AllScreenDoorWaitArea/ScreenDoorWaitArea4.waitPeopleCount]
for index in range(screenDoorAreaInfo.size()):
if screenDoorAreaInfo[index].areaName == curentArea.name and curentArea.waitPeopleCount-1 <= ArrayUtils.removeElementByIndex(waitPeopleCounts,index).min() :
peopleWalkFollow.peopleStopWalk()
goToScreenDoorAreaAndWaitTrain(peopleWalkFollow,index)
var trainLeaveAtDownPlatform = true
func _on_screen_door_wait_area_1_area_entered(area: Area3D) -> void:
if $AllScreenDoorWaitArea/ScreenDoorWaitArea1.waitPeopleCount>=4 and trainLeaveAtDownPlatform:
trainComeAndLeace()
##通过PathFollow运动
func walkByPathFollow(allTargetPos:Array,peopleWalkFollow:PlayerPathFollow,curveAngle=Vector3(),state = "Walk") -> void:
var walkPoints = [peopleWalkFollow.player.position]
for child in allTargetPos:
var xOffset = child.x - peopleWalkFollow.buildPos.x
var yOffset = child.y - peopleWalkFollow.buildPos.y
var zOffset = child.z - peopleWalkFollow.buildPos.z
walkPoints.append(Vector3(xOffset,yOffset,zOffset))
peopleWalkFollow.setPathPoints(walkPoints,curveAngle)
peopleWalkFollow.peopleBeginWalk(state)
##开始生成人的运动
var people_scene = preload("res://sceen/people/peopleWalkFollow.tscn")
func startGeneratePeople() -> void:
$AllTimer/generatePeopleAEntranceTimer.start()
$AllTimer/generatePeopleBEntranceTimer.start()
$AllTimer/generatePeopleAtBTicketingArea.start()
$AllTimer/generatePeopleDownPlatformTimer.start()
func startGeneratePeopleAtCD() -> void:
$AllTimer/generatePeopleCEntranceTimer.start()
$AllTimer/generatePeopleDEntranceTimer.start()
func stopGeneratePeopleAtA() -> void:
$AllTimer/generatePeopleAEntranceTimer.stop()
func stopGeneratePeopleAtB() -> void:
loopAntBEntrance = false
func stopGeneratePeopleAtC() -> void:
$AllTimer/generatePeopleCEntranceTimer.stop()
func stopGeneratePeopleAtD() -> void:
$AllTimer/generatePeopleDEntranceTimer.stop()
##A入口生成
var totalOfAEntrance=0
func generatePeopleAtAEntrance() -> void:
if $AllAreaDetection/APassageAreaDetection.passPeopleCount< 1 and currentActiveCameraOfLarge != Camera_name.APassage:
generatePeopleAPassage()
if $AllAreaDetection/TicketingLfetAreaDetection.waitPeopleCount< 1 and currentActiveCameraOfLarge != Camera_name.BTVM:
generatePeopleAtBTVM()
totalOfAEntrance += 1
var peoplePosition = Vector3(-80,9.8,40.5)
generatePeopleAtDesignatedArea(peoplePosition,PlayerWalkArea3D.entrance,'A','A{0}'.format([totalOfAEntrance]))
##A通道生成
var totalOfAPassage=0
func generatePeopleAPassage() -> void:
totalOfAPassage += 1
var peoplePosition = Vector3(3,5.22,41)
generatePeopleAtDesignatedArea(peoplePosition,PlayerWalkArea3D.stationHallExit,'A','APassage{0}'.format([totalOfAPassage]))
##A闸机生成
var totalOfBTVM=0
func generatePeopleAtBTVM() -> void:
totalOfBTVM += 1
var peoplePosition = Vector3(-11.27,5.22,17.66)
generatePeopleAtDesignatedArea(peoplePosition,PlayerWalkArea3D.entranceGateArea,'A','BTVM{0}'.format([totalOfBTVM]))
##售票厅循环排队
var totalOfBTicketingArea = 0
func generatePeopleAtBTicketingArea() -> void:
if $AllAreaDetection/TicketingAreaDetection.waitPeopleCount < 8:
var peoplrInstance = people_scene.instantiate()
add_child(peoplrInstance)
peoplrInstance.global_position = Vector3(1,5.22,15.84)
peoplrInstance.buildPos = Vector3(1,5.22,15.84)
totalOfBTicketingArea += 1
peoplrInstance.id = 'BTicketing{0}'.format([totalOfBTicketingArea])
walkByPathFollow([Vector3(-11.27,5.22,15.84)],peoplrInstance)
await peoplrInstance.player.ArriveTargetPos
await get_tree().create_timer(5).timeout
walkByPathFollow([Vector3(-11.27,5.22,14.4),Vector3(2,5.22,14.4)],peoplrInstance)
await peoplrInstance.player.ArriveTargetPos
peoplrInstance.queue_free()
##下行站台生成
func letPeopleWaitTrainAtDownPlatform() -> void:
currentNeedGenerate = 16
$AllTimer/generatePeopleDownPlatformTimer.start()
var totalOfDownPlatform = 0
var currentNeedGenerate = 4
func generatePeopleAtDownPlatform() -> void:
if totalOfDownPlatform < currentNeedGenerate :
totalOfDownPlatform += 1
var peoplePosition = Vector3(6.12,0.85,7.62)
generatePeopleAtDesignatedArea(peoplePosition,PlayerWalkArea3D.screenDoorWaitArea,'A','A{0}'.format([totalOfDownPlatform]))
else :
$AllTimer/generatePeopleDownPlatformTimer.stop()
##B入口生成(从进到出3分钟间隔10秒18个人完成循环)
var totalOfBEntrance=18
func generatePeopleAtBEntrance() -> void:
if totalOfBEntrance> 0:
totalOfBEntrance -= 1
var peoplePosition = Vector3(-54.8,9.8,-61)
generatePeopleAtDesignatedArea(peoplePosition,PlayerWalkArea3D.entrance,'B','B{0}'.format([totalOfBEntrance]))
else :
$AllTimer/generatePeopleBEntranceTimer.stop()
##C入口生成(21个人完成循环)
var totalOfCEntrance = 21
func generatePeopleAtCEntrance() -> void:
totalOfCEntrance += 1
var peoplePosition = Vector3(146.12,9.8,-60)
generatePeopleAtDesignatedArea(peoplePosition,PlayerWalkArea3D.entrance,'C','C{0}'.format([totalOfCEntrance]))
##D入口生成
var totalOfDEntrance = 0
func generatePeopleAtDEntrance() -> void:
totalOfDEntrance += 1
if totalOfDEntrance > 10:
$AllTimer/generatePeopleDEntranceTimer.wait_time = 6
var peoplePosition = Vector3(146.12,9.8,46)
generatePeopleAtDesignatedArea(peoplePosition,PlayerWalkArea3D.entrance,'D','D{0}'.format([totalOfDEntrance]))
##在指定区域增加人
func generatePeopleAtDesignatedArea(peoplePosition:Vector3, goToNextArea: PlayerWalkArea3D,generateArea:String, peopleId:String='0A') -> void:
var peoplrInstance = people_scene.instantiate()
add_child(peoplrInstance)
peoplrInstance.global_position = peoplePosition
peoplrInstance.buildPos = peoplePosition
peoplrInstance.generateArea = generateArea
if peopleId :
peoplrInstance.id = peopleId
playerGoToNextArea(peoplrInstance,goToNextArea)
signal trainComingSignal()
func trainComeAndLeace() -> void:
trainLeaveAtDownPlatform = false
trainComingSignal.emit()
self.trainComeAndOpenScreenDoor()
await get_tree().create_timer(25).timeout
self.closeScreenDoorAndTrainLeave()
trainLeaveAtDownPlatform = true
func peopleAtDownPlatformDecreased() -> void:
$AllScreenDoorWaitArea.queue_free()
var allPeopleAtDownPlatform = $AllNoMovePeople/AllPeopleAtDownPlatform.get_children()
for child in allPeopleAtDownPlatform :
child.position.y = 0.85
child.get_node('Player').state_machine.change_state("Idle")
func temporaryTicketOfficeComing() -> void:
$platform.get_node('TemporaryTicketOffice').temporaryTicketOfficeComing()
func allTimerStopAndShowRedStripe() -> void:
$platform.get_node('ShortcutToolModel2').allTimerStopAndShowRedStripe()
func _ready():
$platform.showCameraAndShortcutTool()
$platform.screenDoorOpenAndCloseNoMusic()