Пример #1
0
 public void Load(SkillsPlayer skillsplayer, List <Players> players, List <Txs> txs, int height, string address)
 {
     for (int i = 0; i < txs.Count; i++)
     {
         players = GetPlayers(address, txs[i].Height);
         if (!txs[i].Sender)
         {
             List <Players> _players    = GetPlayers(txs[i].AddressSender, txs[i].Height);
             int            seed        = int.Parse(AttachmentBase58.HexToDecimal(AttachmentBase58.Base58NumericDecode(txs[i].Tx.Substring(0, 4))));
             LinearConRng   rnd         = new LinearConRng(seed);
             int            enemy       = rnd.NextInt(0, _players.Count);
             SkillsPlayer   skillsEnemy = AddressSkills(txs[i].AddressSender, txs[i].Height);
             if (_players[enemy].Address == address && skillsEnemy.Height <= txs[i].Height)
             {
                 var panelGO = Instantiate(GameHistory, transform);
                 panelGO.GetComponent <GameHistoryPanel>().SetStats(txs[i].Tx, txs[i].AddressSender, skillsplayer.Skills, skillsEnemy.Skills, Convert.ToInt32(txs[i].Sender));
                 panels.Add(panelGO);
             }
         }
         else
         {
             int          seed        = int.Parse(AttachmentBase58.HexToDecimal(AttachmentBase58.Base58NumericDecode(txs[i].Tx.Substring(0, 4))));
             LinearConRng rnd         = new LinearConRng(seed);
             int          enemy       = rnd.NextInt(0, players.Count);
             SkillsPlayer skillsEnemy = AddressSkills(players[enemy].Address, txs[i].Height);
             if (skillsEnemy.Height <= txs[i].Height)
             {
                 var panelGO = Instantiate(GameHistory, transform);
                 panelGO.GetComponent <GameHistoryPanel>().SetStats(txs[i].Tx, players[enemy].Address, skillsplayer.Skills, players[enemy].Skills, Convert.ToInt32(txs[i].Sender));
                 panels.Add(panelGO);
             }
         }
     }
 }
Пример #2
0
    public void ShowSavePanel()
    {
        bool rdy = false;

        for (int i = 0; i < SelSkills.Length; i++)
        {
            if (SelSkills[i] == -1)
            {
                rdy = false;
                break;
            }
            rdy = true;
        }
        if (rdy)
        {
            ErrorMsg.SetActive(false);
            string numeric    = SelSkills[0] + "A" + SelSkills[1] + "A" + SelSkills[2];
            string attachment = AttachmentBase58.Base58NumericEncode(BigInteger.Parse(AttachmentBase58.HexToDecimal(numeric)));
            FindObjectOfType <SaveDataPanel>().ShowPanel(attachment, AddressInfo.recipient[0], AddressInfo.Asset);
        }
        else
        {
            ErrorMsg.SetActive(true);
            Debug.Log("Cant show WavesData panel!");
        }
    }
Пример #3
0
    public List <Players> GetPlayers(string address, int height)
    {
        List <Players> playersList = new List <Players>();
        var            node        = new Node(Node.MainNetHost);

        Dictionary <string, object>[] enemies = node.GetTransactionsByAddress(AddressInfo.recipient[0], 1000);
        for (int j = 0; j < enemies.Length; j++)
        {
            bool correctTx = int.Parse(enemies[j].GetValue("type").ToString()) == 4 &&
                             enemies[j].GetValue("assetId") != null &&
                             enemies[j].GetValue("assetId").ToString() == AddressInfo.Asset &&
                             int.Parse(enemies[j].GetValue("amount").ToString()) >= 100000000 &&
                             !string.IsNullOrEmpty(enemies[j].GetValue("attachment").ToString()) &&
                             int.Parse(enemies[j].GetValue("height").ToString()) <= height;

            if (correctTx && enemies[j].GetValue("sender").ToString() != address)
            {
                string enemy    = enemies[j].GetValue("sender").ToString();
                bool   equalStr = false;
                for (int k = 0; k < playersList.Count; k++)
                {
                    if (enemy == playersList[k].Address)
                    {
                        equalStr = true;
                        //has prev skills
                    }
                }
                if (!equalStr)
                {
                    string DecodedAttachment = AttachmentBase58.Base58NumericDecode(Encoding.UTF8.GetString(Base58.Decode(enemies[j].GetValue("attachment").ToString())));

                    string[] info = new string[3];
                    info = DecodedAttachment.Split('A');
                    if (string.IsNullOrEmpty(info[0]))
                    {
                        info[0] = "0";
                    }
                    int[] skillsEnemies = new int[3];
                    try
                    {
                        if (int.TryParse(info[0], out skillsEnemies[0]) &&
                            int.TryParse(info[1], out skillsEnemies[1]) &&
                            int.TryParse(info[2], out skillsEnemies[2]) &&
                            skillsEnemies[0] >= 0 && skillsEnemies[0] < FindObjectOfType <Skills>().skills.Count&&
                            skillsEnemies[1] >= 0 && skillsEnemies[1] < FindObjectOfType <Skills>().skills.Count&&
                            skillsEnemies[2] >= 0 && skillsEnemies[2] < FindObjectOfType <Skills>().skills.Count)
                        {
                            playersList.Add(new Players(enemies[j].GetValue("sender").ToString(), skillsEnemies));
                        }
                    }
                    catch
                    {
                        continue;
                    }
                }
            }
        }
        return(playersList);
    }
