Ejemplo n.º 1
0
        public void ServerRead(ClientNetObject type, Lidgren.Network.NetBuffer msg, Barotrauma.Networking.Client c)
        {
            bool    autoPilot         = msg.ReadBoolean();
            Vector2 newTargetVelocity = targetVelocity;
            bool    maintainPos       = false;
            Vector2?newPosToMaintain  = null;
            bool    headingToStart    = false;

            if (autoPilot)
            {
                maintainPos = msg.ReadBoolean();
                if (maintainPos)
                {
                    newPosToMaintain = new Vector2(
                        msg.ReadFloat(),
                        msg.ReadFloat());
                }
                else
                {
                    headingToStart = msg.ReadBoolean();
                }
            }
            else
            {
                newTargetVelocity = new Vector2(msg.ReadFloat(), msg.ReadFloat());
            }

            if (!item.CanClientAccess(c))
            {
                return;
            }

            AutoPilot = autoPilot;

            if (!AutoPilot)
            {
                targetVelocity = newTargetVelocity;
            }
            else
            {
                MaintainPos   = newPosToMaintain != null;
                posToMaintain = newPosToMaintain;

                if (posToMaintain == null)
                {
                    LevelStartSelected = headingToStart;
                    LevelEndSelected   = !headingToStart;
                    UpdatePath();
                }
                else
                {
                    LevelStartSelected = false;
                    LevelEndSelected   = false;
                }
            }

            //notify all clients of the changed state
            unsentChanges = true;
        }
Ejemplo n.º 2
0
        public static MatchState ReadFromMessage(Lidgren.Network.NetBuffer message)
        {
            //Clients
            int clientCount = message.ReadInt32();
            List <MatchClientState> clients = new List <MatchClientState>();

            for (int i = 0; i < clientCount; i++)
            {
                System.Guid guid = message.ReadGuid();
                string      name = message.ReadString();

                clients.Add(new MatchClientState(guid, name));
            }
            //Players
            int playerCount = message.ReadInt32();
            List <MatchPlayerState> players = new List <MatchPlayerState>();

            for (int i = 0; i < playerCount; i++)
            {
                System.Guid clientGuid  = message.ReadGuid();
                ControlType ctrlType    = (ControlType)message.ReadInt32();
                bool        readyToRace = message.ReadBoolean();
                int         characterId = message.ReadInt32();

                players.Add(new MatchPlayerState(clientGuid, ctrlType, readyToRace, characterId));
            }
            //Match settings
            MatchSettings settings = new MatchSettings()
            {
                StageId             = message.ReadInt32(),
                Laps                = message.ReadInt32(),
                AICount             = message.ReadInt32(),
                AISkill             = (AISkillLevel)message.ReadInt32(),
                AutoStartTime       = message.ReadInt32(),
                AutoStartMinPlayers = message.ReadInt32(),
                AutoReturnTime      = message.ReadInt32(),
                VoteRatio           = message.ReadFloat(),
                StageRotationMode   = (StageRotationMode)message.ReadInt32()
            };
            bool  inRace           = message.ReadBoolean();
            float curAutoStartTime = message.ReadFloat();

            return(new MatchState(clients, players, settings, inRace, curAutoStartTime));
        }
Ejemplo n.º 3
0
        public void ClientRead(ServerNetObject type, Lidgren.Network.NetBuffer msg, float sendingTime)
        {
            long msgStartPos = msg.Position;

            bool    autoPilot         = msg.ReadBoolean();
            Vector2 newTargetVelocity = targetVelocity;
            bool    maintainPos       = false;
            Vector2?newPosToMaintain  = null;
            bool    headingToStart    = false;

            if (autoPilot)
            {
                maintainPos = msg.ReadBoolean();
                if (maintainPos)
                {
                    newPosToMaintain = new Vector2(
                        msg.ReadFloat(),
                        msg.ReadFloat());
                }
                else
                {
                    headingToStart = msg.ReadBoolean();
                }
            }
            else
            {
                newTargetVelocity = new Vector2(msg.ReadFloat(), msg.ReadFloat());
            }

            if (correctionTimer > 0.0f)
            {
                int msgLength = (int)(msg.Position - msgStartPos);
                msg.Position = msgStartPos;
                StartDelayedCorrection(type, msg.ExtractBits(msgLength), sendingTime);
                return;
            }

            AutoPilot = autoPilot;

            if (!AutoPilot)
            {
                targetVelocity = newTargetVelocity;
            }
            else
            {
                MaintainPos   = newPosToMaintain != null;
                posToMaintain = newPosToMaintain;

                if (posToMaintain == null)
                {
                    LevelStartSelected = headingToStart;
                    LevelEndSelected   = !headingToStart;
                    UpdatePath();
                }
                else
                {
                    LevelStartSelected = false;
                    LevelEndSelected   = false;
                }
            }
        }
