private JournalOperation ExtractMarketSell(JObject data)
        {
            string marketSellName;

            if (!converter.TryGet((string)data["Type"], out marketSellName))
            {
                return(null);
            }

            return(new CargoOperation
            {
                CommodityName = marketSellName,
                Size = -1 * data["Count"]?.ToObject <int>() ?? -1
            });
        }
示例#2
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue,
                                        JsonSerializer serializer)
        {
            reader.DateParseHandling = DateParseHandling.None;
            var data = JObject.Load(reader);

            var entry = new JournalEntry
            {
                TimeStamp    = InstantPattern.GeneralPattern.Parse((string)data["timestamp"]).Value,
                OriginalJson = data.ToString()
            };

            JournalEvent journalEvent;

            try
            {
                journalEvent = data["event"].ToObject <JournalEvent>(serializer);
            }
            catch (JsonSerializationException)
            {
                return(entry);
            }

            switch (journalEvent)
            {
            case JournalEvent.ManualUserChange:
                entry.JournalOperation = new ManualChangeOperation
                {
                    Name  = (string)data["Name"],
                    Count = (int)data["Count"]
                };
                break;

            case JournalEvent.MiningRefined:
                string miningRefinedName;
                if (!converter.TryGet((string)data["Type"], out miningRefinedName))
                {
                    break;
                }

                entry.JournalOperation = new CargoOperation
                {
                    CommodityName = miningRefinedName,
                    Size          = 1
                };
                break;

            case JournalEvent.EngineerCraft:
                var engineerCraft = new EngineerOperation
                {
                    IngredientsConsumed = data["Ingredients"]
                                          .Select(c =>
                    {
                        dynamic cc = c;
                        string rewardName;
                        return(Tuple.Create(converter.TryGet((string)cc.Name, out rewardName),
                                            rewardName,
                                            (int)cc.Value));
                    })
                                          .Where(c => c.Item1)
                                          .Select(c => new BlueprintIngredient(entries[c.Item2], c.Item3)).ToList()
                };

                if (engineerCraft.IngredientsConsumed.Any())
                {
                    entry.JournalOperation = engineerCraft;
                }
                break;

            case JournalEvent.MarketSell:
                string marketSellName;
                if (!converter.TryGet((string)data["Type"], out marketSellName))
                {
                    break;
                }

                entry.JournalOperation = new CargoOperation
                {
                    CommodityName = marketSellName,
                    Size          = -1 * data["Count"].ToObject <int>()
                };
                break;

            case JournalEvent.MarketBuy:
                string marketBuyName;
                if (!converter.TryGet((string)data["Type"], out marketBuyName))
                {
                    break;
                }

                entry.JournalOperation = new CargoOperation
                {
                    CommodityName = marketBuyName,
                    Size          = data["Count"].ToObject <int>()
                };
                break;

            case JournalEvent.MaterialDiscarded:
                string materialDiscardedName;
                if (!converter.TryGet((string)data["Name"], out materialDiscardedName))
                {
                    MessageBox.Show($"Unknown material, please contact the author ! {(string) data["Name"]}");
                    break;
                }

                if (((string)data["Category"]).ToLowerInvariant() == "encoded")
                {
                    entry.JournalOperation = new DataOperation
                    {
                        DataName = materialDiscardedName,
                        Size     = -1 * data["Count"].ToObject <int>()
                    };
                }
                else     // Manufactured & Raw
                {
                    entry.JournalOperation = new MaterialOperation
                    {
                        MaterialName = materialDiscardedName,
                        Size         = -1 * data["Count"].ToObject <int>()
                    };
                }

                break;

            case JournalEvent.MaterialCollected:
                string materialCollectedName;
                if (!converter.TryGet((string)data["Name"], out materialCollectedName))
                {
                    MessageBox.Show($"Unknown material, please contact the author ! {(string)data["Name"]}");
                    break;
                }

                if (((string)data["Category"]).ToLowerInvariant() == "encoded")
                {
                    entry.JournalOperation = new DataOperation
                    {
                        DataName = materialCollectedName,
                        Size     = data["Count"].ToObject <int>()
                    };
                }
                else     // Manufactured & Raw
                {
                    entry.JournalOperation = new MaterialOperation
                    {
                        MaterialName = materialCollectedName,
                        Size         = data["Count"].ToObject <int>()
                    };
                }

                break;

            case JournalEvent.MissionCompleted:
                JToken rewardData;

                // TODO: missions can sometimes reward data/material and this is not currently handled

                if (!data.TryGetValue("CommodityReward", out rewardData))
                {
                    break;
                }

                var missionCompleted = new MissionCompletedOperation
                {
                    CommodityRewards = rewardData
                                       .Select(c =>
                    {
                        string rewardName;
                        return(Tuple.Create(c,
                                            converter.TryGet((string)c["Name"], out rewardName),
                                            rewardName));
                    })
                                       .Where(c => c.Item2)
                                       .Select(c =>
                    {
                        var r = new CargoOperation
                        {
                            CommodityName = c.Item3,
                            Size          = c.Item1["Count"].ToObject <int>(),
                            JournalEvent  = JournalEvent.MissionCompleted
                        };
                        return(r);
                    }).ToList()
                };
                if (missionCompleted.CommodityRewards.Any())
                {
                    entry.JournalOperation = missionCompleted;
                }

                break;

            case JournalEvent.CollectCargo:
                string collectCargoName;
                if (!converter.TryGet((string)data["Type"], out collectCargoName))
                {
                    break;
                }

                entry.JournalOperation = new CargoOperation
                {
                    CommodityName = collectCargoName,
                    Size          = 1
                };
                break;

            case JournalEvent.EjectCargo:
                string ejectCargoName;
                if (!converter.TryGet((string)data["Type"], out ejectCargoName))
                {
                    break;
                }

                entry.JournalOperation = new CargoOperation
                {
                    CommodityName = ejectCargoName,
                    Size          = -1
                };
                break;
            }

            if (entry.JournalOperation != null)
            {
                entry.JournalOperation.JournalEvent = journalEvent;
            }

            return(entry);
        }
        private JournalOperation ExtractMaterialsDump(JObject data)
        {
            var dump = new DumpOperation
            {
                ResetFilter = new HashSet <Kind>()
                {
                    Kind.Data,
                    Kind.Material
                },
                DumpOperations = new List <MaterialOperation>()
            };

            foreach (var jToken in data["Raw"].Union(data["Manufactured"]).Union(data["Encoded"]))
            {
                dynamic cc           = jToken;
                string  materialName = cc.Name;
                int?    count        = cc.Value ?? cc.Count;

                if (!converter.TryGet(materialName, out materialName))
                {
                    MessageBox.Show(string.Format(languages.Translate("Unknown material, please contact the author ! {0}"), (string)data["Name"]));
                    continue;
                }

                var operation = new MaterialOperation()
                {
                    MaterialName = materialName,
                    Size         = count ?? 1
                };

                dump.DumpOperations.Add(operation);
            }

            return(dump);
        }
