/// <summary>
 /// Setups player faction accoring to Factions.sbc and Scenario.sbx settings. If faction is not created yet. It will be created
 /// for the player with Faction.sbc settings. Faction have to accept humans.
 /// </summary>
 protected virtual void CreateAndSetPlayerFaction()
 {
     if (Sync.IsServer && this.FactionTag != null && MySession.Static.LocalHumanPlayer != null)
     {
         MyFaction playerFaction = MySession.Static.Factions.TryGetOrCreateFactionByTag(this.FactionTag);
         playerFaction.AcceptJoin(MySession.Static.LocalHumanPlayer.Identity.IdentityId);
     }
 }
Beispiel #2
0
            public override void Apply()
            {
                MyFaction faction = null;

                if (FactionTag != null)
                {
                    faction = MySession.Static.Factions.TryGetOrCreateFactionByTag(FactionTag);
                }

                long factionId = faction != null ? faction.FactionId : 0;

                MyWorldGenerator.SetupBase(PrefabFile, Offset, AsteroidName, BeaconName, factionId);
            }
Beispiel #3
0
            public override void Apply()
            {
                MyFaction faction = null;

                if (FactionTag != null)
                {
                    faction = MySession.Static.Factions.TryGetOrCreateFactionByTag(FactionTag);
                }

                long factionId = faction != null ? faction.FactionId : 0;

                if (RandomRadius == 0f)
                {
                    MyPrefabManager.Static.AddShipPrefab(PrefabFile, Transform.GetMatrix(), factionId, spawnAtOrigin: UseFirstGridOrigin);
                }
                else
                {
                    MyPrefabManager.Static.AddShipPrefabRandomPosition(PrefabFile, Transform.Position, RandomRadius, factionId);
                }
            }
        public override void BeforeStart()
        {
            base.BeforeStart();

            MyFaction pirateFaction = MySession.Static.Factions.TryGetFactionByTag(PIRATE_FACTION_TAG);

            Debug.Assert(pirateFaction != null, "No pirate faction in the world. Pirate antenan needs it.");

            if (pirateFaction != null)
            {
                // Make sure that the pirate identity exists
                if (m_piratesIdentityId != 0)
                {
                    if (Sync.IsServer)
                    {
                        MyIdentity pirateIdentity = Sync.Players.TryGetIdentity(m_piratesIdentityId);
                        Debug.Assert(pirateIdentity != null, "The pirate identity does not exist, although its ID was saved!");

                        if (pirateIdentity == null)
                        {
                            Sync.Players.CreateNewIdentity(IDENTITY_NAME, m_piratesIdentityId, null);
                        }

                        pirateIdentity.LastLoginTime = DateTime.Now;

                        // Check if he is already in a faction.
                        MyFaction oldPirateFaction = MySession.Static.Factions.GetPlayerFaction(m_piratesIdentityId);
                        if (oldPirateFaction == null)
                        {
                            MyFactionCollection.SendJoinRequest(pirateFaction.FactionId, m_piratesIdentityId);
                        }
                    }
                }
                else
                {
                    m_piratesIdentityId = pirateFaction.FounderId;
                }

                if (!Sync.Players.IdentityIsNpc(m_piratesIdentityId))
                {
                    Sync.Players.MarkIdentityAsNPC(m_piratesIdentityId);
                }
            }

            // Make sure that all the drone entities exist
            foreach (var drone in m_droneInfos)
            {
                MyEntity entity;
                MyEntities.TryGetEntityById(drone.Key, out entity);
                if (entity == null)
                {
                    DroneInfo.Deallocate(drone.Value);
                    m_droneInfos.Remove(drone.Key);
                }
                else
                {
                    if (!MySession.Static.Settings.EnableDrones)
                    {
                        MyCubeGrid grid   = entity as MyCubeGrid;
                        var        remote = entity as MyRemoteControl;
                        if (grid == null)
                        {
                            grid = remote.CubeGrid;
                        }

                        UnregisterDrone(entity, immediate: false);
                        grid.Close();
                        //grid.SyncObject.SendCloseRequest();
                    }
                    else
                    {
                        RegisterDrone(drone.Value.AntennaEntityId, entity, immediate: false);
                    }
                }
            }
            m_droneInfos.ApplyRemovals();
        }
        private void RefreshFactionChatHistory(MyFaction faction)
        {
            m_chatHistory.Clear();
            
            var localFaction = MySession.Static.Factions.TryGetPlayerFaction(MySession.Static.LocalPlayerId);
            if (localFaction == null)
            {
                System.Diagnostics.Debug.Fail("Chat shouldn't be refreshed if local player is not a member of a faction!");
                return;
            }
            MyFactionChatHistory factionChat = MyChatSystem.FindFactionChatHistory(faction.FactionId, localFaction.FactionId);
            if (factionChat != null)
            {
                var chat = factionChat.Chat;
                foreach (var item in chat)
                {
                    bool alreadySentToMe;
                    if (item.IdentityId == MySession.Static.LocalPlayerId || (item.PlayersToSendTo.TryGetValue(MySession.Static.LocalPlayerId, out alreadySentToMe) && alreadySentToMe))
                    {
                        int alreadySentToCount = 0;
                        foreach (var keyValue in item.PlayersToSendTo)
                        {
                            if (keyValue.Value)
                            {
                                alreadySentToCount++;
                            }
                        }
                        var identity = MySession.Static.Players.TryGetIdentity(item.IdentityId);

                        if (identity == null) continue;
                        bool isPlayer = identity.IdentityId == MySession.Static.LocalPlayerId;

                        m_chatHistory.AppendText(identity.DisplayName, isPlayer ? MyFontEnum.DarkBlue : MyFontEnum.Blue, m_chatHistory.TextScale, Vector4.One);
                        if (item.PlayersToSendTo != null && item.PlayersToSendTo.Count > 0 && alreadySentToCount < item.PlayersToSendTo.Count)
                        {
                            var pendingText = new StringBuilder();
                            pendingText.Append(" (");
                            pendingText.Append(alreadySentToCount.ToString());
                            pendingText.Append("/");
                            pendingText.Append(item.PlayersToSendTo.Count.ToString());
                            pendingText.Append(") ");
                            m_chatHistory.AppendText(pendingText, MyFontEnum.Red, m_chatHistory.TextScale, Vector4.One);
                        }
                        m_chatHistory.AppendText(": ", isPlayer ? MyFontEnum.DarkBlue : MyFontEnum.Blue, m_chatHistory.TextScale, Vector4.One);
                        m_chatHistory.AppendText(item.Text, MyFontEnum.White, m_chatHistory.TextScale, Vector4.One);
                        m_chatHistory.AppendLine();
                    }
                }
            }

            m_playerList.SelectedItems.Clear();
            m_chatHistory.ScrollbarOffset = 1.0f;
        }
 public FactionWrapper(MyFaction faction)
 {
     Faction = faction;
 }
 public FactionListItem(MyFaction faction)
 {
     Faction = faction;
 }