Esempio n. 1
0
        public void DumpEnumZero()
        {
            var value = MyEnum.Zero;

            var dumper = new Dumper();

            var dump = dumper.Dump(value);

            Assert.NotNull(dump, "Dump shall return a DumpLevel instance.");
            Assert.AreEqual("MyEnum.Zero", dump.Value, "Dump value shall be 'MyEnum.Zero'.");
            Assert.AreEqual(typeof(MyEnum), dump.Type, "Dump type shall be a MyEnum type.");
            Assert.AreEqual(0, dump.Count(), "Dump children count shall be 0.");
        }
Esempio n. 2
0
        public void DumpEmptyStruct()
        {
            var testStruct = new TestStruct();
            var dumper = new Dumper();

            var dump = dumper.Dump(testStruct);

            Assert.NotNull(dump, "Dump shall return a DumpLevel instance.");
            Assert.AreEqual(null, dump.Value, "Dump value shall be null.");
            Assert.AreEqual(typeof(TestStruct), dump.Type, "Dump type shall be a TestStruct type.");
            Assert.AreEqual(1, dump.Count(), "Dump children count shall be 1.");
            Assert.AreEqual(0, dump.Level, "Dump level count shall be 0.");
            var children = new List<DumpLevel>(dump);
            Assert.AreEqual(1, children.Count, "Dump IEnumerable copy shall be count 1 item.");

            Assert.AreEqual("Property", children[0].Header, "First children header shall be 'Property'.");
            Assert.AreEqual(typeof(string), children[0].Type, "First children type shall be a string.");
            Assert.AreEqual(null, children[0].Value, "First children value shall be null.");
            Assert.AreEqual(1, children[0].Level, "First children level shall be 1.");
        }
Esempio n. 3
0
 public void DumpAssembler(Program program, string filename, Dictionary <ImageSegment, List <ImageMapItem> > segmentItems, Formatter wr)
 {
     if (wr == null || program.Architecture == null)
     {
         return;
     }
     try
     {
         Dumper dump = new Dumper(program)
         {
             ShowAddresses = program.User.ShowAddressesInDisassembly,
             ShowCodeBytes = program.User.ShowBytesInDisassembly
         };
         dump.Dump(segmentItems, wr);
     }
     catch (Exception ex)
     {
         eventListener.Error(ex, "An error occurred while write assembly language output.");
     }
 }
        protected override ScoringEfficiency EvaluateGame()
        {
            if (RegionResult == null)
            {
                RegionResult = Search(Agent.Position, Math.Min(Around, Game.Length - Game.Turn + 1));
                Dumper?.Dump();
                Dumper?.Reset();

                if (RegionResult.Ends.Count > 0)
                {
                    Way = new Helper.Way(Agent, RegionResult.Ends.First().Went.ToArray());
                }
                else
                {
                    Console.WriteLine("近傍領域探索:領域を生成できませんでした");
                    return(null);
                }
            }

            return(RegionResult.Ends.FirstOrDefault()?.GetScoringEfficiency());
        }
        public static async Task Execute(ISession session)
        {
            var highestsPokemonCp = await session.Inventory.GetHighestsCp(session.LogicSettings.AmountOfPokemonToDisplayOnStart);

            var pokemonPairedWithStatsCp = highestsPokemonCp.Select(pokemon => Tuple.Create(pokemon, PokemonInfo.CalculateMaxCp(pokemon), PokemonInfo.CalculatePokemonPerfection(pokemon), PokemonInfo.GetLevel(pokemon))).ToList();

            var highestsPokemonPerfect =
                await session.Inventory.GetHighestsPerfect(session.LogicSettings.AmountOfPokemonToDisplayOnStart);

            var pokemonPairedWithStatsIv = highestsPokemonPerfect.Select(pokemon => Tuple.Create(pokemon, PokemonInfo.CalculateMaxCp(pokemon), PokemonInfo.CalculatePokemonPerfection(pokemon), PokemonInfo.GetLevel(pokemon))).ToList();

            session.EventDispatcher.Send(
                new DisplayHighestsPokemonEvent
            {
                SortedBy    = "CP",
                PokemonList = pokemonPairedWithStatsCp
            });

            await Task.Delay(500);

            session.EventDispatcher.Send(
                new DisplayHighestsPokemonEvent
            {
                SortedBy    = "IV",
                PokemonList = pokemonPairedWithStatsIv
            });

            var allPokemonInBag = session.LogicSettings.PrioritizeIvOverCp ? await session.Inventory.GetHighestsPerfect(1000) : await session.Inventory.GetHighestsCp(1000);

            if (session.LogicSettings.DumpPokemonStats)
            {
                const string dumpFileName = "PokeBagStats";
                Dumper.ClearDumpFile(session, dumpFileName);
                foreach (var pokemon in allPokemonInBag)
                {
                    Dumper.Dump(session, $"NAME: {pokemon.PokemonId.ToString().PadRight(16, ' ')}Lvl: { PokemonInfo.GetLevel(pokemon).ToString("00")}\t\tCP: { pokemon.Cp.ToString().PadRight(8, ' ')}\t\t IV: { PokemonInfo.CalculatePokemonPerfection(pokemon).ToString("0.00")}%", dumpFileName);
                }
            }
            await Task.Delay(500);
        }
Esempio n. 6
0
        private void ServerReceived(object sender, MessageReceivedEventArgs e)
        {
            // P <- S
            //Console.WriteLine("P <- S: {0}", e.Message.ID);

            var message      = e.Message;
            var sendingBytes = e.Raw;

            if (Processor.State == 4)
            {
                var body = new byte[e.Plaintext.Length + CoCKeyPair.NonceLength + CoCKeyPair.KeyLength];
                Buffer.BlockCopy(Processor.ServerNonce, 0, body, 0, CoCKeyPair.NonceLength);
                Buffer.BlockCopy(Processor.ServerCrypto.SharedKey, 0, body, CoCKeyPair.NonceLength, CoCKeyPair.KeyLength);
                Buffer.BlockCopy(e.Plaintext, 0, body, CoCKeyPair.NonceLength + CoCKeyPair.KeyLength, e.Plaintext.Length);
                Processor.ClientCrypto.Encrypt(ref body);

                sendingBytes = new byte[body.Length + MessageHeader.Size];
                Buffer.BlockCopy(e.Raw, 0, sendingBytes, 0, MessageHeader.Size);
                Buffer.BlockCopy(body, 0, sendingBytes, MessageHeader.Size, body.Length);
            }
            else if (Processor.State > 4)
            {
                // Could send the e.Raw back because we are using the same keys and nonces.
                // But lets reconstruct the packet because we're badasses.
                var body = (byte[])e.Plaintext.Clone();
                Processor.ClientCrypto.Encrypt(ref body);

                sendingBytes = new byte[body.Length + MessageHeader.Size];
                Buffer.BlockCopy(e.Raw, 0, sendingBytes, 0, MessageHeader.Size);
                Buffer.BlockCopy(body, 0, sendingBytes, MessageHeader.Size, body.Length);
            }

            File.WriteAllBytes(e.Message.ID.ToString(), e.Plaintext);

            Dumper.Dump(message, e.Plaintext);
            Logger.Log(message);
            // Forward data to the client.
            ClientConnection.Socket.Send(sendingBytes);
        }
