Exemple #1
0
        internal static void UpdatePlayerAppearance(sbyte[] packetData, int length)
        {
            int newMobCount = DataOperations.getShort(packetData, 1);
            int off         = 3;

            for (int current = 0; current < newMobCount; current++)
            {
                int index = DataOperations.getShort(packetData, off);
                off += 2;
                if (index < 0)                // || index > playerBufferArray.Length)
                {
                    return;
                }



                Mob mob = MobManager.GetLastPlayer(index);                // playerBufferArray[index];
                if (mob == null)
                {
                    return;
                }

                mob.HairColour    = packetData[off++] & 0xff;
                mob.TopColour     = packetData[off++] & 0xff;
                mob.BottomColour  = packetData[off++] & 0xff;
                mob.SkinColour    = packetData[off++] & 0xff;
                mob.Level         = packetData[off++] & 0xff;
                mob.PlayerSkulled = packetData[off++] & 0xff;
                mob.IsAdmin       = packetData[off++] & 0xff;
                // var isadmin = // TODO to skip the admin flag (should it be removed)
            }
        }
Exemple #2
0
        public static void UpdatePlayerPositionData(sbyte[] packetData, int length)
        {
            try
            {
                if (!Mudclient.hasWorldInfo)
                {
                    return;
                }

                MobManager.lastPlayerCount = MobManager.playerCount;
                for (int k = 0; k < MobManager.lastPlayerCount; k++)
                {
                    MobManager.lastPlayerArray[k] = MobManager.playerArray[k];
                }

                int off = 8;
                Mudclient.SectionX = DataOperations.getBits(packetData, off, 11);
                off += 11;
                Mudclient.SectionY = DataOperations.getBits(packetData, off, 13);
                off += 13;
                int sprite = DataOperations.getBits(packetData, off, 4);

                off += 4;

                // boolean sectionLoaded = loadSection(sectionX, sectionY);
                Debug.Log("Before Load");

                var sectionLoaded = Mudclient.LoadSection(Mudclient.SectionX, Mudclient.SectionY);

                Mudclient.SectionX -= Mudclient.AreaX;
                Mudclient.SectionY -= Mudclient.AreaY;

                int mapEnterX = Mudclient.SectionX * 128 + 64;
                int mapEnterY = Mudclient.SectionY * 128 + 64;



                if (sectionLoaded)
                {
                    Mudclient.TerrainUpdateNecessary = true;

                    if (MobManager.MyPlayer == null)
                    {
                        MobManager.MyPlayer = new Player();
                    }

                    MobManager.MyPlayer.CurrentSprite = sprite;
                    MobManager.MyPlayer.currentX      = mapEnterX;
                    MobManager.MyPlayer.currentY      = mapEnterY;

                    // MobManager.MyPlayer.SectionX
                }

                MobManager.playerCount = 0;


                int newPlayerCount = DataOperations.getBits(packetData, off, 16);
                // off += 8;
                off += 16;
                for (int currentNewPlayer = 0; currentNewPlayer < newPlayerCount; currentNewPlayer++)
                {
                    //Mob mob = lastPlayerArray[currentNewPlayer + 1];
                    Mob mob = MobManager.GetLastPlayer(DataOperations.getBits(packetData, off, 16));
                    off += 16;
                    int playerAtTile = DataOperations.getBits(packetData, off, 1);
                    off++;
                    if (playerAtTile != 0)
                    {
                        int waypointsLeft = DataOperations.getBits(packetData, off, 1);
                        off++;
                        if (waypointsLeft == 0)
                        {
                            int currentNextSprite = DataOperations.getBits(packetData, off, 3);
                            off += 3;
                            int currentWaypoint = mob.WaypointCurrent;
                            int newWaypointX    = mob.WaypointsX[currentWaypoint];
                            int newWaypointY    = mob.WaypointsY[currentWaypoint];
                            if (currentNextSprite == 2 || currentNextSprite == 1 || currentNextSprite == 3)
                            {
                                newWaypointX += Mudclient.gridSize;
                            }
                            if (currentNextSprite == 6 || currentNextSprite == 5 || currentNextSprite == 7)
                            {
                                newWaypointX -= Mudclient.gridSize;
                            }
                            if (currentNextSprite == 4 || currentNextSprite == 3 || currentNextSprite == 5)
                            {
                                newWaypointY += Mudclient.gridSize;
                            }
                            if (currentNextSprite == 0 || currentNextSprite == 1 || currentNextSprite == 7)
                            {
                                newWaypointY -= Mudclient.gridSize;
                            }
                            mob.NextSprite                  = currentNextSprite;
                            mob.WaypointCurrent             = currentWaypoint = (currentWaypoint + 1) % 10;
                            mob.WaypointsX[currentWaypoint] = newWaypointX;
                            mob.WaypointsY[currentWaypoint] = newWaypointY;
                        }
                        else
                        {
                            int needsNextSprite = DataOperations.getBits(packetData, off, 4);
                            off += 4;
                            if ((needsNextSprite & 0xc) == 12)
                            {
                                continue;
                            }
                            mob.NextSprite = needsNextSprite;
                        }
                    }
                    MobManager.playerArray[MobManager.playerCount++] = mob;
                }

                int mobCount = 0;
                while (off + 24 < length * 8)
                {
                    int mobIndex = DataOperations.getBits(packetData, off, 16);
                    off += 16;
                    int areaMobX = DataOperations.getBits(packetData, off, 5);
                    off += 5;
                    if (areaMobX > 15)
                    {
                        areaMobX -= 32;
                    }
                    int areaMobY = DataOperations.getBits(packetData, off, 5);
                    off += 5;
                    if (areaMobY > 15)
                    {
                        areaMobY -= 32;
                    }
                    int mobSprite = DataOperations.getBits(packetData, off, 4);
                    off += 4;
                    int addIndex = DataOperations.getBits(packetData, off, 1);
                    off++;
                    int mobX = (Mudclient.SectionX + areaMobX) * Mudclient.gridSize + 64;
                    int mobY = (Mudclient.SectionY + areaMobY) * Mudclient.gridSize + 64;
                    MobManager.CreatePlayer(mobIndex, mobX, mobY, mobSprite);
                    if (addIndex == 0)
                    {
                        MobManager.playerBufferArrayIndexes[mobCount++] = mobIndex;
                    }
                }
                if (mobCount > 0)
                {
                    Mudclient.Instance.streamClass.createPacket(74);
                    Mudclient.Instance.streamClass.addShort(mobCount);
                    for (int currentMob = 0; currentMob < mobCount; currentMob++)
                    {
                        Mob dummyMob = MobManager.playerBufferArray[MobManager.playerBufferArrayIndexes[currentMob]];
                        Mudclient.Instance.streamClass.addShort(dummyMob.ServerIndex);
                        Mudclient.Instance.streamClass.addShort(dummyMob.WornItemsID);
                    }
                    Mudclient.Instance.streamClass.formatPacket();

                    Mudclient.Instance.streamClass.createPacket(14);                     // 83
                    Mudclient.Instance.streamClass.addShort(mobCount);
                    for (int k40 = 0; k40 < mobCount; k40++)
                    {
                        Mob f5 = MobManager.playerBufferArray[MobManager.playerBufferArrayIndexes[k40]];
                        Mudclient.Instance.streamClass.addShort(f5.ServerIndex);
                        Mudclient.Instance.streamClass.addShort(f5.ServerID);
                    }

                    Mudclient.Instance.streamClass.formatPacket();
                    mobCount = 0;
                }
            }
            catch (Exception exc) { Debug.LogException(exc); }
        }