public static SkillTree CreateSkillTree(startLoadingWindow start = null, UpdateLoadingWindow update = null, closeLoadingWindow finish = null)
        {
            string skilltreeobj = "";

            if (Directory.Exists("Data"))
            {
                if (File.Exists("Data\\Skilltree.txt"))
                {
                    skilltreeobj = File.ReadAllText("Data\\Skilltree.txt");
                }
            }
            else
            {
                Directory.CreateDirectory("Data");
                Directory.CreateDirectory("Data\\Assets");
            }

            if (skilltreeobj == "")
            {
                bool displayProgress = (start != null && update != null && finish != null);
                if (displayProgress)
                {
                    start();
                }
                //loadingWindow.Dispatcher.Invoke(DispatcherPriority.Background,new Action(delegate { }));


                string uriString = "http://web.poe.garena.tw/passive-skill-tree/";
                //string uriString = "http://www.pathofexile.com/passive-skill-tree/";
                HttpWebRequest  req   = (HttpWebRequest)WebRequest.Create(uriString);
                HttpWebResponse resp  = (HttpWebResponse)req.GetResponse();
                string          code  = new StreamReader(resp.GetResponseStream()).ReadToEnd();
                Regex           regex = new Regex("var passiveSkillTreeData.*");
                skilltreeobj = regex.Match(code).Value.Replace("root", "main").Replace("\\/", "/");
                skilltreeobj = skilltreeobj.Substring(27, skilltreeobj.Length - 27 - 2) + "";
                File.WriteAllText("Data\\Skilltree.txt", skilltreeobj);
                if (displayProgress)
                {
                    finish();
                }
            }

            return(new SkillTree(skilltreeobj, start, update, finish));
        }
        public static SkillTree CreateSkillTree(startLoadingWindow start = null, UpdateLoadingWindow update = null, closeLoadingWindow finish = null)
        {

            string skilltreeobj = "";
            if (Directory.Exists("Data"))
            {
                if (File.Exists("Data\\Skilltree.txt"))
                {
                    skilltreeobj = File.ReadAllText("Data\\Skilltree.txt");
                }
            }
            else
            {
                Directory.CreateDirectory("Data");
                Directory.CreateDirectory("Data\\Assets");
            }

            if (skilltreeobj == "")
            {
                bool displayProgress = (start != null && update != null && finish != null);
                if (displayProgress)
                    start();
                //loadingWindow.Dispatcher.Invoke(DispatcherPriority.Background,new Action(delegate { }));


                string uriString = "http://www.pathofexile.com/passive-skill-tree/";
                HttpWebRequest req = (HttpWebRequest)WebRequest.Create(uriString);
                HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
                string code = new StreamReader(resp.GetResponseStream()).ReadToEnd();
                Regex regex = new Regex("var passiveSkillTreeData.*");
                skilltreeobj = regex.Match(code).Value.Replace("root", "main").Replace("\\/", "/");
                skilltreeobj = skilltreeobj.Substring(27, skilltreeobj.Length - 27 - 2) + "";
                File.WriteAllText("Data\\Skilltree.txt", skilltreeobj);
                if (displayProgress)
                    finish();
            }

            return new SkillTree(skilltreeobj, start, update, finish);
        }
