Exemplo n.º 1
0
        // Player is in sector, everything loaded, can process messages
        public void Start()
        {
            if (MyFakes.MULTIPLAYER_DISABLED)
            {
                return;
            }

            Debug.Assert(MyGuiScreenGamePlay.Static != null);
            Debug.Assert(!IsRunning);

            if (IsEditor())
            {
                return;
            }

            MyMwcLog.WriteLine("MyMultiplayerGameplay.Start - START");
            MyMwcLog.IncreaseIndent();

            m_lastPlayerId = 0;

            m_lastConfig         = null;
            m_lastAmmoAssignment = null;
            m_lastCamera         = MyCameraAttachedToEnum.PlayerMinerShip;

            IsRunning = true;


            if (IsSandBox())
            {
                // Everybody is enemy to every other faction
                var values = Enum.GetValues(typeof(MyMwcObjectBuilder_FactionEnum));
                foreach (MyMwcObjectBuilder_FactionEnum f1 in values)
                {
                    foreach (MyMwcObjectBuilder_FactionEnum f2 in values)
                    {
                        // Traders are neutral to all
                        if (f1 == MyMwcObjectBuilder_FactionEnum.Traders || f2 == MyMwcObjectBuilder_FactionEnum.Traders)
                        {
                            MyFactions.SetFactionStatus(f1, f2, MyFactions.RELATION_NEUTRAL, false);
                        }
                        else if (f1 != f2 && f1 != MyMwcObjectBuilder_FactionEnum.None)
                        {
                            MyFactions.SetFactionStatus(f1, f2, MyFactions.RELATION_WORST, false);
                        }
                    }
                }

                // Freelancers are enemies to self, it allows classic deathmatch
                MyFactions.SetFactionStatus(MyMwcObjectBuilder_FactionEnum.Freelancers, MyMwcObjectBuilder_FactionEnum.Freelancers, MyFactions.RELATION_WORST, false);
            }

            if (IsHost)
            {
                MyEntityIdentifier.CurrentPlayerId = GeneratePlayerId();

                // Make playership proper id
                MyEntityIdentifier.RemoveEntity(MySession.PlayerShip.EntityId.Value);
                MySession.PlayerShip.EntityId = MyEntityIdentifier.AllocatePlayershipId();
                MyEntityIdentifier.AddEntityWithId(MySession.PlayerShip);

                NewPlayer += MyMultiplayerGameplay_NewPlayer;
            }


            MyClientServer.LoggedPlayer.Statistics = new MyPlayerStatistics();
            Peers.PlayerDisconnected += Peers_PlayerDisconnected;

            Resume();


            MyMwcLog.DecreaseIndent();
            MyMwcLog.WriteLine("MyMultiplayerGameplay.Start - END");
        }