Esempio n. 7
0
        private void ClientReceived(object sender, MessageReceivedEventArgs e)
        {
            // C -> P
            //Console.WriteLine("C -> P: {0}", e.Message.ID);

            var message      = e.Message;
            var sendingBytes = e.Raw;

            if (Processor.State == 3)
            {
                var body = new byte[e.Plaintext.Length + KeyPair.NonceLength * 2];
                Buffer.BlockCopy(Processor.SessionKey, 0, body, 0, KeyPair.NonceLength);
                Buffer.BlockCopy(Processor.ClientNonce, 0, body, KeyPair.NonceLength, KeyPair.NonceLength);
                Buffer.BlockCopy(e.Plaintext, 0, body, KeyPair.NonceLength * 2, e.Plaintext.Length);

                Processor.ServerCrypto.Encrypt(ref body);

                sendingBytes = new byte[body.Length + MessageHeader.Size + KeyPair.KeyLength];
                Buffer.BlockCopy(e.Raw, 0, sendingBytes, 0, MessageHeader.Size);
                Buffer.BlockCopy(Processor.ServerCrypto.KeyPair.PublicKey, 0, sendingBytes, MessageHeader.Size, KeyPair.KeyLength);
                Buffer.BlockCopy(body, 0, sendingBytes, MessageHeader.Size + KeyPair.KeyLength, body.Length);
            }
            else if (Processor.State > 3)
            {
                // Could send the e.Raw back because we are using the same keys and nonces.
                // But lets reconstruct the packet because we're badasses.
                var body = (byte[])e.Plaintext.Clone();
                Processor.ServerCrypto.Encrypt(ref body);

                sendingBytes = new byte[body.Length + MessageHeader.Size];
                Buffer.BlockCopy(e.Raw, 0, sendingBytes, 0, MessageHeader.Size);
                Buffer.BlockCopy(body, 0, sendingBytes, MessageHeader.Size, body.Length);
            }

            Dumper.Dump(message, e.Plaintext);
            Logger.Log(message);
            // Forward data to the server.
            ServerConnection.Socket.Send(sendingBytes);
        }
Esempio n. 8
0
        public static void Log(object obj = null, Level level = Level.INFO, int maxDepth = 0, int maxLength = 0)
        {
            Dispatcher dispatcher = Dispatcher.GetCurrent(true);
            bool       htmlOut    = dispatcher.Output == LogFormat.Html;
            string     renderedObj;
            string     logLevelValue = LevelValues.Values[level];

            if (level == Level.JAVASCRIPT)
            {
                if (!(obj is Dictionary <string, string>))
                {
                    Debug.Log(new Exception("To log javascript exceptions, call: Desharp.Debug.Log(data as Dictionary<string, string>, Level.JAVASCRIPT);"));
                }
                renderedObj = JavascriptExceptionData.RenderLogedExceptionData(obj as Dictionary <string, string>, htmlOut)
                              + Environment.NewLine;
            }
            else
            {
                try {
                    renderedObj = Dumper.Dump(obj, htmlOut, maxDepth, maxLength);
                } catch (Exception e) {
                    renderedObj = e.Message;
                }
                if (htmlOut && renderedObj.Length > Dumper.HtmlDumpWrapper[0].Length && renderedObj.IndexOf(Dumper.HtmlDumpWrapper[0]) == 0)
                {
                    // remove begin: <div class="desharp-dump"> and end: </div>
                    renderedObj = renderedObj.Substring(Dumper.HtmlDumpWrapper[0].Length, renderedObj.Length - (Dumper.HtmlDumpWrapper[0].Length + Dumper.HtmlDumpWrapper[1].Length));
                }
                renderedObj = Exceptions.RenderCurrentApplicationPoint(
                    renderedObj, "Value", true, htmlOut
                    ) + Environment.NewLine;
                if (Dispatcher.Levels[logLevelValue] == 2)
                {
                    Mailer.Notify(renderedObj, logLevelValue, htmlOut);
                }
            }
            FileLog.Log(renderedObj, logLevelValue);
        }
Esempio n. 9
0
 public override int Invoke(IEnumerable<string> args)
 {
     try
     {
         var extra = Options.Parse(args);
         if (ShowHelp)
         {
             Options.WriteOptionDescriptions(CommandSet.Out);
             return 0;
         }
         if (extra.Count == 0)
         {
             _repl.Console.WriteLine("commands: Missing required argument `command`.");
             _repl.Console.WriteLine("commands: Use `help debug` for details.");
             return 1;
         }
         var cmd = extra[0];
         if (cmd == "get-peer-list")
         {
             Dumper.Dump(_repl.Console, _agent.PeerList, new[] {
                 new Column<PeerInfo> { Title = "Bot ID",    Width = -54, m= info => info.ToString() },
                 new Column<PeerInfo> { Title = "Seen",      Width = -26, m = info => info.LastSeen.ToLocalTime() },
                 new Column<PeerInfo> { Title = "Rep",       Width =   4, m = info => info.Reputation },
                 new Column<PeerInfo> { Title = "SharedKey", Width =  10, m = info => Convert.ToBase64String(info.EncryptionKey).Substring(0, 8) }
             });
         }
         else if(cmd == "clear-peer-list")
         {
             _agent.PeerList.Clear();
         }
         return 0;
     }
     catch (Exception e)
     {
         // _repl.Console.WriteLine("commands: {0}", CommandDemo.Verbosity >= 1 ? e.ToString() : e.Message);
         return 1;
     }
 }
Esempio n. 10
0
        private void Dump(object obj, int?depth)
        {
            // TODO: Test and fix the SdtdConsole output for asynchronous/callbacks

            // We cannot use optional parameter "int depth = 1" because that doesn't work with Mono's dynamic invocation
            if (depth == null)
            {
                depth = 1;
            }

            var output = Dumper.Dump(obj, depth.Value);

            if (output.Length > 1024)
            {
                var truncated = output.Substring(0, 1024);
                SdtdConsole.Instance.Output(truncated + " [...]\r\n[output truncated; full output in log file]");
            }
            else
            {
                SdtdConsole.Instance.Output(output);
            }
            Log.Out(output);
        }
Esempio n. 11
0
        public void Dumper_ShowBytesInDisassembly()
        {
            Given_32bit_Program();
            Given_Disassembly(
                Mnemonic.Add,
                Mnemonic.Mul,
                Mnemonic.Add,
                Mnemonic.Ret);

            Given_ProcedureAt(Address.Ptr32(0x10010));

            var dmp = new Dumper(program);

            dmp.ShowCodeBytes = true;

            var sw = new StringWriter();

            dmp.Dump(new TextFormatter(sw));

            string sExp =
                #region Expected
                @";;; Segment .text (00010000)
00010000 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F ................

;; fn00010010: 00010010
fn00010010 proc
10 11               add
12 13               mul
14 15               add
16 17               ret
00010018                         18 19 1A 1B 1C 1D 1E 1F         ........
";

            #endregion
            AssertOutput(sExp, sw);
        }
Esempio n. 12
0
        public void Dumper_NamedProc()
        {
            Given_32bit_Program();
            Given_Disassembly(
                Mnemonic.Add,
                Mnemonic.Mul,
                Mnemonic.Add,
                Mnemonic.Ret);

            var proc = Given_ProcedureAt(Address.Ptr32(0x10010));

            proc.Name = "__foo@8";

            var dmp = new Dumper(program);

            var sw = new StringWriter();

            dmp.Dump(new TextFormatter(sw));

            string sExp =
                #region Expected
                @";;; Segment .text (00010000)
00010000 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F ................

;; __foo@8: 00010010
__foo@8 proc
	add
	mul
	add
	ret
00010018                         18 19 1A 1B 1C 1D 1E 1F         ........
";

            #endregion
            AssertOutput(sExp, sw);
        }
