Exemplo n.º 1
0
        private static List <ContractItems> getItems(List <ContractItems> items, int AmountToPick)
        {
            List <ContractItems> returnList = new List <ContractItems>();
            List <ContractItems> SortedList = items.OrderByDescending(o => o.chance).ToList();

            SortedList.Reverse();
            int amountPicked = 0;

            //sort the list by descending then reverse it so we check the lowest chances first
            Random random = new Random();

            foreach (ContractItems item in SortedList)
            {
                item.SetAmountToDeliver();
                int chance = random.Next(101);
                if (chance <= item.chance && amountPicked < AmountToPick)
                {
                    returnList.Add(item);
                    amountPicked++;
                }
            }
            //check theres at least one item on the contract, if not pick one at complete random
            if (returnList.Count == 0)
            {
                int           index = random.Next(SortedList.Count - 1);
                ContractItems temp  = SortedList.ElementAt(index);

                returnList.Add(temp);
            }

            return(returnList);
        }
Exemplo n.º 2
0
 public static void AddToHardContractItems(ContractItems item)
 {
     if (hardItems.ContainsKey(item.ContractItemId))
     {
         hardItems.Remove(item.ContractItemId);
         hardItems.Add(item.ContractItemId, item);
     }
     else
     {
         hardItems.Add(item.ContractItemId, item);
     }
 }
Exemplo n.º 3
0
 public static void AddToMediumContractItems(ContractItems item)
 {
     if (mediumItems.ContainsKey(item.ContractItemId))
     {
         mediumItems.Remove(item.ContractItemId);
         mediumItems.Add(item.ContractItemId, item);
     }
     else
     {
         mediumItems.Add(item.ContractItemId, item);
     }
 }
Exemplo n.º 4
0
 public static void AddToEasyContractItems(ContractItems item)
 {
     if (easyItems.ContainsKey(item.ContractItemId))
     {
         easyItems.Remove(item.ContractItemId);
         easyItems.Add(item.ContractItemId, item);
     }
     else
     {
         easyItems.Add(item.ContractItemId, item);
     }
 }
Exemplo n.º 5
0
        public ContractItems ReadContractItem(String[] split, string difficulty)
        {
            foreach (String s in split)
            {
                s.Replace(" ", "");
            }
            ContractItems temp = new ContractItems();

            temp.ContractItemId = split[0].Replace(" ", "");
            temp.ItemType       = split[1].Replace(" ", "");
            temp.SubType        = split[2].Replace(" ", "");
            temp.MinToDeliver   = int.Parse(split[3].Replace(" ", ""));
            temp.MaxToDeliver   = int.Parse(split[4].Replace(" ", ""));
            temp.MinPrice       = int.Parse(split[5].Replace(" ", ""));
            temp.MaxPrice       = int.Parse(split[6].Replace(" ", ""));
            temp.chance         = int.Parse(split[7].Replace(" ", ""));
            temp.reputation     = int.Parse(split[8].Replace(" ", ""));
            temp.difficulty     = difficulty;
            return(temp);
        }
Exemplo n.º 6
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);
        }