Ejemplo n.º 1
0
        public void DeliverContract()
        {
            Contract      contract        = TruckingPlugin.getActiveContract(Context.Player.SteamUserId);
            StringBuilder contractDetails = new StringBuilder();

            if (contract != null)
            {
                Vector3D coords   = contract.GetDeliveryLocation().Coords;
                float    distance = Vector3.Distance(coords, Context.Player.Character.PositionComp.GetPosition());
                if (distance <= 1000)
                {
                    List <VRage.ModAPI.IMyEntity> l = new List <VRage.ModAPI.IMyEntity>();

                    BoundingSphereD sphere = new BoundingSphereD(Context.Player.Character.PositionComp.GetPosition(), 1000);
                    l = MyAPIGateway.Entities.GetEntitiesInSphere(ref sphere);

                    Dictionary <MyDefinitionId, int> itemsToRemove = new Dictionary <MyDefinitionId, int>();
                    int pay = 0;
                    foreach (ContractItems item in contract.getItemsInContract())
                    {
                        if (MyDefinitionId.TryParse("MyObjectBuilder_" + item.ItemType, item.SubType, out MyDefinitionId id))
                        {
                            itemsToRemove.Add(id, item.AmountToDeliver);
                            pay += item.AmountToDeliver * item.GetPrice();
                        }
                        else
                        {
                            Context.Respond("Theres an error in the config for this item, report in a ticket " + id.SubtypeName + " " + id.TypeId);
                        }
                    }

                    foreach (IMyEntity entity in l)
                    {
                        if (entity is MyCubeGrid grid)
                        {
                            List <VRage.Game.ModAPI.IMyInventory> inventories = TakeTheItems.GetInventories(grid);
                            if (FacUtils.IsOwnerOrFactionOwned(grid, Context.Player.IdentityId, true))
                            {
                                if (TakeTheItems.ConsumeComponents(inventories, itemsToRemove, Context.Player.SteamUserId))
                                {
                                    MyBankingSystem.ChangeBalance(Context.Player.Identity.IdentityId, pay);
                                    Database.RemoveContract(Context.Player.SteamUserId, true, contract, Context.Player.IdentityId);
                                    TruckingPlugin.SendMessage("The Boss", "Contract Complete, Payment delivered to bank account.", Color.Purple, Context.Player.SteamUserId);
                                    return;
                                }
                            }
                        }
                    }
                    Context.Respond("Could not find owned grid in vicinity with the required items.", "The Boss");
                }
                else
                {
                    Context.Respond("You arent close enough to the delivery point! Must be within 1km of signal", "The Boss");
                }
            }
            else
            {
                Context.Respond("You dont have an active contract.", "The Boss");
            }
        }
Ejemplo n.º 2
0
 public void TakeContract()
 {
     if (TruckingPlugin.getActiveContract(Context.Player.SteamUserId) != null)
     {
         Context.Respond("You cannot take another contract while you have an active one. To quit a contract use !contract quit", "The Boss");
     }
     else
     {
         TruckingPlugin.GenerateContract(Context.Player.SteamUserId, Context.Player.IdentityId);
     }
 }
Ejemplo n.º 3
0
        public static Boolean StorePatchMethod(MyStoreBlock __instance, long id, int amount, long targetEntityId, MyPlayer player, MyAccountInfo playerAccountInfo)
        {
            MyStoreItem storeItem = (MyStoreItem)null;
            bool        proceed   = false;

            foreach (MyStoreItem playerItem in __instance.PlayerItems)
            {
                MyCubeGrid grid = __instance.CubeGrid;
                if (FacUtils.GetFactionTag(FacUtils.GetOwner(grid)) != null && FacUtils.GetFactionTag(FacUtils.GetOwner(grid)).Length > 3 && TruckingPlugin.config.NPCGridContracts)
                {
                    proceed = true;
                }
                if (!grid.Editable || !grid.DestructibleBlocks)
                {
                    proceed = true;
                }

                if (__instance.DisplayNameText != null && __instance.DisplayNameText.ToLower().Contains("hauling contracts") && proceed)
                {
                    if (playerItem.Id == id)
                    {
                        storeItem = playerItem;
                        break;
                    }
                }
            }
            //this does things
            if (storeItem != null && proceed)
            {
                if (MyBankingSystem.GetBalance(player.Identity.IdentityId) >= storeItem.PricePerUnit)
                {
                    //if it cant generate a contract, return false
                    if (!TruckingPlugin.GenerateContract(player.Id.SteamId, player.Identity.IdentityId))
                    {
                        return(false);
                    }
                    else
                    {
                        //do the money transfers then return false so the item stays in the store
                        MyBankingSystem.ChangeBalance(player.Identity.IdentityId, (storeItem.PricePerUnit * -1));
                        MyBankingSystem.ChangeBalance(__instance.OwnerId, storeItem.PricePerUnit);
                        return(false);
                    }
                }
                else
                {
                    return(false);
                }
            }
            return(true);
        }