Esempio n. 13
0
        public void Dumper_Word32()
        {
            Given_32bit_Program();
            Given_Disassembly(
                Operation.Add,
                Operation.Mul,
                Operation.Add,
                Operation.Ret);

            program.ImageMap.AddItemWithSize(
                Address.Ptr32(0x10004),
                new ImageMapItem
            {
                Address  = Address.Ptr32(0x10004),
                DataType = PrimitiveType.Word32,
                Size     = 4,
            });

            var dmp = new Dumper(program);

            var sw = new StringWriter();

            dmp.Dump(new TextFormatter(sw));

            string sExp =
                #region Expected
                @";;; Segment .text (00010000)
00010000 00 01 02 03                                     ....           
l00010004	dd	0x07060504
00010008                         08 09 0A 0B 0C 0D 0E 0F         ........
00010010 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F ................
";

            #endregion
            AssertOutput(sExp, sw);
        }
Esempio n. 14
0
    public void Test()
    {
        Assert.True(true);

        TestClass putturnA = new TestClass();

        putturnA.pubpubStrA = "pubpubStrA-1";
        putturnA.SetPubpriStrB("pubpriStrB-2");
        putturnA.pubpubIntC = 1231;
        putturnA.SetPripriIntD(4562);
        putturnA.pubpubObjE            = new TestClass();
        putturnA.pubpubObjE.pubpubStrA = "pubpubStrA-2";
        putturnA.pubpubObjE.pubpubObjE = putturnA;
        putturnA.pubpubDictF           = new Dictionary <int, string>();
        putturnA.pubpubDictF.Add(19, "nineteen");
        putturnA.pubpubDictF.Add(17, "seventeen");
        putturnA.pubpubListG = new List <int>();
        putturnA.pubpubListG.Add(21);
        putturnA.pubpubListG.Add(33);

        Debug.Log(Dumper.Dump(putturnA));
        Debug.Log(Dumper.Dump(putturnA, false));
        Debug.Log(Dumper.Dump(putturnA, 8));
    }
Esempio n. 15
0
        public static async Task Execute(ISession session)
        {
            var myPokemonFamilies = await session.Inventory.GetPokemonFamilies();

            var myPokeSettings = await session.Inventory.GetPokemonSettings();

            var highestsPokemonCp =
                await session.Inventory.GetHighestsCp(session.LogicSettings.AmountOfPokemonToDisplayOnStart);

            var pokemonPairedWithStatsCp =
                highestsPokemonCp.Select(
                    pokemon =>
                    Tuple.Create(pokemon, PokemonInfo.CalculateMaxCp(pokemon),
                                 PokemonInfo.CalculatePokemonPerfection(pokemon), PokemonInfo.GetLevel(pokemon),
                                 PokemonInfo.GetPokemonMove1(pokemon), PokemonInfo.GetPokemonMove2(pokemon),
                                 PokemonInfo.GetCandy(pokemon, myPokemonFamilies, myPokeSettings))).ToList();

            var highestsPokemonPerfect =
                await session.Inventory.GetHighestsPerfect(session.LogicSettings.AmountOfPokemonToDisplayOnStart);

            var pokemonPairedWithStatsIv =
                highestsPokemonPerfect.Select(
                    pokemon =>
                    Tuple.Create(pokemon, PokemonInfo.CalculateMaxCp(pokemon),
                                 PokemonInfo.CalculatePokemonPerfection(pokemon), PokemonInfo.GetLevel(pokemon),
                                 PokemonInfo.GetPokemonMove1(pokemon), PokemonInfo.GetPokemonMove2(pokemon),
                                 PokemonInfo.GetCandy(pokemon, myPokemonFamilies, myPokeSettings))).ToList();

            session.EventDispatcher.Send(
                new DisplayHighestsPokemonEvent
            {
                SortedBy    = "CP",
                PokemonList = pokemonPairedWithStatsCp
            });

            session.EventDispatcher.Send(
                new DisplayHighestsPokemonEvent
            {
                SortedBy    = "IV",
                PokemonList = pokemonPairedWithStatsIv
            });

            var allPokemonInBag = session.LogicSettings.PrioritizeIvOverCp
                ? await session.Inventory.GetHighestsPerfect(1000)
                : await session.Inventory.GetHighestsCp(1000);

            if (session.LogicSettings.DumpPokemonStats)
            {
                const string dumpFileName = "PokeBagStats";
                try
                {
                    Dumper.ClearDumpFile(session, dumpFileName);

                    string[] data =
                    {
                        "pokemonid",
                        "pokemonlevel",
                        "cp",
                        "perfection",
                        "stamina",
                        "staminamax",
                        "move1",
                        "move2",
                        "candy",
                        "ownername",
                        "origin",
                        "heightm",
                        "weightkg",
                        "individualattack",
                        "individualdefense",
                        "individualstamina",
                        "cpmultiplier",
                        "battlesattacked",
                        "battlesdefended",
                        "creationtimems",
                        "numupgrades",
                        "additionalcpmultiplier",
                        "favorite",
                        "nickname"
                    };
                    Dumper.Dump(session, data, dumpFileName);

                    // set culture to OS default
                    CultureInfo prevCulture = Thread.CurrentThread.CurrentCulture;
                    CultureInfo culture     = CultureInfo.CurrentUICulture;
                    Thread.CurrentThread.CurrentCulture = culture;

                    foreach (var pokemon in allPokemonInBag)
                    {
                        string[] pokemonData =
                        {
                            session.Translation.GetPokemonTranslation(pokemon.PokemonId),
                            PokemonInfo.GetLevel(pokemon).ToString(),
                            pokemon.Cp.ToString(),
                            PokemonInfo.CalculatePokemonPerfection(pokemon).ToString(),
                            pokemon.Stamina.ToString(),
                            pokemon.StaminaMax.ToString(),
                            pokemon.Move1.ToString(),
                            pokemon.Move2.ToString(),
                            PokemonInfo.GetCandy(pokemon,                                myPokemonFamilies,myPokeSettings).ToString(),
                            pokemon.OwnerName,
                            pokemon.Origin.ToString(),
                            pokemon.HeightM.ToString(),
                            pokemon.WeightKg.ToString(),
                            pokemon.IndividualAttack.ToString(),
                            pokemon.IndividualDefense.ToString(),
                            pokemon.IndividualStamina.ToString(),
                            pokemon.CpMultiplier.ToString(),
                            pokemon.BattlesAttacked.ToString(),
                            pokemon.BattlesDefended.ToString(),
                            pokemon.CreationTimeMs.ToString(),
                            pokemon.NumUpgrades.ToString(),
                            pokemon.AdditionalCpMultiplier.ToString(),
                            pokemon.Favorite.ToString(),
                            pokemon.Nickname
                        };
                        Dumper.Dump(session, pokemonData, dumpFileName);
                    }

                    // restore culture
                    Thread.CurrentThread.CurrentCulture = prevCulture;
                }
                catch (System.IO.IOException)
                {
                    session.EventDispatcher.Send(new ErrorEvent {
                        Message = $"Could not write {dumpFileName} dump file."
                    });
                }
            }
        }
