Ejemplo n.º 1
0
        private void SendGps(HashSet <MyGps> gpsSet, GridsBroadcastConfig config)
        {
            MyGpsCollection gpsCollection = (MyGpsCollection)MyAPIGateway.Session?.GPS;

            if (gpsCollection == null)
            {
                return;
            }

            bool followGrids = config.GpsFollowGrids;
            bool playSound   = config.PlayGpsSound;

            foreach (MyPlayer player in MySession.Static.Players.GetOnlinePlayers())
            {
                Log.Trace($"Sending biggest grid GPS to player '{player.DisplayName}'");
                foreach (MyGps gps in gpsSet)
                {
                    MyGps gpsRef = gps;

                    long entityId = 0L;
                    if (followGrids)
                    {
                        _gpsSendClient.AddOrModifyGps(player.Identity.IdentityId, ref gpsRef, playSound);
                        continue;
                    }

                    gpsCollection.SendAddGps(player.Identity.IdentityId, ref gpsRef, entityId, playSound);
                }
            }
        }
        private void SendGps(HashSet <MyGps> gpsSet, GridsBroadcastConfig config)
        {
            MyGpsCollection gpsCollection = (MyGpsCollection)MyAPIGateway.Session?.GPS;

            if (gpsCollection == null)
            {
                return;
            }

            bool followGrids = config.GpsFollowGrids;
            bool playSound   = config.PlayGpsSound;

            foreach (MyPlayer player in MySession.Static.Players.GetOnlinePlayers())
            {
                foreach (MyGps gps in gpsSet)
                {
                    MyGps gpsRef = gps;

                    long entityId = 0L;
                    if (followGrids)
                    {
                        entityId = gps.EntityId;
                    }

                    gpsCollection.SendAddGps(player.Identity.IdentityId, ref gpsRef, entityId, playSound);
                }
            }
        }
Ejemplo n.º 3
0
        protected override void Init(MyObjectBuilder_DefinitionBase builder)
        {
            base.Init(builder);

            var gpsBuilder = builder as MyObjectBuilder_GpsCollectionDefinition;

            Positions = new List <MyGpsCoordinate>();
            if (gpsBuilder.Positions != null && gpsBuilder.Positions.Length > 0)
            {
                StringBuilder name   = new StringBuilder();
                Vector3D      coords = Vector3D.Zero;

                StringBuilder additionalData = new StringBuilder();

                foreach (var gpsString in gpsBuilder.Positions)
                {
                    if (MyGpsCollection.ParseOneGPSExtended(gpsString, name, ref coords, additionalData))
                    {
                        MyGpsCoordinate newGps = new MyGpsCoordinate()
                        {
                            Name   = name.ToString(),
                            Coords = coords
                        };

                        var additionalString = additionalData.ToString();
                        if (!string.IsNullOrWhiteSpace(additionalString))
                        {
                            string[] split = additionalString.Split(':');
                            for (int i = 0; i < split.Length / 2; ++i)
                            {
                                string first  = split[2 * i + 0];
                                string second = split[2 * i + 1];

                                if (!string.IsNullOrWhiteSpace(first) && !string.IsNullOrWhiteSpace(second))
                                {
                                    if (newGps.Actions == null)
                                    {
                                        newGps.Actions = new List <MyGpsAction>();
                                    }
                                    newGps.Actions.Add(new MyGpsAction()
                                    {
                                        BlockName = first, ActionId = second
                                    });
                                }
                            }
                        }

                        Positions.Add(newGps);
                    }
                    else
                    {
                        Debug.Fail("Invalid GPS: " + gpsString);
                    }
                }
            }
        }
Ejemplo n.º 4
0
        public static IEnumerable <(long IdentityId, MyGps Gps)> GetAllGpss(this MyGpsCollection self)
        {
            var allGpss = new List <(long, MyGps)>();

            foreach (var(identity, gpsCollection) in self.GetPlayerGpss())
            {
                foreach (var(_, gps) in gpsCollection)
                {
                    allGpss.Add((identity, gps));
                }
            }

            return(allGpss);
        }
