예제 #1
0
 public C2SAskKeyboardMovePacket(ByteBuffer buffer) : base(43)
 {
     currentPosition = new SunVector(buffer.ReadBlock(12));
     angle           = buffer.ReadBlock(2);
     tileIndex       = buffer.ReadBlock(2);
     moveState       = buffer.ReadByte();
 }
예제 #2
0
 public S2CAnsPlayerPositionInfo(Character character) : base(31)
 {
     position = new SunVector(
         character.CharacterPosition.LocationX,
         character.CharacterPosition.LocationY,
         character.CharacterPosition.LocationZ
         );
     unk1 = new byte[] { 00, 00 };
 }
예제 #3
0
 public C2SAskPlayerAttack(ByteBuffer buffer) : base(12)
 {
     this.clientSerial    = buffer.ReadUInt32();
     this.attackType      = buffer.ReadByte();
     this.unk1            = buffer.ReadUInt16();
     this.styleCode       = buffer.ReadUInt16();
     this.objKey          = buffer.ReadUInt32();
     this.currentPosition = new SunVector(buffer.ReadBlock(12));
     this.targetPosition  = new SunVector(buffer.ReadBlock(12));
 }
예제 #4
0
 public S2CMonsterEnter(uint objKey, ushort monsterId, SunVector position, uint hp, uint maxHp, ushort moveSpeedratio,
                        ushort attackSpeedRatio, ushort unk1) : base(174)
 {
     this.objKey           = BitConverter.GetBytes(objKey);
     this.monsterId        = BitConverter.GetBytes(monsterId);
     this.position         = position.GetBytes();
     this.hp               = BitConverter.GetBytes(hp);
     this.maxhp            = BitConverter.GetBytes(maxHp);
     this.moveSpeedRatio   = BitConverter.GetBytes(moveSpeedratio);
     this.attackSpeedRatio = BitConverter.GetBytes(attackSpeedRatio);
     this.unk1             = BitConverter.GetBytes(unk1);
 }
예제 #5
0
 public S2CAnsPlayerAttack(uint attackerKey, byte attackType, ushort styleCode, uint clientSerial,
                           SunVector position, uint targetKey, ushort damage, uint targetHp, byte unk, byte effect) : base(109)
 {
     this.attackerKey  = BitConverter.GetBytes(attackerKey);
     this.attackType   = BitConverter.GetBytes(attackType);
     this.styleCode    = BitConverter.GetBytes(styleCode);
     this.clientSerial = BitConverter.GetBytes(clientSerial);
     this.position     = position.GetBytes();
     this.targetKey    = BitConverter.GetBytes(targetKey);
     this.damage       = BitConverter.GetBytes(damage);
     this.targetHp     = BitConverter.GetBytes(targetHp);
     this.unk          = new [] { unk };
     this.effect       = new[] { effect };
 }
예제 #6
0
            public S2CItemEnter(uint fromMonster, uint objKey, uint owner, byte itemType, uint heimAmount, uint unk1, ItemInfo item,
                                SunVector pos) : base(93)
            {
                this.fromMonster = BitConverter.GetBytes(fromMonster);
                this.objKey      = BitConverter.GetBytes(objKey);
                this.owner       = BitConverter.GetBytes(owner);
                this.itemType    = new[] { itemType };
                this.heimAmount  = BitConverter.GetBytes(heimAmount);
                this.unk1        = BitConverter.GetBytes(unk1);
                this.pos         = pos.GetBytes();

                var x = new ItemInfoX(2);

                x.durAmount = 10;
                x.Serial    = 10;

                x.Devine  = 1;
                x.Rank    = 2;
                x.RankD   = 10;
                x.Enchant = 10;
                this.item = x.GetBytes();
                unk2      = new byte[5];
            }
