Beispiel #1
0
        private void UpdatePlayerMask(int mask, int index, JagexBuffer b, Player p)
        {
            if ((mask & 0x400) != 0)
            {
                p.MoveStartX     = b.ReadUByteS();
                p.MoveStartY     = b.ReadUByteS();
                p.MoveEndX       = b.ReadUByteS();
                p.MoveEndY       = b.ReadUByteS();
                p.MoveCycleEnd   = b.ReadLEUShortA() + (int)GameContext.LoopCycle;
                p.MoveCycleStart = b.ReadUShortA() + (int)GameContext.LoopCycle;
                p.MoveDirection  = b.ReadUByteS();
                p.ResetQueuedMovements();
            }

            if ((mask & 0x100) != 0)
            {
                p.SpotAnimIndex = b.ReadLEUShort();
                var info = b.ReadInt();
                p.GraphicOffsetY   = info >> 16;
                p.SpotAnimCycleEnd = (int)GameContext.LoopCycle + (info & 0xffff);
                p.SpotAnimFrame    = 0;
                p.SpotAnimCycle    = 0;

                if (p.SpotAnimCycleEnd > GameContext.LoopCycle)
                {
                    p.SpotAnimFrame = -1;
                }

                if (p.SpotAnimIndex == 65535)
                {
                    p.SpotAnimIndex = -1;
                }
            }

            if ((mask & 8) != 0)
            {
                var seqIndex = b.ReadLEUShort();
                var delay    = b.ReadUByteC();
                if (seqIndex == 65535)
                {
                    seqIndex = -1;
                }

                var seq = GameContext.Cache.GetSeq(seqIndex);
                if (seq != null)
                {
                    if (seqIndex == p.SeqIndex && seqIndex != -1)
                    {
                        var type = seq.Type;
                        if (type == 1)
                        {
                            p.SeqFrame      = 0;
                            p.SeqCycle      = 0;
                            p.SeqDelayCycle = delay;
                            p.SeqResetCycle = 0;
                        }
                        else if (type == 2)
                        {
                            p.SeqResetCycle = 0;
                        }
                    }
                    else if (seqIndex == -1 || p.SeqIndex == -1 || (GameContext.Cache.GetSeq(p.SeqIndex) != null && seq.Priority >= GameContext.Cache.GetSeq(p.SeqIndex).Priority))
                    {
                        p.SeqIndex          = seqIndex;
                        p.SeqFrame          = 0;
                        p.SeqCycle          = 0;
                        p.SeqDelayCycle     = delay;
                        p.SeqResetCycle     = 0;
                        p.StillPathPosition = p.PathPosition;
                    }
                }
            }

            if ((mask & 4) != 0)
            {
                p.SpokenMessage = b.ReadString(10);

                if (p.SpokenMessage.ToCharArray()[0] == '~')
                {
                    p.SpokenMessage = p.SpokenMessage.Substring(1);
                    GameContext.Chat.Add(new ChatMessage(MessageType.Player, p.Name, p.SpokenMessage));
                }
                else if (p == GameContext.Self)
                {
                    GameContext.Chat.Add(new ChatMessage(MessageType.Player, p.Name, p.SpokenMessage));
                }

                p.SpokenColor  = 0;
                p.SpokenEffect = 0;
                p.SpokenLife   = 150;
            }

            if ((mask & 0x80) != 0)
            {
                var settings = b.ReadShort();
                var rights   = b.ReadByte();
                b.ReadByte();
                var length   = b.ReadUByteC();
                var startOff = b.Position();
                if (p.Name != null)
                {
                    var buf = new DefaultJagexBuffer(new byte[5000]);
                    b.ReadBytesReversed(buf.Array(), 0, length);
                    p.SpokenMessage = StringUtils.GetFormatted(length, buf);
                    p.SpokenEffect  = settings & 0xFF;
                    p.SpokenColor   = settings >> 8;
                    p.SpokenLife    = 150;

                    var sb = new StringBuilder();
                    sb.Append(p.Name);

                    var msg = new ChatMessage(MessageType.Player, sb.ToString(), p.SpokenMessage);
                    if (rights > 0)
                    {
                        msg.CrownIndex = rights;
                    }

                    GameContext.Chat.Add(msg);
                }

                b.Position(startOff + length);
            }

            if ((mask & 1) != 0)
            {
                p.FaceEntity = b.ReadLEUShort();

                if (p.FaceEntity == 65535)
                {
                    p.FaceEntity = -1;
                }
            }

            if ((mask & 0x10) != 0)
            {
                var payload = new byte[b.ReadUByteC()];
                b.ReadBytes(payload, 0, payload.Length);
                var pb = new DefaultJagexBuffer(payload);
                GameContext.PlayerBuffers[index] = pb;
                p.Update(pb);
            }

            if ((mask & 2) != 0)
            {
                p.FaceX = b.ReadLEUShortA();
                p.FaceY = b.ReadLEUShort();
            }

            if ((mask & 0x20) != 0)
            {
                var damage = b.ReadUShortA();
                var type   = b.ReadUByte();
                var icon   = b.ReadUByte();
                var soak   = b.ReadUShortA();
                p.QueueHit(type, damage, (int)GameContext.LoopCycle);
                p.CurrentHealth  = b.ReadUShortA();
                p.MaxHealth      = b.ReadUShortA();
                p.EndCombatCycle = (int)GameContext.LoopCycle + 300;
            }

            if ((mask & 0x200) != 0)
            {
                var damage = b.ReadUShortA();
                var type   = b.ReadUByte();
                var icon   = b.ReadUByte();
                var soak   = b.ReadUShortA();
                p.QueueHit(type, damage, (int)GameContext.LoopCycle);
                p.CurrentHealth  = b.ReadUShortA();
                p.MaxHealth      = b.ReadUShortA();
                p.EndCombatCycle = (int)GameContext.LoopCycle + 300;
            }
        }
 public void Handle(int opcode, JagexBuffer buffer)
 {
     GameContext.FriendsStorageType = (SocialStorageCap)buffer.ReadUByteA();
     GameContext.LocalPlayerIndex   = buffer.ReadLEUShortA();
 }