Ejemplo n.º 5
0
        protected override void Init(MyObjectBuilder_DefinitionBase builder)
        {
            base.Init(builder);
            MyObjectBuilder_GpsCollectionDefinition definition = builder as MyObjectBuilder_GpsCollectionDefinition;

            this.Positions = new List <MyGpsCoordinate>();
            if ((definition.Positions != null) && (definition.Positions.Length != 0))
            {
                StringBuilder name           = new StringBuilder();
                Vector3D      zero           = Vector3D.Zero;
                StringBuilder additionalData = new StringBuilder();
                string[]      positions      = definition.Positions;
                for (int i = 0; i < positions.Length; i++)
                {
                    if (MyGpsCollection.ParseOneGPSExtended(positions[i], name, ref zero, additionalData))
                    {
                        MyGpsCoordinate item = new MyGpsCoordinate {
                            Name   = name.ToString(),
                            Coords = zero
                        };
                        string str = additionalData.ToString();
                        if (!string.IsNullOrWhiteSpace(str))
                        {
                            char[]   separator = new char[] { ':' };
                            string[] strArray2 = str.Split(separator);
                            for (int j = 0; j < (strArray2.Length / 2); j++)
                            {
                                string str2 = strArray2[2 * j];
                                string str3 = strArray2[(2 * j) + 1];
                                if (!string.IsNullOrWhiteSpace(str2) && !string.IsNullOrWhiteSpace(str3))
                                {
                                    if (item.Actions == null)
                                    {
                                        item.Actions = new List <MyGpsAction>();
                                    }
                                    MyGpsAction action = new MyGpsAction {
                                        BlockName = str2,
                                        ActionId  = str3
                                    };
                                    item.Actions.Add(action);
                                }
                            }
                        }
                        this.Positions.Add(item);
                    }
                }
            }
        }
        private bool SendGps(MyGps gps, long playerId)
        {
            MyGpsCollection gpsCollection = (MyGpsCollection)MyAPIGateway.Session?.GPS;

            if (gpsCollection == null)
            {
                return(false);
            }

            bool playSound = true;
            long entityId  = 0L;

            gpsCollection.SendAddGps(playerId, ref gps, entityId, playSound);

            return(true);
        }
Ejemplo n.º 7
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.º 8
0
        public void test(IPlayer p)
        {
            //load the contracts on login
            if (p == null)
            {
                return;
            }

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

            if (id == null)
            {
                return;
            }

            Contract contract = Database.TryGetContract(p.SteamId);

            if (contract != null)
            {
                TruckingPlugin.activeContracts.Remove(p.SteamId);
                TruckingPlugin.activeContracts.Add(p.SteamId, contract);
                StringBuilder contractDetails = new StringBuilder();
                int           pay             = TruckingPlugin.GetMinimumPay(contract.getItemsInContract());
                contractDetails = TruckingPlugin.MakeContractDetails(contract.getItemsInContract());
                contractDetails.AppendLine("");

                contractDetails.AppendLine("Minimum Payment " + String.Format("{0:n0}", pay) + " SC.");
                MyGps gps = contract.GetDeliveryLocation();

                List <IMyGps> playerList = new List <IMyGps>();
                MySession.Static.Gpss.GetGpsList(id.IdentityId, playerList);
                MyGpsCollection gpscol = (MyGpsCollection)MyAPIGateway.Session?.GPS;
                foreach (IMyGps gps2 in playerList)
                {
                    if (gps2.Name.Contains("Delivery Location, bring hauling vehicle within 300m"))
                    {
                        MyAPIGateway.Session?.GPS.RemoveGps(id.IdentityId, gps2);
                    }
                }
                gpscol.SendAddGps(id.IdentityId, ref gps);
            }
        }