Ejemplo n.º 4
0
 public void QuitContract()
 {
     if (TruckingPlugin.getActiveContract(Context.Player.SteamUserId) != null)
     {
         TruckingPlugin.SendMessage("The Boss", "Contract quit, reputation lowered", Color.Purple, Context.Player.SteamUserId);
         Database.RemoveContract(Context.Player.SteamUserId, false, TruckingPlugin.getActiveContract(Context.Player.SteamUserId), Context.Player.IdentityId);
         List <IMyGps> playerList = new List <IMyGps>();
         MySession.Static.Gpss.GetGpsList(Context.Player.IdentityId, playerList);
         foreach (IMyGps gps in playerList)
         {
             if (gps.Name.Contains("Delivery Location, bring hauling vehicle within 300m"))
             {
                 MyAPIGateway.Session?.GPS.RemoveGps(Context.Player.Identity.IdentityId, gps);
             }
         }
     }
 }
Ejemplo n.º 5
0
        public MyGps GetDeliveryLocation()
        {
            MyGps gps = new MyGps
            {
                Coords         = new Vector3D(GpsX, GpsY, GpsZ),
                Name           = "Delivery Location, bring hauling vehicle within 300m",
                DisplayName    = "Delivery Location, bring hauling vehicle within 300m",
                Description    = TruckingPlugin.MakeContractDetails(items).ToString(),
                GPSColor       = Color.Orange,
                IsContainerGPS = true,
                ShowOnHud      = true,
                DiscardAt      = new TimeSpan(50000)
            };

            gps.UpdateHash();
            return(gps);
        }
Ejemplo n.º 6
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.º 7
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.º 8
0
        public static bool ConsumeComponents(IEnumerable <VRage.Game.ModAPI.IMyInventory> inventories, IDictionary <MyDefinitionId, int> components, ulong steamId)
        {
            List <MyTuple <VRage.Game.ModAPI.IMyInventory, VRage.Game.ModAPI.IMyInventoryItem, VRage.MyFixedPoint> > toRemove = new List <MyTuple <VRage.Game.ModAPI.IMyInventory, VRage.Game.ModAPI.IMyInventoryItem, VRage.MyFixedPoint> >();

            foreach (KeyValuePair <MyDefinitionId, int> c in components)
            {
                MyFixedPoint needed = CountComponents(inventories, c.Key, c.Value, toRemove);
                if (needed > 0)
                {
                    TruckingPlugin.SendMessage("The Boss", "Missing " + needed + " " + c.Key.SubtypeName + " " + c.Key.TypeId.ToString().Replace("MyObjectBuilder_", "") + " All items must be inside one grid.", Color.Purple, steamId);
                    // Context.Respond("Missing " + needed + " " + c.Key.SubtypeName + " All items must be inside one grid.");
                    return(false);
                }
            }

            foreach (MyTuple <VRage.Game.ModAPI.IMyInventory, VRage.Game.ModAPI.IMyInventoryItem, MyFixedPoint> item in toRemove)
            {
                MyAPIGateway.Utilities.InvokeOnGameThread(() =>
                {
                    item.Item1.RemoveItemAmount(item.Item2, item.Item3);
                });
            }
            return(true);
        }
Ejemplo n.º 9
0
 public void reload()
 {
     TruckingPlugin.LoadConfig();
     Context.Respond("Reloaded");
 }