예제 #7
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            int year = 2017;
            //int tasks = 1;
            //if (this.mt) tasks = Environment.ProcessorCount;
            int             tasks   = Environment.ProcessorCount;
            ParallelOptions paropts = new ParallelOptions {
                MaxDegreeOfParallelism = tasks
            };
            //ParallelOptions paropts_1cpu = new ParallelOptions { MaxDegreeOfParallelism = 1 };


            //////////////////////////////////////////////////////////////////////////////////////////
            /// INPUTS
            int reclvl = 0;

            if (!DA.GetData(0, ref reclvl))
            {
                return;
            }

            bool drawviewfactors = false;

            if (!DA.GetData(1, ref drawviewfactors))
            {
                drawviewfactors = false;
            }

            bool drawcumskymatrix = false;

            if (!DA.GetData(2, ref drawcumskymatrix))
            {
                drawcumskymatrix = false;
            }

            bool draw_sunpath = true;

            if (!DA.GetData(3, ref draw_sunpath))
            {
                draw_sunpath = true;
            }

            bool draw_solarvec = true;

            if (!DA.GetData(4, ref draw_solarvec))
            {
                draw_solarvec = true;
            }

            List <int> hoy = new List <int>();

            if (!DA.GetDataList(5, hoy))
            {
                return;
            }

            List <double> loc = new List <double>();

            if (!DA.GetDataList(6, loc))
            {
                return;
            }
            double longitude = loc[0];
            double latitude  = loc[1];

            List <double> dni = new List <double>();
            List <double> dhi = new List <double>();

            DA.GetDataList(7, dni);
            DA.GetDataList(8, dhi);

            double domesize = 1.2;

            if (!DA.GetData(9, ref domesize))
            {
                domesize = 1.2;
            }

            List <Mesh> context = new List <Mesh>();

            DA.GetDataList(10, context);

            Point3d sp = new Point3d();

            if (!DA.GetData(11, ref sp))
            {
                return;
            }


            //////////////////////////////////////////////////////////////////////////////////////////
            /// size of skydome
            Point3d anchor = sp;
            Point3d bb_furthest_point;    // max distance to furthest corner of context
            double  bb_max_distance = double.MinValue;

            if (context.Count > 0)
            {
                Mesh context_joined = new Mesh();
                foreach (Mesh msh in context)
                {
                    context_joined.Append(msh);
                }
                BoundingBox bb_context = context_joined.GetBoundingBox(false);
                if (bb_context.IsDegenerate(-1.0) == 4)
                {
                    bb_furthest_point = new Point3d(sp.X + 1.0, sp.Y + 1.0, sp.Z + 1.0);
                }
                else
                {
                    Point3d[] _pts     = bb_context.GetCorners();
                    int       _p_index = 0;
                    for (int i = 0; i < _pts.Length; i++)
                    {
                        double _d = sp.DistanceTo(_pts[i]);
                        if (_d > bb_max_distance)
                        {
                            bb_max_distance = _d;
                            _p_index        = i;
                        }
                    }
                    bb_furthest_point = _pts[_p_index];
                }
            }
            else
            {
                bb_furthest_point = new Point3d(sp.X + 1.0, sp.Y + 1.0, sp.Z + 1.0);
            }
            Vector3d vec_sp = bb_furthest_point - sp;

            vec_sp = Vector3d.Multiply(vec_sp, domesize);
            double vec_sp_len = vec_sp.Length;


            //////////////////////////////////////////////////////////////////////////////////////////
            /// SKYDOME
            /// View factors and/or Cumulative SkyMatrix
            SkyDome dome = new SkyDome(reclvl);

            // create 2 meshes, one with obstructed views (make it black transparent), and one unobstructed (regular GH_Mesh color)
            Mesh meshObstructed = new Mesh();

            foreach (double[] p in dome.VertexVectorsSphere)
            {
                Vector3d vec = new Vector3d(p[0], p[1], p[2]);
                vec = Vector3d.Multiply(vec_sp_len, vec);
                meshObstructed.Vertices.Add(vec + sp);
            }
            foreach (int[] f in dome.Faces)
            {
                meshObstructed.Faces.AddFace(f[0], f[1], f[2]);
            }
            meshObstructed.UnifyNormals();

            if (drawviewfactors)
            {
                List <Vector3d> vec_sky_list = new List <Vector3d>();
                List <int>      vec_int      = new List <int>();
                for (int i = 0; i < meshObstructed.Vertices.Count; i++)
                {
                    Vector3d testvec = meshObstructed.Vertices[i] - sp;
                    if (testvec.Z >= 0.0)
                    {
                        vec_sky_list.Add(testvec);
                        vec_int.Add(i);
                    }
                }
                Color[] colors = new Color[meshObstructed.Vertices.Count];
                for (int i = 0; i < meshObstructed.Vertices.Count; i++)
                {
                    colors[i] = Color.FromArgb(100, 255, 255, 255);  //alpha not working
                }
                meshObstructed.VertexColors.SetColors(colors);
                Vector3d[] vec_sky = vec_sky_list.ToArray();
                bool[]     shadow  = new bool[vec_sky_list.Count];
                if (context.Count > 0)
                {
                    CShadow.CalcShadowMT(sp, new Vector3d(0, 0, 1), 0.001, vec_sky, context.ToArray(), ref shadow, paropts);
                }

                int j = 0;
                foreach (int i in vec_int)
                {
                    Color c = new Color();
                    if (shadow[j])
                    {
                        // Custom material, DisplayMaterial (rhinostyle) rendering material. and make in override DrawViewportMesh
                        c = Color.FromArgb(100, 0, 0, 0);   //alpha not working
                        meshObstructed.VertexColors.SetColor(i, c);
                        _vectorsObstructed.Add(i);
                    }
                    j++;
                }
            }
            else if (drawcumskymatrix)
            {
                // https://www.sciencedirect.com/science/article/pii/S0038092X04001161
                // http://alexandria.tue.nl/openaccess/635611/p1153final.pdf
                // Solarmodel.dll needs new function to compute cumulative sky view matrix (requires obstruction check from drawviewfactors
                // 1. calc perez diffuse for each hour. use that value (hor, circum, dome) and assign it to each mesh face
                // 2. DNI is computed directly onto SP
                // 3. visualize colored dome for diff only.
                // 4. add text to sensorpoint, stating annual irradiation (DNI plus diff)
                //
                // cumskymatrix seperate component!! coz it can be re-used for several sensor points
                // matrix inversion as in robinson stone to compute irradiation on all sensor points with refl.?
                //
                // needs a separate component that uses cumskymatrix on a number of SPs and visualizes that analysis surface.
                //... or use this component, output the sensorpoints, give it to a surface and make surface evaluate with the points, and recolor that surface

                if (dni.Count == 8760 && dhi.Count == 8760)     // only continue, if solar irradiance time series are provided
                {
                    //Rhino.RhinoApp.WriteLine("Leggo!");
                    //Context.cWeatherdata weather;
                    //weather.DHI = dhi;
                    //weather.DNI = dni;
                    //weather.Snow = new List<double>();
                    //double[] beta = new double[1] { beta_in };
                    //double[] psi = new double[1] { psi_in };
                    //Sensorpoints.p3d[] coord = new Sensorpoints.p3d[1];   //dummy variables. will not be used in this simplified simulation
                    //coord[0].X = 0;
                    //coord[0].Y = 0;
                    //coord[0].Z = 0;
                    //Sensorpoints.v3d[] normal = new Sensorpoints.v3d[1];   //dummy variables. will not be used in this simplified simulation
                    //normal[0].X = 0;
                    //normal[0].Y = 1;
                    //normal[0].Z = 0;


                    //double[] albedo = new double[8760];
                    //for (int t = 0; t < 8760; t++)
                    //{
                    //    albedo[t] = albedo1;
                    //}

                    //Console.WriteLine("Calculating irradiation...");
                    //Sensorpoints p = new Sensorpoints(beta, psi, coord, normal, reclvl);
                    //p.SetSimpleSkyMT(beta, paropts);
                    //p.SetSimpleGroundReflectionMT(beta, albedo, weather, sunvectors.ToArray(), paropts);
                    //p.CalcIrradiationMT(weather, sunvectors.ToArray(), paropts);

                    // hold on... i need a new function in SolarModel for CumSkyMatrix
                }
                else
                {
                    Rhino.RhinoApp.WriteLine("No data for Direct Normal Irradiance and Diffuse Horizontal Irradiance provided... Please provide 8760 time series for each.");
                }
            }

            if (drawviewfactors || drawcumskymatrix)
            {
                //_colouredMesh.Add(meshObstructed);
                _viewFactors = meshObstructed;
            }

            //////////////////////////////////////////////////////////////////////////////////////////
            /// Solar Vectors
            List <Sphere>    spheres  = new List <Sphere>();
            double           fontsize = vec_sp_len / 50.0;
            List <SunVector> sunvectors_list;

            SunVector.Create8760SunVectors(out sunvectors_list, longitude, latitude, year);
            int count = 0;

            if (draw_solarvec)
            {
                foreach (int h in hoy)
                {
                    Vector3d vec = new Vector3d(sunvectors_list[h].udtCoordXYZ.x, sunvectors_list[h].udtCoordXYZ.y, sunvectors_list[h].udtCoordXYZ.z);
                    vec = Vector3d.Multiply(vec_sp_len, vec);
                    Point3d solarpoint = new Point3d(Point3d.Add(sp, vec));
                    Line    ln         = new Line(sp, solarpoint);
                    ln.Flip();
                    _solar_vectors.Add(ln);
                    if (sunvectors_list[h].udtCoordXYZ.z < 0)
                    {
                        _night_time.Add(true);
                    }
                    else
                    {
                        _night_time.Add(false);
                    }

                    int    year_now  = sunvectors_list[h].udtTime.iYear;
                    int    month_now = sunvectors_list[h].udtTime.iMonth;
                    int    day_now   = sunvectors_list[h].udtTime.iDay;
                    double hour_now  = sunvectors_list[h].udtTime.dHours;
                    string hour_now2 = Convert.ToString(hour_now);
                    if (hour_now < 10)
                    {
                        hour_now2 = "0" + Convert.ToString(hour_now);
                    }
                    string strval = Convert.ToString(year_now) + "/ " + Convert.ToString(month_now) + "/ " + Convert.ToString(day_now) + "/ " + hour_now2 + ":00";
                    Plane  pl     = new Plane(ln.From, new Vector3d(-1, 0, 0));
                    //Plane pl = new Plane(ln.From, vec);
                    var te = Rhino.RhinoDoc.ActiveDoc.Objects.AddText(strval, pl, fontsize, "Baskerville", false, false);
                    Rhino.DocObjects.TextObject txt = Rhino.RhinoDoc.ActiveDoc.Objects.Find(te) as Rhino.DocObjects.TextObject;
                    _txt.Add(new List <Curve>());
                    if (txt != null)
                    {
                        var     tt = txt.Geometry as Rhino.Geometry.TextEntity;
                        Curve[] A  = tt.Explode();

                        foreach (Curve crv in A)
                        {
                            _txt[count].Add(crv);
                        }
                    }
                    count++;
                    Rhino.RhinoDoc.ActiveDoc.Objects.Delete(te, true);

                    Sphere sph = new Sphere(ln.From, vec_sp_len / 30.0);
                    spheres.Add(sph);
                }
            }


            //////////////////////////////////////////////////////////////////////////////////////////
            /// SUN PATH
            /// !!! wierd sun paths at extreme longitudes -> time shift... +/- UCT
            // draw solar paths: curves that connect each month, but for the same hour
            if (draw_sunpath)
            {
                for (int hod = 0; hod < 24; hod++)
                {
                    List <Point3d> pts = new List <Point3d>();
                    for (int d = 0; d < 365; d++)
                    {
                        int      h   = hod + 24 * d;
                        Vector3d vec = new Vector3d(sunvectors_list[h].udtCoordXYZ.x, sunvectors_list[h].udtCoordXYZ.y, sunvectors_list[h].udtCoordXYZ.z);
                        vec = Vector3d.Multiply(vec_sp_len, vec);
                        if (vec.Z > 0)
                        {
                            Point3d solarpoint = new Point3d(Point3d.Add(sp, vec));
                            pts.Add(solarpoint);
                        }
                    }
                    if (pts.Count > 0)
                    {
                        PolylineCurve crv = new PolylineCurve(pts);
                        _sun_paths.Add(crv);
                    }
                }

                // draw solar paths; curves that connects each hour, but for the same month
                int interv = 365 / 12;
                for (int m = 0; m < 12; m++)
                {
                    List <Point3d> pts = new List <Point3d>();
                    for (int hod = 0; hod < 24; hod++)
                    {
                        int      h   = hod + ((m * interv + interv / 2) * 24);
                        Vector3d vec = new Vector3d(sunvectors_list[h].udtCoordXYZ.x, sunvectors_list[h].udtCoordXYZ.y, sunvectors_list[h].udtCoordXYZ.z);
                        vec = Vector3d.Multiply(vec_sp_len, vec);
                        if (vec.Z > 0)
                        {
                            Point3d solarpoint = new Point3d(Point3d.Add(sp, vec));
                            pts.Add(solarpoint);
                        }
                    }
                    if (pts.Count > 0)
                    {
                        PolylineCurve crv = new PolylineCurve(pts);
                        _sun_paths.Add(crv);
                    }
                }
            }


            //////////////////////////////////////////////////////////////////////////////////////////
            /// OUTPUT
            DA.SetData(0, _viewFactors);        // this mesh needs to be colored according to view factor or cumulative sky matrix
            DA.SetDataList(1, _solar_vectors);
            DA.SetDataList(2, _sun_paths);
            DA.SetDataList(3, spheres);
        }