Beispiel #3
0
        public void UpdateActorMasks(JagexBuffer b)
        {
            for (int i = 0; i < entityCount; i++)
            {
                Actor a    = GameContext.Actors[entityIndices[i]];
                int   mask = b.ReadUByte();

                if ((mask & 0x10) != 0)
                {
                    int SeqIndex = b.ReadLEUShort();

                    if (SeqIndex == 65535)
                    {
                        SeqIndex = -1;
                    }

                    int delay = b.ReadUByte();

                    if (SeqIndex == a.SeqIndex && SeqIndex != -1)
                    {
                        int type = GameContext.Cache.GetSeq(SeqIndex).Type;
                        if (type == 1)
                        {
                            a.SeqFrame      = 0;
                            a.SeqCycle      = 0;
                            a.SeqDelayCycle = delay;
                            a.SeqResetCycle = 0;
                        }
                        if (type == 2)
                        {
                            a.SeqResetCycle = 0;
                        }
                    }
                    else if (SeqIndex == -1 || a.SeqIndex == -1 || GameContext.Cache.GetSeq(SeqIndex).Priority >= GameContext.Cache.GetSeq(a.SeqIndex).Priority)
                    {
                        a.SeqIndex          = SeqIndex;
                        a.SeqFrame          = 0;
                        a.SeqCycle          = 0;
                        a.SeqDelayCycle     = delay;
                        a.SeqResetCycle     = 0;
                        a.StillPathPosition = a.PathPosition;
                    }
                }

                if ((mask & 8) != 0)
                {
                    var damage = b.ReadUShortA();
                    var type   = b.ReadUByteC();
                    var icon   = b.ReadUByte();
                    a.QueueHit(type, damage, (int)GameContext.LoopCycle);
                    a.EndCombatCycle = (int)GameContext.LoopCycle + 300;
                    a.CurrentHealth  = b.ReadUShortA();
                    a.MaxHealth      = b.ReadUShortA();
                }

                if ((mask & 0x80) != 0)
                {
                    a.SpotAnimIndex = b.ReadUShort();

                    int info = b.ReadInt();
                    a.GraphicOffsetY   = info >> 16;
                    a.SpotAnimCycleEnd = (int)GameContext.LoopCycle + (info & 0xFFFF);

                    a.SpotAnimFrame = 0;
                    a.SpotAnimCycle = 0;

                    if (a.SpotAnimCycleEnd > GameContext.LoopCycle)
                    {
                        a.SpotAnimFrame = -1;
                    }

                    if (a.SpotAnimIndex == 65535)
                    {
                        a.SpotAnimIndex = -1;
                    }
                }

                if ((mask & 0x20) != 0)
                {
                    a.FaceEntity = b.ReadUShort();

                    if (a.FaceEntity == 65535)
                    {
                        a.FaceEntity = -1;
                    }
                }

                if ((mask & 1) != 0)
                {
                    a.SpokenMessage = b.ReadString(10);
                    a.SpokenLife    = 100;
                }

                if ((mask & 0x40) != 0)
                {
                    var damage = b.ReadUShortA();
                    var type   = b.ReadUByteS();
                    var icon   = b.ReadUByte();
                    a.QueueHit(type, damage, (int)GameContext.LoopCycle);
                    a.EndCombatCycle = (int)GameContext.LoopCycle + 300;
                    a.CurrentHealth  = b.ReadUShortA();
                    a.MaxHealth      = b.ReadUShortA();
                }

                if ((mask & 2) != 0)
                {
                    a.Config             = GameContext.Cache.GetActorConfig(b.ReadLEUShortA());
                    a.TileSize           = a.Config.HasOptions;
                    a.RotateSpeed        = a.Config.TurnSpeed;
                    a.WalkAnimation      = a.Config.MoveAnim;
                    a.Turn180Animation   = a.Config.Turn180Anim;
                    a.TurnRightAnimation = a.Config.TurnRightAnim;
                    a.TurnLeftAnimation  = a.Config.TurnLeftAnim;
                    a.StandAnimation     = a.Config.StandAnim;
                }

                if ((mask & 4) != 0)
                {
                    a.FaceX = b.ReadLEUShort();
                    a.FaceY = b.ReadLEUShort();
                }
            }
        }