Esempio n. 16
0
        public static async Task Execute(ISession session)
        {
            var highestsPokemonCp = await
                                    session.Inventory.GetHighestsCp(session.LogicSettings.AmountOfPokemonToDisplayOnStart).ConfigureAwait(false);

            var pokemonPairedWithStatsCp =
                highestsPokemonCp.Select(
                    pokemon =>
                    Tuple.Create(
                        pokemon,
                        PokemonInfo.CalculateMaxCp(pokemon.PokemonId),
                        PokemonInfo.CalculatePokemonPerfection(pokemon),
                        PokemonInfo.GetLevel(pokemon),
                        PokemonInfo.GetPokemonMove1(pokemon),
                        PokemonInfo.GetPokemonMove2(pokemon),
                        PokemonInfo.GetCandy(session, pokemon).Result
                        )
                    )
                .ToList();

            var highestsPokemonPerfect = await
                                         session.Inventory.GetHighestsPerfect(session.LogicSettings.AmountOfPokemonToDisplayOnStart).ConfigureAwait(false);

            var pokemonPairedWithStatsIv =
                highestsPokemonPerfect.Select(
                    pokemon =>
                    Tuple.Create(
                        pokemon,
                        PokemonInfo.CalculateMaxCp(pokemon.PokemonId),
                        PokemonInfo.CalculatePokemonPerfection(pokemon),
                        PokemonInfo.GetLevel(pokemon),
                        PokemonInfo.GetPokemonMove1(pokemon),
                        PokemonInfo.GetPokemonMove2(pokemon),
                        PokemonInfo.GetCandy(session, pokemon).Result
                        )
                    )
                .ToList();

            session.EventDispatcher.Send(
                new DisplayHighestsPokemonEvent
            {
                SortedBy    = "CP",
                PokemonList = pokemonPairedWithStatsCp
            });

            session.EventDispatcher.Send(
                new DisplayHighestsPokemonEvent
            {
                SortedBy    = "IV",
                PokemonList = pokemonPairedWithStatsIv
            });

            var allPokemonInBag = session.LogicSettings.PrioritizeIvOverCp
                ? await session.Inventory.GetHighestsPerfect(1000).ConfigureAwait(false)
                : await session.Inventory.GetHighestsCp(1000).ConfigureAwait(false);

            if (session.LogicSettings.DumpPokemonStats)
            {
                _MultiAccountManager = new MultiAccountManager();
                var    account      = _MultiAccountManager.GetCurrentAccount();
                string dumpFileName = account.Nickname; // "-PokeBagStats";

                //If user dump file exists then cancel file dump
                if (File.Exists(Path.Combine(Path.Combine(session.LogicSettings.ProfilePath, "Dumps"), $"{dumpFileName}-NecroBot2 DumpFile.csv")))
                {
                    return;
                }

                try
                {
                    Dumper.ClearDumpFile(session, dumpFileName);

                    string[] data =
                    {
                        "Pokemon",
                        "Candies",
                        "Slashed",
                        "Nickname",
                        "Level",
                        "CP",
                        "IV",
                        "Power Ups",
                        "Favorite",
                        "Stamina",
                        "Stamina Max",
                        "Move1",
                        "Move2",
                        "Owner Name",
                        "Origin",
                        "Height(M)",
                        "Weight(KG)",
                        "Attack",
                        "Defense",
                        "Stamina",
                        "CP Multi",
                        "Gyms Attacked",
                        "Gyms Defended",
                        "Creationtimems",
                        "Add CP Multi"
                    };
                    Dumper.Dump(session, data, dumpFileName);

                    // set culture to OS default
                    CultureInfo prevCulture = Thread.CurrentThread.CurrentCulture;
                    CultureInfo culture     = CultureInfo.CurrentUICulture;
                    Thread.CurrentThread.CurrentCulture = culture;

                    foreach (var pokemon in allPokemonInBag)
                    {
                        string[] pokemonData =
                        {
                            session.Translation.GetPokemonTranslation(pokemon.PokemonId).Replace(' ', '_'),
                            session.Inventory.GetCandyCount(pokemon.PokemonId).ToString(),            // PokemonInfo.GetCandy(session, pokemon.PokemonId).ToString(),
                            pokemon.IsBad.ToString(),
                            pokemon.Nickname.Replace(' ',                                             '_'),
                            PokemonInfo.GetLevel(pokemon).ToString(),
                            pokemon.Cp.ToString(),
                            PokemonInfo.CalculatePokemonPerfection(pokemon).ToString(),
                            pokemon.NumUpgrades.ToString(),
                            pokemon.Favorite.ToString(),
                            pokemon.Stamina.ToString(),
                            pokemon.StaminaMax.ToString(),
                            pokemon.Move1.ToString(),
                            pokemon.Move2.ToString(),
                            pokemon.OwnerName,
                            pokemon.Origin.ToString(),
                            pokemon.HeightM.ToString(),
                            pokemon.WeightKg.ToString(),
                            pokemon.IndividualAttack.ToString(),
                            pokemon.IndividualDefense.ToString(),
                            pokemon.IndividualStamina.ToString(),
                            pokemon.CpMultiplier.ToString(),
                            pokemon.BattlesAttacked.ToString(),
                            pokemon.BattlesDefended.ToString(),
                            pokemon.CreationTimeMs.ToString(),
                            pokemon.AdditionalCpMultiplier.ToString()
                        };
                        Dumper.Dump(session, pokemonData, dumpFileName);
                    }

                    // restore culture
                    Thread.CurrentThread.CurrentCulture = prevCulture;
                }
                catch (IOException)
                {
                    session.EventDispatcher.Send(
                        new ErrorEvent {
                        Message = $"Could not write {dumpFileName} dump file."
                    }
                        );
                }
            }
        }