Пример #4
0
    public SkillsPlayer AddressSkills(string address, int height)
    {
        SkillsPlayer skills = new SkillsPlayer();
        var          node   = new Node(Node.MainNetHost);

        Dictionary <string, object>[] player = node.GetTransactionsByAddress(AddressInfo.recipient[0], 1000);
        for (int j = 0; j < player.Length; j++)
        {
            bool correctTx = int.Parse(player[j].GetValue("type").ToString()) == 4 &&
                             player[j].GetValue("assetId") != null &&
                             player[j].GetValue("assetId").ToString() == AddressInfo.Asset &&
                             int.Parse(player[j].GetValue("amount").ToString()) >= 100000000 &&
                             !string.IsNullOrEmpty(player[j].GetValue("attachment").ToString()) &&
                             int.Parse(player[j].GetValue("height").ToString()) <= height;

            if (correctTx && player[j].GetValue("sender").ToString() == address)
            {
                string DecodedAttachment = AttachmentBase58.Base58NumericDecode(Encoding.UTF8.GetString(Base58.Decode(player[j].GetValue("attachment").ToString())));

                string[] info = new string[3];
                info = DecodedAttachment.Split('A');
                if (string.IsNullOrEmpty(info[0]))
                {
                    info[0] = "0";
                }
                int[] skillsArr = new int[3];
                try
                {
                    if (int.TryParse(info[0], out skillsArr[0]) &&
                        int.TryParse(info[1], out skillsArr[1]) &&
                        int.TryParse(info[2], out skillsArr[2]) &&
                        skillsArr[0] >= 0 && skillsArr[0] < FindObjectOfType <Skills>().skills.Count&&
                        skillsArr[1] >= 0 && skillsArr[1] < FindObjectOfType <Skills>().skills.Count&&
                        skillsArr[2] >= 0 && skillsArr[2] < FindObjectOfType <Skills>().skills.Count)
                    {
                        if (skills.Height == -1)
                        {
                            skills = new SkillsPlayer(skillsArr, int.Parse(player[j].GetValue("height").ToString()));
                        }
                        else
                        {
                            skills.SetPrevSkills(true, int.Parse(player[j].GetValue("height").ToString()));
                            return(skills);
                        }
                    }
                }
                catch
                {
                    continue;
                }
            }
        }

        return(skills);
    }
Пример #5
0
    public void SetStats(string tx, string enemy, int[] skills, int[] skillsEnemy, int txChoose)
    {
        Tx.text    = "ID: " + tx;
        Enemy.text = "Enemy: " + enemy;

        Skills      = skills;
        SkillsEnemy = skillsEnemy;
        int result;

        Debug.Log(txChoose);
        if (txChoose == 1)
        {
            result = Fight.CalculateFight(skills, skillsEnemy, int.Parse(AttachmentBase58.HexToDecimal(AttachmentBase58.Base58NumericDecode(tx.Substring(0, 4)))));
        }
        else
        {
            result = Fight.CalculateFight(skillsEnemy, skills, int.Parse(AttachmentBase58.HexToDecimal(AttachmentBase58.Base58NumericDecode(tx.Substring(0, 4)))));
        }

        if (txChoose == 1 && result == 0)
        {
            win.SetActive(true);
        }
        else if (txChoose == 1 && result == 1)
        {
            defeat.SetActive(true);
        }
        else if (txChoose == 0 && result == 0)
        {
            defeat.SetActive(true);
        }
        else if (txChoose == 0 && result == 1)
        {
            win.SetActive(true);
        }
        else
        {
            draw.SetActive(true);
        }

        for (int i = 0; i < SkillsEnemy.Length; i++)
        {
            transform.GetChild(i).GetComponent <Image>().sprite = Resources.LoadAll <Sprite>("SkillPreview")[SkillsEnemy[i]];
        }
    }