Ejemplo n.º 9
0
        public void ContractDetails()
        {
            StringBuilder contractDetails = new StringBuilder();

            if (TruckingPlugin.getActiveContract(Context.Player.SteamUserId) != null)
            {
                Contract contract = TruckingPlugin.getActiveContract(Context.Player.SteamUserId);
                int      pay      = TruckingPlugin.GetMinimumPay(contract.getItemsInContract());
                contractDetails = TruckingPlugin.MakeContractDetails(contract.getItemsInContract());
                MyGps gps = TruckingPlugin.getDeliveryLocation();

                MyGpsCollection gpscol = (MyGpsCollection)MyAPIGateway.Session?.GPS;

                gpscol.SendAddGps(Context.Player.Identity.IdentityId, ref gps);
                DialogMessage m = new DialogMessage("Contract Details", "Obtain and deliver these items", contractDetails.ToString());
                ModCommunication.SendMessageTo(m, Context.Player.SteamUserId);
            }
            else
            {
                Context.Respond("You dont currently have a contract", "The Boss");
            }
        }
Ejemplo n.º 10
0
 public static void SendAddGps(this MyGpsCollection self, long identityId, MyGps gps, bool playSound)
 {
     self.SendAddGps(identityId, ref gps, gps.EntityId, playSound);
 }
Ejemplo n.º 11
0
        public void transmit()
        {
            foreach (MyPlayer p in MySession.Static.Players.GetOnlinePlayers())
            {
                List <IMyGps> playergpsList = MyAPIGateway.Session?.GPS.GetGpsList(p.Identity.IdentityId);

                if (playergpsList == null)
                {
                    break;
                }

                foreach (IMyGps gps in playergpsList)
                {
                    if (gps.Description.Contains("Cronch"))
                    {
                        MyAPIGateway.Session?.GPS.RemoveGps(p.Identity.IdentityId, gps);
                    }
                }
            }
            foreach (var group in MyCubeGridGroups.Static.Logical.Groups)
            {
                bool NPC = false;
                foreach (var item in group.Nodes)
                {
                    MyCubeGrid grid = item.NodeData;
                    // TransmitPlugin.Log.Info(grid.DisplayName);
                    if (((int)grid.Flags & 4) != 0)
                    {
                        //concealed
                        break;
                    }
                    if (grid.IsStatic && !TransmitPlugin.config.broadcastStations)
                    {
                        break;
                    }
                    if (MyGravityProviderSystem.IsPositionInNaturalGravity(grid.PositionComp.GetPosition()) && !TransmitPlugin.config.broadcastInGravity)
                    {
                        break;
                    }

                    //this bit requires a fac utils to get the faction tag, you can remove it if you dont need it
                    foreach (long l in grid.BigOwners)
                    {
                        if (FacUtils.GetFactionTag(l) != null && FacUtils.GetFactionTag(l).Length > 3)
                        {
                            NPC = true;
                        }
                    }

                    if (NPC)
                    {
                        break;
                    }
                    int PCU = 0;
                    PCU = grid.BlocksPCU;
                    Vector3 location = grid.PositionComp.GetPosition();
                    //get the gps
                    float           broadcastRange = 0;
                    MyGpsCollection gpsCollection  = (MyGpsCollection)MyAPIGateway.Session?.GPS;


                    broadcastRange = grid.BlocksPCU * TransmitPlugin.config.meterPerPCU;


                    if (PCU < TransmitPlugin.config.minimumPCU)
                    {
                        break;
                    }
                    IMyFaction gridOwner = FacUtils.GetPlayersFaction(FacUtils.GetOwner(grid));

                    foreach (MyPlayer p in MySession.Static.Players.GetOnlinePlayers())
                    {
                        List <MyGps> gpsList  = new List <MyGps>();
                        float        distance = Vector3.Distance(location, p.GetPosition());
                        if (distance <= broadcastRange)
                        {
                            MyGps gps;
                            //add a new gps point if player is in range
                            if (gridOwner != null)
                            {
                                if (gridOwner.IsNeutral(p.Identity.IdentityId) || gridOwner.IsFriendly(p.Identity.IdentityId))
                                {
                                    gps = CreateGps(grid, Color.RoyalBlue, 60, broadcastRange);
                                }
                                else
                                {
                                    gps = CreateGps(grid, Color.Red, 60, broadcastRange);
                                }
                            }
                            else
                            {
                                gps = CreateGps(grid, Color.Red, 60, broadcastRange);
                            }

                            gpsList.Add(gps);
                        }
                        foreach (MyGps gps in gpsList)
                        {
                            MyGps gpsRef   = gps;
                            long  entityId = 0L;
                            entityId = gps.EntityId;
                            gpsCollection.SendAddGps(p.Identity.IdentityId, ref gpsRef, entityId, TransmitPlugin.config.soundForGPS);
                        }
                    }
                }
            }
        }