Esempio n. 17
0
        public static async Task Execute(ISession session)
        {
            var myPokemonFamilies = await session.Inventory.GetPokemonFamilies();

            var myPokeSettings = await session.Inventory.GetPokemonSettings();

            var highestsPokemonCp =
                await session.Inventory.GetHighestsCp(session.LogicSettings.AmountOfPokemonToDisplayOnStart);

            var highestsPokemonCpForUpgrade = await session.Inventory.GetHighestsCp(50);

            var highestsPokemonIvForUpgrade = await session.Inventory.GetHighestsPerfect(50);

            var pokemonPairedWithStatsCp =
                highestsPokemonCp.Select(
                    pokemon =>
                    Tuple.Create(pokemon, PokemonInfo.CalculateMaxCp(pokemon),
                                 PokemonInfo.CalculatePokemonPerfection(pokemon), PokemonInfo.GetLevel(pokemon),
                                 PokemonInfo.GetPokemonMove1(pokemon), PokemonInfo.GetPokemonMove2(pokemon),
                                 PokemonInfo.GetCandy(pokemon, myPokemonFamilies, myPokeSettings))).ToList();
            var pokemonPairedWithStatsCpForUpgrade =
                highestsPokemonCpForUpgrade.Select(
                    pokemon =>
                    Tuple.Create(pokemon, PokemonInfo.CalculateMaxCp(pokemon),
                                 PokemonInfo.CalculatePokemonPerfection(pokemon), PokemonInfo.GetLevel(pokemon),
                                 PokemonInfo.GetPokemonMove1(pokemon), PokemonInfo.GetPokemonMove2(pokemon))).ToList();
            var highestsPokemonPerfect =
                await session.Inventory.GetHighestsPerfect(session.LogicSettings.AmountOfPokemonToDisplayOnStart);

            var pokemonPairedWithStatsIv =
                highestsPokemonPerfect.Select(
                    pokemon =>
                    Tuple.Create(pokemon, PokemonInfo.CalculateMaxCp(pokemon),
                                 PokemonInfo.CalculatePokemonPerfection(pokemon), PokemonInfo.GetLevel(pokemon),
                                 PokemonInfo.GetPokemonMove1(pokemon), PokemonInfo.GetPokemonMove2(pokemon),
                                 PokemonInfo.GetCandy(pokemon, myPokemonFamilies, myPokeSettings))).ToList();
            var pokemonPairedWithStatsIvForUpgrade =
                highestsPokemonIvForUpgrade.Select(
                    pokemon =>
                    Tuple.Create(pokemon, PokemonInfo.CalculateMaxCp(pokemon),
                                 PokemonInfo.CalculatePokemonPerfection(pokemon), PokemonInfo.GetLevel(pokemon),
                                 PokemonInfo.GetPokemonMove1(pokemon), PokemonInfo.GetPokemonMove2(pokemon))).ToList();

            session.EventDispatcher.Send(
                new DisplayHighestsPokemonEvent
            {
                SortedBy    = "CP",
                PokemonList = pokemonPairedWithStatsCp
            });

            await Task.Delay(500);

            session.EventDispatcher.Send(
                new DisplayHighestsPokemonEvent
            {
                SortedBy    = "IV",
                PokemonList = pokemonPairedWithStatsIv
            });

            foreach (var pokemon in pokemonPairedWithStatsIvForUpgrade)
            {
                var dgdfs = pokemon.ToString();

                var tokens   = dgdfs.Split(new[] { "id" }, StringSplitOptions.None);
                var splitone = tokens[1].Split('"');
                var iv       = session.Inventory.GetPerfect(pokemon.Item1);
                if (iv >= session.LogicSettings.UpgradePokemonIvMinimum)
                {
                    PokemonId.Add(ulong.Parse(splitone[2]));
                }
            }
            foreach (var t in pokemonPairedWithStatsCpForUpgrade)
            {
                var dgdfs            = t.ToString();
                var tokens           = dgdfs.Split(new[] { "id" }, StringSplitOptions.None);
                var splitone         = tokens[1].Split('"');
                var tokensSplit      = tokens[1].Split(new[] { "cp" }, StringSplitOptions.None);
                var tokenSplitAgain  = tokensSplit[1].Split(' ');
                var tokenSplitAgain2 = tokenSplitAgain[1].Split(',');
                if (float.Parse(tokenSplitAgain2[0]) >= session.LogicSettings.UpgradePokemonCpMinimum)
                {
                    PokemonIdcp.Add(ulong.Parse(splitone[2]));
                }
            }
            var allPokemonInBag = session.LogicSettings.PrioritizeIvOverCp
                ? await session.Inventory.GetHighestsPerfect(1000)
                : await session.Inventory.GetHighestsCp(1000);

            if (session.LogicSettings.DumpPokemonStats)
            {
                const string dumpFileName = "PokeBagStats";
                Dumper.ClearDumpFile(session, dumpFileName);
                Dumper.Dump(session, "pokemonid,pokemonlevel,cp,perfection,stamina,staminamax,move1,move2,candy,ownername,origin,heightm,weightkg,individualattack,individualdefense,individualstamina,cpmultiplier,battlesattacked,battlesdefended,creationtimems,numupgrades,additionalcpmultiplier,favorite,nickname", dumpFileName);
                foreach (var pokemon in allPokemonInBag)
                {
                    Dumper.Dump(session,
                                $"{pokemon.PokemonId},{PokemonInfo.GetLevel(pokemon)},{pokemon.Cp},{PokemonInfo.CalculatePokemonPerfection(pokemon)},{pokemon.Stamina},{pokemon.StaminaMax},{pokemon.Move1},{pokemon.Move2},{PokemonInfo.GetCandy(pokemon, myPokemonFamilies, myPokeSettings)},{pokemon.OwnerName},{pokemon.Origin},{pokemon.HeightM},{pokemon.WeightKg},{pokemon.IndividualAttack},{pokemon.IndividualDefense},{pokemon.IndividualStamina},{pokemon.CpMultiplier},{pokemon.BattlesAttacked},{pokemon.BattlesDefended},{pokemon.CreationTimeMs},{pokemon.NumUpgrades},{pokemon.AdditionalCpMultiplier},{pokemon.Favorite},{pokemon.Nickname}",
                                dumpFileName);
                }
            }
            await Task.Delay(500);
        }
        public static async Task Execute(ISession session)
        {
            var highestsPokemonCp =
                await session.Inventory.GetHighestsCp(session.LogicSettings.AmountOfPokemonToDisplayOnStart);

            var highestsPokemonCpForUpgrade = await session.Inventory.GetHighestsCp(50);

            var highestsPokemonIvForUpgrade = await session.Inventory.GetHighestsPerfect(50);

            var pokemonPairedWithStatsCp =
                highestsPokemonCp.Select(
                    pokemon =>
                    Tuple.Create(pokemon, PokemonInfo.CalculateMaxCp(pokemon),
                                 PokemonInfo.CalculatePokemonPerfection(pokemon), PokemonInfo.GetLevel(pokemon),
                                 PokemonInfo.GetPokemonMove1(pokemon), PokemonInfo.GetPokemonMove2(pokemon),
                                 (PokemonMoveInfo.GetPokemonMoveSet(PokemonMoveInfo.GetMoveSetCombinationIndex(pokemon.PokemonId, PokemonInfo.GetPokemonMove1(pokemon), PokemonInfo.GetPokemonMove2(pokemon))) != null ? PokemonMoveInfo.GetPokemonMoveSet(PokemonMoveInfo.GetMoveSetCombinationIndex(pokemon.PokemonId, PokemonInfo.GetPokemonMove1(pokemon), PokemonInfo.GetPokemonMove2(pokemon))).GetRankVsType("Average") : 0)
                                 )).ToList();
            var pokemonPairedWithStatsCpForUpgrade =
                highestsPokemonCpForUpgrade.Select(
                    pokemon =>
                    Tuple.Create(pokemon, PokemonInfo.CalculateMaxCp(pokemon),
                                 PokemonInfo.CalculatePokemonPerfection(pokemon), PokemonInfo.GetLevel(pokemon),
                                 PokemonInfo.GetPokemonMove1(pokemon), PokemonInfo.GetPokemonMove2(pokemon),

                                 (PokemonMoveInfo.GetPokemonMoveSet(PokemonMoveInfo.GetMoveSetCombinationIndex(pokemon.PokemonId, PokemonInfo.GetPokemonMove1(pokemon), PokemonInfo.GetPokemonMove2(pokemon))) != null ? PokemonMoveInfo.GetPokemonMoveSet(PokemonMoveInfo.GetMoveSetCombinationIndex(pokemon.PokemonId, PokemonInfo.GetPokemonMove1(pokemon), PokemonInfo.GetPokemonMove2(pokemon))).GetRankVsType("Average") : 0)
                                 )).ToList();
            var highestsPokemonPerfect =
                await session.Inventory.GetHighestsPerfect(session.LogicSettings.AmountOfPokemonToDisplayOnStart);

            var pokemonPairedWithStatsIv =
                highestsPokemonPerfect.Select(
                    pokemon =>
                    Tuple.Create(pokemon, PokemonInfo.CalculateMaxCp(pokemon),
                                 PokemonInfo.CalculatePokemonPerfection(pokemon), PokemonInfo.GetLevel(pokemon),
                                 PokemonInfo.GetPokemonMove1(pokemon), PokemonInfo.GetPokemonMove2(pokemon),

                                 (PokemonMoveInfo.GetPokemonMoveSet(PokemonMoveInfo.GetMoveSetCombinationIndex(pokemon.PokemonId, PokemonInfo.GetPokemonMove1(pokemon), PokemonInfo.GetPokemonMove2(pokemon))) != null ? PokemonMoveInfo.GetPokemonMoveSet(PokemonMoveInfo.GetMoveSetCombinationIndex(pokemon.PokemonId, PokemonInfo.GetPokemonMove1(pokemon), PokemonInfo.GetPokemonMove2(pokemon))).GetRankVsType("Average") : 0)
                                 )).ToList();
            var pokemonPairedWithStatsIvForUpgrade =
                highestsPokemonIvForUpgrade.Select(
                    pokemon =>
                    Tuple.Create(pokemon, PokemonInfo.CalculateMaxCp(pokemon),
                                 PokemonInfo.CalculatePokemonPerfection(pokemon), PokemonInfo.GetLevel(pokemon),
                                 PokemonInfo.GetPokemonMove1(pokemon), PokemonInfo.GetPokemonMove2(pokemon),

                                 (PokemonMoveInfo.GetPokemonMoveSet(PokemonMoveInfo.GetMoveSetCombinationIndex(pokemon.PokemonId, PokemonInfo.GetPokemonMove1(pokemon), PokemonInfo.GetPokemonMove2(pokemon))) != null ? PokemonMoveInfo.GetPokemonMoveSet(PokemonMoveInfo.GetMoveSetCombinationIndex(pokemon.PokemonId, PokemonInfo.GetPokemonMove1(pokemon), PokemonInfo.GetPokemonMove2(pokemon))).GetRankVsType("Average") : 0)
                                 )).ToList();

            session.EventDispatcher.Send(
                new DisplayHighestsPokemonEvent
            {
                SortedBy    = "CP",
                PokemonList = pokemonPairedWithStatsCp
            });
            if (session.LogicSettings.Teleport)
            {
                await Task.Delay(session.LogicSettings.DelayDisplayPokemon);
            }
            else
            {
                await Task.Delay(500);
            }

            session.EventDispatcher.Send(
                new DisplayHighestsPokemonEvent
            {
                SortedBy    = "IV",
                PokemonList = pokemonPairedWithStatsIv
            });

            var allPokemonInBag = session.LogicSettings.PrioritizeIvOverCp
                ? await session.Inventory.GetHighestsPerfect(1000)
                : await session.Inventory.GetHighestsCp(1000);

            if (session.LogicSettings.DumpPokemonStats)
            {
                const string dumpFileName = "PokeBagStats";
                string       toDumpCSV    = "Name,Level,CP,IV,Move1,Move2\r\n";
                string       toDumpTXT    = "";
                Dumper.ClearDumpFile(session, dumpFileName);
                Dumper.ClearDumpFile(session, dumpFileName, "csv");

                foreach (var pokemon in allPokemonInBag)
                {
                    toDumpTXT += $"NAME: {session.Translation.GetPokemonName(pokemon.PokemonId).PadRight(16, ' ')}Lvl: {PokemonInfo.GetLevel(pokemon).ToString("00")}\t\tCP: {pokemon.Cp.ToString().PadRight(8, ' ')}\t\t IV: {PokemonInfo.CalculatePokemonPerfection(pokemon).ToString("0.00")}%\t\t\tMOVE1: {pokemon.Move1}\t\t\tMOVE2: {pokemon.Move2}\r\n";
                    toDumpCSV += $"{session.Translation.GetPokemonName(pokemon.PokemonId)},{PokemonInfo.GetLevel(pokemon).ToString("00")},{pokemon.Cp},{PokemonInfo.CalculatePokemonPerfection(pokemon).ToString("0.00")}%,{pokemon.Move1},{pokemon.Move2}\r\n";
                }

                Dumper.Dump(session, toDumpTXT, dumpFileName);
                Dumper.Dump(session, toDumpCSV, dumpFileName, "csv");
            }
            if (session.LogicSettings.Teleport)
            {
                await Task.Delay(session.LogicSettings.DelayDisplayPokemon);
            }
            else
            {
                await Task.Delay(500);
            }
        }
