public Commodity(Commodity Commodity)
 {
     this.EDDBID = Commodity.EDDBID;
     this.EDName = Commodity.EDName;
     this.name = Commodity.name;
     this.category = Commodity.category;
     this.avgprice = Commodity.avgprice;
     this.rare = Commodity.rare;
 }
 public CommoditySoldEvent(DateTime timestamp, Commodity commodity, int amount, long price, long profit, bool illegal, bool stolen, bool blackmarket) : base(timestamp, NAME)
 {
     this.commodity = (commodity == null ? "unknown commodity" : commodity.name);
     this.amount = amount;
     this.price = price;
     this.profit = profit;
     this.illegal = illegal;
     this.stolen = stolen;
     this.blackmarket = blackmarket;
 }
 public CommodityRefinedEvent(DateTime timestamp, Commodity commodity) : base(timestamp, NAME)
 {
     this.commodity = (commodity == null ? "unknown commodity" : commodity.name);
 }
 public CommodityPurchasedEvent(DateTime timestamp, Commodity commodity, int amount, long price) : base(timestamp, NAME)
 {
     this.commodity = (commodity == null ? "unknown commodity" : commodity.name);
     this.amount = amount;
     this.price = price;
 }
 public CommodityEjectedEvent(DateTime timestamp, Commodity commodity , int amount, bool abandoned) : base(timestamp, NAME)
 {
     this.commodity = (commodity == null ? "unknown commodity" : commodity.name);
     this.amount = amount;
     this.abandoned = abandoned;
 }
 public CommodityCollectedEvent(DateTime timestamp, Commodity commodity, bool stolen) : base(timestamp, NAME)
 {
     this.commodity = (commodity == null ? "unknown commodity" : commodity.name);
     this.stolen = stolen;
 }
        // Obtain the list of commodities from the profile
        public static List<Commodity> CommoditiesFromProfile(dynamic json)
        {
            List<Commodity> Commodities = new List<Commodity>();

            if (json["lastStarport"] != null && json["lastStarport"]["commodities"] != null)
            {
                foreach (dynamic commodity in json["lastStarport"]["commodities"])
                {
                    dynamic commodityJson = commodity.Value;
                    Commodity Commodity = CommodityDefinitions.CommodityFromEliteID((long)commodity["id"]);
                    if (Commodity == null || Commodity.name == null)
                    {
                        Commodity = new Commodity();
                        Commodity.EDName = (string)commodity["name"];
                        Commodity.category = (string)commodity["categoryName"];
                    }
                    Commodity.avgprice = (int)commodity["meanPrice"];
                    Commodity.buyprice = (int)commodity["buyPrice"];
                    Commodity.stock = (int)commodity["stock"];
                    Commodity.stockbracket = (dynamic)commodity["stockBracket"];
                    Commodity.sellprice = (int)commodity["sellPrice"];
                    Commodity.demand = (int)commodity["demand"];
                    Commodity.demandbracket = (dynamic)commodity["demandBracket"];

                    List<string> StatusFlags = new List<string>();
                    foreach (dynamic statusFlag in commodity["statusFlags"])
                    {
                        StatusFlags.Add((string)statusFlag);
                    }
                    Commodity.StatusFlags = StatusFlags;
                    Commodities.Add(Commodity);
                }
            }

            return Commodities;
        }
        public static Commodity FromName(string name)
        {
            if (name == null)
            {
                return null;
            }

            Commodity Commodity = new Commodity();

            string cleanedName = name
                .Replace("$", "") // Header for types from mining refined events
                .Replace("_name;", "") // Trailer for types from mining refined events
                ;

            // First try to map from cargo name to the commodity name
            string cargoName;
            cargoNamesMapping.TryGetValue(cleanedName, out cargoName);
            if (cargoName == null) { cargoName = cleanedName; }

            // Now try to fetch the commodity by name
            Commodity Template;
            bool found = CommoditiesByName.TryGetValue(cargoName, out Template);
            if (!found)
            {
                // Failed to find it; try again using the external name
                string edName;
                nameMapping.TryGetValue(cargoName, out edName);
                if (edName != null)
                {
                    found = CommoditiesByName.TryGetValue(edName, out Template);
                }
            }
            if (found)
            {
                Commodity.EDDBID = Template.EDDBID;
                Commodity.EDName = Template.EDName;
                Commodity.name = Template.name;
                Commodity.category = Template.category;
                Commodity.rare = Template.rare;
                Commodity.avgprice = Template.avgprice;
            }
            else
            {
                // Put some basic information in place
                Commodity.EDName = name;
                Commodity.name = cleanedName;
            }
            return Commodity;
        }
        public static Commodity CommodityFromEliteID(long id)
        {
            Commodity Commodity = new Commodity();

            Commodity Template;
            if (CommoditiesByEliteID.TryGetValue(id, out Template))
            {
                Commodity.EDDBID = Template.EDDBID;
                Commodity.EDName = Template.EDName;
                Commodity.name = Template.name;
                Commodity.category = Template.category;
                Commodity.rare = Template.rare;
                Commodity.avgprice = Template.avgprice;
            }
            return Commodity;
        }
Ejemplo n.º 10
0
        public static Commodity FromName(string name)
        {
            if (name == null)
            {
                return(null);
            }

            Commodity Commodity = new Commodity();

            string cleanedName = name.ToLowerInvariant()
                                 .Replace("$", "")      // Header for types from mining and mission events
                                 .Replace("_name;", "") // Trailer for types from mining and mission events
            ;

            // Map from ED name to sensible name
            string edName;

            nameMapping.TryGetValue(cleanedName, out edName);

            // Now try to fetch the commodity by either ED or real name
            Commodity Template = null;
            bool      found    = false;

            if (edName != null)
            {
                found = CommoditiesByEDName.TryGetValue(edName, out Template);
                if (!found)
                {
                    found = CommoditiesByName.TryGetValue(edName, out Template);
                }
            }
            if (!found)
            {
                found = CommoditiesByEDName.TryGetValue(cleanedName, out Template);
            }
            if (!found)
            {
                found = CommoditiesByName.TryGetValue(cleanedName, out Template);
            }
            if (found)
            {
                Commodity.EDDBID   = Template?.EDDBID ?? Commodity.EDDBID;
                Commodity.EDName   = Template?.EDName ?? Commodity.EDName;
                Commodity.name     = Template?.name ?? Commodity.name;
                Commodity.category = Template?.category ?? Commodity.category;
                Commodity.avgprice = Template?.avgprice ?? Commodity.avgprice;
                Commodity.rare     = Template?.rare ?? Commodity.rare;
            }
            else
            {
                var badCommodity = new Dictionary <string, object>();
                badCommodity["name"] = name;
                string badCommodityJSON = JsonConvert.SerializeObject(badCommodity);
                Logging.Report("Unknown commodity", badCommodityJSON);

                // Put some basic information in place
                Commodity.EDName = name;
                Commodity.name   = Regex.Replace(name.Replace("$", "").Replace("_Name;", ""), "([a-z])([A-Z])", "$1 $2");
            }
            return(Commodity);
        }