Ejemplo n.º 12
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.º 13
0
#pragma warning restore 649

        public static Dictionary <long, Dictionary <int, MyGps> > GetPlayerGpss(this MyGpsCollection self)
        {
            return((Dictionary <long, Dictionary <int, MyGps> >)_fieldInfo.GetValue(self));
        }
Ejemplo n.º 14
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);
                }
            }
        }
Ejemplo n.º 15
0
        public void LoadFromHangar(string slotNumber)
        {
            if (!AlliancePlugin.config.HangarEnabled)
            {
                Context.Respond("Alliance hangar is not enabled.");
                return;
            }
            if (cooldowns.TryGetValue(Context.Player.IdentityId, out DateTime value))
            {
                if (DateTime.Now <= value)
                {
                    Context.Respond(GetCooldownMessage(value));
                    return;
                }
                else
                {
                    cooldowns[Context.Player.IdentityId] = DateTime.Now.AddSeconds(60);
                }
            }
            else
            {
                cooldowns.Add(Context.Player.IdentityId, DateTime.Now.AddSeconds(60));
            }
            MyFaction fac = MySession.Static.Factions.GetPlayerFaction(Context.Player.IdentityId);

            if (fac == null)
            {
                Context.Respond("You must be in a faction to use alliance features.");
                return;
            }
            Alliance alliance = AlliancePlugin.GetAlliance(fac);

            if (alliance == null)
            {
                Context.Respond("You are not a member of an alliance.");
                return;
            }
            if (AlliancePlugin.HasFailedUpkeep(alliance))
            {
                Context.Respond("Alliance failed to pay upkeep. Upgrades disabled.");
                return;
            }
            if (!alliance.HasAccess(Context.Player.SteamUserId, AccessLevel.HangarLoad) && !alliance.HasAccess(Context.Player.SteamUserId, AccessLevel.HangarLoadOther))
            {
                Context.Respond("Current rank does not have access to hangar load.");
                return;
            }
            if (alliance.hasUnlockedHangar)
            {
                HangarData hangar = alliance.LoadHangar();
                if (hangar == null)
                {
                    Context.Respond("Error loading the hangar.");
                    return;
                }
                int slot;
                try
                {
                    slot = int.Parse(slotNumber);
                }
                catch (Exception)
                {
                    Context.Respond("Cannot parse that number.");
                    return;
                }
                if (!hangar.ItemsInHangar.ContainsKey(slot))
                {
                    Context.Respond("No grid available to load for that number!");
                    return;
                }
                HangarItem item = hangar.ItemsInHangar[slot];

                //this took up way too much of one line

                if (hangar.LoadGridFromHangar(slot, Context.Player.SteamUserId, alliance, Context.Player.Identity as MyIdentity, fac))
                {
                    Context.Respond("Grid should be loaded!");
                }
                else
                {
                    Context.Respond("Could not load, are there enemies within 15km?");
                    MyGps gps = new MyGps
                    {
                        Coords         = item.position,
                        Name           = item.name + " Failed load location",
                        DisplayName    = item.name + " Failed load location",
                        Description    = "Failed load location",
                        GPSColor       = Color.LightBlue,
                        IsContainerGPS = true,
                        ShowOnHud      = true,
                        DiscardAt      = new TimeSpan(50000)
                    };
                    gps.UpdateHash();
                    MyGpsCollection gpscol = (MyGpsCollection)MyAPIGateway.Session?.GPS;


                    gpscol.SendAddGps(Context.Player.IdentityId, ref gps);
                }
            }
            else
            {
                Context.Respond("Alliance has not unlocked the hangar to unlock use !ah unlock.");
            }
        }