Esempio n. 3
0
        public SkillTree(String treestring, startLoadingWindow start = null, UpdateLoadingWindow update = null, closeLoadingWindow finish = null)
        {
            bool displayProgress = (start != null && update != null && finish != null);
            // RavenJObject jObject = RavenJObject.Parse( treestring.Replace( "Additional " , "" ) );
            JsonSerializerSettings jss = new JsonSerializerSettings
            {
                Error = delegate(object sender, Newtonsoft.Json.Serialization.ErrorEventArgs args)
                {
                    Debug.WriteLine(args.ErrorContext.Error.Message);
                    args.ErrorContext.Handled = true;
                }
            };

            var inTree = JsonConvert.DeserializeObject <PoEClasses.PoESkillTree>(treestring.Replace("Additional ", ""), jss);

            foreach (var obj in inTree.skillSprites)
            {
                if (obj.Key.Contains("inactive"))
                {
                    continue;
                }
                iconActiveSkills.Images[obj.Value[3].filename] = null;
                foreach (var o in obj.Value[3].coords)
                {
                    iconActiveSkills.SkillPositions[o.Key] = new KeyValuePair <Rect, string>(new Rect(o.Value.x, o.Value.y, o.Value.w, o.Value.h), obj.Value[3].filename);
                }
            }
            foreach (var obj in inTree.skillSprites)
            {
                if (obj.Key.Contains("active"))
                {
                    continue;
                }
                iconActiveSkills.Images[obj.Value[3].filename] = null;
                foreach (var o in obj.Value[3].coords)
                {
                    iconActiveSkills.SkillPositions[o.Key] = new KeyValuePair <Rect, string>(new Rect(o.Value.x, o.Value.y, o.Value.w, o.Value.h), obj.Value[3].filename);
                }
            }

            foreach (var ass in inTree.assets)
            {
                assets[ass.Key] = new Asset(ass.Key, ass.Value.ContainsKey(0.3835f)?ass.Value[0.3835f]:ass.Value.Values.First());
            }

            if (displayProgress)
            {
                start( );
            }
            iconActiveSkills.OpenOrDownloadImages(update);
            iconInActiveSkills.OpenOrDownloadImages(update);
            if (displayProgress)
            {
                finish( );
            }
            foreach (var c in inTree.characterData)
            {
                CharBaseAttributes[c.Key] = new Dictionary <string, float>()
                {
                    { "+# to Strength", c.Value.base_str }, { "+# to Dexterity", c.Value.base_dex }, { "+# to Intelligence", c.Value.base_int }
                };
            }
            foreach (var nd in inTree.nodes)
            {
                Skillnodes.Add(nd.id, new SkillTree.SkillNode()
                {
                    id         = nd.id,
                    name       = nd.dn,
                    attributes = nd.sd,
                    orbit      = nd.o,
                    orbitIndex = nd.oidx,
                    icon       = nd.icon,
                    linkID     = nd.ot,
                    g          = nd.g,
                    da         = nd.da,
                    ia         = nd.ia,
                    ks         = nd.ks,
                    not        = nd.not,
                    sa         = nd.sa,
                    Mastery    = nd.m,
                    spc        = nd.spc.Count() > 0?(int?)nd.spc[0]:null
                });
            }
            List <ushort[]> links = new List <ushort[]>( );

            foreach (var skillNode in Skillnodes)
            {
                foreach (ushort i in skillNode.Value.linkID)
                {
                    if (
                        links.Count(
                            nd => (nd[0] == i && nd[1] == skillNode.Key) || nd[0] == skillNode.Key && nd[1] == i) ==
                        1)
                    {
                        continue;
                    }
                    links.Add(new ushort[] { skillNode.Key, i });
                }
            }
            foreach (ushort[] ints in links)
            {
                if (!Skillnodes[ints[0]].Neighbor.Contains(Skillnodes[ints[1]]))
                {
                    Skillnodes[ints[0]].Neighbor.Add(Skillnodes[ints[1]]);
                }
                if (!Skillnodes[ints[1]].Neighbor.Contains(Skillnodes[ints[0]]))
                {
                    Skillnodes[ints[1]].Neighbor.Add(Skillnodes[ints[0]]);
                }
            }

            foreach (var gp in inTree.groups)
            {
                NodeGroup ng = new NodeGroup();

                ng.OcpOrb   = gp.Value.oo;
                ng.Position = new Vector2D(gp.Value.x, gp.Value.y);
                ng.Nodes    = gp.Value.n;
                NodeGroups.Add(ng);
            }

            foreach (SkillTree.NodeGroup group in NodeGroups)
            {
                foreach (ushort node in group.Nodes)
                {
                    Skillnodes[node].NodeGroup = group;
                }
            }

            TRect = new Rect2D(new Vector2D(inTree.min_x * 1.1, inTree.min_y * 1.1),
                               new Vector2D(inTree.max_x * 1.1, inTree.max_y * 1.1));



            InitNodeSurround( );
            DrawNodeSurround( );
            DrawNodeBaseSurround( );
            DrawSkillIconLayer( );
            DrawBackgroundLayer( );
            InitFaceBrushesAndLayer( );
            DrawLinkBackgroundLayer( );
            InitOtherDynamicLayers( );
            CreateCombineVisual( );


            Regex regexAttrib = new Regex("[0-9]*\\.?[0-9]+");

            foreach (var skillNode in Skillnodes)
            {
                skillNode.Value.Attributes = new Dictionary <string, List <float> >( );
                foreach (string s in skillNode.Value.attributes)
                {
                    List <float> values = new List <float>( );

                    foreach (Match m in regexAttrib.Matches(s))
                    {
                        if (!AttributeTypes.Contains(regexAttrib.Replace(s, "#")))
                        {
                            AttributeTypes.Add(regexAttrib.Replace(s, "#"));
                        }
                        if (m.Value == "")
                        {
                            values.Add(float.NaN);
                        }
                        else
                        {
                            values.Add(float.Parse(m.Value, System.Globalization.CultureInfo.InvariantCulture));
                        }
                    }
                    string cs = (regexAttrib.Replace(s, "#"));

                    skillNode.Value.Attributes[cs] = values;
                }
            }

            Solver = new Solver(Skillnodes);
        }
        public SkillTree(String treestring, startLoadingWindow start = null, UpdateLoadingWindow update = null, closeLoadingWindow finish = null)
        {
            bool displayProgress = ( start != null && update != null && finish != null );
           // RavenJObject jObject = RavenJObject.Parse( treestring.Replace( "Additional " , "" ) );
          JsonSerializerSettings jss = new JsonSerializerSettings
            {
            Error = delegate(object sender, Newtonsoft.Json.Serialization.ErrorEventArgs args)
            {
            Debug.WriteLine(args.ErrorContext.Error.Message);
            args.ErrorContext.Handled = true;
            }
            };

          var inTree = JsonConvert.DeserializeObject<PoEClasses.PoESkillTree>(treestring.Replace("Additional ", ""), jss);
            int qindex = 0;


            foreach (var obj in inTree.skillSprites)
            {
                if (obj.Key.Contains("inactive"))
                    continue;
                iconActiveSkills.Images[obj.Value[3].filename] = null;
                foreach (var o in obj.Value[3].coords)
                {
                    iconActiveSkills.SkillPositions[o.Key] = new KeyValuePair<Rect, string>(new Rect(o.Value.x, o.Value.y, o.Value.w, o.Value.h), obj.Value[3].filename);
                }
            }
            foreach (var obj in inTree.skillSprites)
            {
                if (obj.Key.Contains("active"))
                    continue;
                iconActiveSkills.Images[obj.Value[3].filename] = null;
                foreach (var o in obj.Value[3].coords)
                {
                    iconActiveSkills.SkillPositions[o.Key] = new KeyValuePair<Rect, string>(new Rect(o.Value.x, o.Value.y, o.Value.w, o.Value.h), obj.Value[3].filename);
                }
            }   
            qindex = 0;    

            foreach(var ass in inTree.assets)
            {
               
                assets[ass.Key] = new Asset(ass.Key,ass.Value.ContainsKey(0.3835f)?ass.Value[0.3835f]:ass.Value.Values.First());
                                     
            }
           
            if ( displayProgress )
                start( );
            iconActiveSkills.OpenOrDownloadImages(update );
            iconInActiveSkills.OpenOrDownloadImages(update );
            if ( displayProgress )
                finish( );
            foreach( var c in inTree.characterData)
            {
                CharBaseAttributes[c.Key] = new Dictionary<string, float>() { { "+# to Strength", c.Value.base_str }, { "+# to Dexterity", c.Value.base_dex }, { "+# to Intelligence", c.Value.base_int } };
            }
           foreach (var nd in inTree.nodes)
           {
               Skillnodes.Add(nd.id, new SkillTree.SkillNode()
               {
                   id = nd.id,                
                   name = nd.dn,
                   attributes = nd.sd,
                   orbit = nd.o,
                   orbitIndex =nd.oidx,
                   icon = nd.icon,
                   linkID =nd.ot,
                   g = nd.g,
                   da = nd.da,
                   ia = nd.ia,
                   ks = nd.ks,
                   not = nd.not,
                   sa = nd.sa,
                   Mastery = nd.m,
                   spc=nd.spc.Count()>0?(int?)nd.spc[0]:null
               });
           }         
            List<ushort[]> links = new List<ushort[]>( );
            foreach ( var skillNode in Skillnodes )
            {
                foreach ( ushort i in skillNode.Value.linkID )
                {
                    if (
                        links.Count(
                            nd => ( nd[ 0 ] == i && nd[ 1 ] == skillNode.Key ) || nd[ 0 ] == skillNode.Key && nd[ 1 ] == i ) ==
                        1 )
                    {
                        continue;
                    }
                    links.Add( new ushort[] { skillNode.Key , i } );
                }
            }
            foreach ( ushort[] ints in links )
            {
                if ( !Skillnodes[ ints[ 0 ] ].Neighbor.Contains( Skillnodes[ ints[ 1 ] ] ) )
                    Skillnodes[ ints[ 0 ] ].Neighbor.Add( Skillnodes[ ints[ 1 ] ] );
                if ( !Skillnodes[ ints[ 1 ] ].Neighbor.Contains( Skillnodes[ ints[ 0 ] ] ) )
                    Skillnodes[ ints[ 1 ] ].Neighbor.Add( Skillnodes[ ints[ 0 ] ] );
            }
           
            foreach(var gp in inTree.groups )
            {
                NodeGroup ng = new NodeGroup();

                ng.OcpOrb = gp.Value.oo;
                ng.Position = new Vector2D(gp.Value.x, gp.Value.y);
                ng.Nodes = gp.Value.n;
                NodeGroups.Add(ng);
            }
          
            foreach ( SkillTree.NodeGroup group in NodeGroups )
            {
                foreach ( ushort node in group.Nodes )
                {
                    Skillnodes[ node ].NodeGroup = group;
                }
            }

            TRect = new Rect2D( new Vector2D( inTree.min_x * 1.1 , inTree.min_y * 1.1 ) ,
                               new Vector2D(inTree.max_x * 1.1, inTree.max_y * 1.1));




            InitNodeSurround( );
            DrawNodeSurround( );
            DrawNodeBaseSurround( );
            DrawSkillIconLayer( );
            DrawBackgroundLayer( );
            InitFaceBrushesAndLayer( );
            DrawLinkBackgroundLayer( links );
            InitOtherDynamicLayers( );
            CreateCombineVisual( );


            Regex regexAttrib = new Regex( "[0-9]*\\.?[0-9]+" );
            foreach ( var skillNode in Skillnodes )
            {
                skillNode.Value.Attributes = new Dictionary<string , List<float>>( );
                foreach ( string s in skillNode.Value.attributes )
                {

                    List<float> values = new List<float>( );

                    foreach ( Match m in regexAttrib.Matches( s ) )
                    {

                        if ( !AttributeTypes.Contains( regexAttrib.Replace( s , "#" ) ) )
                            AttributeTypes.Add( regexAttrib.Replace( s , "#" ) );
                        if ( m.Value == "" )
                            values.Add( float.NaN );
                        else
                            values.Add( float.Parse( m.Value , System.Globalization.CultureInfo.InvariantCulture ) );

                    }
                    string cs = ( regexAttrib.Replace( s , "#" ) );

                    skillNode.Value.Attributes[ cs ] = values;



                }
            }


        }