public void HandlePacketFullGameState(PacketFullGameState pFullGameState) { DreamFullState fullState = pFullGameState.FullState; Program.OpenDream.IconAppearances.Clear(); foreach (IconAppearance iconAppearance in fullState.IconAppearances) { Program.OpenDream.IconAppearances.Add(iconAppearance); } Program.OpenDream.ATOMs.Clear(); foreach (KeyValuePair <UInt32, DreamFullState.Atom> stateAtom in fullState.Atoms) { ATOM atom = new ATOM(stateAtom.Key, stateAtom.Value.Type, stateAtom.Value.IconAppearanceID); atom.Icon.Appearance = Program.OpenDream.IconAppearances[stateAtom.Value.IconAppearanceID]; atom.ScreenLocation = stateAtom.Value.ScreenLocation; if (stateAtom.Value.LocationID != UInt32.MaxValue) { if (Program.OpenDream.ATOMs.ContainsKey(stateAtom.Value.LocationID)) { atom.Loc = Program.OpenDream.ATOMs[stateAtom.Value.LocationID]; } else { Console.WriteLine("Full game state packet gave an atom an invalid location, which was ignored (ID " + stateAtom.Value.AtomID + ")(Location ID " + stateAtom.Value.LocationID + ")"); } } else { atom.Loc = null; } } ATOM[,] turfs = new ATOM[fullState.Turfs.GetLength(0), fullState.Turfs.GetLength(1)]; for (int x = 0; x < turfs.GetLength(0); x++) { for (int y = 0; y < turfs.GetLength(1); y++) { UInt32 turfAtomID = fullState.Turfs[x, y]; if (Program.OpenDream.ATOMs.ContainsKey(turfAtomID)) { ATOM turf = Program.OpenDream.ATOMs[turfAtomID]; turf.X = x; turf.Y = y; turfs[x, y] = turf; } else { Console.WriteLine("Full game state packet defines a turf as an atom that doesn't exist, and was ignored (ID " + turfAtomID + ")(Location " + x + ", " + y + ")"); } } } Program.OpenDream.Map = new Map(turfs); if (pFullGameState.EyeID != UInt32.MaxValue) { if (Program.OpenDream.ATOMs.ContainsKey(pFullGameState.EyeID)) { Program.OpenDream.Eye = Program.OpenDream.ATOMs[pFullGameState.EyeID]; } else { Console.WriteLine("Full game state packet gives an invalid atom for the eye (ID " + pFullGameState.EyeID + ")"); Program.OpenDream.Eye = null; } } else { Program.OpenDream.Eye = null; } Program.OpenDream.ScreenObjects.Clear(); foreach (UInt32 screenObjectAtomID in pFullGameState.ScreenObjects) { if (Program.OpenDream.ATOMs.ContainsKey(screenObjectAtomID)) { Program.OpenDream.ScreenObjects.Add(Program.OpenDream.ATOMs[screenObjectAtomID]); } else { Console.WriteLine("Full games state packet defines a screen object that doesn't exist, and was ignored (ID " + screenObjectAtomID + ")"); } } }
public void HandlePacketFullGameState(PacketFullGameState pFullGameState) { DreamFullState fullState = pFullGameState.FullState; Program.OpenDream.IconAppearances.Clear(); foreach (IconAppearance iconAppearance in fullState.IconAppearances) { Program.OpenDream.IconAppearances.Add(iconAppearance); } Program.OpenDream.ATOMs.Clear(); Dictionary <ATOM, UInt32> atomLocations = new(); foreach (KeyValuePair <UInt32, DreamFullState.Atom> stateAtom in fullState.Atoms) { ATOM atom = new ATOM(stateAtom.Key, stateAtom.Value.Type, stateAtom.Value.IconAppearanceID); atom.Icon.Appearance = Program.OpenDream.IconAppearances[stateAtom.Value.IconAppearanceID]; atom.ScreenLocation = stateAtom.Value.ScreenLocation; atomLocations.Add(atom, stateAtom.Value.LocationID); } 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; } } Program.OpenDream.Map = new Map(); for (int z = 0; z < fullState.Levels.Count; z++) { DreamFullState.Level level = fullState.Levels[z]; int levelWidth = level.Turfs.GetLength(0); int levelHeight = level.Turfs.GetLength(1); ATOM[,] turfs = new ATOM[levelWidth, levelHeight]; for (int x = 0; x < levelWidth; x++) { for (int y = 0; y < levelHeight; y++) { UInt32 turfAtomID = level.Turfs[x, y]; if (Program.OpenDream.ATOMs.ContainsKey(turfAtomID)) { ATOM turf = Program.OpenDream.ATOMs[turfAtomID]; turf.X = x; turf.Y = y; turf.Z = z; turfs[x, y] = turf; } else { Console.WriteLine("Full game state packet defines a turf as an atom that doesn't exist, and was ignored (ID " + turfAtomID + ")(Location " + x + ", " + y + ", " + z + ")"); } } } Program.OpenDream.Map.Levels.Add(new Map.Level() { Turfs = turfs }); } if (pFullGameState.EyeID != UInt32.MaxValue) { if (Program.OpenDream.ATOMs.ContainsKey(pFullGameState.EyeID)) { Program.OpenDream.Eye = Program.OpenDream.ATOMs[pFullGameState.EyeID]; } else { Console.WriteLine("Full game state packet gives an invalid atom for the eye (ID " + pFullGameState.EyeID + ")"); Program.OpenDream.Eye = null; } } else { Program.OpenDream.Eye = null; } Program.OpenDream.ScreenObjects.Clear(); foreach (UInt32 screenObjectAtomID in pFullGameState.ScreenObjects) { if (Program.OpenDream.ATOMs.ContainsKey(screenObjectAtomID)) { Program.OpenDream.ScreenObjects.Add(Program.OpenDream.ATOMs[screenObjectAtomID]); } else { Console.WriteLine("Full games state packet defines a screen object that doesn't exist, and was ignored (ID " + screenObjectAtomID + ")"); } } }