Ejemplo n.º 10
0
        public static void RemoveContract(ulong steamid, Boolean completed, Contract contract, long identityid)
        {
            MySqlConnection conn = new MySqlConnection(connStr);

            try
            {
                conn.Open();
                //I dont remember why i load this, the contract ID is already in the contract object, so this probably isnt necessary unless the contract id is null
                string          sql        = "select * from spacetrucking.players where playerid=" + steamid;
                MySqlCommand    cmd        = new MySqlCommand(sql, conn);
                MySqlDataReader reader     = cmd.ExecuteReader();
                Guid            contractId = new Guid();
                int             read       = 0;
                while (reader.Read())
                {
                    read++;
                    if (!reader.IsDBNull(4))
                    {
                        //yeah i really dont understand why i load that from the database then do nothing with it
                        contractId = Guid.Parse(reader.GetString(4));
                    }
                }
                if (read == 0)
                {
                    TruckingPlugin.Log.Info("No contract to load from database " + steamid);
                    return;
                }

                reader.Close();
                if (completed)
                {
                    sql = "UPDATE spacetrucking.players SET currentContract = NULL, completed = completed + 1, reputation = reputation + " + contract.GetReputation() + " where playerId =" + steamid;
                    if (TruckingPlugin.reputation.TryGetValue(steamid, out int rep))
                    {
                        TruckingPlugin.reputation.Remove(steamid);
                        TruckingPlugin.reputation.Add(steamid, contract.GetReputation() + rep);
                    }
                    else
                    {
                        TruckingPlugin.reputation.Remove(steamid);
                        TruckingPlugin.reputation.Add(steamid, contract.GetReputation());
                    }
                }
                else
                {
                    sql = "UPDATE spacetrucking.players SET currentContract = NULL, failed = failed + 1, reputation = reputation - " + (contract.GetReputation() * 2) + " where playerId =" + steamid;
                    if (TruckingPlugin.reputation.TryGetValue(steamid, out int rep))
                    {
                        TruckingPlugin.reputation.Remove(steamid);
                        TruckingPlugin.reputation.Add(steamid, rep - contract.GetReputation());
                    }
                    else
                    {
                        TruckingPlugin.reputation.Remove(steamid);
                        TruckingPlugin.reputation.Add(steamid, contract.GetReputation() * -1);
                    }
                }
                cmd = new MySqlCommand(sql, conn);
                TruckingPlugin.RemoveContract(steamid, identityid);
                cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                conn.Close();
                TruckingPlugin.Log.Info(ex.ToString());
            }
            conn.Close();
            return;
        }
Ejemplo n.º 11
0
        public static Contract TryGetContract(ulong steamid)
        {
            MySqlConnection conn = new MySqlConnection(connStr);

            try
            {
                conn.Open();
                //this runs more queries than i would like, but the current version of mysql errors if any field in a query is null, when thats fixed it can go back to select * from players where playerId = steamid
                string          sql    = "select reputation from spacetrucking.players where playerid=" + steamid + "";
                MySqlCommand    cmd    = new MySqlCommand(sql, conn);
                MySqlDataReader reader = cmd.ExecuteReader();
                //load their reputation first
                while (reader.Read())
                {
                    TruckingPlugin.reputation.Remove(steamid);
                    TruckingPlugin.reputation.Add(steamid, reader.GetInt32(0));
                }
                reader.Close();
                //this runs more queries than i would like, but the current version of mysql errors if any field in a query is null, when thats fixed it can go back to select * from players where playerId = steamid
                sql    = "select * from spacetrucking.players where playerid=" + steamid;
                cmd    = new MySqlCommand(sql, conn);
                reader = cmd.ExecuteReader();
                Guid contractId = new Guid();
                int  read       = 0;
                while (reader.Read())
                {
                    //position 4 is the contract id
                    read++;
                    if (reader[4] != null)
                    {
                        contractId = reader.GetGuid(4);
                    }
                    else
                    {
                        conn.Close();
                        TruckingPlugin.Log.Info("No contract to load " + steamid);
                        return(null);
                    }
                }
                //additional check to return if there is no contract, probably isnt necessary here as the one above catches it
                if (read == 0)
                {
                    conn.Close();
                    TruckingPlugin.Log.Info("No contract to load " + steamid);
                    return(null);
                }
                reader.Close();
                double x = 0, y = 0, z = 0;
                int    reputation = 0;
                sql = "select * from spacetrucking.contracts where contractId='" + contractId + "'";
                //load the main contract to get its position and reputation gain/reduction
                cmd    = new MySqlCommand(sql, conn);
                reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    x          = reader.GetDouble(1);
                    y          = reader.GetDouble(2);
                    z          = reader.GetDouble(3);
                    reputation = reader.GetInt32(4);
                }

                List <ContractItems> items = new List <ContractItems>();
                reader.Close();
                //now load all the items on the contract
                sql    = "select * from spacetrucking.contractItems where contractId='" + contractId + "'";
                cmd    = new MySqlCommand(sql, conn);
                reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    ContractItems item = new ContractItems();
                    if (TruckingPlugin.getItemFromLists(reader.GetString(2), reader.GetString(3)) != null)
                    {
                        item = (TruckingPlugin.getItemFromLists(reader.GetString(2), reader.GetString(3)));
                        item.SetAmountToDeliver(reader.GetInt32(4));
                        items.Add(item);
                    }
                }
                Contract contract = new Contract(contractId, steamid, items, x, y, z, reputation);
                reader.Close();
                conn.Close();
                TruckingPlugin.Log.Info("Loading data for whoever this is " + steamid);
                return(contract);
            }
            catch (Exception ex)
            {
                conn.Close();
                TruckingPlugin.Log.Info("Error on loading data, either not connected or user has no data " + steamid);
            }
            conn.Close();
            return(null);
        }
