public static void UpdateNpcPositionData(sbyte[] data, int length) { try { MobManager.lastNpcCount = MobManager.npcCount; MobManager.npcCount = 0; for (int lastNpcIndex = 0; lastNpcIndex < MobManager.lastNpcCount; lastNpcIndex++) { MobManager.lastNpcArray[lastNpcIndex] = MobManager.npcArray[lastNpcIndex]; } // MobManager.LastNpcList = MobManager.NpcList.ToList(); // .ToList() to force it to make it into a copy // MobManager.NpcList.Clear(); int newNpcOffset = 8; int newNpcCount = DataOperations.getBits(data, newNpcOffset, 16); newNpcOffset += 16; for (int newNpcIndex = 0; newNpcIndex < newNpcCount; newNpcIndex++) { int serverIndex = DataOperations.getBits(data, newNpcOffset, 16); Mob newNPC = MobManager.GetLastNpc(serverIndex); newNpcOffset += 16; int npcNeedsUpdate = DataOperations.getBits(data, newNpcOffset, 1); newNpcOffset++; if (npcNeedsUpdate != 0) { int i32 = DataOperations.getBits(data, newNpcOffset, 1); newNpcOffset++; if (i32 == 0) { int nextSprite = DataOperations.getBits(data, newNpcOffset, 3); newNpcOffset += 3; int waypointCurrent = newNPC.WaypointCurrent; int waypointX = newNPC.WaypointsX[waypointCurrent]; int waypointY = newNPC.WaypointsY[waypointCurrent]; if (nextSprite == 2 || nextSprite == 1 || nextSprite == 3) { waypointX += 128; } if (nextSprite == 6 || nextSprite == 5 || nextSprite == 7) { waypointX -= 128; } if (nextSprite == 4 || nextSprite == 3 || nextSprite == 5) { waypointY += 128; } if (nextSprite == 0 || nextSprite == 1 || nextSprite == 7) { waypointY -= 128; } newNPC.NextSprite = nextSprite; newNPC.WaypointCurrent = waypointCurrent = (waypointCurrent + 1) % 10; newNPC.WaypointsX[waypointCurrent] = waypointX; newNPC.WaypointsY[waypointCurrent] = waypointY; } else { int nextSpriteOffset = DataOperations.getBits(data, newNpcOffset, 4); newNpcOffset += 4; if ((nextSpriteOffset & 0xc) == 12) { continue; } newNPC.NextSprite = nextSpriteOffset; } } MobManager.npcArray[MobManager.npcCount++] = newNPC; //Mudclient.npcCount++; } while (newNpcOffset + 34 < length * 8) { int serverIndex = DataOperations.getBits(data, newNpcOffset, 16); newNpcOffset += 16; int offsetX = DataOperations.getBits(data, newNpcOffset, 5); newNpcOffset += 5; if (offsetX > 15) { offsetX -= 32; } int offsetY = DataOperations.getBits(data, newNpcOffset, 5); newNpcOffset += 5; if (offsetY > 15) { offsetY -= 32; } int nextSprite = DataOperations.getBits(data, newNpcOffset, 4); newNpcOffset += 4; int x = (Mudclient.SectionX + offsetX) * 128 + 64; int y = (Mudclient.SectionY + offsetY) * 128 + 64; int type = DataOperations.getBits(data, newNpcOffset, 10); newNpcOffset += 10; if (type >= Data.npcCount) { type = 24; } MobManager.CreateNPC(serverIndex, x, y, nextSprite, type); /* addNPC(serverIndex, x, y, nextSprite, type); */ } } catch { } }