Ejemplo n.º 1
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.º 2
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.º 3
0
        public static MyObjectBuilder_ShipBlueprintDefinition[] getBluePrint(string name, long newOwner, bool keepProjection, List <MyCubeGrid> grids)
        {
            List <MyObjectBuilder_CubeGrid> objectBuilders = new List <MyObjectBuilder_CubeGrid>();

            foreach (MyCubeGrid grid in grids)
            {
                /* What else should it be? LOL? */
                if (!(grid.GetObjectBuilder(true) is MyObjectBuilder_CubeGrid objectBuilder))
                {
                    throw new ArgumentException(grid + " has a ObjectBuilder thats not for a CubeGrid");
                }

                objectBuilders.Add(objectBuilder);
            }

            MyObjectBuilder_ShipBlueprintDefinition definition = MyObjectBuilderSerializer.CreateNewObject <MyObjectBuilder_ShipBlueprintDefinition>();

            definition.Id        = new MyDefinitionId(new MyObjectBuilderType(typeof(MyObjectBuilder_ShipBlueprintDefinition)), name);
            definition.CubeGrids = objectBuilders.Select(x => (MyObjectBuilder_CubeGrid)x.Clone()).ToArray();

            /* Reset ownership as it will be different on the new server anyway */
            foreach (MyObjectBuilder_CubeGrid cubeGrid in definition.CubeGrids)
            {
                cubeGrid.DisplayName = newOwner.ToString();

                foreach (MyObjectBuilder_CubeBlock cubeBlock in cubeGrid.CubeBlocks)
                {
                    long ownerID = AlliancePlugin.GetIdentityByNameOrId(newOwner.ToString()).IdentityId;
                    cubeBlock.Owner   = ownerID;
                    cubeBlock.BuiltBy = ownerID;


                    /* Remove Projections if not needed */
                    if (!keepProjection)
                    {
                        if (cubeBlock is MyObjectBuilder_ProjectorBase projector)
                        {
                            projector.ProjectedGrid  = null;
                            projector.ProjectedGrids = null;
                        }
                    }



                    /* Remove Pilot and Components (like Characters) from cockpits */
                    if (cubeBlock is MyObjectBuilder_Cockpit cockpit)
                    {
                        cockpit.Pilot = null;

                        if (cockpit.ComponentContainer != null)
                        {
                            var components = cockpit.ComponentContainer.Components;

                            if (components != null)
                            {
                                for (int i = components.Count - 1; i >= 0; i--)
                                {
                                    var component = components[i];

                                    if (component.TypeId == "MyHierarchyComponentBase")
                                    {
                                        components.RemoveAt(i);
                                        continue;
                                    }
                                }
                            }
                        }
                    }
                }
            }

            MyObjectBuilder_Definitions builderDefinition = MyObjectBuilderSerializer.CreateNewObject <MyObjectBuilder_Definitions>();

            builderDefinition.ShipBlueprints = new MyObjectBuilder_ShipBlueprintDefinition[] { definition };

            return(builderDefinition.ShipBlueprints);
        }
Ejemplo n.º 4
0
        public static bool LoadShipBlueprint(MyObjectBuilder_ShipBlueprintDefinition shipBlueprint,
                                             Vector3D playerPosition, bool keepOriginalLocation, long steamID, string Name, CommandContext context = null, bool force = false)
        {
            var grids = shipBlueprint.CubeGrids;

            if (grids == null || grids.Length == 0)
            {
                Log.Warn("No grids in blueprint!");

                if (context != null)
                {
                    context.Respond("No grids in blueprint!");
                }

                return(false);
            }

            foreach (var grid in grids)
            {
                foreach (MyObjectBuilder_CubeBlock block in grid.CubeBlocks)
                {
                    long ownerID = AlliancePlugin.GetIdentityByNameOrId(steamID.ToString()).IdentityId;
                    block.Owner   = ownerID;
                    block.BuiltBy = ownerID;
                }
            }

            List <MyObjectBuilder_EntityBase> objectBuilderList = new List <MyObjectBuilder_EntityBase>(grids.ToList());

            if (!keepOriginalLocation)
            {
                /* Where do we want to paste the grids? Lets find out. */
                var pos = FindPastePosition(grids, playerPosition);
                if (pos == null)
                {
                    Log.Warn("No free Space found!");

                    if (context != null)
                    {
                        context.Respond("No free space available!");
                    }

                    return(false);
                }

                var newPosition = pos.Value;

                /* Update GridsPosition if that doesnt work get out of here. */
                if (!UpdateGridsPosition(grids, newPosition))
                {
                    if (context != null)
                    {
                        context.Respond("The File to be imported does not seem to be compatible with the server!");
                    }

                    return(false);
                }
                Sandbox.Game.Entities.Character.MyCharacter player = MySession.Static.Players.GetPlayerByName(AlliancePlugin.GetIdentityByNameOrId(steamID.ToString()).DisplayName).Character;
                MyGps           gps           = CreateGps(pos.Value, Color.LightGreen, 60, Name);
                MyGpsCollection gpsCollection = (MyGpsCollection)MyAPIGateway.Session?.GPS;
                MyGps           gpsRef        = gps;
                long            entityId      = 0L;
                entityId = gps.EntityId;
                gpsCollection.SendAddGps(player.GetPlayerIdentityId(), ref gpsRef, entityId, true);
            }
            else if (!force)
            {
                var sphere = FindBoundingSphere(grids);

                var position = grids[0].PositionAndOrientation.Value;

                sphere.Center = position.Position;

                List <MyEntity> entities = new List <MyEntity>();
                MyGamePruningStructure.GetAllTopMostEntitiesInSphere(ref sphere, entities);

                foreach (var entity in entities)
                {
                    if (entity is MyCubeGrid)
                    {
                        if (context != null)
                        {
                            context.Respond("There are potentially other grids in the way. If you are certain is free you can set 'force' to true!");
                        }

                        return(false);
                    }
                }
            }
            /* Stop grids */
            foreach (var grid in grids)
            {
                grid.AngularVelocity = new SerializableVector3();
                grid.LinearVelocity  = new SerializableVector3();

                Random random = new Random();
            }
            /* Remapping to prevent any key problems upon paste. */
            MyEntities.RemapObjectBuilderCollection(objectBuilderList);

            bool hasMultipleGrids = objectBuilderList.Count > 1;

            if (!hasMultipleGrids)
            {
                foreach (var ob in objectBuilderList)
                {
                    MyEntities.CreateFromObjectBuilderParallel(ob, true);
                }
            }
            else
            {
                MyEntities.Load(objectBuilderList, out _);
            }

            return(true);
        }
Ejemplo n.º 5
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);
            }
        }