Ejemplo n.º 4
0
        public void ServerRead(ClientNetObject type, Lidgren.Network.NetBuffer msg, Barotrauma.Networking.Client c)
        {
            bool    autoPilot         = msg.ReadBoolean();
            Vector2 newTargetVelocity = targetVelocity;
            bool    maintainPos       = false;
            Vector2?newPosToMaintain  = null;
            bool    headingToStart    = false;

            if (autoPilot)
            {
                maintainPos = msg.ReadBoolean();
                if (maintainPos)
                {
                    newPosToMaintain = new Vector2(
                        msg.ReadFloat(),
                        msg.ReadFloat());
                }
                else
                {
                    headingToStart = msg.ReadBoolean();
                }
            }
            else
            {
                newTargetVelocity = new Vector2(msg.ReadFloat(), msg.ReadFloat());
            }

            if (lastuser == null)
            {
                lastuser = c.Character;
            }

            if (!item.CanClientAccess(c))
            {
                return;
            }

            if (lastuser != c.Character)
            {
                if (!CoroutineManager.IsCoroutineRunning("warnislocked_" + item.ID + "_" + c.Character.ID))
                {
                    CoroutineManager.StartCoroutine(Warnislocked(c, item), "warnislocked_" + item.ID + "_" + c.Character.ID);
                }
                return;
            }

            AutoPilot = autoPilot;

            if (!AutoPilot)
            {
                targetVelocity = newTargetVelocity;
            }
            else
            {
                MaintainPos   = newPosToMaintain != null;
                posToMaintain = newPosToMaintain;

                if (posToMaintain == null)
                {
                    LevelStartSelected = headingToStart;
                    LevelEndSelected   = !headingToStart;
                    UpdatePath();
                }
                else
                {
                    LevelStartSelected = false;
                    LevelEndSelected   = false;
                }
            }

            //notify all clients of the changed state
            unsentChanges = true;
        }
Ejemplo n.º 5
0
        public void ServerRead(ClientNetObject type, Lidgren.Network.NetBuffer msg, Barotrauma.Networking.Client c)
        {
            bool    autoPilot            = msg.ReadBoolean();
            bool    dockingButtonClicked = msg.ReadBoolean();
            Vector2 newSteeringInput     = targetVelocity;
            bool    maintainPos          = false;
            Vector2?newPosToMaintain     = null;
            bool    headingToStart       = false;

            if (autoPilot)
            {
                maintainPos = msg.ReadBoolean();
                if (maintainPos)
                {
                    newPosToMaintain = new Vector2(
                        msg.ReadFloat(),
                        msg.ReadFloat());
                }
                else
                {
                    headingToStart = msg.ReadBoolean();
                }
            }
            else
            {
                newSteeringInput = new Vector2(msg.ReadFloat(), msg.ReadFloat());
            }

            if (!item.CanClientAccess(c))
            {
                return;
            }

            user      = c.Character;
            AutoPilot = autoPilot;

            if (dockingButtonClicked)
            {
                item.SendSignal(0, "1", "toggle_docking", sender: Character.Controlled);
            }

            if (!AutoPilot)
            {
                steeringInput       = newSteeringInput;
                steeringAdjustSpeed = MathHelper.Lerp(0.2f, 1.0f, c.Character.GetSkillLevel("helm") / 100.0f);
            }
            else
            {
                MaintainPos   = newPosToMaintain != null;
                posToMaintain = newPosToMaintain;

                if (posToMaintain == null)
                {
                    LevelStartSelected = headingToStart;
                    LevelEndSelected   = !headingToStart;
                    UpdatePath();
                }
                else
                {
                    LevelStartSelected = false;
                    LevelEndSelected   = false;
                }
            }

            //notify all clients of the changed state
            unsentChanges = true;
        }