@@ -176,6 +176,8 @@ public static readonly (long Min, long Max) OrderDeliveryDurationRange = (
176176 20000 , 60000
177177 ) ;
178178
179+ public const decimal OrderForceContactScopeRadius = 16M ;
180+
179181 /// <summary>
180182 /// The order number of each game part.
181183 /// </summary>
@@ -187,24 +189,6 @@ public static readonly (long Min, long Max) OrderDeliveryDurationRange = (
187189 { GameStageType . PreMatch , null }
188190 } ;
189191
190- /// <summary>
191- /// The sound to play when delivering an order.
192- /// </summary>
193- public static readonly SoundPlayer OrderSoundDeliver = new SoundPlayer (
194- @"Assets/Sounds/Deliver.wav"
195- ) ;
196-
197- /// <summary>
198- /// The sound to play when taking an order.
199- /// </summary>
200- public static readonly SoundPlayer OrderSoundTake = new SoundPlayer (
201- @"Assets/Sounds/Order.wav"
202- ) ;
203-
204-
205- public static readonly SoundPlayer SetChargingPileSound = new SoundPlayer (
206- @"Assets/Sounds/SetChargingPile.wav"
207- ) ;
208192 #endregion
209193
210194 #region Parameters related to vehicles
@@ -329,8 +313,45 @@ public long? RemainingTime
329313
330314 #endregion
331315
316+
332317 #region Private properties and fields
333318
319+ private static readonly SoundPlayer _soundDeliverOrder = new SoundPlayer (
320+ @"Assets/Sounds/Deliver.wav"
321+ ) ;
322+
323+ private static readonly SoundPlayer _soundTakeOrder = new SoundPlayer (
324+ @"Assets/Sounds/Order.wav"
325+ ) ;
326+
327+ private static readonly SoundPlayer _soundNotMoving = new SoundPlayer (
328+ @"Assets/Sounds/NotMoving.wav"
329+ ) ;
330+ private static bool _isSoundNotMovingPlaying = false ;
331+
332+ private static readonly SoundPlayer _soundInBarrier = new SoundPlayer (
333+ @"Assets/Sounds/InBarrier.wav"
334+ ) ;
335+ private static bool _isSoundInBarrierPlaying = false ;
336+
337+ private static readonly SoundPlayer _soundCharging = new SoundPlayer (
338+ @"Assets/Sounds/Charging.wav"
339+ ) ;
340+ private static bool _isSoundChargingPlaying = false ;
341+
342+ private static readonly SoundPlayer _soundDischarging = new SoundPlayer (
343+ @"Assets/Sounds/InBarrier.wav"
344+ ) ;
345+ private static bool _isSoundDischargingPlaying = false ;
346+
347+ private static readonly SoundPlayer _soundAutoCharge = new SoundPlayer (
348+ @"Assets/Sounds/AutoCharge.wav"
349+ ) ;
350+
351+ private static readonly SoundPlayer _soundSetChargingPile = new SoundPlayer (
352+ @"Assets/Sounds/SetChargingPile.wav"
353+ ) ;
354+
334355 private readonly List < Barrier > _barrierList ;
335356
336357 private CampType ? _camp = null ;
@@ -378,9 +399,14 @@ public long? RemainingTime
378399 public Game ( )
379400 {
380401 // Load sounds
381- Game . OrderSoundDeliver . Load ( ) ;
382- Game . OrderSoundTake . Load ( ) ;
383- Game . SetChargingPileSound . Load ( ) ;
402+ Game . _soundDeliverOrder . Load ( ) ;
403+ Game . _soundTakeOrder . Load ( ) ;
404+ Game . _soundNotMoving . Load ( ) ;
405+ Game . _soundInBarrier . Load ( ) ;
406+ Game . _soundCharging . Load ( ) ;
407+ Game . _soundDischarging . Load ( ) ;
408+ Game . _soundAutoCharge . Load ( ) ;
409+ Game . _soundSetChargingPile . Load ( ) ;
384410
385411 // Generate barriers
386412 this . _barrierList = new List < Barrier > ( ) ;
@@ -594,9 +620,85 @@ public void End()
594620 throw new Exception ( "The game is not running or paused." ) ;
595621 }
596622
623+ Game . _soundDeliverOrder . Stop ( ) ;
624+ Game . _soundTakeOrder . Stop ( ) ;
625+ Game . _soundNotMoving . Stop ( ) ;
626+ Game . _soundInBarrier . Stop ( ) ;
627+ Game . _soundCharging . Stop ( ) ;
628+ Game . _soundDischarging . Stop ( ) ;
629+ Game . _soundAutoCharge . Stop ( ) ;
630+ Game . _soundSetChargingPile . Stop ( ) ;
631+
597632 this . _gameState = GameStatusType . Ended ;
598633 }
599634
635+ /// <summary>
636+ /// Force to take or deliver an order.
637+ /// </summary>
638+ public void ForceToTakeOrDeliverOrder ( ForceToTakeOrDeliverOrderType action )
639+ {
640+ var vehicle = this . _vehicle [ ( CampType ) this . _camp ] ;
641+
642+ if ( vehicle ? . Position == null )
643+ {
644+ return ;
645+ }
646+
647+ var vehiclePosition = ( Dot ) vehicle . Position ;
648+
649+
650+ // Count the orders in delivery.
651+ var deliveringOrderNumber = 0 ;
652+ foreach ( var order in this . _orderList )
653+ {
654+ if ( order . Status == OrderStatusType . InDelivery )
655+ {
656+ ++ deliveringOrderNumber ;
657+ }
658+ }
659+
660+ foreach ( var order in this . _orderList )
661+ {
662+ // Take orders.
663+ if ( order . Status == OrderStatusType . Pending && action == ForceToTakeOrDeliverOrderType . Take )
664+ {
665+ // Check if the capacity is full.
666+ if ( deliveringOrderNumber >= Game . OrderDeliveryCapacity )
667+ {
668+ continue ;
669+ }
670+
671+ if ( ( decimal ) Dot . Distance ( order . DeparturePosition , vehiclePosition )
672+ <= Game . OrderForceContactScopeRadius )
673+ {
674+ order . Take ( ( long ) this . GameTime ) ;
675+
676+ // Play the take sound.
677+ Game . _soundTakeOrder . Play ( ) ;
678+ }
679+ }
680+ else if ( order . Status == OrderStatusType . InDelivery )
681+ {
682+ if ( ( decimal ) Dot . Distance ( order . DestinationPosition , vehiclePosition )
683+ <= Game . OrderForceContactScopeRadius )
684+ {
685+ order . Deliver ( ( long ) this . GameTime ) ;
686+
687+ if ( order . OvertimeDuration == null )
688+ {
689+ throw new Exception ( "The overtime duration of the order is null." ) ;
690+ }
691+
692+ this . _score [ ( CampType ) this . _camp ] +=
693+ Math . Max ( ( decimal ) order . Commission + Game . ScoreDeliveryOvertimeRate * ( byte ) order . OvertimeDuration , 0 ) ;
694+
695+ // Player the deliver sound.
696+ Game . _soundDeliverOrder . Play ( ) ;
697+ }
698+ }
699+ }
700+ }
701+
600702 /// <summary>
601703 /// Set a charging pile.
602704 /// </summary>
@@ -640,7 +742,7 @@ public void SetChargingPile()
640742
641743 this . _score [ ( CampType ) this . _camp ] += Game . ScoreSetChargingPile ;
642744
643- Game . SetChargingPileSound . Play ( ) ;
745+ Game . _soundSetChargingPile . Play ( ) ;
644746 }
645747
646748 #endregion
@@ -661,6 +763,8 @@ private void AutoCharge()
661763
662764 if ( vehicle . IsPowerExhausted )
663765 {
766+ Game . _soundAutoCharge . Play ( ) ;
767+
664768 // Exchange time for power.
665769 this . _startTime -= Game . VehicleAutoChargingStep ;
666770 vehicle . IncreaseMaxDistance (
@@ -822,9 +926,22 @@ void ScoreMoving()
822926 ( long ) vehicle . ParkingDuration >= 5000 + this . LastTickDuration
823927 )
824928 {
929+ if ( ! Game . _isSoundNotMovingPlaying )
930+ {
931+ Game . _isSoundNotMovingPlaying = true ;
932+ Game . _soundNotMoving . PlayLooping ( ) ;
933+ }
825934 this . _score [ ( CampType ) this . _camp ] +=
826935 Game . ScoreOvertimeParkingRate * this . LastTickDuration ;
827936 }
937+ else
938+ {
939+ if ( Game . _isSoundNotMovingPlaying )
940+ {
941+ Game . _isSoundNotMovingPlaying = false ;
942+ Game . _soundNotMoving . Stop ( ) ;
943+ }
944+ }
828945 }
829946
830947 /// <summary>
@@ -843,10 +960,24 @@ void TackleBarriers()
843960
844961 if ( this . IsInBarrier ( vehiclePosition ) )
845962 {
963+ if ( ! Game . _isSoundInBarrierPlaying )
964+ {
965+ Game . _isSoundInBarrierPlaying = true ;
966+ Game . _soundInBarrier . PlayLooping ( ) ;
967+ }
968+
846969 vehicle . IncreaseMaxDistance (
847970 ( int ) Math . Round ( Game . BarrierDischargingRate * this . LastTickDuration )
848971 ) ;
849972 }
973+ else
974+ {
975+ if ( Game . _isSoundInBarrierPlaying )
976+ {
977+ Game . _isSoundInBarrierPlaying = false ;
978+ Game . _soundInBarrier . Stop ( ) ;
979+ }
980+ }
850981 }
851982
852983 /// <summary>
@@ -873,21 +1004,49 @@ void TackleChargingPiles()
8731004 camp : ( CampType ) this . _camp
8741005 ) )
8751006 {
1007+ if ( ! Game . _isSoundChargingPlaying )
1008+ {
1009+ Game . _isSoundChargingPlaying = true ;
1010+ Game . _soundCharging . PlayLooping ( ) ;
1011+ }
1012+
8761013 vehicle . IncreaseMaxDistance (
8771014 ( int ) Math . Round ( Game . ChargingPileChargingRate * this . LastTickDuration )
8781015 ) ;
8791016 }
1017+ else
1018+ {
1019+ if ( Game . _isSoundChargingPlaying )
1020+ {
1021+ Game . _isSoundChargingPlaying = false ;
1022+ Game . _soundCharging . Stop ( ) ;
1023+ }
1024+ }
8801025
8811026 if ( this . IsInChargingPileInfluenceScope (
8821027 position : vehiclePosition ,
8831028 camp : ( CampType ) this . _camp ,
8841029 reverse : true
8851030 ) )
8861031 {
1032+ if ( ! Game . _isSoundDischargingPlaying )
1033+ {
1034+ Game . _isSoundDischargingPlaying = true ;
1035+ Game . _soundDischarging . PlayLooping ( ) ;
1036+ }
1037+
8871038 vehicle . IncreaseMaxDistance (
8881039 ( int ) Math . Round ( Game . ChargingPileDischargingRate * this . LastTickDuration )
8891040 ) ;
8901041 }
1042+ else
1043+ {
1044+ if ( Game . _isSoundDischargingPlaying )
1045+ {
1046+ Game . _isSoundDischargingPlaying = false ;
1047+ Game . _soundDischarging . Stop ( ) ;
1048+ }
1049+ }
8911050 }
8921051
8931052 /// <summary>
@@ -932,7 +1091,7 @@ void TakeAndDeliverOrder()
9321091 order . Take ( ( long ) this . GameTime ) ;
9331092
9341093 // Play the take sound.
935- Game . OrderSoundTake . Play ( ) ;
1094+ Game . _soundTakeOrder . Play ( ) ;
9361095 }
9371096 }
9381097 else if ( order . Status == OrderStatusType . InDelivery )
@@ -951,7 +1110,7 @@ void TakeAndDeliverOrder()
9511110 Math . Max ( ( decimal ) order . Commission + Game . ScoreDeliveryOvertimeRate * ( long ) order . OvertimeDuration , 0 ) ;
9521111
9531112 // Player the deliver sound.
954- Game . OrderSoundDeliver . Play ( ) ;
1113+ Game . _soundDeliverOrder . Play ( ) ;
9551114 }
9561115 }
9571116 }
0 commit comments