Пример #1
0
        private void ReadAtomCreationsSection(PacketStream stream)
        {
            UInt16 atomCreationsCount = stream.ReadUInt16();

            for (int i = 0; i < atomCreationsCount; i++)
            {
                UInt32 atomID = stream.ReadUInt32();
                DreamDeltaState.AtomCreation atomCreation = new DreamDeltaState.AtomCreation((AtomType)stream.ReadByte(), (int)stream.ReadUInt32());

                atomCreation.LocationID = stream.ReadUInt32();
                if (atomCreation.Type == AtomType.Movable)
                {
                    atomCreation.ScreenLocation = stream.ReadScreenLocation();
                }

                DeltaState.AtomCreations.Add(atomID, atomCreation);
            }
        }
Пример #2
0
        private void WriteAtomCreationsSection(PacketStream stream)
        {
            stream.WriteByte((byte)SectionID.AtomCreations);
            stream.WriteUInt16((UInt16)DeltaState.AtomCreations.Count);

            foreach (KeyValuePair <UInt32, DreamDeltaState.AtomCreation> atomCreationPair in DeltaState.AtomCreations)
            {
                DreamDeltaState.AtomCreation atomCreation = atomCreationPair.Value;

                stream.WriteUInt32(atomCreationPair.Key);
                stream.WriteByte((byte)atomCreation.Type);
                stream.WriteUInt32((UInt32)atomCreation.IconAppearanceID);
                stream.WriteUInt32(atomCreation.LocationID);
                if (atomCreation.Type == AtomType.Movable)
                {
                    stream.WriteScreenLocation(atomCreation.ScreenLocation);
                }
            }
        }
Пример #3
0
        public void HandlePacketDeltaGameState(PacketDeltaGameState pDeltaGameState)
        {
            DreamDeltaState deltaState = pDeltaGameState.DeltaState;

            foreach (IconAppearance appearance in deltaState.NewIconAppearances)
            {
                Program.OpenDream.IconAppearances.Add(appearance);
            }

            foreach (KeyValuePair <UInt32, DreamDeltaState.AtomCreation> atomCreationPair in deltaState.AtomCreations)
            {
                UInt32 atomID = atomCreationPair.Key;
                DreamDeltaState.AtomCreation atomCreation = atomCreationPair.Value;

                if (!Program.OpenDream.ATOMs.ContainsKey(atomID))
                {
                    ATOM atom = new ATOM(atomID, atomCreation.Type, atomCreation.IconAppearanceID);

                    atom.Icon.Appearance = Program.OpenDream.IconAppearances[atomCreation.IconAppearanceID];
                    atom.ScreenLocation  = atomCreation.ScreenLocation;

                    if (atomCreation.LocationID != UInt32.MaxValue)
                    {
                        if (Program.OpenDream.ATOMs.ContainsKey(atomCreation.LocationID))
                        {
                            atom.Loc = Program.OpenDream.ATOMs[atomCreation.LocationID];
                        }
                        else
                        {
                            Console.WriteLine("Delta state packet gave a new atom an invalid location, so it was not assigned one (ID " + atomID + ")(Location ID " + atomCreation.LocationID + ")");
                        }
                    }
                    else
                    {
                        atom.Loc = null;
                    }
                }
                else
                {
                    Console.WriteLine("Delta state packet created a new atom that already exists, and was ignored (ID " + atomID + ")");
                }
            }

            foreach (UInt32 atomID in deltaState.AtomDeletions)
            {
                if (Program.OpenDream.ATOMs.ContainsKey(atomID))
                {
                    ATOM atom = Program.OpenDream.ATOMs[atomID];

                    atom.Loc = null;
                    Program.OpenDream.ATOMs.Remove(atomID);
                }
                else
                {
                    Console.WriteLine("Delta state packet gives an atom deletion for an invalid atom, and was ignored (ID " + atomID + ")");
                }
            }

            foreach (KeyValuePair <UInt32, DreamDeltaState.AtomDelta> atomDeltaPair in deltaState.AtomDeltas)
            {
                UInt32 atomID = atomDeltaPair.Key;
                DreamDeltaState.AtomDelta atomDelta = atomDeltaPair.Value;

                if (Program.OpenDream.ATOMs.ContainsKey(atomID))
                {
                    ATOM atom = Program.OpenDream.ATOMs[atomID];

                    if (atomDelta.NewIconAppearanceID.HasValue)
                    {
                        if (Program.OpenDream.IconAppearances.Count > atomDelta.NewIconAppearanceID.Value)
                        {
                            atom.Icon.Appearance = Program.OpenDream.IconAppearances[atomDelta.NewIconAppearanceID.Value];
                        }
                        else
                        {
                            Console.WriteLine("Invalid appearance ID " + atomDelta.NewIconAppearanceID.Value);
                        }
                    }

                    if (atomDelta.ScreenLocation.HasValue)
                    {
                        atom.ScreenLocation = atomDelta.ScreenLocation.Value;
                    }
                }
                else
                {
                    Console.WriteLine("Delta state packet contains delta values for an invalid ATOM, and was ignored (ID " + atomID + ")");
                }
            }

            foreach (DreamDeltaState.AtomLocationDelta atomLocationDelta in deltaState.AtomLocationDeltas)
            {
                if (Program.OpenDream.ATOMs.ContainsKey(atomLocationDelta.AtomID))
                {
                    ATOM atom = Program.OpenDream.ATOMs[atomLocationDelta.AtomID];

                    if (atomLocationDelta.LocationID != UInt32.MaxValue)
                    {
                        if (Program.OpenDream.ATOMs.ContainsKey(atomLocationDelta.LocationID))
                        {
                            atom.Loc = Program.OpenDream.ATOMs[atomLocationDelta.LocationID];
                        }
                        else
                        {
                            Console.WriteLine("Delta state packet gave an atom a new invalid location, so it was not changed (ID " + atomLocationDelta.AtomID + ")(Location ID " + atomLocationDelta.LocationID + ")");
                        }
                    }
                    else
                    {
                        atom.Loc = null;
                    }
                }
                else
                {
                    Console.WriteLine("Delta state packet contains a location delta for an invalid ATOM, and was ignored (ID " + atomLocationDelta.AtomID + ")");
                }
            }

            foreach (KeyValuePair <(int X, int Y), UInt32> turfDelta in deltaState.TurfDeltas)
            {
                int    x          = turfDelta.Key.X;
                int    y          = turfDelta.Key.Y;
                UInt32 turfAtomID = turfDelta.Value;

                if (Program.OpenDream.ATOMs.ContainsKey(turfAtomID))
                {
                    ATOM turf = Program.OpenDream.ATOMs[turfAtomID];

                    turf.X = x;
                    turf.Y = y;
                    Program.OpenDream.Map.Turfs[x, y] = turf;
                }
                else
                {
                    Console.WriteLine("Delta state packet sets a turf to an invalid atom, and was ignored (ID " + turfAtomID + ")(Location " + x + ", " + y + ")");
                }
            }

            if (pDeltaGameState.ClientDelta != null)
            {
                ApplyClientDelta(pDeltaGameState.ClientDelta);
            }
        }