Esempio n. 19
0
        public void DumpObjectWithValueTypeFirstLevel2Text()
        {
            var valueTest = new ObjectWithValueTypeTest();
            var dumper = new Dumper{MaxDumpLevel = 1};

            var dumpText = dumper.Dump(valueTest).ToText();

            Trace.WriteLine(dumpText);

            var expected = "DumpObjectTests.Dump2TextExtension.ObjectWithValueTypeTest" + Environment.NewLine +
                           "	 - PublicProperty : ..." + Environment.NewLine +
                           "	 - PublicProperty2 : ...";

            Assert.AreEqual(expected, dumpText);
        }
Esempio n. 20
0
        public void DumpObjectWithValueType2Text()
        {
            var valueTest = new ObjectWithValueTypeTest();
            var dumper = new Dumper();

            var dumpText = dumper.Dump(valueTest).ToText();

            Trace.WriteLine(dumpText);

            var expected = "DumpObjectTests.Dump2TextExtension.ObjectWithValueTypeTest" + Environment.NewLine +
                           "	 - PublicProperty : publicProp" + Environment.NewLine +
                           "	 - PublicProperty2 : <null>";

            Assert.AreEqual(expected, dumpText);
        }
        public static async Task Execute(ISession session)
        {
            var myPokemonFamilies = await session.Inventory.GetPokemonFamilies();

            var myPokeSettings = await session.Inventory.GetPokemonSettings();

            var highestsPokemonCp =
                await session.Inventory.GetHighestsCp(session.LogicSettings.AmountOfPokemonToDisplayOnStart);

            var pokemonPairedWithStatsCp =
                highestsPokemonCp.Select(
                    pokemon =>
                    Tuple.Create(pokemon, PokemonInfo.CalculateMaxCp(pokemon),
                                 PokemonInfo.CalculatePokemonPerfection(pokemon), PokemonInfo.GetLevel(pokemon),
                                 PokemonInfo.GetPokemonMove1(pokemon), PokemonInfo.GetPokemonMove2(pokemon),
                                 PokemonInfo.GetCandy(pokemon, myPokemonFamilies, myPokeSettings))).ToList();

            var highestsPokemonPerfect =
                await session.Inventory.GetHighestsPerfect(session.LogicSettings.AmountOfPokemonToDisplayOnStart);

            var pokemonPairedWithStatsIv =
                highestsPokemonPerfect.Select(
                    pokemon =>
                    Tuple.Create(pokemon, PokemonInfo.CalculateMaxCp(pokemon),
                                 PokemonInfo.CalculatePokemonPerfection(pokemon), PokemonInfo.GetLevel(pokemon),
                                 PokemonInfo.GetPokemonMove1(pokemon), PokemonInfo.GetPokemonMove2(pokemon),
                                 PokemonInfo.GetCandy(pokemon, myPokemonFamilies, myPokeSettings))).ToList();

            session.EventDispatcher.Send(
                new DisplayHighestsPokemonEvent
            {
                SortedBy    = "CP",
                PokemonList = pokemonPairedWithStatsCp
            });

            session.EventDispatcher.Send(
                new DisplayHighestsPokemonEvent
            {
                SortedBy    = "IV",
                PokemonList = pokemonPairedWithStatsIv
            });

            var allPokemonInBag = session.LogicSettings.PrioritizeIvOverCp
                ? await session.Inventory.GetHighestsPerfect(1000)
                : await session.Inventory.GetHighestsCp(1000);

            if (session.LogicSettings.DumpPokemonStats)
            {
                const string dumpFileName = "PokeBagStats";
                try
                {
                    Dumper.ClearDumpFile(session, dumpFileName);
                    Dumper.Dump(session,
                                "pokemonid,pokemonlevel,cp,perfection,stamina,staminamax,move1,move2,candy,ownername,origin,heightm,weightkg,individualattack,individualdefense,individualstamina,cpmultiplier,battlesattacked,battlesdefended,creationtimems,numupgrades,additionalcpmultiplier,favorite,nickname",
                                dumpFileName);
                    foreach (var pokemon in allPokemonInBag)
                    {
                        Dumper.Dump(session,
                                    $"{session.Translation.GetPokemonTranslation(pokemon.PokemonId)},{PokemonInfo.GetLevel(pokemon)},{pokemon.Cp},{PokemonInfo.CalculatePokemonPerfection(pokemon)},{pokemon.Stamina},{pokemon.StaminaMax},{pokemon.Move1},{pokemon.Move2},{PokemonInfo.GetCandy(pokemon, myPokemonFamilies, myPokeSettings)},{pokemon.OwnerName},{pokemon.Origin},{pokemon.HeightM},{pokemon.WeightKg},{pokemon.IndividualAttack},{pokemon.IndividualDefense},{pokemon.IndividualStamina},{pokemon.CpMultiplier},{pokemon.BattlesAttacked},{pokemon.BattlesDefended},{pokemon.CreationTimeMs},{pokemon.NumUpgrades},{pokemon.AdditionalCpMultiplier},{pokemon.Favorite},{pokemon.Nickname}",
                                    dumpFileName);
                    }
                }
                catch (IOException)
                {
                    session.EventDispatcher.Send(new ErrorEvent {
                        Message = $"Could not write {dumpFileName} dump file."
                    });
                }
            }
        }
