Ejemplo n.º 1
0
            static void Postfix(long playerId1,
                                long playerId2, ref MyRelationsBetweenPlayerAndBlock __result)
            {
                if (playerId1 == playerId2)
                {
                    return;
                }
                IMyFaction playerFaction1 = MySession.Static.Factions.TryGetPlayerFaction(playerId1);
                IMyFaction playerFaction2 = MySession.Static.Factions.TryGetPlayerFaction(playerId2);

                if (playerFaction1 != null && playerFaction2 != null)
                {
                    if (AlliancePlugin.GetAllianceNoLoading(playerFaction1 as MyFaction) != null && AlliancePlugin.GetAllianceNoLoading(playerFaction2 as MyFaction) != null)
                    {
                        if (AlliancePlugin.GetAllianceNoLoading(playerFaction1 as MyFaction) == AlliancePlugin.GetAllianceNoLoading(playerFaction2 as MyFaction))
                        {
                            //    AlliancePlugin.Log.Info("Same alliance?");
                            __result = MyRelationsBetweenPlayerAndBlock.Friends;
                            return;
                        }
                    }
                    if (MySession.Static.Factions.AreFactionsFriends(playerFaction1.FactionId, playerFaction2.FactionId))
                    {
                        __result = MyRelationsBetweenPlayerAndBlock.Friends;
                        return;
                    }
                }

                return;
                // make sure you only skip if really necessary
            }
