Ejemplo n.º 1
0
        public override void FixedUpdate()
        {
            // 処理に自信がないので念の為tryで囲っておく
            try{
                if (PlayerControl.LocalPlayer.isRole(RoleType.Trapper) && Trap.traps.Count != 0 && !Trap.hasTrappedPlayer() && !meetingFlag)
                {
                    // トラップを踏んだプレイヤーを動けなくする
                    foreach (var p in PlayerControl.AllPlayerControls)
                    {
                        foreach (var trap in Trap.traps)
                        {
                            if (DateTime.UtcNow.Subtract(trap.Value.placedTime).TotalSeconds < extensionTime)
                            {
                                continue;
                            }
                            if (trap.Value.isActive || p.isDead() || p.inVent || meetingFlag)
                            {
                                continue;
                            }
                            var p1 = p.transform.localPosition;
                            Dictionary <GameObject, byte> listActivate = new Dictionary <GameObject, byte>();
                            var p2       = trap.Value.trap.transform.localPosition;
                            var distance = Vector3.Distance(p1, p2);
                            if (distance < trapRange)
                            {
                                TMPro.TMP_Text text;
                                RoomTracker    roomTracker = HudManager.Instance?.roomTracker;
                                GameObject     gameObject  = UnityEngine.Object.Instantiate(roomTracker.gameObject);
                                UnityEngine.Object.DestroyImmediate(gameObject.GetComponent <RoomTracker>());
                                gameObject.transform.SetParent(HudManager.Instance.transform);
                                gameObject.transform.localPosition = new Vector3(0, -1.8f, gameObject.transform.localPosition.z);
                                gameObject.transform.localScale    = Vector3.one * 2f;
                                text      = gameObject.GetComponent <TMPro.TMP_Text>();
                                text.text = String.Format(ModTranslation.getString("trapperGetTrapped"), p.name);
                                HudManager.Instance.StartCoroutine(Effects.Lerp(3f, new Action <float>((p) => {
                                    if (p == 1f && text != null && text.gameObject != null)
                                    {
                                        UnityEngine.Object.Destroy(text.gameObject);
                                    }
                                })));
                                MessageWriter writer = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId, (byte)CustomRPC.ActivateTrap, Hazel.SendOption.Reliable, -1);
                                writer.Write(trap.Key);
                                writer.Write(PlayerControl.LocalPlayer.PlayerId);
                                writer.Write(p.PlayerId);
                                AmongUsClient.Instance.FinishRpcImmediately(writer);
                                RPCProcedure.activateTrap(trap.Key, PlayerControl.LocalPlayer.PlayerId, p.PlayerId);
                                break;
                            }
                        }
                    }
                }

                if (PlayerControl.LocalPlayer.isRole(RoleType.Trapper) && Trap.hasTrappedPlayer() && !meetingFlag)
                {
                    // トラップにかかっているプレイヤーを救出する
                    foreach (var trap in Trap.traps)
                    {
                        if (trap.Value.trap == null || !trap.Value.isActive)
                        {
                            return;
                        }
                        Vector3 p1 = trap.Value.trap.transform.position;
                        foreach (var player in PlayerControl.AllPlayerControls)
                        {
                            if (player.PlayerId == trap.Value.target.PlayerId || player.isDead() || player.inVent || player.isRole(RoleType.Trapper))
                            {
                                continue;
                            }
                            Vector3 p2       = player.transform.position;
                            float   distance = Vector3.Distance(p1, p2);
                            if (distance < 0.5)
                            {
                                MessageWriter writer = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId, (byte)CustomRPC.DisableTrap, Hazel.SendOption.Reliable, -1);
                                writer.Write(trap.Key);
                                AmongUsClient.Instance.FinishRpcImmediately(writer);
                                RPCProcedure.disableTrap(trap.Key);
                            }
                        }
                    }
                }
            }
            catch (NullReferenceException e) {
                Helpers.log(e.Message);
            }
        }