예제 #8
0
 public SunMap(ushort mapCode, SunVector wayPointPosition, List <ushort> WayPointPortalList)
 {
     this.mapCode            = mapCode;
     this.wayPointPosition   = wayPointPosition;
     this.WayPointPortalList = WayPointPortalList;
 }
예제 #9
0
        static void Main(string[] args)
        {
            ParallelOptions paropts = new ParallelOptions {
                MaxDegreeOfParallelism = 1
            };

            Console.WriteLine("SolarModel V2.0");
            Console.WriteLine();
            Console.WriteLine("You will need: 2 txt files with hourly values for DHI and DNI respectively. They need to be named DNI.txt and DHI.txt");
            Console.WriteLine("Please define path for reading inputs and writing result files:");
            string path = Console.ReadLine(); //"C:\Users\wach\Desktop

            Console.WriteLine();

            //load in weather file DHI
            List <double> DHI     = new List <double>();
            List <double> DNI     = new List <double>();
            int           counter = 0;
            string        line;

            // Read the file and display it line by line.
            Console.WriteLine("Reading inputs...");
            System.IO.StreamReader file =
                new System.IO.StreamReader(path + "\\DHI.txt");
            while ((line = file.ReadLine()) != null)
            {
                DHI.Add(Convert.ToDouble(line));
                //Console.WriteLine(line);
                counter++;
            }
            file.Close();

            System.IO.StreamReader file2 = new System.IO.StreamReader(path + "\\DNI.txt");
            while ((line = file2.ReadLine()) != null)
            {
                DNI.Add(Convert.ToDouble(line));
                //Console.WriteLine(line);
                counter++;
            }
            file.Close();
            Console.WriteLine();



            int recursion = 2;      //resolution of skydome

            int    year;
            double longitude, latitude;

            Console.WriteLine("Longitude: ");
            if (!double.TryParse(Console.ReadLine(), out longitude))
            {
                Console.WriteLine("You need to input a real number. Hit any key to close.");
                Console.ReadLine();
            }
            Console.WriteLine("Latitude: ");
            if (!double.TryParse(Console.ReadLine(), out latitude))
            {
                Console.WriteLine("You need to input a real number. Hit any key to close.");
                Console.ReadLine();
            }
            Console.WriteLine("Year: ");
            if (!int.TryParse(Console.ReadLine(), out year))
            {
                Console.WriteLine("You need to input an integer number. Hit any key to close.");
                Console.ReadLine();
            }
            Console.WriteLine();
            //double longitude = 8.539;
            //double latitude = 47.370;
            //int year = 2005;



            List <SunVector> sunvectors;

            SunVector.Create8760SunVectors(out sunvectors, longitude, latitude, year);
            Context.cWeatherdata weather;
            weather.DHI  = new List <double>();
            weather.DNI  = new List <double>();
            weather.Snow = new List <double>();
            for (int i = 0; i < 8760; i++)
            {
                weather.DHI.Add(DHI[i]);
                weather.DNI.Add(DNI[i]);
            }

            Context.cLocation location;
            location.dLatitude  = latitude;
            location.dLongitude = longitude;
            location.dTgmt      = 1;


            Dictionary <string, double> albedos = new Dictionary <string, double>();

            albedos.Add("LAWN", 0.205);
            albedos.Add("UNTILTEDFIELD", 0.26);
            albedos.Add("NAKEDGROUND", 0.17);
            albedos.Add("CONCRETE", 0.3);
            albedos.Add("SNOW", 0.85);
            albedos.Add("OLDSNOW", 0.58);

            Console.WriteLine("Ground albedo: allowed inputs 'LAWN', 'UNTILTEDFIELD', 'NAKEDGROUND', 'CONCRETE', 'SNOW', 'OLDSNOW'.");
            string albedo_string = Console.ReadLine();
            double albedo1       = albedos[albedo_string];

            double[] albedo = new double[8760];
            for (int t = 0; t < 8760; t++)
            {
                albedo[t] = albedo1;
            }

            double beta_in, psi_in;

            Console.WriteLine("Tilt angle in degree: ");
            if (!double.TryParse(Console.ReadLine(), out beta_in))
            {
                Console.WriteLine("You need to input a real number. Hit any key to close.");
                Console.ReadLine();
                return;
            }
            Console.WriteLine("Azimuth angle in degree (North is 0, South is 180): ");
            if (!double.TryParse(Console.ReadLine(), out psi_in))
            {
                Console.WriteLine("You need to input a real number. Hit any key to close.");
                Console.ReadLine();
                return;
            }
            Console.WriteLine();

            //double []beta = new double[1]{20};
            //double [] psi=new double[1]{180};
            double[] beta = new double[1] {
                beta_in
            };
            double [] psi = new double[1] {
                psi_in
            };
            Sensorpoints.p3d [] coord = new Sensorpoints.p3d[1];    //dummy variables. will not be used in this simplified simulation
            coord[0].X = 0;
            coord[0].Y = 0;
            coord[0].Z = 0;
            Sensorpoints.v3d[] normal = new Sensorpoints.v3d[1];   //dummy variables. will not be used in this simplified simulation
            normal[0].X = 0;
            normal[0].Y = 1;
            normal[0].Z = 0;

            Console.WriteLine("Calculating irradiation...");
            Sensorpoints p = new Sensorpoints(beta, psi, coord, normal, recursion);

            p.SetSimpleSkyMT(beta, paropts);
            p.SetSimpleGroundReflectionMT(beta, albedo, weather, sunvectors.ToArray(), paropts);
            p.CalcIrradiationMT(weather, sunvectors.ToArray(), paropts);

            Console.WriteLine("Writing to path...");
            System.IO.StreamWriter write  = new System.IO.StreamWriter(path + "\\calc.txt");
            System.IO.StreamWriter write2 = new System.IO.StreamWriter(path + "\\calcbeam.txt");
            System.IO.StreamWriter write3 = new System.IO.StreamWriter(path + "\\calcdiff.txt");
            System.IO.StreamWriter write4 = new System.IO.StreamWriter(path + "\\calcgroundrefl.txt");
            for (int i = 0; i < p.I[0].Count(); i++)
            {
                //Console.WriteLine(p.I[0][i]);
                write.WriteLine(p.I[0][i]);
                write2.WriteLine(p.Ibeam[0][i]);
                write3.WriteLine(p.Idiff[0][i]);
                write4.WriteLine(p.Irefl_diff[0][i]);
            }
            write.Close();
            write2.Close();
            write3.Close();
            write4.Close();
            Console.WriteLine();
            Console.WriteLine("Done. Press any key to quit");
            Console.ReadKey();
        }
예제 #10
0
 public C2SSyncMoveStop(ByteBuffer buffer) : base(123)
 {
     pos = new SunVector(buffer.ReadBlock(12));
 }
예제 #11
0
 public C2SSyncNewPositionAfterJump(ByteBuffer buffer) : base(69)
 {
     pos = new SunVector(buffer.ReadBlock(12));
 }
예제 #12
0
 public C2SAskMouseMove(ByteBuffer buffer) : base(202)
 {
     unk1                = buffer.ReadBlock(2);
     currentPosition     = new SunVector(buffer.ReadBlock(12));
     destinationPosition = new SunVector(buffer.ReadBlock(16));
 }
예제 #13
0
 public void UpdatePosition(SunVector pos)
 {
     CharacterPosition.LocationX = pos.x;
     CharacterPosition.LocationY = pos.y;
     CharacterPosition.LocationZ = pos.z;
 }