Ejemplo n.º 12
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);
            }
        }
Ejemplo n.º 13
0
        private void SessionChanged(ITorchSession session, TorchSessionState state)
        {
            if (state == TorchSessionState.Loaded)
            {
                session.Managers.GetManager <IMultiplayerManagerBase>().PlayerJoined += test;
                Database.testConnection();
                if (!System.IO.File.Exists(TruckingPlugin.path + "//SpaceTrucking"))
                {
                    System.IO.Directory.CreateDirectory(TruckingPlugin.path + "//SpaceTrucking");
                }
                if (!System.IO.File.Exists(TruckingPlugin.path + "//SpaceTrucking//deliveryLocations.txt"))
                {
                    MyGps    bob  = new MyGps();
                    Vector3D alan = new Vector3D(100, 100, 100);
                    bob.Coords      = alan;
                    bob.Name        = "Example GPS";
                    bob.DisplayName = "Example GPS";

                    File.WriteAllText(TruckingPlugin.path + "//SpaceTrucking//deliveryLocations.txt", bob.ToString());
                }
                if (!System.IO.File.Exists(TruckingPlugin.path + "//SpaceTrucking//definitions.csv"))
                {
                    StringBuilder ingots     = new StringBuilder();
                    StringBuilder components = new StringBuilder();
                    StringBuilder ore        = new StringBuilder();
                    StringBuilder ammo       = new StringBuilder();
                    foreach (MyDefinitionBase def in MyDefinitionManager.Static.GetAllDefinitions())
                    {
                        if (def.Id.TypeId.ToString().Equals("MyObjectBuilder_Ingot"))
                        {
                            ingots.AppendLine(def.Id.TypeId.ToString().Replace("MyObjectBuilder_", "") + "," + def.Id.SubtypeId + ",1" + ",10" + ",20" + ",50" + ",50" + ",1");
                        }
                        if (def.Id.TypeId.ToString().Equals("MyObjectBuilder_Component"))
                        {
                            components.AppendLine(def.Id.TypeId.ToString().Replace("MyObjectBuilder_", "") + "," + def.Id.SubtypeId + ",1" + ",10" + ",20" + ",50" + ",50" + ",1");
                        }
                        if (def.Id.TypeId.ToString().Equals("MyObjectBuilder_Ore"))
                        {
                            ore.AppendLine(def.Id.TypeId.ToString().Replace("MyObjectBuilder_", "") + "," + def.Id.SubtypeId + ",1" + ",10" + ",20" + ",50" + ",50" + ",1");
                        }
                        if (def.Id.TypeId.ToString().Equals("MyObjectBuilder_AmmoMagazine"))
                        {
                            ammo.AppendLine(def.Id.TypeId.ToString().Replace("MyObjectBuilder_", "") + "," + def.Id.SubtypeId + ",1" + ",10" + ",20" + ",50" + ",50" + ",1");
                        }
                    }
                    StringBuilder output = new StringBuilder();
                    output.AppendLine("TypeId, SubtypeId, minAmount,maxAmount,minPrice,maxPrice,percentageChance,reputation");
                    output.AppendLine(ingots.ToString());
                    output.AppendLine(components.ToString());
                    output.AppendLine(ore.ToString());
                    output.AppendLine(ammo.ToString());
                    File.WriteAllText(TruckingPlugin.path + "//SpaceTrucking//definitions.csv", output.ToString());
                }

                if (System.IO.File.Exists(TruckingPlugin.path + "//SpaceTrucking//deliveryLocations.txt"))
                {
                    String[] line = File.ReadAllLines(TruckingPlugin.path + "//SpaceTrucking//deliveryLocations.txt");
                    for (int i = 0; i < line.Length; i++)
                    {
                        if (ScanChat(line[i]) != null)
                        {
                            MyGps gpsRef = ScanChat(line[i]);
                            DeliveryLocations.Add(gpsRef);
                        }
                    }
                }
                if (System.IO.File.Exists(TruckingPlugin.path + "//SpaceTrucking//easy.csv"))
                {
                    String[] line = File.ReadAllLines(TruckingPlugin.path + "//SpaceTrucking//easy.csv");

                    for (int i = 1; i < line.Length; i++)
                    {
                        String[] split = line[i].Split(',');
                        TruckingPlugin.AddToEasyContractItems(ReadContractItem(split, "easy"));
                    }
                }
                else
                {
                    StringBuilder easy = new StringBuilder();
                    easy.AppendLine("ContractItemId,TypeId,SubtypeId,minAmount,maxAmount,minPrice,maxPrice,percentageChance,reputation");
                    easy.AppendLine("EasyIngot1,Ingot,Iron,1,10,20,50,50,3");
                    easy.AppendLine("EasyComponent1,Component,SteelPlate,1,10,20,50,50,3");
                    easy.AppendLine("EasyOre1,Ore,Iron,1,10,20,50,50,3");



                    if (!System.IO.File.Exists(TruckingPlugin.path + "//SpaceTrucking//easy.csv"))
                    {
                        File.WriteAllText(TruckingPlugin.path + "//SpaceTrucking//easy.csv", easy.ToString());
                    }
                }
                if (System.IO.File.Exists(TruckingPlugin.path + "//SpaceTrucking//medium.csv"))
                {
                    String[] line = File.ReadAllLines(TruckingPlugin.path + "//SpaceTrucking//medium.csv");

                    for (int i = 1; i < line.Length; i++)
                    {
                        String[] split = line[i].Split(',');
                        TruckingPlugin.AddToMediumContractItems(ReadContractItem(split, "medium"));
                    }
                }
                else
                {
                    StringBuilder medium = new StringBuilder();
                    medium.AppendLine("ContractItemId,TypeId,SubtypeId,minAmount,maxAmount,minPrice,maxPrice,percentageChance,reputation");
                    medium.AppendLine("MediumIngot1,Ingot,Iron,1,10,20,50,50,1");
                    medium.AppendLine("MediumComponent1,Component,SteelPlate,1,10,20,50,50,1");
                    medium.AppendLine("MediumOre1,Ore,Iron,1,10,20,50,50,1");

                    if (!System.IO.File.Exists(TruckingPlugin.path + "//SpaceTrucking//medium.csv"))
                    {
                        File.WriteAllText(TruckingPlugin.path + "//SpaceTrucking//medium.csv", medium.ToString());
                    }
                }
                if (System.IO.File.Exists(TruckingPlugin.path + "//SpaceTrucking//hard.csv"))
                {
                    String[] line = File.ReadAllLines(TruckingPlugin.path + "//SpaceTrucking//hard.csv");

                    for (int i = 1; i < line.Length; i++)
                    {
                        String[] split = line[i].Split(',');
                        TruckingPlugin.AddToHardContractItems(ReadContractItem(split, "hard"));
                    }
                }
                else
                {
                    if (!System.IO.File.Exists(TruckingPlugin.path + "//SpaceTrucking//hard.csv"))
                    {
                        StringBuilder hard = new StringBuilder();
                        hard.AppendLine("ContractItemId,TypeId,SubtypeId,minAmount,maxAmount,minPrice,maxPrice,percentageChance,reputation");
                        hard.AppendLine("HardIngot1,Ingot,Iron,1,10,20,50,50,1");
                        hard.AppendLine("HardComponent1,Component,SteelPlate,1,10,20,50,50,1");
                        hard.AppendLine("HardOre1,Ore,Iron,1,10,20,50,50,1");
                        File.WriteAllText(TruckingPlugin.path + "//SpaceTrucking//hard.csv", hard.ToString());
                    }
                }
                if (System.IO.File.Exists(TruckingPlugin.path + "//SpaceTrucking//bonusRewards.csv"))
                {
                    String[] line = File.ReadAllLines(TruckingPlugin.path + "//SpaceTrucking//bonusRewards.csv");

                    for (int i = 1; i < line.Length; i++)
                    {
                        String[] split = line[i].Split(',');
                    }
                }
                else
                {
                    if (!System.IO.File.Exists(TruckingPlugin.path + "//SpaceTrucking//bonusRewards.csv"))
                    {
                        StringBuilder hard = new StringBuilder();
                        hard.AppendLine("TypeId,SubtypeId,minAmount,maxAmount,percentageChance");
                        hard.AppendLine("Ingot,Iron,1,10,20");
                        File.WriteAllText(TruckingPlugin.path + "//SpaceTrucking//bonusRewards.csv", hard.ToString());
                    }
                }
            }
        }
