예제 #1
0
        private EngineerOperation ExtractEngineerOperation(JObject data)
        {
            var operation = 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()
            };

            return(operation.IngredientsConsumed.Any() ? operation : null);
        }
예제 #2
0
        private JournalOperation ExtractSynthesis(JObject data)
        {
            var synthesisOperation = new EngineerOperation(BlueprintCategory.Synthesis, null)
            {
                IngredientsConsumed = new List <BlueprintIngredient>()
            };

            foreach (var jToken in data["Materials"])
            {
                dynamic cc = jToken;
                var     synthesisIngredientName = converter.GetOrCreate((string)cc.Name);
                int?    count = cc.Value ?? cc.Count;

                synthesisOperation.IngredientsConsumed.Add(new BlueprintIngredient(entries[synthesisIngredientName],
                                                                                   count ?? 1));
            }

            return(synthesisOperation.IngredientsConsumed.Any() ? synthesisOperation : null);
        }
예제 #3
0
 public void OnBlueprintCrafted(EngineerOperation operation)
 {
     BlueprintCrafted?.Invoke(this, operation);
 }
예제 #4
0
 public void ApplyCraft(EngineerOperation engineerOperation)
 {
     Loadout.ApplyCraft(engineerOperation);
 }
예제 #5
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);
        }