예제 #1
0
        /// <summary>
        /// </summary>
        /// <param name="stream">
        /// </param>
        /// <returns>
        /// </returns>
        public static StatelData ReadFromStream(Stream stream)
        {
            StatelData statel = new StatelData();
            FlatIdentity fi = new FlatIdentity();
            fi.ReadFromStream(stream);
            statel.StatelIdentity = fi.Id;

            // Skip 4, is always 1?
            stream.ReadByte();
            stream.ReadByte();
            stream.ReadByte();
            stream.ReadByte();
            PFCoordHeading pfc = new PFCoordHeading();
            pfc.ReadFromStream(stream);

            statel.X = pfc.Coordinate.X;
            statel.Y = pfc.Coordinate.Y;
            statel.Z = pfc.Coordinate.Z;

            statel.HeadingX = pfc.Heading.X;
            statel.HeadingY = pfc.Heading.Y;
            statel.HeadingZ = pfc.Heading.Z;
            statel.HeadingW = pfc.Heading.W;

            statel.PlayfieldId = pfc.PlayfieldIdentity;

            BinaryReader br = new BinaryReader(stream);
            br.ReadInt32();
            statel.TemplateId = br.ReadInt32();
            int len2 = br.ReadInt32();
            byte[] HighLow = br.ReadBytes(len2);
            MemoryStream ms = new MemoryStream(HighLow);

            BinaryReader br2 = new BinaryReader(ms);
            br2.ReadBytes(8);
            int C1 = IPAddress.NetworkToHostOrder(br2.ReadInt32());
            Debug.Assert(C1 % 0x3f1 == 0, "Wrong 3f1 encountered... stop please");

            int evcount = IPAddress.NetworkToHostOrder(br2.ReadInt32());
            while (evcount > 0)
            {
                int dataType = IPAddress.NetworkToHostOrder(br2.ReadInt32());
                switch (dataType)
                {
                    case 2:
                        HLFlatEvent flatEvent = new HLFlatEvent();
                        flatEvent.ReadFromStream(ms);
                        statel.Events.Add(flatEvent.ToEvents());
                        break;
                    default:

                        // Console.WriteLine("DataType " + dataType + " found... stop please");
                        break;
                }

                evcount--;
            }

            return statel;
        }
예제 #2
0
 public static void SpawnEmptyVendorFromTemplate(StatelData statelData, IPlayfield playfield, int instance)
 {
     Identity pfIdentity = new Identity() { Type = IdentityType.Playfield, Instance = statelData.PlayfieldId };
     Identity freeIdentity = new Identity()
                             {
                                 Type = IdentityType.VendingMachine,
                                 Instance =
                                     Pool.Instance.GetFreeInstance<Vendor>(
                                         0x70000000,
                                         IdentityType.VendingMachine)
                             };
     Vendor v = new Vendor(pfIdentity, freeIdentity, statelData.TemplateId);
     v.OriginalIdentity = statelData.Identity;
     v.RawCoordinates = new Vector3(statelData.X, statelData.Y, statelData.Z);
     v.Heading = new Quaternion(
         statelData.HeadingX,
         statelData.HeadingY,
         statelData.HeadingZ,
         statelData.HeadingW);
     v.Playfield = playfield;
 }
예제 #3
0
        public static void SpawnVendorsForPlayfield(IPlayfield playfield, StatelData[] rdbVendors)
        {
            IEnumerable<DBVendor> vendors = VendorDao.Instance.GetWhere(new { Playfield = playfield.Identity.Instance });

            foreach (StatelData sd in rdbVendors)
            {
                int id = (((sd.Identity.Instance) >> 16) & 0xff | (playfield.Identity.Instance << 16));

                DBVendor vendor = vendors.FirstOrDefault(x => x.Id == id);
                if (vendor != null)
                {
                    LogUtil.Debug(DebugInfoDetail.Statel, sd.Identity.ToString(true) + " - DB " + vendor.TemplateId);
                    SpawnVendorFromDatabaseTemplate(vendor, playfield);
                }
                else
                {
                    LogUtil.Debug(DebugInfoDetail.Statel, sd.Identity.ToString(true) + " -    " + sd.TemplateId);
                    SpawnEmptyVendorFromTemplate(sd, playfield, id);
                }
            }
        }