示例#4
0
        private JournalOperation ExtractTechnologyBroker(JObject data)
        {
            var operation = new EngineerOperation(BlueprintCategory.Technology, null)
            {
                IngredientsConsumed = data["Ingredients"].Select(c =>
                {
                    dynamic cc = c;
                    return(Tuple.Create(converter.TryGet((string)cc.Name, out var ingredient), ingredient, (int)cc.Count));
                })
                                      .Where(c => c.Item1)
                                      .Select(c => new BlueprintIngredient(entries[c.Item2], c.Item3)).ToList()
            };

            return(operation.IngredientsConsumed.Any() ? operation : null);
        }
示例#5
0
        private JournalOperation ExtractTechnologyBroker(JObject data)
        {
            var operation = new EngineerOperation(BlueprintCategory.Technology, null, null, null, null, null, null)
            {
                IngredientsConsumed = (data["Ingredients"]?.Select(c =>
                {
                    dynamic cc = c;
                    return(Tuple.Create(converter.TryGet(Kind.Data | Kind.Material | Kind.Commodity, (string)cc.Name, out var ingredient), ingredient, (int)cc.Count));
                }) ?? Enumerable.Empty <Tuple <bool, string, int> >())
                                      .Union(data["Materials"]?.Select(c =>
                {
                    dynamic cc = c;
                    var filter = cc.Category == "Encoded" ? Kind.Data : Kind.Material;
                    return(Tuple.Create(converter.TryGet(filter, (string)cc.Name, out var ingredient), ingredient, (int)cc.Count));
                }) ?? Enumerable.Empty <Tuple <bool, string, int> >())
                                      .Union(data["Commodities"]?.Select(c =>
                {
                    dynamic cc = c;
                    return(Tuple.Create(converter.TryGet(Kind.Commodity, (string)cc.Name, out var ingredient), ingredient, (int)cc.Count));
                }) ?? Enumerable.Empty <Tuple <bool, string, int> >())
                                      .Where(c => c.Item1)
                                      .Select(c => new BlueprintIngredient(entries[c.Item2], c.Item3)).ToList()
            };

            return(operation.IngredientsConsumed.Any() ? operation : null);
        }
示例#6
0
        private JournalOperation ExtractEngineerContribution(JObject data)
        {
            string name;

            if (!converter.TryGet((string)data["Commodity"], out name) &&
                !converter.TryGet((string)data["Material"], out name) &&
                !converter.TryGet((string)data["Encoded"], out name) &&
                !converter.TryGet((string)data["Raw"], out name) &&
                !converter.TryGet((string)data["Manufactured"], out name) &&
                !converter.TryGet((string)data["Data"], out name) &&
                !converter.TryGet((string)data["Commodity"], out name) &&
                !converter.TryGet((string)data["Name"], out name))
            {
                return(null);
            }

            var type = ((string)data["Type"]).ToLowerInvariant();

            switch (type)
            {
            case "encoded":
            case "data":
                return(new DataOperation()
                {
                    DataName = name,
                    Size = -1 * data["Quantity"]?.ToObject <int>() ?? 1
                });

            case "commodity":
                return(null); // ignore commodity

            default:          // materials
                return(new MaterialOperation
                {
                    MaterialName = name,
                    Size = -1 * data["Quantity"]?.ToObject <int>() ?? 1
                });
            }
        }
        private JournalOperation ExtractBackpackChange(JObject data)
        {
            if (data.ContainsKey("Added"))
            {
                foreach (var item in data["Added"])
                {
                    if (((string)item["Type"]) == "Data")// No way to detect data download
                    {
                        var collect = new CollectItemOperation();
                        converter.TryGet(Kind.OdysseyIngredient, (string)item["Name"], out var ingredient);
                        if (ingredient == null)
                        {
                            return(null);
                        }

                        var quantity = (int)item["Count"];
                        collect.MaterialName = ingredient;
                        collect.Size         = quantity;
                        return(collect);
                    }
                }
            }

            return(null);
        }