Ejemplo n.º 16
0
        public static Boolean GenerateContract(ulong steamid, long identityid)
        {
            if (config.UsingWhitelist)
            {
                if (!Whitelist.Contains(steamid))
                {
                    DialogMessage m = new DialogMessage("Contract Failure", "Fail", config.WhitelistMessage);
                    ModCommunication.SendMessageTo(m, steamid);
                    return(false);
                }
            }
            if (getActiveContract(steamid) != null)
            {
                TruckingPlugin.SendMessage("The Boss", "You already have a contract!", Color.Red, steamid);
                DialogMessage m = new DialogMessage("Contract fail", "", "You already have a contract, to quit use !contract quit");
                ModCommunication.SendMessageTo(m, steamid);
                return(false);
            }
            else
            {
                //this code is awful and i want to redo it, probably throwing the generation in a new method and changing this reputation check to just change the amount

                if (reputation.TryGetValue(steamid, out int rep))
                {
                    int    potentialMax = 1;
                    string type         = "easy";
                    int    min          = 1;
                    Random random       = new Random();
                    int    chance       = random.Next(0, 101);
                    if (rep >= config.HardContractRep && chance <= config.HardContractChance)
                    {
                        min          += 2;
                        type          = "hard";
                        potentialMax += 2;
                    }
                    else
                    {
                        if (rep >= config.MediumContractRep && chance <= config.MediumContractChance)
                        {
                            min          += 1;
                            type          = "medium";
                            potentialMax += 1;
                        }
                    }
                    //change to max in config file
                    if (potentialMax > 5)
                    {
                        potentialMax = 5;
                    }

                    int max = random.Next(min - 1, potentialMax + 1);
                    if (max == 0)
                    {
                        max = 1;
                    }


                    List <ContractItems> items = getRandomContractItem(type, max);
                    MyGps    gps      = getDeliveryLocation();
                    Contract contract = new Contract(steamid, items, gps.Coords.X, gps.Coords.Y, gps.Coords.Z);

                    Database.addNewContract(steamid, contract);
                    StringBuilder contractDetails = new StringBuilder();
                    contractDetails = TruckingPlugin.MakeContractDetails(contract.getItemsInContract());


                    gps = contract.GetDeliveryLocation();
                    MyGpsCollection gpscol = (MyGpsCollection)MyAPIGateway.Session?.GPS;


                    gpscol.SendAddGps(identityid, ref gps);
                    // MyAPIGateway.Session?.GPS.AddGps(Context.Player.IdentityId, gps);
                    DialogMessage m = new DialogMessage("Contract Details", "Obtain and deliver these items", contractDetails.ToString());
                    ModCommunication.SendMessageTo(m, steamid);
                }
                else
                {
                    List <ContractItems> items = getRandomContractItem("easy", 1);
                    MyGps    gps      = getDeliveryLocation();
                    Contract contract = new Contract(steamid, items, gps.Coords.X, gps.Coords.Y, gps.Coords.Z);

                    Database.addNewContract(steamid, contract);
                    StringBuilder contractDetails = new StringBuilder();
                    contractDetails = TruckingPlugin.MakeContractDetails(contract.getItemsInContract());


                    gps = contract.GetDeliveryLocation();
                    MyGpsCollection gpscol = (MyGpsCollection)MyAPIGateway.Session?.GPS;


                    gpscol.SendAddGps(identityid, ref gps);
                    // MyAPIGateway.Session?.GPS.AddGps(Context.Player.IdentityId, gps);
                    DialogMessage m = new DialogMessage("Contract Details", "Obtain and deliver these items", contractDetails.ToString());
                    ModCommunication.SendMessageTo(m, steamid);
                }
                return(true);
            }
        }