private void Factions_FactionStateChanged(MyFactionCollection.MyFactionStateChange action, long fromFactionId, long toFactionId, long playerId, long senderId)
        {
            if (MySession.Static.LocalHumanPlayer == null)
            {
                return;
            }
            // get player id
            long localPlayerID = MySession.Static.LocalHumanPlayer.Identity.IdentityId;

            // get player faction
            IMyFaction myFaction = MySession.Static.Factions.TryGetPlayerFaction(MySession.Static.LocalHumanPlayer.Identity.IdentityId);

            if (myFaction == null)
            {
                return;
            }

            if ((myFaction.IsLeader(localPlayerID) || myFaction.IsFounder(localPlayerID)) &&    // is leader or founder
                (myFaction.FactionId == fromFactionId || myFaction.FactionId == toFactionId) && // its our faction in this deal
                action == MyFactionCollection.MyFactionStateChange.AcceptPeace)                 // is it peace?
            {
                NotifyAchieved();
                MySession.Static.Factions.FactionStateChanged -= Factions_FactionStateChanged;
            }
        }
예제 #2
0
        private void Factions_FactionStateChanged(MyFactionCollection.MyFactionStateChange action, long fromFactionId, long toFactionId, long playerId, long senderId)
        {
            if (MySession.Static.LocalHumanPlayer == null)
            {
                return;
            }
            // get player id
            long localPlayerID = MySession.Static.LocalHumanPlayer.Identity.IdentityId;

            // get player faction
            IMyFaction myFaction = MySession.Static.Factions.TryGetPlayerFaction(localPlayerID);

            if (myFaction == null)
            {
                return;
            }

            // Player declaring war
            if ((myFaction.IsFounder(localPlayerID) || myFaction.IsLeader(localPlayerID)) && // is player leader/fouder of faction
                myFaction.FactionId == fromFactionId &&                                      // is sending war not recieving
                action == MyFactionCollection.MyFactionStateChange.DeclareWar)               // is it war?
            {
                NotifyAchieved();
                MySession.Static.Factions.FactionStateChanged -= Factions_FactionStateChanged;
            }
        }
        private void RefreshUserInfo()
        {
            m_userIsFounder = false;
            m_userIsLeader  = false;
            m_userFaction   = MySession.Static.Factions.TryGetPlayerFaction(MySession.LocalPlayerId);

            if (m_userFaction != null)
            {
                m_userIsFounder = m_userFaction.IsFounder(MySession.LocalPlayerId);
                m_userIsLeader  = m_userFaction.IsLeader(MySession.LocalPlayerId);
            }
        }
        private void RefreshRightSideButtons(MyGuiControlTable.Row selected)
        {
            m_buttonPromote.Enabled    = false;
            m_buttonKick.Enabled       = false;
            m_buttonAcceptJoin.Enabled = false;
            m_buttonDemote.Enabled     = false;

            if (selected != null)
            {
                var data = (MyFactionMember)selected.UserData;
                m_selectedUserId = data.PlayerId;
                var identity = Sync.Players.TryGetIdentity(data.PlayerId);
                m_selectedUserName = identity.DisplayName;

                if (m_selectedUserId != MySession.LocalPlayerId)
                {
                    if (m_userIsFounder && m_userFaction.IsLeader(m_selectedUserId))
                    {
                        m_buttonKick.Enabled   = true;
                        m_buttonDemote.Enabled = true;
                    }
                    else if (m_userIsFounder && m_userFaction.IsMember(m_selectedUserId))
                    {
                        m_buttonKick.Enabled    = true;
                        m_buttonPromote.Enabled = true;
                    }
                    else if (m_userIsLeader &&
                             m_userFaction.IsMember(m_selectedUserId) &&
                             !m_userFaction.IsLeader(m_selectedUserId) &&
                             !m_userFaction.IsFounder(m_selectedUserId))
                    {
                        m_buttonKick.Enabled = true;
                    }
                    else if ((m_userIsLeader || m_userIsFounder) && m_userFaction.JoinRequests.ContainsKey(m_selectedUserId))
                    {
                        m_buttonAcceptJoin.Enabled = true;
                    }
                }
            }
        }
        public override bool HandleCommand(ulong userId, string[] words)
        {
            if (!PluginSettings.Instance.WaypointsEnabled)
            {
                return(false);
            }

            if (words.Count() != 1)
            {
                Communication.SendPrivateInformation(userId, GetHelp());
                return(true);
            }

            string     playerName = PlayerMap.Instance.GetPlayerNameFromSteamId(userId);
            long       playerId   = PlayerMap.Instance.GetFastPlayerIdFromSteamId(userId);
            IMyFaction faction    = MyAPIGateway.Session.Factions.TryGetPlayerFaction(playerId);

            if (faction == null)
            {
                Communication.SendPrivateInformation(userId, string.Format("Unable to find your faction information.  You must be in a faction to use this."));
                return(true);
            }

            List <WaypointItem> items = Waypoints.Instance.Get((ulong)faction.FactionId);
            WaypointItem        item  = items.FirstOrDefault(x => x.Name.ToLower() == words[0].ToLower());

            if (item == null)
            {
                Communication.SendPrivateInformation(userId, string.Format("You do not have a faction waypoint with the name: {0}", words[0]));
                return(true);
            }

            if (item.Leader && !faction.IsLeader(playerId))
            {
                Communication.SendPrivateInformation(userId, string.Format("You must be a faction leader to remove the waypoint: {0}", words[0]));
                return(true);
            }

            Waypoints.Instance.Remove((ulong)faction.FactionId, words[0]);
            foreach (ulong steamId in PlayerManager.Instance.ConnectedPlayers)
            {
                if (Player.CheckPlayerSameFaction(userId, steamId))
                {
                    //Communication.SendClientMessage(steamId, string.Format("/waypoint remove '{0}'", words[0]));
                    item.Remove = true;
                    Communication.WaypointMessage(item);
                }
            }

            Communication.SendFactionClientMessage(userId, string.Format("/message Server {0} has removed the waypoint: '{1}'", playerName, words[0]));
            return(true);
        }
        public override bool HandleCommand(ulong userId, string[] words)
        {
            if (!PluginSettings.Instance.WaypointsEnabled)
            {
                return(false);
            }

            if (words.Length != 2)
            {
                Communication.SendPrivateInformation(userId, GetHelp());
                return(true);
            }

            string name  = words[0];
            string group = words[1];

            List <WaypointItem> items = Waypoints.Instance.Get(userId);
            WaypointItem        item  = items.FirstOrDefault(x => x.Name.ToLower() == words[0]);

            if (item != null)
            {
                if (Waypoints.Instance.GroupAdd(userId, words[0], words[1]))
                {
                    Communication.SendPrivateInformation(userId, string.Format("Waypoint '{0}' added to the group '{1}'", name, group));
                }
                else
                {
                    Communication.SendPrivateInformation(userId, string.Format("Failed to add waypoint '{0}' to the group '{1}'", name, group));
                }

                return(true);
            }

            string     playerName = PlayerMap.Instance.GetPlayerNameFromSteamId(userId);
            long       playerId   = PlayerMap.Instance.GetFastPlayerIdFromSteamId(userId);
            IMyFaction faction    = MyAPIGateway.Session.Factions.TryGetPlayerFaction(playerId);

            if (faction != null)
            {
                items = Waypoints.Instance.Get((ulong)faction.FactionId);
                item  = items.FirstOrDefault(x => x.Name.ToLower() == words[0]);

                if (item != null)
                {
                    if (item.Leader && !faction.IsLeader(playerId))
                    {
                        Communication.SendPrivateInformation(userId, "Only a faction leader can modify this item");
                        return(true);
                    }

                    if (Waypoints.Instance.GroupAdd((ulong)faction.FactionId, words[0], words[1]))
                    {
                        Communication.SendFactionClientMessage(userId, string.Format("/message Server {0} added the waypoint '{1}' to the group '{2}'", playerName, name, group));
                    }
                    else
                    {
                        Communication.SendPrivateInformation(userId, string.Format("Failed to add faction waypoint '{0}' to the group '{1}'", name, group));
                    }

                    return(true);
                }
            }

            Communication.SendPrivateInformation(userId, string.Format("You do not have a waypoint with the name '{0}'", name));
            return(true);
        }
        private void RefreshTableMembers()
        {
            m_tableMembers.Clear();

            foreach (var entry in m_selectedFaction.Members)
            {
                var member = entry.Value;

                var identity = Sync.Players.TryGetIdentity(member.PlayerId);
                System.Diagnostics.Debug.Assert(identity != null, "Faction member is not known identity!");
                if (identity == null)
                {
                    continue;
                }

                var   row        = new MyGuiControlTable.Row(member);
                var   compare    = MyMemberComparerEnum.Member;
                var   statusEnum = MySpaceTexts.Member;
                Color?txtColor   = null;

                if (m_selectedFaction.IsFounder(member.PlayerId))
                {
                    compare    = MyMemberComparerEnum.Founder;
                    statusEnum = MySpaceTexts.Founder;
                }
                else if (m_selectedFaction.IsLeader(member.PlayerId))
                {
                    compare    = MyMemberComparerEnum.Leader;
                    statusEnum = MySpaceTexts.Leader;
                }
                else if (m_selectedFaction.JoinRequests.ContainsKey(member.PlayerId))
                {
                    txtColor   = COLOR_CUSTOM_GREY;
                    compare    = MyMemberComparerEnum.Applicant;
                    statusEnum = MySpaceTexts.Applicant;
                }

                row.AddCell(new MyGuiControlTable.Cell(text:    new StringBuilder(identity.DisplayName),
                                                       toolTip: identity.DisplayName,
                                                       userData: entry, textColor: txtColor));
                row.AddCell(new MyGuiControlTable.Cell(text: MyTexts.Get(statusEnum), userData: compare, textColor: txtColor));
                m_tableMembers.Add(row);
            }

            foreach (var entry in m_selectedFaction.JoinRequests)
            {
                var request = entry.Value;
                var row     = new MyGuiControlTable.Row(request);

                var identity = Sync.Players.TryGetIdentity(request.PlayerId);
                System.Diagnostics.Debug.Assert(identity != null, "Player is not in allplayers list!");
                if (identity != null)
                {
                    row.AddCell(new MyGuiControlTable.Cell(text: new StringBuilder(identity.DisplayName),
                                                           toolTip: identity.DisplayName,
                                                           userData: entry, textColor: COLOR_CUSTOM_GREY));

                    row.AddCell(new MyGuiControlTable.Cell(text: MyTexts.Get(MySpaceTexts.Applicant),
                                                           userData: MyMemberComparerEnum.Applicant,
                                                           textColor: COLOR_CUSTOM_GREY));
                    m_tableMembers.Add(row);
                }
            }
        }
        private void RefreshUserInfo()
        {
            m_userIsFounder = false;
            m_userIsLeader  = false;
            m_userFaction = MySession.Static.Factions.TryGetPlayerFaction(MySession.Static.LocalPlayerId);

            if (m_userFaction != null)
            {
                m_userIsFounder = m_userFaction.IsFounder(MySession.Static.LocalPlayerId);
                m_userIsLeader = m_userFaction.IsLeader(MySession.Static.LocalPlayerId);
            }
        }
        public override bool HandleCommand(ulong userId, string[] words)
        {
            if (!PluginSettings.Instance.WaypointsEnabled)
            {
                return(false);
            }

            if (words.Length != 6 && words.Length != 7 && words.Length != 1)
            {
                Communication.SendPrivateInformation(userId, GetHelp());
                return(true);
            }

            string     playerName = PlayerMap.Instance.GetPlayerNameFromSteamId(userId);
            long       playerId   = PlayerMap.Instance.GetFastPlayerIdFromSteamId(userId);
            IMyFaction faction    = MyAPIGateway.Session.Factions.TryGetPlayerFaction(playerId);

            if (faction == null)
            {
                Communication.SendPrivateInformation(userId, string.Format("Unable to find your faction information.  You must be in a faction to use this."));
                return(true);
            }

            List <WaypointItem> items = Waypoints.Instance.Get((ulong)faction.FactionId);

            if (PluginSettings.Instance.WaypointsMaxPerFaction > 0 && items.Count >= PluginSettings.Instance.WaypointsMaxPerFaction)
            {
                Communication.SendPrivateInformation(userId, string.Format("Waypoint limit has been reached.  You may only have {0} faction waypoints at a time on this server.  Please remove some waypoints in order to add new ones.", PluginSettings.Instance.WaypointsMaxPerPlayer));
                return(true);
            }

            if (words.Length == 1)
            {
                IMyEntity playerEntity = Player.FindControlledEntity(playerId);
                if (playerEntity == null)
                {
                    Communication.SendPrivateInformation(userId, string.Format("Can't find your position"));
                    return(true);
                }

                Vector3D pos  = playerEntity.GetPosition();
                string   name = words[0];

                foreach (ulong steamId in PlayerManager.Instance.ConnectedPlayers)
                {
                    if (Player.CheckPlayerSameFaction(userId, steamId))
                    {
                        Communication.WaypointMessage(steamId, string.Format("add '{0}' '{0}' Neutral {1} {2} {3}", name, Math.Floor(pos.X), Math.Floor(pos.Y), Math.Floor(pos.Z)));
                    }
                }

                WaypointItem item = new WaypointItem
                {
                    SteamId      = (ulong)faction.FactionId,
                    Name         = name,
                    Text         = name,
                    Position     = pos,
                    WaypointType = WaypointTypes.Neutral,
                    Leader       = faction.IsLeader(playerId)
                };
                Waypoints.Instance.Add(item);

                Communication.SendFactionClientMessage(userId, string.Format("/message Server {2} has added the waypoint: '{0}' at {1} by '{2}'", item.Name, General.Vector3DToString(item.Position), playerName));
            }
            else
            {
                for (int r = 3; r < 6; r++)
                {
                    double test;
                    if (!double.TryParse(words[r], out test))
                    {
                        Communication.SendPrivateInformation(userId, string.Format("Invalid position information: {0} is invalid", words[r]));
                        return(true);
                    }
                }

                string add = string.Join(" ", words.Select(s => s.ToLowerInvariant()));

                foreach (ulong steamId in PlayerManager.Instance.ConnectedPlayers)
                {
                    if (Player.CheckPlayerSameFaction(userId, steamId))
                    {
                        Communication.WaypointMessage(steamId, string.Format("add {0}", add));
                    }
                }

                string group = "";
                if (words.Length == 7)
                {
                    group = words[7];
                }

                WaypointItem item = new WaypointItem
                {
                    SteamId = (ulong)faction.FactionId,
                    Name    = words[0],
                    Text    = words[1]
                };
                WaypointTypes type;
                Enum.TryParse(words[2], true, out type);
                item.WaypointType = type;
                item.Position     = new Vector3D(double.Parse(words[3]), double.Parse(words[4]), double.Parse(words[5]));
                item.Group        = group;
                item.Leader       = faction.IsLeader(playerId);
                Waypoints.Instance.Add(item);

                Communication.SendFactionClientMessage(userId, string.Format("/message Server {2} has added the waypoint: '{0}' at {1} by '{2}'", item.Name, General.Vector3DToString(item.Position), playerName));
            }
            return(true);
        }
        public override bool HandleCommand(ulong userId, string command)
        {
            string[] words = command.Split(' ');
            if (!PluginSettings.Instance.WaypointsEnabled)
            {
                return(false);
            }

            string[] splits = General.SplitString(string.Join(" ", words));

            if (splits.Length != 1)
            {
                Communication.SendPrivateInformation(userId, GetHelp());
                return(true);
            }

            string name = splits[0];

            List <WaypointItem> items = Waypoints.Instance.Get(userId);
            WaypointItem        item  = items.FirstOrDefault(x => x.Name.ToLower() == splits[0]);

            if (item != null)
            {
                if (Waypoints.Instance.GroupRemove(userId, name))
                {
                    Communication.SendPrivateInformation(userId, string.Format("Waypoint '{0}' removed from group", name));
                }
                else
                {
                    Communication.SendPrivateInformation(userId, string.Format("Failed to remove waypoint '{0}' from group", name));
                }

                return(true);
            }

            string     playerName = PlayerMap.Instance.GetPlayerNameFromSteamId(userId);
            long       playerId   = PlayerMap.Instance.GetFastPlayerIdFromSteamId(userId);
            IMyFaction faction    = MyAPIGateway.Session.Factions.TryGetPlayerFaction(playerId);

            if (faction != null)
            {
                items = Waypoints.Instance.Get((ulong)faction.FactionId);
                item  = items.FirstOrDefault(x => x.Name.ToLower() == splits[0]);

                if (item != null)
                {
                    if (item.Leader && !faction.IsLeader(playerId))
                    {
                        Communication.SendPrivateInformation(userId, "Only a faction leader can modify this item");
                        return(true);
                    }

                    if (Waypoints.Instance.GroupRemove((ulong)faction.FactionId, name))
                    {
                        Communication.SendFactionClientMessage(userId, string.Format("/message Server {0} removed the waypoint '{1}' from it's group", playerName, name));
                    }
                    else
                    {
                        Communication.SendPrivateInformation(userId, string.Format("Failed to remove faction waypoint '{0}' from it's group", name));
                    }

                    return(true);
                }
            }

            return(true);
        }