Guest User

Untitled

a guest
Jan 6th, 2018
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 18.28 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using UnityEngine;
  4. using UnityEngine.Networking;
  5. using static Misc;
  6. using static Player;
  7.  
  8. public class Door : Passage, ILockable, IServerInitialisable
  9. {
  10.   public int initialLock = 0;
  11.  
  12.   [Header("Visuals")]
  13.   public Sprite[] doorStates;
  14.  
  15.   [HideInInspector]
  16.   [SyncVar(hook = "SyncDoorProgress")]
  17.   private short openProgress;
  18.   private bool Closed => openProgress == 0;
  19.   private bool Open => openProgress == 100;
  20.  
  21.   private float unlockTime = 0f;
  22.   private int unlockDifficulty = 0;
  23.   private bool Locked => unlockDifficulty != 0;
  24.  
  25.   private bool AllowsPassage => !DoorBlocked && !Locked;
  26.  
  27.   public AudioClip openDoorSound;
  28.   public AudioClip closeDoorSound;
  29.   public AudioClip unlockSound;
  30.   public AudioClip breakingUnlockSound;
  31.  
  32.   private NetworkAudioSource audioSource;
  33.  
  34.   private Door DoorTarget => (Door)target;
  35.  
  36.   //Block Door Logic
  37.   private bool myBlocking;
  38.  
  39.   [SyncVar(hook = "OnDoorBlockChange")]
  40.   private bool doorBlocked;
  41.   private bool DoorBlocked
  42.   {
  43.     get { return doorBlocked; }
  44.     set { if (value != doorBlocked) { doorBlocked = value; DoorTarget.doorBlocked = value; } }
  45.   }
  46.  
  47.   private bool myBreaking;
  48.   private bool DoorUnderSiege
  49.   {
  50.     get { return myBreaking; }
  51.     set
  52.     {
  53.       myBreaking = value;
  54.       DoorTarget.myBreaking = value;
  55.     }
  56.   }
  57.  
  58.   [SyncVar]
  59.   private short doorHealth = 100;
  60.   private short DoorHealth
  61.   {
  62.     get { return doorHealth; }
  63.     set { if (value != doorHealth) { doorHealth = value; DoorTarget.doorHealth = value; } }
  64.   }
  65.  
  66.   private Coroutine serverBreakRoutine;
  67.   private Coroutine soundCoRoutine;
  68.  
  69.   private DoorChallenge currentChallenge;
  70.   private bool challengeAvailable = false;
  71.   private DoorChallengeResult? breakerResult;
  72.   private DoorChallengeResult? blockerResult;
  73.   private int challengeID;
  74.  
  75.   private Action exitChallenge = null;
  76.  
  77.   private bool Broken => doorHealth == 0;
  78.  
  79.   public override bool CanBeUsed => base.CanBeUsed && !DoorBlocked;
  80.  
  81.   private bool CanRepair => Broken && User.InventoryManager.SrvHasObjects(new NailsData(), new WoodPlankData());
  82.   private bool CanBlock => !Broken && Closed;
  83.   private bool CanPick => Locked;
  84.   private bool CanClose => !Closed && !Broken;
  85.  
  86.   private const float doorRepairTime = 30f;
  87.  
  88.   void Start()
  89.   {
  90.     audioSource = GetComponent<NetworkAudioSource>();
  91.     if (target != null)
  92.     {
  93.       Debug.Assert(target is Door, "Target for Door must be a door");
  94.     }
  95.   }
  96.  
  97.   protected override bool Action()
  98.   {
  99.     if (DoorBlocked)
  100.     {
  101.       RpcBreakDoor(User.connectionToClient);
  102.       return true;
  103.     }    
  104.  
  105.     RpcOpenMenu(User.connectionToClient, CanRepair, CanBlock, CanPick, CanClose);
  106.     return true;
  107.   }
  108.  
  109.   [Server]
  110.   public override bool ChooseAction(Position position)
  111.   {
  112.     if(position == Position.Left && CanRepair)
  113.     {
  114.       Wait(doorRepairTime, OnDoorRepaired);
  115.       return true;
  116.     }
  117.   }
  118.  
  119.   [TargetRpc]
  120.   private void RpcBreakDoor(NetworkConnection conn)
  121.   {
  122.     LocalPlayer.ProgressMenu.Activate();
  123.     LocalPlayer.PlayerController.RouteInputHook = HandleBreak;
  124.   }
  125.  
  126.   [TargetRpc]
  127.   private void RpcOpenMenu(NetworkConnection conn, bool canRepair, bool canBlock, bool canPick, bool canClose)
  128.   {
  129.     if (canRepair)
  130.     {
  131.       LocalPlayer.ActionMenu.SetImageAndText(Position.Left, Localisation.Active.RepairTextAM, Localisation.Active.RepairSpriteAM, RepairDoor);
  132.     }
  133.  
  134.     if (canBlock)
  135.     {
  136.       LocalPlayer.ActionMenu.SetImageAndText(Position.Right, Localisation.Active.BlockTextAM, Localisation.Active.BlockSpriteAM, BlockDoor);
  137.     }
  138.  
  139.     if (canPick)
  140.     {
  141.       LocalPlayer.ActionMenu.SetImageAndText(Position.Up, Localisation.Active.PickTextAM, Localisation.Active.PickSpriteAM, Unlock);
  142.     }
  143.     else
  144.     {
  145.       LocalPlayer.ActionMenu.SetImageAndText(Position.Up, Localisation.Active.EnterTextAM, Localisation.Active.EnterSpriteAM, Enter);
  146.     }
  147.  
  148.     if(canClose)
  149.     {
  150.       LocalPlayer.ActionMenu.SetImageAndText(Position.Down, Localisation.Active.CloseTextAM, Localisation.Active.CloseSpriteAM, Close);
  151.     }
  152.  
  153.     LocalPlayer.ActionMenu.Activate(Leave, () => DoorBlocked);
  154.   }
  155.  
  156.   public override void Exit() { }  
  157.  
  158.   private void SyncDoorProgress(short progress)
  159.   {
  160.     float p = progress / 100f;
  161.     int idx = Mathf.RoundToInt(p * (doorStates.Length - 1));
  162.     if (idx > doorStates.Length)
  163.     {
  164.       idx = doorStates.Length - 1;
  165.     }
  166.     GetComponent<SpriteRenderer>().sprite = doorStates[idx];
  167.     openProgress = progress;
  168.   }
  169.  
  170.   private void Enter()
  171.   {
  172.     // Opens the door if necessary, then enters
  173.     if (Open)
  174.     {
  175.       OnDoorOpened();
  176.     }
  177.     else
  178.     {
  179.       audioSource.PlayOneShot(openDoorSound, 1f);
  180.       LocalPlayer.ProgressMenu.RegisterWaitTimeWithProgressing((100 - openProgress) / 100f, Localisation.Active.Opening, OnDoorOpened, Exit, (short progress) => LocalPlayer.UseableManager.Action(NetIdent, PROGRESS_MSG, progress.ToString()), openProgress);
  181.     }
  182.   }
  183.  
  184.   private void Close()
  185.   {
  186.     LocalPlayer.ProgressMenu.RegisterWaitTimeWithProgressing(
  187.       openProgress / 100f,
  188.       Localisation.Active.Closing,
  189.       OnDoorClosed,
  190.       Exit,
  191.       (short progress) => LocalPlayer.UseableManager.Action(NetIdent, PROGRESS_MSG, (100 - progress).ToString()), 100 - openProgress
  192.       );
  193.   }
  194.  
  195.   private void RepairDoor()
  196.   {
  197.     audioSource.LoopRandomClips(4f, 7f, AudioPool.Hammer1, AudioPool.Hammer2, AudioPool.Hammer3);
  198.     LocalPlayer.ProgressMenu.RegisterChallengedWaitTime(30f, Localisation.Active.Repairing, 6,
  199.     () => {
  200.       LocalPlayer.InventoryManager.RemoveItem("Nails");
  201.       LocalPlayer.InventoryManager.RemoveItem("Wood Plank");
  202.       LocalPlayer.UseableManager.Action(NetIdent, REPAIR_MSG);
  203.       audioSource.StopLoopRandomClips();
  204.       Leave();
  205.     },
  206.     () =>
  207.     {
  208.       audioSource.StopLoopRandomClips();
  209.       Leave();
  210.     });
  211.   }
  212.  
  213.   private void OnDoorOpened()
  214.   {
  215.     LocalPlayer.UseableManager.Action(NetIdent, PROGRESS_MSG, "100");
  216.     LocalPlayer.UseableManager.Action(NetIdent, TELEPORT_MSG);
  217.     Leave();
  218.   }
  219.  
  220.   private void OnDoorClosed()
  221.   {
  222.     LocalPlayer.UseableManager.Action(NetIdent, PROGRESS_MSG, "0");
  223.     Leave();
  224.   }
  225.  
  226.   protected void Leave()
  227.   {
  228.     base.Leave();
  229.     exitChallenge?.Invoke();
  230.  
  231.     LocalPlayer.PlayerController.RouteInputHook = null;
  232.     LocalPlayer.ProgressMenu.Deactivate();    
  233.   }
  234.  
  235.   [Server]
  236.   public override void Interconnect(Passage otherDoor)
  237.   {
  238.     base.Interconnect(otherDoor);
  239.     Debug.Assert(target is Door, "Target for Door must be a door");
  240.  
  241.     audioSource.AddLinkedSource(DoorTarget.audioSource, 1f, true);
  242.   }
  243.  
  244.   [Server]
  245.   public void Lock(int difficulty)
  246.   {
  247.     if (difficulty == 0)
  248.     {
  249.       unlockDifficulty = 0;
  250.     }
  251.     else
  252.     {
  253.       unlockDifficulty = Mathf.Min(10, unlockDifficulty + difficulty);
  254.       unlockTime += 3f * difficulty;
  255.     }
  256.  
  257.     if (Linked)
  258.     {
  259.       DoorTarget.unlockDifficulty = unlockDifficulty;
  260.       DoorTarget.unlockTime = unlockTime;
  261.     }
  262.     else
  263.     {
  264.       Debug.Log($"There is an unlinked door in {GetComponentInParent<Room>().gameObject.name} that cannot be locked.");
  265.     }
  266.   }
  267.  
  268.   [Server]
  269.   public void ServerInit(Room room)
  270.   {
  271.     if (room.LockDoorsInThisRoom != LockType.None)
  272.     {
  273.       if (initialLock == 0)
  274.       {
  275.         Lock(GetRandomDifficulty(room.LockDoorsInThisRoom));
  276.       }
  277.       else
  278.       {
  279.         Lock(initialLock);
  280.       }
  281.     }
  282.   }
  283.  
  284.   [Client]
  285.   private void Unlock()
  286.   {
  287.     float tmpUnlockTime = unlockTime;
  288.     int tmpUnlockDiff = unlockDifficulty;
  289.     string breakText = Localisation.Active.BreakingLock;
  290.  
  291.     if (LocalPlayer.InventoryManager.HasObject("Lockpick"))
  292.     {
  293.       tmpUnlockTime *= 0.5f;
  294.       tmpUnlockDiff = Mathf.Max(1, tmpUnlockDiff - 3);
  295.       breakText = Localisation.Active.PickingLock;
  296.       audioSource.PlayAndLoop(unlockSound, 1f);
  297.     }
  298.     else
  299.     {
  300.       audioSource.PlayAndLoop(breakingUnlockSound, 1f);
  301.     }
  302.  
  303.     LocalPlayer.ProgressMenu.RegisterChallengedWaitTime(tmpUnlockTime, breakText, tmpUnlockDiff, () =>
  304.     {
  305.       audioSource.FadeOut(0.5f);
  306.       LocalPlayer.UseableManager.Action(NetIdent, UNLOCK_MSG);
  307.       Leave();
  308.     }, () =>
  309.     {
  310.       audioSource.FadeOut(0.5f);
  311.       Leave();
  312.       });
  313.   }
  314.  
  315.   public bool CheckLockConditionsOk()
  316.   {
  317.     if (!Closed)
  318.     {
  319.       RpcCloseDoorsFirst(User.connectionToClient);
  320.       return false;
  321.     }
  322.  
  323.     return true;
  324.   }
  325.  
  326.   [TargetRpc]
  327.   private void RpcCloseDoorsFirst(NetworkConnection conn)
  328.   {
  329.     LocalPlayer.PlayerVisuals.CreateTextEffect(Localisation.Active.CloseDoorsFirst);
  330.   }
  331.  
  332.   private void BlockDoor()
  333.   {
  334.     myBlocking = true;
  335.     LocalPlayer.ProgressMenu.Activate();
  336.     LocalPlayer.PlayerController.RouteInputHook = HandleBlock;
  337.     LocalPlayer.UseableManager.Action(NetIdent, START_BLOCKING);
  338.   }
  339.  
  340.   private void StopBlockDoor()
  341.   {
  342.     myBlocking = false;
  343.     LocalPlayer.UseableManager.Action(NetIdent, STOP_BLOCKING);
  344.   }
  345.  
  346.   private void HandleBlock()
  347.   {
  348.     if (Input.GetKeyDown(KeyboardConfiguration.Use))
  349.     {
  350.       StopBlockDoor();
  351.       Leave();
  352.       return;
  353.     }
  354.  
  355.     if (Broken || !myBlocking)
  356.     {
  357.       Leave();
  358.       return;
  359.     }
  360.  
  361.     HandleProgressAndChallenges(false);
  362.   }
  363.  
  364.   private void HandleBreak()
  365.   {
  366.     if (Input.GetKeyDown(KeyboardConfiguration.Use))
  367.     {
  368.       LocalPlayer.UseableManager.Action(NetIdent, STOP_BREAKING);
  369.       Leave();
  370.       return;
  371.     }
  372.  
  373.     if (Broken || !DoorBlocked)
  374.     {
  375.       Leave();
  376.       return;
  377.     }
  378.  
  379.     HandleProgressAndChallenges(true);
  380.   }
  381.  
  382.   private void OnDoorBlockChange(bool value)
  383.   {
  384.     myBlocking = value;
  385.     DoorTarget.myBlocking = value;
  386.  
  387.     DoorBlocked = value;
  388.     if(!value)
  389.     {
  390.       Leave();
  391.     }
  392.   }
  393.  
  394.   private void HandleProgressAndChallenges(bool breaker)
  395.   {
  396.     LocalPlayer.ProgressMenu.SetProgress(Convert.ToSingle(DoorHealth) / 100);
  397.     if (breaker)
  398.     {
  399.       LocalPlayer.ProgressMenu.SetStatusText(Localisation.Active.Breaking);
  400.     }
  401.     else
  402.     {
  403.       LocalPlayer.ProgressMenu.SetStatusText(Localisation.Active.Blocking);
  404.     }
  405.  
  406.     if (challengeAvailable)
  407.     {
  408.       challengeAvailable = false;
  409.       LocalPlayer.ProgressMenu.Deactivate();
  410.  
  411.       LocalPlayer.ProgressMenu.ChallengeSystem.RequestSpecificChallenge(
  412.           currentChallenge.challengeType,
  413.           currentChallenge.difficulty,
  414.           (result) =>
  415.           {
  416.             SendBreakBlockResult(result, breaker, currentChallenge.id);
  417.             LocalPlayer.ProgressMenu.Activate();
  418.             exitChallenge = null;
  419.             if (breaker)
  420.             {
  421.               LocalPlayer.PlayerController.RouteInputHook = HandleBreak;
  422.             }
  423.             else
  424.             {
  425.               LocalPlayer.PlayerController.RouteInputHook = HandleBlock;
  426.             }
  427.           },
  428.           out exitChallenge);
  429.     }
  430.   }
  431.  
  432.   private void SendBreakBlockResult(ChallengeResult result, bool breaking, int id)
  433.   {
  434.     if (DoorBlocked)
  435.     {
  436.       LocalPlayer.UseableManager.Action(NetIdent, SEND_RESULT, Misc.ConvertObjectsToString(breaking.ToString(), id.ToString(), result.success.ToString()));
  437.       LocalPlayer.ProgressMenu.Activate();
  438.     }
  439.   }
  440.  
  441.   public void Action(Player player, byte action, string message)
  442.   {
  443.     switch (action)
  444.     {
  445.       case TELEPORT_MSG:
  446.         if (AllowsPassage)
  447.         {
  448.           RpcTeleportUser(player.NetworkIdentity, Misc.ConvertObjectsToString(target.spawner.position.x, target.spawner.position.y, target.spawner.position.z));
  449.         }
  450.         break;
  451.       case PROGRESS_MSG:
  452.         if (AllowsPassage && !Broken)
  453.         {
  454.           short progress = short.Parse(message);
  455.           SetProgress(progress);
  456.         }
  457.         break;
  458.       case UNLOCK_MSG:
  459.         unlockDifficulty = 0;
  460.         unlockTime = 0f;
  461.  
  462.         DoorTarget.unlockDifficulty = unlockDifficulty;
  463.         DoorTarget.unlockTime = unlockTime;
  464.         break;
  465.       case START_BREAKING:
  466.         SrvStartBreaking();
  467.         break;
  468.       case STOP_BREAKING:
  469.         SrvStopBreaking();
  470.         break;
  471.       case START_BLOCKING:
  472.         SrvBlockDoor();
  473.         break;
  474.       case STOP_BLOCKING:
  475.         SrvStopBlockDoor();
  476.         break;
  477.       case SEND_RESULT:
  478.         // breaking, id, success
  479.         string[] messageParts = Misc.ConvertStringToStringArr(message);
  480.         bool breakingRes = bool.Parse(messageParts[0]);
  481.         int idRes = int.Parse(messageParts[1]);
  482.         bool successRes = bool.Parse(messageParts[2]);
  483.  
  484.         DoorChallengeResult res = new DoorChallengeResult()
  485.         {
  486.           id = idRes,
  487.           success = successRes
  488.         };
  489.  
  490.         SrvSendResult(breakingRes, res);
  491.         break;
  492.       case REPAIR_MSG:
  493.         DoorHealth = 100;
  494.         break;
  495.     }
  496.   }
  497.  
  498.   [Server]
  499.   private void SetProgress(short progress)
  500.   {
  501.     openProgress = progress;
  502.     DoorTarget.openProgress = progress;
  503.  
  504.     if(progress == 0)
  505.     {
  506.       audioSource.PlayOneShot(closeDoorSound, 1f);
  507.     }
  508.   }
  509.  
  510.   [Server]
  511.   private void SrvBreakDoor()
  512.   {
  513.     DoorHealth = 0;
  514.     audioSource.PlayOneShot(AudioPool.BreakdownDoor, 1f);
  515.     DoorUnderSiege = false;
  516.  
  517.     unlockDifficulty = 0;
  518.     DoorTarget.unlockDifficulty = 0;
  519.  
  520.     unlockTime = 0;
  521.     DoorTarget.unlockTime = 0;
  522.  
  523.     DoorBlocked = false;
  524.  
  525.     SetProgress(100);
  526.   }
  527.  
  528.   [Server]
  529.   private void SrvBlockDoor()
  530.   {
  531.     if (!Broken)
  532.     {
  533.       DoorBlocked = true;
  534.     }
  535.   }
  536.  
  537.   [Server]
  538.   private void SrvStopBlockDoor()
  539.   {
  540.     DoorBlocked = false;
  541.  
  542.     if(DoorUnderSiege)
  543.     {
  544.       SrvBreakDoor();
  545.     }
  546.   }
  547.  
  548.   [Server]
  549.   private void SrvStartBreaking()
  550.   {
  551.     if (DoorBlocked)
  552.     {
  553.       DoorUnderSiege = true;
  554.       serverBreakRoutine = StartCoroutine(BreakDoor());
  555.       soundCoRoutine = StartCoroutine(CauseBreakingSounds());
  556.     }
  557.   }
  558.  
  559.   [Server]
  560.   private void SrvStopBreaking()
  561.   {
  562.     DoorUnderSiege = false;
  563.     StopCoroutine(serverBreakRoutine);
  564.     StopCoroutine(soundCoRoutine);
  565.   }
  566.  
  567.   [Server]
  568.   private void SrvSendResult(bool breaker, DoorChallengeResult result)
  569.   {
  570.     if (breaker)
  571.     {
  572.       breakerResult = result;
  573.       DoorTarget.breakerResult = result;
  574.     }
  575.     else
  576.     {
  577.       blockerResult = result;
  578.       DoorTarget.blockerResult = result;
  579.     }
  580.   }
  581.  
  582.   [ClientRpc]
  583.   private void RpcSetChallenge(DoorChallenge challenge)
  584.   {
  585.     currentChallenge = challenge;
  586.     DoorTarget.currentChallenge = challenge;
  587.  
  588.     challengeAvailable = true;
  589.     DoorTarget.challengeAvailable = true;
  590.   }
  591.  
  592.   [ClientRpc]
  593.   private void RpcShake()
  594.   {
  595.     LocalPlayer.ProgressMenu.Shake();
  596.   }
  597.  
  598.   [ClientRpc]
  599.   private void RpcShakeDoor()
  600.   {
  601.     StartCoroutine(ShakeDoor());
  602.   }
  603.  
  604.   [Client]
  605.   private IEnumerator ShakeDoor()
  606.   {
  607.     float animationDuration = 0.1f;
  608.     float pause = GlobalVars.GetNextFloat(0.1f, 0.3f);
  609.  
  610.     for(int i = 0; i< 2; i++)
  611.     {
  612.       float passedTime = 0f;
  613.       while(passedTime < animationDuration)
  614.       {
  615.         passedTime += Time.deltaTime;
  616.         float progress = Math.Min(passedTime / animationDuration, 1f);
  617.         float size = Mathf.Lerp(1, 1.05f, progress);
  618.         transform.localScale = new Vector3(size, size, size);
  619.         yield return null;
  620.       }
  621.       passedTime = 0f;
  622.       while (passedTime < animationDuration)
  623.       {
  624.         passedTime += Time.deltaTime;
  625.         float progress = Math.Min(passedTime / animationDuration, 1f);
  626.         float size = Mathf.Lerp(1.05f, 1f, progress);
  627.         transform.localScale = new Vector3(size, size, size);
  628.         yield return null;
  629.       }
  630.  
  631.       yield return new WaitForSeconds(pause);
  632.     }
  633.   }
  634.  
  635.   [Server]
  636.   private IEnumerator BreakDoor()
  637.   {
  638.     byte currentDifficulty = 5;
  639.  
  640.     while (DoorUnderSiege)
  641.     {
  642.       blockerResult = null;
  643.       breakerResult = null;
  644.  
  645.       yield return new WaitForSeconds(GlobalVars.Random.Next(2, 4));
  646.  
  647.       byte chosenChallenge = Convert.ToByte(GlobalVars.Random.Next(ChallengeSystem.NUMBER_OF_CHALLENGES));
  648.       RpcSetChallenge(CreateChallenge(currentDifficulty, chosenChallenge, out challengeID));
  649.  
  650.       // Players have four seconds to solve the challenge
  651.       yield return new WaitForSeconds(4);
  652.  
  653.       if (!breakerResult.HasValue || breakerResult.Value.id != challengeID)
  654.       {
  655.         DoorHealth = 100;
  656.       }
  657.       else if (!blockerResult.HasValue || blockerResult.Value.id != challengeID)
  658.       {
  659.         SrvBreakDoor();
  660.         yield break;
  661.       }
  662.       else
  663.       {
  664.         float baseDamage = 20f;
  665.  
  666.         if (breakerResult.Value.success)
  667.         {
  668.           baseDamage *= 2f;
  669.         }
  670.  
  671.         if (blockerResult.Value.success)
  672.         {
  673.           baseDamage *= 0.5f;
  674.         }
  675.  
  676.         DoorHealth -= Convert.ToInt16(Math.Ceiling(baseDamage));
  677.  
  678.         if (DoorHealth <= 0)
  679.         {
  680.           // Door is broken
  681.           SrvBreakDoor();
  682.           yield break;
  683.         }
  684.         if (breakerResult.Value.success && blockerResult.Value.success)
  685.         {
  686.           // Both succeeded, increasing difficulty
  687.           currentDifficulty = (byte)Math.Min(10, currentDifficulty + 1);
  688.         }
  689.  
  690.         if (!breakerResult.Value.success && !blockerResult.Value.success)
  691.         {
  692.           // Both failed, decrease diff
  693.           currentDifficulty = (byte)Math.Max(5, currentDifficulty - 1);
  694.         }
  695.       }
  696.     }
  697.   }
  698.  
  699.   [Server]
  700.   private IEnumerator CauseBreakingSounds()
  701.   {
  702.     AudioClip[] clips = new AudioClip[3]
  703.     {
  704.        AudioPool.DoorHammer01,
  705.        AudioPool.DoorHammer02,
  706.        AudioPool.DoorHammer03
  707.     };
  708.  
  709.     while (DoorUnderSiege)
  710.     {
  711.       audioSource.PlayOneShot(clips[GlobalVars.Random.Next(0, clips.Length)], 1f);
  712.       RpcShake();
  713.       RpcShakeDoor();
  714.       DoorTarget.RpcShakeDoor();
  715.       yield return new WaitForSeconds(GlobalVars.GetNextFloat(3f, 4f));
  716.     }
  717.   }
  718.  
  719.   [Server]
  720.   private DoorChallenge CreateChallenge(byte difficulty, byte type, out int id)
  721.   {
  722.     DoorChallenge challenge = new DoorChallenge
  723.     {
  724.       id = GlobalVars.Random.Next(),
  725.       difficulty = difficulty,
  726.       challengeType = type
  727.     };
  728.  
  729.     id = challenge.id;
  730.  
  731.     return challenge;
  732.   }
  733.  
  734.   private struct DoorChallenge
  735.   {
  736.     public int id;
  737.     public byte difficulty;
  738.     public byte challengeType;
  739.   }
  740.  
  741.   private struct DoorChallengeResult
  742.   {
  743.     public int id;
  744.     public bool success;
  745.   }
  746. }
Advertisement
Add Comment
Please, Sign In to add comment