Ejemplo n.º 14
0
        public override void Update()
        {
            try
            {
                //slow this shit down so it doesnt lag out console, 32 is fine but i dont think it needs to check that often
                ++this.tick;


                if (this.tick % 128 == 0)
                {
                    if (DateTime.Now >= nextUpdate && config.UsingWhitelist)
                    {
                        nextUpdate = DateTime.Now.AddMinutes(5);
                        Whitelist.Clear();
                        Database.LoadWhitelist();
                    }
                    foreach (MyPlayer onlinePlayer in MySession.Static.Players.GetOnlinePlayers())
                    {
                        MyPlayer playerOnline = onlinePlayer;
                        if (onlinePlayer.Character != null && onlinePlayer?.Controller.ControlledEntity is MyCockpit controller)
                        {
                            MyCubeGrid grid = controller.CubeGrid;
                            if (TruckingPlugin.getActiveContract(onlinePlayer.Id.SteamId) != null)
                            {
                                Contract contract = TruckingPlugin.getActiveContract(onlinePlayer.Id.SteamId);
                                Vector3D coords   = contract.GetDeliveryLocation().Coords;
                                float    distance = Vector3.Distance(coords, onlinePlayer.Character.PositionComp.GetPosition());
                                if (distance <= 300)
                                {
                                    List <VRage.ModAPI.IMyEntity> l = new List <VRage.ModAPI.IMyEntity>();

                                    BoundingSphereD sphere = new BoundingSphereD(onlinePlayer.Character.PositionComp.GetPosition(), 1000);
                                    l = MyAPIGateway.Entities.GetEntitiesInSphere(ref sphere);

                                    Dictionary <MyDefinitionId, int> itemsToRemove = new Dictionary <MyDefinitionId, int>();
                                    int pay = 0;
                                    //calculate the pay since we only show the player the minimum they can get, this could be removed if the pay is made part of the contract
                                    //when its generated and stored in the db, reputation when completed could give a bonus percent
                                    foreach (ContractItems item in contract.getItemsInContract())
                                    {
                                        if (MyDefinitionId.TryParse("MyObjectBuilder_" + item.ItemType, item.SubType, out MyDefinitionId id))
                                        {
                                            itemsToRemove.Add(id, item.AmountToDeliver);
                                            pay += item.AmountToDeliver * item.GetPrice();
                                        }
                                    }


                                    List <VRage.Game.ModAPI.IMyInventory> inventories = TakeTheItems.GetInventories(grid);

                                    if (FacUtils.IsOwnerOrFactionOwned(grid, onlinePlayer.Identity.IdentityId, true) && Vector3.Distance(coords, grid.PositionComp.GetPosition()) <= 300)
                                    {
                                        if (TakeTheItems.ConsumeComponents(inventories, itemsToRemove, onlinePlayer.Id.SteamId))
                                        {
                                            MyBankingSystem.ChangeBalance(onlinePlayer.Identity.IdentityId, pay);
                                            Database.RemoveContract(onlinePlayer.Id.SteamId, true, contract, onlinePlayer.Identity.IdentityId);
                                            TruckingPlugin.SendMessage("The Boss", "Contract Complete, Payment delivered to bank account.", Color.Purple, onlinePlayer.Id.SteamId);
                                            //if (TruckingPlugin.config.DoBonusRewards)
                                            //{
                                            //    List<ContractItems> SortedList = bonusRewards.OrderByDescending(o => o.chance).ToList();
                                            //    Random random = new Random();
                                            //    foreach (ContractItems item in SortedList)
                                            //    {

                                            //        int chance = random.Next(101);
                                            //        if (chance <= item.chance)
                                            //        {

                                            //        }
                                            //    }
                                            //}
                                            return;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                TruckingPlugin.Log.Info("Space trucking error " + ex.ToString());
            }
        }