Esempio n. 22
0
        /// <summary>
        /// Dump exception instance to application output if output dumping is enabled. It renders:<para /><ul>
        /// <li>exception <b>type</b><para /></li>
        /// <li>exception <b>message</b><para /></li>
        /// <li>if exception has been <b>caught</b> or <b>not caught</b><para /></li>
        /// <li>exception <b>hash id</b><para /></li>
        /// <li><b>error file</b> where exception has been thrown<para /></li>
        /// <li>thread call stack<para /></li>
        /// <li>all inner exceptions after this exception in the same way<para /></li>
        /// </ul></summary>
        /// <param name="exception">Exception instance to dump.</param>
        /// <param name="options">Dump options collection (optional) - just create new instance with public fields of that:<para /><br />
        /// For this dump call you can change options:<para /><ul>
        /// <li><b>Return</b> (bool, optional) - if exception will be dumped into application output (as default) or returned as dumped string value.<para /></li>
        /// </ul></param>
        /// <returns>Returns empty string if debug printing is disabled and also returns empty string if second param <c>DumpOptions.Return</c> is <c>false</c> (by default), but if true, return dumped exception as string.</returns>
        public static string Dump(Exception exception = null, DumpOptions?options = null)
        {
            Dispatcher dispatcher = Dispatcher.GetCurrent();

            dispatcher.LastError = exception;
            if (dispatcher.Enabled != true)
            {
                return("");
            }
            if (!options.HasValue)
            {
                options = new DumpOptions {
                    Return         = false,
                    Depth          = 0,
                    MaxLength      = 0,
                    SourceLocation = Dispatcher.SourceLocation
                }
            }
            ;
            DumpOptions   optionsValue    = options.Value;
            string        dumpResult      = "";
            List <string> exceptionResult = new List <string>();
            bool          htmlOut         = Dispatcher.EnvType == EnvType.Web;

            if (exception == null)
            {
                dumpResult = Dumper.Dump(null);
            }
            else if (exception is Exception)
            {
                if (!optionsValue.CatchedException.HasValue)
                {
                    optionsValue.CatchedException = true;
                }
                exceptionResult = Exceptions.RenderExceptions(
                    exception, false, htmlOut, optionsValue.CatchedException.Value
                    );
            }
            else
            {
                if (!optionsValue.Depth.HasValue)
                {
                    optionsValue.Depth = 0;
                }
                if (!optionsValue.MaxLength.HasValue)
                {
                    optionsValue.MaxLength = 0;
                }
                if (!optionsValue.Return.HasValue)
                {
                    optionsValue.Return = false;
                }
                if (!optionsValue.SourceLocation.HasValue)
                {
                    optionsValue.SourceLocation = Dispatcher.SourceLocation;
                }
                dumpResult = Dumper.Dump(exception, htmlOut, optionsValue.Depth.Value, optionsValue.MaxLength.Value);
                if (optionsValue.SourceLocation.HasValue && optionsValue.SourceLocation.Value)
                {
                    dumpResult += Desharp.Renderers.FileLink.Render(
                        Completers.StackTrace.CompleteCallerPoint(), htmlOut
                        );
                }
            }
            if (!optionsValue.Return.HasValue || (optionsValue.Return.HasValue && !optionsValue.Return.Value))
            {
                if (dumpResult.Length == 0 && exceptionResult.Count > 0)
                {
                    dispatcher.WriteExceptionToOutput(exceptionResult);
                }
                else
                {
                    dispatcher.WriteDumpToOutput(dumpResult);
                }
                return("");
            }
            if (dumpResult.Length == 0 && exceptionResult.Count > 0)
            {
                return(String.Join(Environment.NewLine, exceptionResult.ToArray()));
            }
            else
            {
                return(dumpResult);
            }
        }
        public static async Task Execute(ISession session)
        {
            var highestsPokemonCp =
                await session.Inventory.GetHighestsCp(session.LogicSettings.AmountOfPokemonToDisplayOnStart);

            var highestsPokemonCpForUpgrade = await session.Inventory.GetHighestsCp(50);

            var highestsPokemonIvForUpgrade = await session.Inventory.GetHighestsPerfect(50);

            var pokemonPairedWithStatsCp =
                highestsPokemonCp.Select(
                    pokemon =>
                    Tuple.Create(pokemon, PokemonInfo.CalculateMaxCp(pokemon),
                                 PokemonInfo.CalculatePokemonPerfection(pokemon), PokemonInfo.GetLevel(pokemon),
                                 PokemonInfo.GetPokemonMove1(pokemon), PokemonInfo.GetPokemonMove2(pokemon))).ToList();
            var pokemonPairedWithStatsCpForUpgrade =
                highestsPokemonCpForUpgrade.Select(
                    pokemon =>
                    Tuple.Create(pokemon, PokemonInfo.CalculateMaxCp(pokemon),
                                 PokemonInfo.CalculatePokemonPerfection(pokemon), PokemonInfo.GetLevel(pokemon),
                                 PokemonInfo.GetPokemonMove1(pokemon), PokemonInfo.GetPokemonMove2(pokemon))).ToList();
            var highestsPokemonPerfect =
                await session.Inventory.GetHighestsPerfect(session.LogicSettings.AmountOfPokemonToDisplayOnStart);

            var pokemonPairedWithStatsIv =
                highestsPokemonPerfect.Select(
                    pokemon =>
                    Tuple.Create(pokemon, PokemonInfo.CalculateMaxCp(pokemon),
                                 PokemonInfo.CalculatePokemonPerfection(pokemon), PokemonInfo.GetLevel(pokemon),
                                 PokemonInfo.GetPokemonMove1(pokemon), PokemonInfo.GetPokemonMove2(pokemon))).ToList();
            var pokemonPairedWithStatsIvForUpgrade =
                highestsPokemonIvForUpgrade.Select(
                    pokemon =>
                    Tuple.Create(pokemon, PokemonInfo.CalculateMaxCp(pokemon),
                                 PokemonInfo.CalculatePokemonPerfection(pokemon), PokemonInfo.GetLevel(pokemon),
                                 PokemonInfo.GetPokemonMove1(pokemon), PokemonInfo.GetPokemonMove2(pokemon))).ToList();

            session.EventDispatcher.Send(
                new DisplayHighestsPokemonEvent
            {
                SortedBy    = "CP",
                PokemonList = pokemonPairedWithStatsCp
            });

            await Task.Delay(500);

            session.EventDispatcher.Send(
                new DisplayHighestsPokemonEvent
            {
                SortedBy    = "IV",
                PokemonList = pokemonPairedWithStatsIv
            });

            foreach (var pokemon in pokemonPairedWithStatsIvForUpgrade)
            {
                var dgdfs = pokemon.ToString();

                var tokens   = dgdfs.Split(new[] { "id" }, StringSplitOptions.None);
                var splitone = tokens[1].Split('"');
                var iv       = session.Inventory.GetPerfect(pokemon.Item1);
                if (iv >= session.LogicSettings.UpgradePokemonIvMinimum)
                {
                    PokemonId.Add(ulong.Parse(splitone[2]));
                }
            }
            foreach (var t in pokemonPairedWithStatsCpForUpgrade)
            {
                var dgdfs            = t.ToString();
                var tokens           = dgdfs.Split(new[] { "id" }, StringSplitOptions.None);
                var splitone         = tokens[1].Split('"');
                var tokensSplit      = tokens[1].Split(new[] { "cp" }, StringSplitOptions.None);
                var tokenSplitAgain  = tokensSplit[1].Split(' ');
                var tokenSplitAgain2 = tokenSplitAgain[1].Split(',');
                if (float.Parse(tokenSplitAgain2[0]) >= session.LogicSettings.UpgradePokemonCpMinimum)
                {
                    PokemonIdcp.Add(ulong.Parse(splitone[2]));
                }
            }
            var allPokemonInBag = session.LogicSettings.PrioritizeIvOverCp
                ? await session.Inventory.GetHighestsPerfect(1000)
                : await session.Inventory.GetHighestsCp(1000);

            if (session.LogicSettings.DumpPokemonStats)
            {
                const string dumpFileName = "PokeBagStats";
                Dumper.ClearDumpFile(session, dumpFileName);
                foreach (var pokemon in allPokemonInBag)
                {
                    Dumper.Dump(session,
                                $"NAME: {pokemon.PokemonId.ToString().PadRight(16, ' ')}Lvl: {PokemonInfo.GetLevel(pokemon).ToString("00")}\t\tCP: {pokemon.Cp.ToString().PadRight(8, ' ')}\t\t IV: {PokemonInfo.CalculatePokemonPerfection(pokemon).ToString("0.00")}%\t\t\tMOVE1: {pokemon.Move1}\t\t\tMOVE2: {pokemon.Move2}",
                                dumpFileName);
                }
            }
            await Task.Delay(500);
        }