Пример #4
0
        public void HandlePacketDeltaGameState(PacketDeltaGameState pDeltaGameState)
        {
            DreamDeltaState deltaState = pDeltaGameState.DeltaState;

            foreach (IconAppearance appearance in deltaState.NewIconAppearances)
            {
                Program.OpenDream.IconAppearances.Add(appearance);
            }

            Dictionary <ATOM, UInt32> atomLocations = new();

            foreach (KeyValuePair <UInt32, DreamDeltaState.AtomCreation> atomCreationPair in deltaState.AtomCreations)
            {
                UInt32 atomID = atomCreationPair.Key;
                DreamDeltaState.AtomCreation atomCreation = atomCreationPair.Value;

                if (!Program.OpenDream.ATOMs.ContainsKey(atomID))
                {
                    ATOM atom = new ATOM(atomID, atomCreation.Type, atomCreation.IconAppearanceID);

                    atom.Icon.Appearance = Program.OpenDream.IconAppearances[atomCreation.IconAppearanceID];
                    atom.ScreenLocation  = atomCreation.ScreenLocation;
                    atomLocations.Add(atom, atomCreation.LocationID);
                }
                else
                {
                    Console.WriteLine("Delta state packet created a new atom that already exists, and was ignored (ID " + atomID + ")");
                }
            }

            foreach (KeyValuePair <ATOM, UInt32> atomLocation in atomLocations)
            {
                UInt32 locationId = atomLocation.Value;

                if (locationId != UInt32.MaxValue)
                {
                    if (Program.OpenDream.ATOMs.ContainsKey(locationId))
                    {
                        atomLocation.Key.Loc = Program.OpenDream.ATOMs[locationId];
                    }
                    else
                    {
                        Console.WriteLine("Full game state packet gave an atom an invalid location, which was ignored (ID " + atomLocation.Key.ID + ")(Location ID " + locationId + ")");
                    }
                }
                else
                {
                    atomLocation.Key.Loc = null;
                }
            }

            foreach (UInt32 atomID in deltaState.AtomDeletions)
            {
                if (Program.OpenDream.ATOMs.ContainsKey(atomID))
                {
                    ATOM atom = Program.OpenDream.ATOMs[atomID];

                    atom.Loc = null;
                    Program.OpenDream.ATOMs.Remove(atomID);
                }
                else
                {
                    Console.WriteLine("Delta state packet gives an atom deletion for an invalid atom, and was ignored (ID " + atomID + ")");
                }
            }

            foreach (KeyValuePair <UInt32, DreamDeltaState.AtomDelta> atomDeltaPair in deltaState.AtomDeltas)
            {
                UInt32 atomID = atomDeltaPair.Key;
                DreamDeltaState.AtomDelta atomDelta = atomDeltaPair.Value;

                if (Program.OpenDream.ATOMs.ContainsKey(atomID))
                {
                    ATOM atom = Program.OpenDream.ATOMs[atomID];

                    if (atomDelta.NewIconAppearanceID.HasValue)
                    {
                        if (Program.OpenDream.IconAppearances.Count > atomDelta.NewIconAppearanceID.Value)
                        {
                            atom.Icon.Appearance = Program.OpenDream.IconAppearances[atomDelta.NewIconAppearanceID.Value];
                        }
                        else
                        {
                            Console.WriteLine("Invalid appearance ID " + atomDelta.NewIconAppearanceID.Value);
                        }
                    }

                    if (atomDelta.ScreenLocation.HasValue)
                    {
                        atom.ScreenLocation = atomDelta.ScreenLocation.Value;
                    }
                }
                else
                {
                    Console.WriteLine("Delta state packet contains delta values for an invalid ATOM, and was ignored (ID " + atomID + ")");
                }
            }

            foreach (DreamDeltaState.AtomLocationDelta atomLocationDelta in deltaState.AtomLocationDeltas)
            {
                if (Program.OpenDream.ATOMs.ContainsKey(atomLocationDelta.AtomID))
                {
                    ATOM atom = Program.OpenDream.ATOMs[atomLocationDelta.AtomID];

                    if (atomLocationDelta.LocationID != UInt32.MaxValue)
                    {
                        if (Program.OpenDream.ATOMs.ContainsKey(atomLocationDelta.LocationID))
                        {
                            atom.Loc = Program.OpenDream.ATOMs[atomLocationDelta.LocationID];
                        }
                        else
                        {
                            Console.WriteLine("Delta state packet gave an atom a new invalid location, so it was not changed (ID " + atomLocationDelta.AtomID + ")(Location ID " + atomLocationDelta.LocationID + ")");
                        }
                    }
                    else
                    {
                        atom.Loc = null;
                    }
                }
                else
                {
                    Console.WriteLine("Delta state packet contains a location delta for an invalid ATOM, and was ignored (ID " + atomLocationDelta.AtomID + ")");
                }
            }

            foreach (KeyValuePair <(int X, int Y, int Z), UInt32> turfDelta in deltaState.TurfDeltas)
            {
                int    x          = turfDelta.Key.X;
                int    y          = turfDelta.Key.Y;
                int    z          = turfDelta.Key.Z;
                UInt32 turfAtomID = turfDelta.Value;

                if (z >= Program.OpenDream.Map.Levels.Count)   //Z-Level doesn't exist, create it
                {
                    while (Program.OpenDream.Map.Levels.Count <= z)
                    {
                        int levelWidth  = Program.OpenDream.Map.Levels[0].Turfs.GetLength(0);
                        int levelHeight = Program.OpenDream.Map.Levels[0].Turfs.GetLength(1);

                        Program.OpenDream.Map.Levels.Add(new Map.Level()
                        {
                            Turfs = new ATOM[levelWidth, levelHeight]
                        });
                    }
                }

                if (Program.OpenDream.ATOMs.ContainsKey(turfAtomID))
                {
                    ATOM turf = Program.OpenDream.ATOMs[turfAtomID];

                    turf.X = x;
                    turf.Y = y;
                    turf.Z = z;
                    Program.OpenDream.Map.Levels[z].Turfs[x, y] = turf;
                }
                else
                {
                    Console.WriteLine("Delta state packet sets a turf to an invalid atom, and was ignored (ID " + turfAtomID + ")(Location " + x + ", " + y + ", " + z + ")");
                }
            }

            if (pDeltaGameState.ClientDelta != null)
            {
                ApplyClientDelta(pDeltaGameState.ClientDelta);
            }
        }