Пример #1
0
    public Champion(int a_ID, string a_Key, string a_Name, string a_Title, double a_Price, bool a_Owned, int a_Kills, int a_Deaths, int a_Wins, int a_Losses, int a_CreepScore, MasteryInfo a_MasteryInfo, ViabilityInfo a_Viability)
    {
        ID = a_ID;
        Name = a_Name;
        Key = a_Key;
        Title = a_Title;
        Price = a_Price;
        Owned = a_Owned;
        Mastery = a_MasteryInfo;
        Viability = a_Viability;

        Kills = a_Kills;
        Deaths = a_Deaths;
        CreepScore = a_CreepScore;

        Wins = a_Wins;
        Losses = a_Losses;

        if (Champions.ContainsKey(a_ID) == false)
        {
            Champions.Add(a_ID, this);
        }
    }
Пример #2
0
    public static bool Setup(JSONArray a_Champions)
    {
        if (m_Setup)
            return true;

        if (a_Champions == null)
            return false;

        TextAsset ChampionData = Resources.Load<TextAsset>("Data/Champions");
        JSONArray JSONChampD = JSON.Parse(ChampionData.text).AsArray;
        Dictionary<string, ViabilityInfo> ViabilityInfos = new Dictionary<string, ViabilityInfo>();
        foreach (JSONNode JSONChamp in JSONChampD)
        {
            //voeg champion toe aan dictionary
            if (!ViabilityInfos.ContainsKey(JSONChamp["key"]))
            {
                ViabilityInfos.Add(JSONChamp["key"], new ViabilityInfo());
            }

            //if jungle, etc. show winrate
            ViabilityInfo Viability = ViabilityInfos[JSONChamp["key"]];
            string role = JSONChamp["role"].Value;

            if (role == "Top")
            {
                Viability.Top = JSONChamp["general"]["winPercent"].AsDouble / 100.0;
            }

            else if (role == "Jungle")
            {
                Viability.Jungle = JSONChamp["general"]["winPercent"].AsDouble / 100.0;
            }

            else if (role == "Middle")
            {
                Viability.Mid = JSONChamp["general"]["winPercent"].AsDouble / 100.0;
            }

            else if (role == "ADC")
            {
                Viability.Marksman = JSONChamp["general"]["winPercent"].AsDouble / 100.0;
            }

            else if (role == "Support")
            {
                Viability.Support = JSONChamp["general"]["winPercent"].AsDouble / 100.0;
            }

            Viability.Meta += JSONChamp["general"]["playPercent"].AsDouble / 100.0;

            ViabilityInfos[JSONChamp["key"]] = Viability;
        }
         
        foreach(JSONNode a_Champion in a_Champions)
        {
            var t_Time = (new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).AddMilliseconds(a_Champion["mastery"]["lastPlayTime"].AsInt);

            MasteryInfo t_Mastery;
            if (a_Champion["mastery"].Count > 0)
            {
                t_Mastery = new MasteryInfo
                (
                    a_Champion["mastery"]["championLevel"].AsInt,
                    a_Champion["mastery"]["championPoints"].AsInt,
                    t_Time
                );
            }
            else t_Mastery = MasteryInfo.NoMastery;

            //Debug.Log("You are level " + t_Mastery.Level + " with " + a_Champion["name"] + ".");

            Champion t_Champion = new Champion
            (
                a_Champion["id"].AsInt, // ID
                a_Champion["key"].Value, // Key name
                a_Champion["name"].Value, // Name
                a_Champion["title"].Value, // Title
                a_Champion["price"].AsDouble, // Price
                a_Champion["owned"].AsBool, // Owned
                a_Champion["personal"]["kills"].AsInt, // int a_Kills, 
                a_Champion["personal"]["deaths"].AsInt, // int a_Deaths, 
                a_Champion["personal"]["wins"].AsInt, // int a_Wins, 
                a_Champion["personal"]["losses"].AsInt, // int a_Losses, 
                a_Champion["personal"]["creep_score"].AsInt, // int a_CreepScore,
                t_Mastery,
                ViabilityInfos[a_Champion["key"]]
            );

            // Get image
            JSONNode t_ImageInfo = a_Champion["image"];
            Rect t_Rect = new Rect();

            t_Rect.x = t_ImageInfo["x"].AsFloat;
            t_Rect.y = t_ImageInfo["y"].AsFloat;
            t_Rect.width = t_ImageInfo["w"].AsFloat;
            t_Rect.height = t_ImageInfo["h"].AsFloat;

            // Check if we've loaded it before
            if (m_Textures.ContainsKey(t_ImageInfo["sprite"]) == false)
            {
                string ImageURL = Settings.ChampionImageDirectory + t_ImageInfo["sprite"];
                HTTP.Request(ImageURL, delegate (WWW a_Request)
                {
                    if (m_Textures.ContainsKey(t_ImageInfo["sprite"]) == false)
                        m_Textures.Add(t_ImageInfo["sprite"], a_Request.texture);

                    t_Rect.y = a_Request.texture.height - t_Rect.y - t_Rect.height;
                    t_Champion.Image = Sprite.Create(a_Request.texture, t_Rect, Vector2.zero);
                }, false);
            }
            else
            {
                Texture2D t_Texture = m_Textures[t_ImageInfo["sprite"]];

                t_Rect.y = t_Texture.height - t_Rect.y - t_Rect.height;
                t_Champion.Image = Sprite.Create(t_Texture, t_Rect, Vector2.zero);
            }

            if (Champions.ContainsKey(t_Champion.ID) == false)
                Champions.Add(t_Champion.ID, t_Champion);

            if (Translation.ContainsKey(t_Champion.Name) == false)
                Translation.Add(t_Champion.Name, t_Champion.ID);
        }

        //Debug.Log(Champions.Values.Count + " champions added.");
        m_Setup = true;
        return true;
    }