Esempio n. 24
0
        public static async Task Execute(ISession session, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();
            var trainerLevel = 40;

            var highestsPokemonCp = await session.Inventory.GetHighestsCp(session.LogicSettings.AmountOfPokemonToDisplayOnStart);

            var pokemonPairedWithStatsCp = highestsPokemonCp?.Select(pokemon => new PokemonAnalysis(pokemon, trainerLevel)).ToList();


            var highestsPokemonPerfect = await session.Inventory.GetHighestsPerfect(session.LogicSettings.AmountOfPokemonToDisplayOnStart);

            var pokemonPairedWithStatsIv = highestsPokemonPerfect?.Select(pokemon => new PokemonAnalysis(pokemon, trainerLevel)).ToList();


            session.EventDispatcher.Send(
                new DisplayHighestsPokemonEvent
            {
                SortedBy    = "CP",
                PokemonList = pokemonPairedWithStatsCp,
                DisplayPokemonMaxPoweredCp = session.LogicSettings.DisplayPokemonMaxPoweredCp,
                DisplayPokemonMovesetRank  = session.LogicSettings.DisplayPokemonMovesetRank
            });
            await Task.Delay(session.LogicSettings.DelayDisplayPokemon, cancellationToken);

            cancellationToken.ThrowIfCancellationRequested();
            session.EventDispatcher.Send(
                new DisplayHighestsPokemonEvent
            {
                SortedBy    = "IV",
                PokemonList = pokemonPairedWithStatsIv,
                DisplayPokemonMaxPoweredCp = session.LogicSettings.DisplayPokemonMaxPoweredCp,
                DisplayPokemonMovesetRank  = session.LogicSettings.DisplayPokemonMovesetRank
            });

            var allPokemonInBag = session.LogicSettings.PrioritizeIvOverCp
                ? await session.Inventory.GetHighestsPerfect(1000)
                : await session.Inventory.GetHighestsCp(1000);

            cancellationToken.ThrowIfCancellationRequested();
            if (session.LogicSettings.DumpPokemonStats)
            {
                const string dumpFileName = "PokeBagStats";
                var          toDumpCsv    = "Name,Level,CP,IV,Move1,Move2\r\n";
                var          toDumpTxt    = "";
                Dumper.ClearDumpFile(session, dumpFileName);
                Dumper.ClearDumpFile(session, dumpFileName, "csv");

                if (allPokemonInBag != null)
                {
                    foreach (var pokemon in allPokemonInBag)
                    {
                        toDumpTxt += $"NAME: {session.Translation.GetPokemonName(pokemon.PokemonId).PadRight(16, ' ')}Lvl: {PokemonInfo.GetLevel(pokemon).ToString("00")}\t\tCP: {pokemon.Cp.ToString().PadRight(8, ' ')}\t\t IV: {pokemon.CalculatePokemonPerfection().ToString("0.00")}%\t\t\tMOVE1: {pokemon.Move1}\t\t\tMOVE2: {pokemon.Move2}\r\n";
                        toDumpCsv += $"{session.Translation.GetPokemonName(pokemon.PokemonId)},{PokemonInfo.GetLevel(pokemon).ToString("00")},{pokemon.Cp},{pokemon.CalculatePokemonPerfection().ToString("0.00")}%,{pokemon.Move1},{pokemon.Move2}\r\n";
                    }
                }

                Dumper.Dump(session, toDumpTxt, dumpFileName);
                Dumper.Dump(session, toDumpCsv, dumpFileName, "csv");
            }
            await Task.Delay(session.LogicSettings.DelayDisplayPokemon, cancellationToken);
        }