Ejemplo n.º 2
0
        public static void Login(IPlayer p)
        {
            if (p == null)
            {
                return;
            }

            MyIdentity id = AlliancePlugin.GetIdentityByNameOrId(p.SteamId.ToString());

            if (id == null)
            {
                return;
            }
            IMyFaction playerFac = MySession.Static.Factions.GetPlayerFaction(id.IdentityId);
            MyFaction  arrr      = MySession.Static.Factions.TryGetFactionByTag("arrr");

            if (arrr != null)
            {
                if (playerFac != null && !MySession.Static.Factions.AreFactionsEnemies(arrr.FactionId, FacUtils.GetPlayersFaction(id.IdentityId).FactionId))
                {
                    Sandbox.Game.Multiplayer.MyFactionCollection.DeclareWar(playerFac.FactionId, arrr.FactionId);
                }
            }

            MyFaction ACME = MySession.Static.Factions.TryGetFactionByTag("ACME");

            if (ACME != null)
            {
                MySession.Static.Factions.SetReputationBetweenPlayerAndFaction(id.IdentityId, ACME.FactionId, 0);
                MySession.Static.Factions.AddFactionPlayerReputation(id.IdentityId, ACME.FactionId, 0);
            }
            MyFaction GAIA = MySession.Static.Factions.TryGetFactionByTag("GAIA");

            if (GAIA != null)
            {
                MySession.Static.Factions.SetReputationBetweenPlayerAndFaction(id.IdentityId, GAIA.FactionId, 0);
                MySession.Static.Factions.AddFactionPlayerReputation(id.IdentityId, GAIA.FactionId, 0);
            }
            MyFaction wolf = MySession.Static.Factions.TryGetFactionByTag("WOLF");

            if (wolf != null)
            {
                if (playerFac != null && !MySession.Static.Factions.AreFactionsEnemies(wolf.FactionId, FacUtils.GetPlayersFaction(id.IdentityId).FactionId))
                {
                    Sandbox.Game.Multiplayer.MyFactionCollection.DeclareWar(playerFac.FactionId, wolf.FactionId);
                }
            }
            if (File.Exists(AlliancePlugin.path + "//PlayerData//" + p.SteamId + ".xml") && playerFac != null)
            {
                PlayerData data = utils.ReadFromXmlFile <PlayerData>(AlliancePlugin.path + "//PlayerData//" + p.SteamId + ".xml");
                if (data.InAllianceChat)
                {
                    if (AlliancePlugin.GetAllianceNoLoading(playerFac as MyFaction) != null)
                    {
                        PeopleInAllianceChat.Remove(p.SteamId);
                        PeopleInAllianceChat.Add(p.SteamId, AlliancePlugin.GetAllianceNoLoading(playerFac as MyFaction).AllianceId);
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public void distress(string reason = "")
        {
            if (Context.Player == null)
            {
                Context.Respond("no no console no distress");
                return;
            }


            IMyFaction playerFac = FacUtils.GetPlayersFaction(Context.Player.Identity.IdentityId);

            if (playerFac == null)
            {
                Context.Respond("You dont have a faction.");
                return;
            }
            if (reason != "")
            {
                reason = Context.RawArgs;
            }
            MyFaction fac = MySession.Static.Factions.GetPlayerFaction(Context.Player.IdentityId);

            if (fac == null)
            {
                Context.Respond("A faction is required to use alliance features.");
                return;
            }

            if (distressCooldowns.TryGetValue(Context.Player.IdentityId, out DateTime time))
            {
                if (DateTime.Now < time)
                {
                    Context.Respond(AllianceCommands.GetCooldownMessage(time));
                    return;
                }
                else
                {
                    distressCooldowns[Context.Player.IdentityId] = DateTime.Now.AddSeconds(30);
                }
            }
            else
            {
                distressCooldowns.Add(Context.Player.IdentityId, DateTime.Now.AddSeconds(30));
            }
            Alliance alliance = AlliancePlugin.GetAllianceNoLoading(fac);

            if (alliance != null)
            {
                distressCount++;
                AllianceChat.SendChatMessage(alliance.AllianceId, "Distress Signal", CreateGps(Context.Player.Character.GetPosition(), Color.Yellow, 600, distressCount.ToString(), reason).ToString(), true, 0);
            }
        }
Ejemplo n.º 4
0
        public static void SendChatMessageFromDiscord(Guid allianceId, string prefix, string message, ulong discordId = 0)
        {
            log.Info(allianceId.ToString() + " : " + prefix + " " + message);
            Alliance     alliance     = AlliancePlugin.GetAllianceNoLoading(allianceId);
            List <ulong> OtherMembers = new List <ulong>();

            foreach (MyPlayer player in MySession.Static.Players.GetOnlinePlayers())
            {
                MyFaction fac = MySession.Static.Factions.TryGetPlayerFaction(player.Identity.IdentityId) as MyFaction;
                if (fac != null)
                {
                    if (alliance.AllianceMembers.Contains(fac.FactionId))
                    {
                        OtherMembers.Add(player.Id.SteamId);
                    }
                }
            }
            if (discordId > 0)
            {
                log.Info(allianceId.ToString() + " : " + alliance.name + " : " + prefix + " " + message + " discord id " + discordId);
            }
            else
            {
                log.Info(allianceId.ToString() + " : " + alliance.name + " : " + prefix + " " + message + " the bot");
            }
            foreach (ulong id in OtherMembers)
            {
                ShipyardCommands.SendMessage(prefix, message, new Color(alliance.r, alliance.g, alliance.b), (long)id);
                MyGpsCollection gpscol = (MyGpsCollection)MyAPIGateway.Session?.GPS;

                if (ScanChat(message, null) != null)
                {
                    MyGps gpsRef = ScanChat(message, null);
                    gpsRef.GPSColor      = Color.Yellow;
                    gpsRef.AlwaysVisible = true;
                    gpsRef.ShowOnHud     = true;

                    long idenId = MySession.Static.Players.TryGetIdentityId(id);
                    MyAPIGateway.Utilities.InvokeOnGameThread(() =>
                    {
                        gpscol.SendAddGps(idenId, ref gpsRef);
                    });
                }
            }
        }
Ejemplo n.º 5
0
 public void UnlockKoth(string name, string allianceName = "")
 {
     foreach (KothConfig koth in AlliancePlugin.KOTHs)
     {
         if (koth.KothName.Equals(name))
         {
             koth.nextCaptureAvailable = DateTime.Now;
             koth.nextCaptureInterval  = DateTime.Now;
             koth.CaptureStarted       = true;
             koth.nextCaptureAvailable = DateTime.Now.AddSeconds(1);
             // koth.owner = Guid.Empty;
             if (!allianceName.Equals(""))
             {
                 Alliance alliance = AlliancePlugin.GetAllianceNoLoading(allianceName);
                 koth.capturingNation = alliance.AllianceId;
             }
             else
             {
                 koth.capturingNation = Guid.Empty;
             }
             Context.Respond("Unlocked the koth");
         }
     }
 }
Ejemplo n.º 6
0
        public void DoTags()
        {
            Dictionary <String, String> tagsAndNames = new Dictionary <string, string>();
            Dictionary <String, String> friends      = new Dictionary <string, string>();
            Dictionary <String, String> neutrals     = new Dictionary <string, string>();
            Dictionary <String, String> alliances    = new Dictionary <String, string>();

            foreach (MyPlayer player in MySession.Static.Players.GetOnlinePlayers())
            {
                string     name     = MyMultiplayer.Static.GetMemberName(player.Id.SteamId);
                MyIdentity identity = AlliancePlugin.GetIdentityByNameOrId(player.Id.SteamId.ToString());
                if (FacUtils.GetPlayersFaction(player.Identity.IdentityId) != null)
                {
                    IMyFaction playerFac = null;
                    if (FacUtils.GetPlayersFaction(Context.Player.Identity.IdentityId) != null)
                    {
                        playerFac = FacUtils.GetPlayersFaction(Context.Player.Identity.IdentityId);
                    }
                    if (playerFac == null)
                    {
                        Context.Respond("Make a faction. This command does not work without being in a faction.");
                        return;
                    }
                    if (FacUtils.GetPlayersFaction(player.Identity.IdentityId) == null)
                    {
                        continue;
                    }
                    Alliance alliance = AlliancePlugin.GetAllianceNoLoading(FacUtils.GetPlayersFaction(player.Identity.IdentityId) as MyFaction);
                    if (alliance != null)
                    {
                        if (alliances.ContainsKey(alliance.name))
                        {
                            alliances.TryGetValue(alliance.name, out String temp);


                            if (FacUtils.GetPlayersFaction(player.Identity.IdentityId).IsFounder(player.Identity.IdentityId))
                            {
                                temp += "\n [" + FacUtils.GetPlayersFaction(player.Identity.IdentityId).Tag + "] - " + player.DisplayName + " (Founder)";
                            }
                            else
                            {
                                if (FacUtils.GetPlayersFaction(player.Identity.IdentityId).IsLeader(player.Identity.IdentityId))
                                {
                                    temp += "\n [" + FacUtils.GetPlayersFaction(player.Identity.IdentityId).Tag + "] - " + player.DisplayName + " (Leader)";
                                }

                                else
                                {
                                    temp += "\n [" + FacUtils.GetPlayersFaction(player.Identity.IdentityId).Tag + "] - " + player.DisplayName;
                                }
                            }
                            alliances.Remove(alliance.name);
                            alliances.Add(alliance.name, temp);
                        }
                        else
                        {
                            String temp = "";
                            if (FacUtils.GetPlayersFaction(player.Identity.IdentityId).IsFounder(player.Identity.IdentityId))
                            {
                                temp += " [" + FacUtils.GetPlayersFaction(player.Identity.IdentityId).Tag + "] - " + player.DisplayName + " (Founder)";
                            }
                            else
                            {
                                if (FacUtils.GetPlayersFaction(player.Identity.IdentityId).IsLeader(player.Identity.IdentityId))
                                {
                                    temp += " [" + FacUtils.GetPlayersFaction(player.Identity.IdentityId).Tag + "] - " + player.DisplayName + " (Leader)";
                                }

                                else
                                {
                                    temp += " [" + FacUtils.GetPlayersFaction(player.Identity.IdentityId).Tag + "] - " + player.DisplayName;
                                }
                            }

                            alliances.Add(alliance.name, temp);
                        }
                    }
                    else
                    {
                        if (friends.ContainsKey(FacUtils.GetPlayersFaction(player.Identity.IdentityId).Tag))
                        {
                            friends.TryGetValue(FacUtils.GetPlayersFaction(player.Identity.IdentityId).Tag, out String temp);


                            if (FacUtils.GetPlayersFaction(player.Identity.IdentityId).IsFounder(player.Identity.IdentityId))
                            {
                                temp += "\n [" + FacUtils.GetPlayersFaction(player.Identity.IdentityId).Tag + "] - " + player.DisplayName + " (Founder)";
                            }
                            else
                            {
                                if (FacUtils.GetPlayersFaction(player.Identity.IdentityId).IsLeader(player.Identity.IdentityId))
                                {
                                    temp += "\n [" + FacUtils.GetPlayersFaction(player.Identity.IdentityId).Tag + "] - " + player.DisplayName + " (Leader)";
                                }

                                else
                                {
                                    temp += "\n [" + FacUtils.GetPlayersFaction(player.Identity.IdentityId).Tag + "] - " + player.DisplayName;
                                }
                            }
                            friends.Remove(FacUtils.GetPlayersFaction(player.Identity.IdentityId).Tag);
                            friends.Add(FacUtils.GetPlayersFaction(player.Identity.IdentityId).Tag, temp);
                        }
                        if (MySession.Static.Factions.AreFactionsEnemies(playerFac.FactionId, FacUtils.GetPlayersFaction(player.Identity.IdentityId).FactionId))
                        {
                            if (tagsAndNames.ContainsKey(FacUtils.GetPlayersFaction(player.Identity.IdentityId).Tag))
                            {
                                tagsAndNames.TryGetValue(FacUtils.GetPlayersFaction(player.Identity.IdentityId).Tag, out String temp);


                                if (FacUtils.GetPlayersFaction(player.Identity.IdentityId).IsFounder(player.Identity.IdentityId))
                                {
                                    temp += "\n [" + FacUtils.GetPlayersFaction(player.Identity.IdentityId).Tag + "] - " + player.DisplayName + " (Founder)";
                                }
                                else
                                {
                                    if (FacUtils.GetPlayersFaction(player.Identity.IdentityId).IsLeader(player.Identity.IdentityId))
                                    {
                                        temp += "\n [" + FacUtils.GetPlayersFaction(player.Identity.IdentityId).Tag + "] - " + player.DisplayName + " (Leader)";
                                    }

                                    else
                                    {
                                        temp += "\n [" + FacUtils.GetPlayersFaction(player.Identity.IdentityId).Tag + "] - " + player.DisplayName;
                                    }
                                }
                                tagsAndNames.Remove(FacUtils.GetPlayersFaction(player.Identity.IdentityId).Tag);
                                tagsAndNames.Add(FacUtils.GetPlayersFaction(player.Identity.IdentityId).Tag, temp);
                            }
                            else
                            {
                                String temp = "";
                                if (FacUtils.GetPlayersFaction(player.Identity.IdentityId).IsFounder(player.Identity.IdentityId))
                                {
                                    temp += "\n [" + FacUtils.GetPlayersFaction(player.Identity.IdentityId).Tag + "] - " + player.DisplayName + " (Founder)";
                                }
                                else
                                {
                                    if (FacUtils.GetPlayersFaction(player.Identity.IdentityId).IsLeader(player.Identity.IdentityId))
                                    {
                                        temp += "\n [" + FacUtils.GetPlayersFaction(player.Identity.IdentityId).Tag + "] - " + player.DisplayName + " (Leader)";
                                    }

                                    else
                                    {
                                        temp += "\n [" + FacUtils.GetPlayersFaction(player.Identity.IdentityId).Tag + "] - " + player.DisplayName;
                                    }
                                }

                                tagsAndNames.Add(FacUtils.GetPlayersFaction(player.Identity.IdentityId).Tag, temp);
                            }
                        }
                        else
                        {
                            if (neutrals.ContainsKey(FacUtils.GetPlayersFaction(player.Identity.IdentityId).Tag))
                            {
                                neutrals.TryGetValue(FacUtils.GetPlayersFaction(player.Identity.IdentityId).Tag, out String temp);


                                if (FacUtils.GetPlayersFaction(player.Identity.IdentityId).IsFounder(player.Identity.IdentityId))
                                {
                                    temp += "\n [" + FacUtils.GetPlayersFaction(player.Identity.IdentityId).Tag + "] - " + player.DisplayName + " (Founder)";
                                }
                                else
                                {
                                    if (FacUtils.GetPlayersFaction(player.Identity.IdentityId).IsLeader(player.Identity.IdentityId))
                                    {
                                        temp += "\n [" + FacUtils.GetPlayersFaction(player.Identity.IdentityId).Tag + "] - " + player.DisplayName + " (Leader)";
                                    }

                                    else
                                    {
                                        temp += "\n [" + FacUtils.GetPlayersFaction(player.Identity.IdentityId).Tag + "] - " + player.DisplayName;
                                    }
                                }
                                neutrals.Remove(FacUtils.GetPlayersFaction(player.Identity.IdentityId).Tag);
                                neutrals.Add(FacUtils.GetPlayersFaction(player.Identity.IdentityId).Tag, temp);
                            }
                            else
                            {
                                String temp = "";
                                if (FacUtils.GetPlayersFaction(player.Identity.IdentityId).IsFounder(player.Identity.IdentityId))
                                {
                                    temp += "\n [" + FacUtils.GetPlayersFaction(player.Identity.IdentityId).Tag + "] - " + player.DisplayName + " (Founder)";
                                }
                                else
                                {
                                    if (FacUtils.GetPlayersFaction(player.Identity.IdentityId).IsLeader(player.Identity.IdentityId))
                                    {
                                        temp += "\n [" + FacUtils.GetPlayersFaction(player.Identity.IdentityId).Tag + "] - " + player.DisplayName + " (Leader)";
                                    }

                                    else
                                    {
                                        temp += "\n [" + FacUtils.GetPlayersFaction(player.Identity.IdentityId).Tag + "] - " + player.DisplayName;
                                    }
                                }

                                neutrals.Add(FacUtils.GetPlayersFaction(player.Identity.IdentityId).Tag, temp);
                            }
                        }
                    }
                }
            }
            var sb = new StringBuilder();

            foreach (KeyValuePair <String, String> keys in alliances)
            {
                sb.AppendLine(keys.Key);
                sb.AppendLine(keys.Value);
                sb.AppendLine("");
            }
            sb.Append("At War");
            foreach (KeyValuePair <String, String> keys in tagsAndNames)
            {
                sb.Append(keys.Value);
            }
            sb.Append("\n ");
            sb.Append("\n Friends");
            foreach (KeyValuePair <String, String> keys in friends)
            {
                sb.Append(keys.Value);
            }
            sb.Append("\n ");
            sb.Append("\n Neutral");
            foreach (KeyValuePair <String, String> keys in neutrals)
            {
                sb.Append(keys.Value);
            }

            DialogMessage m = new DialogMessage("Tags of online players", "", sb.ToString());

            ModCommunication.SendMessageTo(m, Context.Player.SteamUserId);
        }
Ejemplo n.º 7
0
        public static void DoChatMessage(TorchChatMessage msg, ref bool consumed)
        {
            if (msg.AuthorSteamId == null)
            {
                return;
            }
            if (msg.Channel == Sandbox.Game.Gui.ChatChannel.Private || msg.Channel == Sandbox.Game.Gui.ChatChannel.Faction)
            {
                return;
            }
            if (msg.Message.StartsWith("!"))
            {
                return;
            }

            if (PeopleInAllianceChat.ContainsKey((ulong)msg.AuthorSteamId))
            {
                MyIdentity identity;
                if (IdentityIds.ContainsKey((ulong)msg.AuthorSteamId))
                {
                    identity = MySession.Static.Players.TryGetIdentity(IdentityIds[(ulong)msg.AuthorSteamId]);
                }
                else
                {
                    identity = AlliancePlugin.GetIdentityByNameOrId(msg.AuthorSteamId.ToString());
                }

                if (identity == null)
                {
                    return;
                }
                MyFaction fac = MySession.Static.Factions.GetPlayerFaction(identity.IdentityId);
                if (fac == null)
                {
                    bool noFac = true;
                    if (AlliancePlugin.GetIdentityByNameOrId(msg.Author) != null)
                    {
                        if (MySession.Static.Factions.GetPlayerFaction(AlliancePlugin.GetIdentityByNameOrId(msg.Author).IdentityId) != null)
                        {
                            noFac = false;
                            fac   = MySession.Static.Factions.GetPlayerFaction(AlliancePlugin.GetIdentityByNameOrId(msg.Author).IdentityId);
                        }
                    }

                    if (noFac)
                    {
                        PeopleInAllianceChat.Remove((ulong)msg.AuthorSteamId);
                        AlliancePlugin.SendChatMessage("Failsafe", "Faction null");
                    }
                    return;
                }
                if (AlliancePlugin.GetAllianceNoLoading(fac) == null)
                {
                    PeopleInAllianceChat.Remove((ulong)msg.AuthorSteamId);
                    AlliancePlugin.SendChatMessage("Failsafe", "Alliance null");
                    return;
                }
                consumed = true;
                Guid         allianceId   = PeopleInAllianceChat[(ulong)msg.AuthorSteamId];
                List <ulong> OtherMembers = new List <ulong>();

                Alliance alliance = AlliancePlugin.GetAllianceNoLoading(allianceId);
                // ShipyardCommands.SendMessage(msg.Author, "You are in alliance chat", Color.BlueViolet, (long)msg.AuthorSteamId);
                if (alliance.GetTitle((ulong)msg.AuthorSteamId).Equals(""))
                {
                    SendChatMessage(allianceId, msg.Author, msg.Message, true, identity.IdentityId);
                }
                else
                {
                    SendChatMessage(allianceId, alliance.GetTitle((ulong)msg.AuthorSteamId) + " | " + msg.Author, msg.Message, true, identity.IdentityId);
                }
            }
            else
            {
                //  PeopleInAllianceChat.Remove((ulong)msg.AuthorSteamId);
            }
        }
Ejemplo n.º 8
0
        public static void SendChatMessage(Guid allianceId, string prefix, string message, bool toDiscord, long playerId)
        {
            prefix = prefix.Replace(":", "");
            Alliance     alliance     = AlliancePlugin.GetAllianceNoLoading(allianceId);
            List <ulong> OtherMembers = new List <ulong>();

            message = message.Replace("@", "");

            log.Info(allianceId.ToString() + " : " + alliance.name + " : " + prefix + " " + message);
            if (toDiscord && DiscordStuff.AllianceHasBot(allianceId))
            {
                try
                {
                    DiscordStuff.SendAllianceMessage(alliance, prefix, message);
                }
                catch (Exception ex)
                {
                    AlliancePlugin.Log.Error(ex);
                    if (DiscordStuff.debugMode)
                    {
                        if (MySession.Static.Players.GetPlayerByName("Crunch") != null)
                        {
                            MyPlayer player = MySession.Static.Players.GetPlayerByName("Crunch");
                            ShipyardCommands.SendMessage("Discord", "Bot not connected 1", Color.Blue, (long)player.Id.SteamId);
                        }
                    }
                }
            }
            else
            {
                if (DiscordStuff.debugMode)
                {
                    if (MySession.Static.Players.GetPlayerByName("Crunch") != null)
                    {
                        MyPlayer player = MySession.Static.Players.GetPlayerByName("Crunch");
                        ShipyardCommands.SendMessage("Discord", "Bot not connected 2", Color.Blue, (long)player.Id.SteamId);
                    }
                }
            }

            foreach (MyPlayer player in MySession.Static.Players.GetOnlinePlayers())
            {
                if (player.Identity.IdentityId == playerId)
                {
                    ShipyardCommands.SendMessage("Alliance chat", "You are in alliance chat.", new Color(alliance.r, alliance.g, alliance.b), (long)player.Id.SteamId);
                    continue;
                }
                MyFaction fac = MySession.Static.Factions.TryGetPlayerFaction(player.Identity.IdentityId) as MyFaction;
                if (fac != null)
                {
                    if (alliance.AllianceMembers.Contains(fac.FactionId))
                    {
                        OtherMembers.Add(player.Id.SteamId);
                    }
                }
            }

            foreach (ulong id in OtherMembers)
            {
                ShipyardCommands.SendMessage(prefix, message, new Color(alliance.r, alliance.g, alliance.b), (long)id);
                MyGpsCollection gpscol = (MyGpsCollection)MyAPIGateway.Session?.GPS;

                if (ScanChat(message, null) != null)
                {
                    MyGps gpsRef = ScanChat(message, null);
                    gpsRef.GPSColor      = Color.Yellow;
                    gpsRef.AlwaysVisible = true;
                    gpsRef.ShowOnHud     = true;

                    long idenId = MySession.Static.Players.TryGetIdentityId(id);
                    gpscol.SendAddGps(idenId, ref gpsRef);
                }
            }
        }