コード例 #1
0
        public override void FixedUpdate()
        {
            if (player == PlayerControl.LocalPlayer)
            {
                if (numInfections > 0 && player.isAlive())
                {
                    currentTarget = setTarget(untargetablePlayers: infected.Values.ToList());
                    setPlayerOutline(currentTarget, PlagueDoctor.color);
                }

                if (!meetingFlag && (canWinDead || player.isAlive()))
                {
                    List <PlayerControl> newInfected = new List <PlayerControl>();
                    foreach (PlayerControl target in PlayerControl.AllPlayerControls)
                    { // 非感染プレイヤーのループ
                        if (target == player || target.isDead() || infected.ContainsKey(target.PlayerId) || target.inVent)
                        {
                            continue;
                        }

                        // データが無い場合は作成する
                        if (!progress.ContainsKey(target.PlayerId))
                        {
                            progress[target.PlayerId] = 0f;
                        }

                        foreach (var source in infected.Values.ToList())
                        { // 感染プレイヤーのループ
                            if (source.isDead())
                            {
                                continue;
                            }
                            float distance = Vector3.Distance(source.transform.position, target.transform.position);
                            // 障害物判定
                            bool anythingBetween = PhysicsHelpers.AnythingBetween(source.GetTruePosition(), target.GetTruePosition(), Constants.ShipAndObjectsMask, false);

                            if (distance <= infectDistance && !anythingBetween)
                            {
                                progress[target.PlayerId] += Time.fixedDeltaTime;

                                // 他のクライアントに進行状況を通知する
                                MessageWriter writer = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId, (byte)CustomRPC.PlagueDoctorUpdateProgress, Hazel.SendOption.Reliable, -1);
                                writer.Write(target.PlayerId);
                                writer.Write(progress[target.PlayerId]);
                                AmongUsClient.Instance.FinishRpcImmediately(writer);

                                // Only update a player's infection once per FixedUpdate
                                break;
                            }
                        }

                        // 既定値を超えたら感染扱いにする
                        if (progress[target.PlayerId] >= infectDuration)
                        {
                            newInfected.Add(target);
                        }
                    }

                    // 感染者に追加する
                    foreach (PlayerControl p in newInfected)
                    {
                        byte          targetId = p.PlayerId;
                        MessageWriter writer   = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId, (byte)CustomRPC.PlagueDoctorSetInfected, Hazel.SendOption.Reliable, -1);
                        writer.Write(targetId);
                        AmongUsClient.Instance.FinishRpcImmediately(writer);
                        RPCProcedure.plagueDoctorInfected(targetId);
                    }

                    // 勝利条件を満たしたか確認する
                    bool winFlag = true;
                    foreach (PlayerControl p in PlayerControl.AllPlayerControls)
                    {
                        if (p.isDead())
                        {
                            continue;
                        }
                        if (p == player)
                        {
                            continue;
                        }
                        if (!infected.ContainsKey(p.PlayerId))
                        {
                            winFlag = false;
                            break;
                        }
                    }

                    if (winFlag)
                    {
                        MessageWriter winWriter = AmongUsClient.Instance.StartRpcImmediately(PlayerControl.LocalPlayer.NetId, (byte)CustomRPC.PlagueDoctorWin, Hazel.SendOption.Reliable, -1);
                        AmongUsClient.Instance.FinishRpcImmediately(winWriter);
                        RPCProcedure.plagueDoctorWin();
                    }
                }
            }
            UpdateStatusText();
        }