private static void appendChatTextUpdate(Player p, PacketBuilder updateBlock)
 {
     updateBlock.addLEShort((p.getLastChatMessage().getColour() << 8) + p.getLastChatMessage().getEffect());
     updateBlock.addByte((byte)p.getRights());
     byte[] chatStr = p.getLastChatMessage().getPacked();
     updateBlock.addByte((byte)(chatStr.Length));
     updateBlock.addBytesReverse(chatStr, chatStr.Length, 0);
     //}
 }
        private static void appendForceMovement(Player p, PacketBuilder updateBlock)
        {
            Location      myLocation = p.getUpdateFlags().getLastRegion();
            ForceMovement fm         = p.getForceMovement();

            updateBlock.addByteC(fm.getX1());
            updateBlock.addByte((byte)(fm.getY1()));
            updateBlock.addByteA(fm.getX2());
            updateBlock.addByte((byte)fm.getY2());
            updateBlock.addLEShort(fm.getSpeed1());
            updateBlock.addLEShort(fm.getSpeed2());
            updateBlock.addByteC(fm.getDirection());
        }
Esempio n. 3
0
        public void setArrowOnEntity(int type, int id)
        {
            PacketBuilder pb     = new PacketBuilder().setId(217);
            int           offset = pb.curLength;

            pb.addByte((byte)type);                   // 10 player, 1 npc
            pb.addByte((byte)((id < 32768) ? 0 : 1)); // arrowtype
            pb.addUShort(id);
            pb.curLength += 3;
            pb.addUShort(65535);
            for (int i = (pb.curLength - offset); i < 9; i++)
            {
                pb.addByte((byte)0);
            }
            connection.SendPacket(pb.toPacket());
        }
Esempio n. 4
0
        public void newClanMessage(Clan c, ChatMessage chatMessage)
        {
            PacketBuilder pb = new PacketBuilder();

            pb.setId(54).setSize(Packet.Size.VariableByte);
            pb.addLong(chatMessage.getPlayer().getLoginDetails().getLongName());
            pb.addByte((byte)1); // dummy
            pb.addLong(misc.playerNameToLong(c.getClanName()));
            pb.addUShort(0);     // some message counter bs
            string message        = chatMessage.getChatText();
            int    messageCounter = player.getFriends().getNextUniqueId();

            pb.addThreeBytes(messageCounter);
            pb.addByte((byte)chatMessage.getPlayer().getRights());
            pb.addBytes(chatMessage.getPacked());
            connection.SendPacket(pb.toPacket());
        }
Esempio n. 5
0
        public void setArrowOnPosition(int x, int y, int height)
        {
            PacketBuilder pb     = new PacketBuilder().setId(217);
            int           offset = pb.curLength;

            pb.addByte((byte)2);
            pb.addByte((byte)0);
            pb.addUShort(x);
            pb.addUShort(y);
            pb.addByte((byte)height);
            pb.addUShort(65535);
            for (int i = (pb.curLength - offset); i < 9; i++)
            {
                pb.addByte((byte)0);
            }
            connection.SendPacket(pb.toPacket());
        }
Esempio n. 6
0
        private static void appendAnimationUpdate(Npc Npc, PacketBuilder updateBlock)
        {
            Animation anim = Npc.getLastAnimation();

            if (anim != null)
            {
                updateBlock.addUShort(anim.getId());
                updateBlock.addByte((byte)anim.getDelay());
            }
        }
Esempio n. 7
0
        public void updateClan(Clan c)
        {
            PacketBuilder pb = new PacketBuilder();

            pb.setId(55).setSize(Packet.Size.VariableShort);
            pb.addLong(misc.playerNameToLong(c.getClanOwner()));
            pb.addLong(misc.playerNameToLong(c.getClanName()));
            pb.addByte((byte)c.getKickRights());
            pb.addByte((byte)c.getUserList().Count);
            foreach (ClanUser list in c.getUserList())
            {
                Player p = list.getClanMember();
                pb.addLong(p.getLoginDetails().getLongName());
                pb.addUShort(p.getWorld());
                int rights = Convert.ToInt32(list.getClanRights());
                pb.addByte((byte)rights);
                pb.addString("Server " + p.getWorld());
            }
            connection.SendPacket(pb.toPacket());
        }
Esempio n. 8
0
        private static void appendHitUpdate(Npc Npc, PacketBuilder updateBlock)
        {
            NpcData npcDef = NpcData.forId(Npc.getId());
            int     ratio  = 1;

            if (npcDef != null)
            {
                ratio = Npc.getHp() * 255 / npcDef.getHitpoints();
            }
            else
            {
                misc.WriteError("Missing npcDef npcId: " + Npc.getId());
            }
            updateBlock.addByte((byte)Npc.getHits().getHitDamage1());
            updateBlock.addByteC((int)Npc.getHits().getHitType1());
            updateBlock.addByteS((byte)ratio);
        }
        private static void appendHitUpdate(Player p, PacketBuilder updateBlock)
        {
            int ratio = (p.getSkills().getCurLevel(Skills.SKILL.HITPOINTS) * 255) / p.getSkills().getMaxLevel(Skills.SKILL.HITPOINTS);

            if (p.getSkills().getCurLevel(Skills.SKILL.HITPOINTS) > p.getSkills().getMaxLevel(Skills.SKILL.HITPOINTS))
            {
                ratio = (p.getSkills().getMaxLevel(Skills.SKILL.HITPOINTS) * 255) / p.getSkills().getCurLevel(Skills.SKILL.HITPOINTS);
            }

            if (p.getHits().getHitDamage1() < 128) //damage can be either addByte [for damage less then 128 otherwise UShort]
            {
                updateBlock.addByte((byte)p.getHits().getHitDamage1());
            }
            else
            {
                updateBlock.addUShort(p.getHits().getHitDamage1() + 0x8000);
            }
            updateBlock.addByteA((byte)p.getHits().getHitType1());
            updateBlock.addByteS(ratio);
        }
        private static void appendUpdateBlock(Npc Npc, PacketBuilder updateBlock)
        {
            int mask = 0x0;
            if (Npc.getUpdateFlags().isHit2UpdateRequired())
            {
                mask |= 0x2;
            }
            if (Npc.getUpdateFlags().isEntityFocusUpdateRequired())
            {
                mask |= 0x4;
            }
            if (Npc.getUpdateFlags().isAnimationUpdateRequired())
            {
                mask |= 0x10;
            }
            if (Npc.getUpdateFlags().isForceTextUpdateRequired())
            {
                mask |= 0x20;
            }
            if (Npc.getUpdateFlags().isHitUpdateRequired())
            {
                mask |= 0x40;
            }
            if (Npc.getUpdateFlags().isGraphicsUpdateRequired())
            {
                mask |= 0x80;
            }
            if (Npc.getUpdateFlags().isFaceLocationUpdateRequired())
            {
                mask |= 0x200;
            }

            if (mask >= 0x100)
            {
                mask |= 0x8;
                updateBlock.addLEShort(mask);

                //updateBlock.addByte((byte)(mask & 0xFF));
                //updateBlock.addByte((byte)(mask >> 8));
            }
            else
            {
                updateBlock.addByte((byte)(mask & 0xFF));
            }

            if (Npc.getUpdateFlags().isHitUpdateRequired())
            {
                appendHitUpdate(Npc, updateBlock);
            }
            if (Npc.getUpdateFlags().isHit2UpdateRequired())
            {
                appendHit2Update(Npc, updateBlock);
            }
            if (Npc.getUpdateFlags().isAnimationUpdateRequired())
            {
                appendAnimationUpdate(Npc, updateBlock);
            }
            if (Npc.getUpdateFlags().isEntityFocusUpdateRequired())
            {
                appendEntityFocusUdate(Npc, updateBlock);
            }
            if (Npc.getUpdateFlags().isGraphicsUpdateRequired())
            {
                appendGraphicsUpdate(Npc, updateBlock);
            }
            //0x1
            if (Npc.getUpdateFlags().isForceTextUpdateRequired())
            {
                appendForceTextUpdate(Npc, updateBlock);
            }
            //0x100
            if (Npc.getUpdateFlags().isFaceLocationUpdateRequired())
            {
                appendFaceLocationUpdate(Npc, updateBlock);
            }
        }
        private static void appendAppearanceUpdate(Player p, PacketBuilder updateBlock) {
		    PacketBuilder playerProps = new PacketBuilder().setSize(Packet.Size.Bare);
		
		    Appearance app = p.getAppearance();
		    playerProps.addByte((byte) (app.getGender() & 0xFF));
		    if((app.getGender() & 0x2) == 2) {
			    playerProps.addByte((byte) 0);
			    playerProps.addByte((byte) 0);
		    }
		    playerProps.addByte((byte) p.getPrayers().getPkIcon());
		    playerProps.addByte((byte) p.getPrayers().getHeadIcon());
		    if (!app.isInvisible()) {
			    if(!app.isNpc()) {
				    for(int i = 0; i < 4; i++) {
					    if(p.getEquipment().getItemInSlot((ItemData.EQUIP)i) != -1) {
                            playerProps.addUShort(32768 + p.getEquipment().getSlot((ItemData.EQUIP)i).getDefinition().getEquipId());
					    } else {
						    playerProps.addByte((byte) 0);
					    }
				    }
                    if (p.getEquipment().getItemInSlot(ItemData.EQUIP.CHEST) != -1)
                    {
                        playerProps.addUShort(32768 + p.getEquipment().getSlot(ItemData.EQUIP.CHEST).getDefinition().getEquipId());
				    } else {
                        playerProps.addUShort(0x100 + app.getLook(ItemData.EQUIP.AMULET));
				    }
                    if (p.getEquipment().getItemInSlot(ItemData.EQUIP.SHIELD) != -1)
                    {
                        playerProps.addUShort(32768 + p.getEquipment().getSlot(ItemData.EQUIP.SHIELD).getDefinition().getEquipId());
				    } else {
					    playerProps.addByte((byte) 0);
				    }
                    Item chest = p.getEquipment().getSlot(ItemData.EQUIP.CHEST);
                    if (chest != null && chest.getDefinition() != null)
                    {
					    if(!ItemData.isFullBody(chest.getDefinition())) {
                            playerProps.addUShort(0x100 + app.getLook(ItemData.EQUIP.WEAPON));
					    } else {
						    playerProps.addByte((byte) 0);
					    }
				    } else {
                        playerProps.addUShort(0x100 + app.getLook(ItemData.EQUIP.WEAPON));
				    }
                    if (p.getEquipment().getItemInSlot(ItemData.EQUIP.LEGS) != -1)
                    {
                        playerProps.addUShort(32768 + p.getEquipment().getSlot(ItemData.EQUIP.LEGS).getDefinition().getEquipId());
				    } else {
                        playerProps.addUShort(0x100 + app.getLook(ItemData.EQUIP.SHIELD));
				    }
                    Item hat = p.getEquipment().getSlot(ItemData.EQUIP.HAT);
                    if (hat != null && hat.getDefinition() != null)
                    {
					    if(!ItemData.isFullHat(hat.getDefinition()) && !ItemData.isFullMask(hat.getDefinition())) {
                            playerProps.addUShort(0x100 + app.getLook(ItemData.EQUIP.HAT));
					    } else {
						    playerProps.addByte((byte) 0);
					    }
				    } else {
                        playerProps.addUShort(0x100 + app.getLook(ItemData.EQUIP.HAT));
				    }
                    if (p.getEquipment().getItemInSlot(ItemData.EQUIP.HANDS) != -1)
                    {
                        playerProps.addUShort(32768 + p.getEquipment().getSlot(ItemData.EQUIP.HANDS).getDefinition().getEquipId());
				    } else {
                        playerProps.addUShort(0x100 + app.getLook(ItemData.EQUIP.CHEST));
				    }
                    if (p.getEquipment().getItemInSlot(ItemData.EQUIP.FEET) != -1)
                    {
                        playerProps.addUShort(32768 + p.getEquipment().getSlot(ItemData.EQUIP.FEET).getDefinition().getEquipId());
				    } else {
					    playerProps.addUShort(0x100 + app.getLook(6));
				    }
                    if (hat != null && hat.getDefinition() != null)
                    {
					    if(!ItemData.isFullMask(hat.getDefinition())) {
                            playerProps.addUShort(0x100 + app.getLook(ItemData.EQUIP.CAPE));
					    } else {
						    playerProps.addByte((byte) 0);
					    }
				    } else {
                        playerProps.addUShort(0x100 + app.getLook(ItemData.EQUIP.CAPE));
				    }
			    } else {
				    playerProps.addUShort(-1);
				    playerProps.addUShort(app.getNpcId());
				    playerProps.addByte((byte) 255);
			    }
		    } else {
			    for (int i = 0; i < 12; i++) {
				    playerProps.addByte((byte) 0);
			    }
		    }
		    foreach(int colour in app.getColoursArray()) {
			    playerProps.addByte((byte) colour);
		    }
		    playerProps.addUShort(p.getEquipment().getStandWalkAnimation());
		    playerProps.addLong(p.getLoginDetails().getLongName());
		    playerProps.addByte((byte) p.getSkills().getCombatLevel());
		    playerProps.addUShort(0);
		    playerProps.addByte((byte) 0);
		    updateBlock.addByteA((byte) (playerProps.getLength() & 0xFF));
		    updateBlock.addBytes(playerProps.toPacket().getData(), 0, playerProps.getLength());
	    }
 private static void appendChatTextUpdate(Player p, PacketBuilder updateBlock)
 {
     updateBlock.addLEShort((p.getLastChatMessage().getColour() << 8) + p.getLastChatMessage().getEffect());
     updateBlock.addByte((byte)p.getRights());
     byte[] chatStr = p.getLastChatMessage().getPacked();
     updateBlock.addByte((byte)(chatStr.Length));
     updateBlock.addBytesReverse(chatStr, chatStr.Length, 0);
     //}
 }
 private static void appendAnimationUpdate(Player p, PacketBuilder updateBlock)
 {
     updateBlock.addUShort(p.getLastAnimation().getId());
     updateBlock.addByte((byte)p.getLastAnimation().getDelay());
 }
        private static void appendHitUpdate(Player p, PacketBuilder updateBlock)
        {
            int ratio = (p.getSkills().getCurLevel(Skills.SKILL.HITPOINTS) * 255) / p.getSkills().getMaxLevel(Skills.SKILL.HITPOINTS);
            if (p.getSkills().getCurLevel(Skills.SKILL.HITPOINTS) > p.getSkills().getMaxLevel(Skills.SKILL.HITPOINTS))
                ratio = (p.getSkills().getMaxLevel(Skills.SKILL.HITPOINTS) * 255) / p.getSkills().getCurLevel(Skills.SKILL.HITPOINTS);

            if(p.getHits().getHitDamage1() < 128) //damage can be either addByte [for damage less then 128 otherwise UShort]
                updateBlock.addByte((byte)p.getHits().getHitDamage1()); 
            else
                updateBlock.addUShort(p.getHits().getHitDamage1() + 0x8000);
            updateBlock.addByteA((byte)p.getHits().getHitType1());
            updateBlock.addByteS(ratio);
        }
Esempio n. 15
0
        private static void appendUpdateBlock(Npc Npc, PacketBuilder updateBlock)
        {
            int mask = 0x0;

            if (Npc.getUpdateFlags().isHit2UpdateRequired())
            {
                mask |= 0x2;
            }
            if (Npc.getUpdateFlags().isEntityFocusUpdateRequired())
            {
                mask |= 0x4;
            }
            if (Npc.getUpdateFlags().isAnimationUpdateRequired())
            {
                mask |= 0x10;
            }
            if (Npc.getUpdateFlags().isForceTextUpdateRequired())
            {
                mask |= 0x20;
            }
            if (Npc.getUpdateFlags().isHitUpdateRequired())
            {
                mask |= 0x40;
            }
            if (Npc.getUpdateFlags().isGraphicsUpdateRequired())
            {
                mask |= 0x80;
            }
            if (Npc.getUpdateFlags().isFaceLocationUpdateRequired())
            {
                mask |= 0x200;
            }

            if (mask >= 0x100)
            {
                mask |= 0x8;
                updateBlock.addLEShort(mask);

                //updateBlock.addByte((byte)(mask & 0xFF));
                //updateBlock.addByte((byte)(mask >> 8));
            }
            else
            {
                updateBlock.addByte((byte)(mask & 0xFF));
            }

            if (Npc.getUpdateFlags().isHitUpdateRequired())
            {
                appendHitUpdate(Npc, updateBlock);
            }
            if (Npc.getUpdateFlags().isHit2UpdateRequired())
            {
                appendHit2Update(Npc, updateBlock);
            }
            if (Npc.getUpdateFlags().isAnimationUpdateRequired())
            {
                appendAnimationUpdate(Npc, updateBlock);
            }
            if (Npc.getUpdateFlags().isEntityFocusUpdateRequired())
            {
                appendEntityFocusUdate(Npc, updateBlock);
            }
            if (Npc.getUpdateFlags().isGraphicsUpdateRequired())
            {
                appendGraphicsUpdate(Npc, updateBlock);
            }
            //0x1
            if (Npc.getUpdateFlags().isForceTextUpdateRequired())
            {
                appendForceTextUpdate(Npc, updateBlock);
            }
            //0x100
            if (Npc.getUpdateFlags().isFaceLocationUpdateRequired())
            {
                appendFaceLocationUpdate(Npc, updateBlock);
            }
        }
 private static void appendHit2Update(Player p, PacketBuilder updateBlock)
 {
     updateBlock.addByte((byte)p.getHits().getHitDamage2());
     updateBlock.addByteS((byte)p.getHits().getHitType2());
 }
        private static void appendUpdateBlock(Player p, PacketBuilder updateBlock, bool forceAppearance)
        {
            int mask = 0x0;

            AppearanceUpdateFlags flags = p.getUpdateFlags();
            if (flags.isHitUpdateRequired())
            {
                mask |= 0x1;
            }
            if (flags.isEntityFocusUpdateRequired())
            {
                mask |= 0x2;
            }
            if (flags.isAppearanceUpdateRequired() || forceAppearance)
            {
                mask |= 0x4;
            }
            if (flags.isAnimationUpdateRequired())
            {
                mask |= 0x8;
            }
            if (flags.isForceTextUpdateRequired())
            {
                mask |= 0x20;
            }
            if (flags.isFaceLocationUpdateRequired())
            {
                mask |= 0x40;
            }
            if (flags.isChatTextUpdateRequired())
            {
                mask |= 0x80;
            }
            if (flags.isGraphicsUpdateRequired())
            {
                mask |= 0x100;
            }
            if (flags.isHit2UpdateRequired())
            {
                mask |= 0x200;
            }
            if (flags.isForceMovementRequired())
            {
                mask |= 0x400; //mask |= 0x800;
            }

            if (mask >= 0x100) //0x100=256 [full byte], so use two bytes.
            {
                mask |= 0x10;
                updateBlock.addLEShort(mask);

                //updateBlock.addByte((byte)(mask & 0xFF));
                //updateBlock.addByte((byte)(mask >> 8));
            }
            else
            {
                updateBlock.addByte((byte)(mask & 0xFF));
            }

            if (flags.isChatTextUpdateRequired())
            {
                appendChatTextUpdate(p, updateBlock);
            }
            if (flags.isHitUpdateRequired())
            {
                appendHitUpdate(p, updateBlock);
            }
            if (flags.isAnimationUpdateRequired())
            {
                appendAnimationUpdate(p, updateBlock);
            }
            if (flags.isAppearanceUpdateRequired() || forceAppearance)
            {
                appendAppearanceUpdate(p, updateBlock);
            }
            if (flags.isEntityFocusUpdateRequired())
            {
                appendFaceEntityUpdate(p, updateBlock);
            }
            if (flags.isForceMovementRequired())
            {
                appendForceMovement(p, updateBlock);
            }
            if (flags.isForceTextUpdateRequired())
            {
                appendForceTextUpdate(p, updateBlock);
            }
            if (flags.isHit2UpdateRequired())
            {
                appendHit2Update(p, updateBlock);
            }
            if (flags.isGraphicsUpdateRequired())
            {
                appendGraphicsUpdate(p, updateBlock);
            }
            if (flags.isFaceLocationUpdateRequired())
            {
                appendFaceLocationUpdate(p, updateBlock);
            }
        }
        private static void appendUpdateBlock(Player p, PacketBuilder updateBlock, bool forceAppearance)
        {
            int mask = 0x0;

            AppearanceUpdateFlags flags = p.getUpdateFlags();

            if (flags.isHitUpdateRequired())
            {
                mask |= 0x1;
            }
            if (flags.isEntityFocusUpdateRequired())
            {
                mask |= 0x2;
            }
            if (flags.isAppearanceUpdateRequired() || forceAppearance)
            {
                mask |= 0x4;
            }
            if (flags.isAnimationUpdateRequired())
            {
                mask |= 0x8;
            }
            if (flags.isForceTextUpdateRequired())
            {
                mask |= 0x20;
            }
            if (flags.isFaceLocationUpdateRequired())
            {
                mask |= 0x40;
            }
            if (flags.isChatTextUpdateRequired())
            {
                mask |= 0x80;
            }
            if (flags.isGraphicsUpdateRequired())
            {
                mask |= 0x100;
            }
            if (flags.isHit2UpdateRequired())
            {
                mask |= 0x200;
            }
            if (flags.isForceMovementRequired())
            {
                mask |= 0x400; //mask |= 0x800;
            }

            if (mask >= 0x100) //0x100=256 [full byte], so use two bytes.
            {
                mask |= 0x10;
                updateBlock.addLEShort(mask);

                //updateBlock.addByte((byte)(mask & 0xFF));
                //updateBlock.addByte((byte)(mask >> 8));
            }
            else
            {
                updateBlock.addByte((byte)(mask & 0xFF));
            }

            if (flags.isChatTextUpdateRequired())
            {
                appendChatTextUpdate(p, updateBlock);
            }
            if (flags.isHitUpdateRequired())
            {
                appendHitUpdate(p, updateBlock);
            }
            if (flags.isAnimationUpdateRequired())
            {
                appendAnimationUpdate(p, updateBlock);
            }
            if (flags.isAppearanceUpdateRequired() || forceAppearance)
            {
                appendAppearanceUpdate(p, updateBlock);
            }
            if (flags.isEntityFocusUpdateRequired())
            {
                appendFaceEntityUpdate(p, updateBlock);
            }
            if (flags.isForceMovementRequired())
            {
                appendForceMovement(p, updateBlock);
            }
            if (flags.isForceTextUpdateRequired())
            {
                appendForceTextUpdate(p, updateBlock);
            }
            if (flags.isHit2UpdateRequired())
            {
                appendHit2Update(p, updateBlock);
            }
            if (flags.isGraphicsUpdateRequired())
            {
                appendGraphicsUpdate(p, updateBlock);
            }
            if (flags.isFaceLocationUpdateRequired())
            {
                appendFaceLocationUpdate(p, updateBlock);
            }
        }
Esempio n. 19
0
 public void updateClan(Clan c)
 {
     PacketBuilder pb = new PacketBuilder();
     pb.setId(55).setSize(Packet.Size.VariableShort);
     pb.addLong(misc.playerNameToLong(c.getClanOwner()));
     pb.addLong(misc.playerNameToLong(c.getClanName()));
     pb.addByte((byte)c.getKickRights());
     pb.addByte((byte)c.getUserList().Count);
     foreach (ClanUser list in c.getUserList())
     {
         Player p = list.getClanMember();
         pb.addLong(p.getLoginDetails().getLongName());
         pb.addUShort(p.getWorld());
         int rights = Convert.ToInt32(list.getClanRights());
         pb.addByte((byte)rights);
         pb.addString("Server " + p.getWorld());
     }
     connection.SendPacket(pb.toPacket());
 }
Esempio n. 20
0
        public void newClanMessage(Clan c, ChatMessage chatMessage) {
			PacketBuilder pb = new PacketBuilder();
            pb.setId(54).setSize(Packet.Size.VariableByte);
            pb.addLong(chatMessage.getPlayer().getLoginDetails().getLongName());
            pb.addByte((byte)1); // dummy
            pb.addLong(misc.playerNameToLong(c.getClanName()));
            pb.addUShort(0); // some message counter bs
            string message = chatMessage.getChatText();
			int messageCounter = player.getFriends().getNextUniqueId();
            pb.addThreeBytes(messageCounter);
            pb.addByte((byte)chatMessage.getPlayer().getRights());
            pb.addBytes(chatMessage.getPacked());
            connection.SendPacket(pb.toPacket());
        }
 private static void appendAnimationUpdate(Player p, PacketBuilder updateBlock)
 {
     updateBlock.addUShort(p.getLastAnimation().getId());
     updateBlock.addByte((byte)p.getLastAnimation().getDelay());
 }
 private static void appendHitUpdate(Npc Npc, PacketBuilder updateBlock)
 {
     NpcData npcDef = NpcData.forId(Npc.getId());
     int ratio = 1;
     if (npcDef != null)
         ratio = Npc.getHp() * 255 / npcDef.getHitpoints();
     else
         misc.WriteError("Missing npcDef npcId: " + Npc.getId());
     updateBlock.addByte((byte)Npc.getHits().getHitDamage1());
     updateBlock.addByteC((int)Npc.getHits().getHitType1());
     updateBlock.addByteS((byte)ratio);
 }
 private static void appendForceMovement(Player p, PacketBuilder updateBlock)
 {
     Location myLocation = p.getUpdateFlags().getLastRegion();
     ForceMovement fm = p.getForceMovement();
     updateBlock.addByteC(fm.getX1());
     updateBlock.addByte((byte)(fm.getY1()));
     updateBlock.addByteA(fm.getX2());
     updateBlock.addByte((byte)fm.getY2());
     updateBlock.addLEShort(fm.getSpeed1());
     updateBlock.addLEShort(fm.getSpeed2());
     updateBlock.addByteC(fm.getDirection());
 }
 private static void appendAnimationUpdate(Npc Npc, PacketBuilder updateBlock)
 {
     Animation anim = Npc.getLastAnimation();
     if (anim != null)
     {
         updateBlock.addUShort(anim.getId());
         updateBlock.addByte((byte)anim.getDelay());
     }
 }
 private static void appendHit2Update(Player p, PacketBuilder updateBlock)
 {
     updateBlock.addByte((byte)p.getHits().getHitDamage2());
     updateBlock.addByteS((byte)p.getHits().getHitType2());
 }
Esempio n. 26
0
 public void setArrowOnEntity(int type, int id)
 {
     PacketBuilder pb = new PacketBuilder().setId(217);
     int offset = pb.curLength;
     pb.addByte((byte)type); // 10 player, 1 npc
     pb.addByte((byte)((id < 32768) ? 0 : 1)); // arrowtype
     pb.addUShort(id);
     pb.curLength += 3;
     pb.addUShort(65535);
     for (int i = (pb.curLength - offset); i < 9; i++)
     {
         pb.addByte((byte)0);
     }
     connection.SendPacket(pb.toPacket());
 }
        private static void appendAppearanceUpdate(Player p, PacketBuilder updateBlock)
        {
            PacketBuilder playerProps = new PacketBuilder().setSize(Packet.Size.Bare);

            Appearance app = p.getAppearance();

            playerProps.addByte((byte)(app.getGender() & 0xFF));
            if ((app.getGender() & 0x2) == 2)
            {
                playerProps.addByte((byte)0);
                playerProps.addByte((byte)0);
            }
            playerProps.addByte((byte)p.getPrayers().getPkIcon());
            playerProps.addByte((byte)p.getPrayers().getHeadIcon());
            if (!app.isInvisible())
            {
                if (!app.isNpc())
                {
                    for (int i = 0; i < 4; i++)
                    {
                        if (p.getEquipment().getItemInSlot((ItemData.EQUIP)i) != -1)
                        {
                            playerProps.addUShort(32768 + p.getEquipment().getSlot((ItemData.EQUIP)i).getDefinition().getEquipId());
                        }
                        else
                        {
                            playerProps.addByte((byte)0);
                        }
                    }
                    if (p.getEquipment().getItemInSlot(ItemData.EQUIP.CHEST) != -1)
                    {
                        playerProps.addUShort(32768 + p.getEquipment().getSlot(ItemData.EQUIP.CHEST).getDefinition().getEquipId());
                    }
                    else
                    {
                        playerProps.addUShort(0x100 + app.getLook(ItemData.EQUIP.AMULET));
                    }
                    if (p.getEquipment().getItemInSlot(ItemData.EQUIP.SHIELD) != -1)
                    {
                        playerProps.addUShort(32768 + p.getEquipment().getSlot(ItemData.EQUIP.SHIELD).getDefinition().getEquipId());
                    }
                    else
                    {
                        playerProps.addByte((byte)0);
                    }
                    Item chest = p.getEquipment().getSlot(ItemData.EQUIP.CHEST);
                    if (chest != null && chest.getDefinition() != null)
                    {
                        if (!ItemData.isFullBody(chest.getDefinition()))
                        {
                            playerProps.addUShort(0x100 + app.getLook(ItemData.EQUIP.WEAPON));
                        }
                        else
                        {
                            playerProps.addByte((byte)0);
                        }
                    }
                    else
                    {
                        playerProps.addUShort(0x100 + app.getLook(ItemData.EQUIP.WEAPON));
                    }
                    if (p.getEquipment().getItemInSlot(ItemData.EQUIP.LEGS) != -1)
                    {
                        playerProps.addUShort(32768 + p.getEquipment().getSlot(ItemData.EQUIP.LEGS).getDefinition().getEquipId());
                    }
                    else
                    {
                        playerProps.addUShort(0x100 + app.getLook(ItemData.EQUIP.SHIELD));
                    }
                    Item hat = p.getEquipment().getSlot(ItemData.EQUIP.HAT);
                    if (hat != null && hat.getDefinition() != null)
                    {
                        if (!ItemData.isFullHat(hat.getDefinition()) && !ItemData.isFullMask(hat.getDefinition()))
                        {
                            playerProps.addUShort(0x100 + app.getLook(ItemData.EQUIP.HAT));
                        }
                        else
                        {
                            playerProps.addByte((byte)0);
                        }
                    }
                    else
                    {
                        playerProps.addUShort(0x100 + app.getLook(ItemData.EQUIP.HAT));
                    }
                    if (p.getEquipment().getItemInSlot(ItemData.EQUIP.HANDS) != -1)
                    {
                        playerProps.addUShort(32768 + p.getEquipment().getSlot(ItemData.EQUIP.HANDS).getDefinition().getEquipId());
                    }
                    else
                    {
                        playerProps.addUShort(0x100 + app.getLook(ItemData.EQUIP.CHEST));
                    }
                    if (p.getEquipment().getItemInSlot(ItemData.EQUIP.FEET) != -1)
                    {
                        playerProps.addUShort(32768 + p.getEquipment().getSlot(ItemData.EQUIP.FEET).getDefinition().getEquipId());
                    }
                    else
                    {
                        playerProps.addUShort(0x100 + app.getLook(6));
                    }
                    if (hat != null && hat.getDefinition() != null)
                    {
                        if (!ItemData.isFullMask(hat.getDefinition()))
                        {
                            playerProps.addUShort(0x100 + app.getLook(ItemData.EQUIP.CAPE));
                        }
                        else
                        {
                            playerProps.addByte((byte)0);
                        }
                    }
                    else
                    {
                        playerProps.addUShort(0x100 + app.getLook(ItemData.EQUIP.CAPE));
                    }
                }
                else
                {
                    playerProps.addUShort(-1);
                    playerProps.addUShort(app.getNpcId());
                    playerProps.addByte((byte)255);
                }
            }
            else
            {
                for (int i = 0; i < 12; i++)
                {
                    playerProps.addByte((byte)0);
                }
            }
            foreach (int colour in app.getColoursArray())
            {
                playerProps.addByte((byte)colour);
            }
            playerProps.addUShort(p.getEquipment().getStandWalkAnimation());
            playerProps.addLong(p.getLoginDetails().getLongName());
            playerProps.addByte((byte)p.getSkills().getCombatLevel());
            playerProps.addUShort(0);
            playerProps.addByte((byte)0);
            updateBlock.addByteA((byte)(playerProps.getLength() & 0xFF));
            updateBlock.addBytes(playerProps.toPacket().getData(), 0, playerProps.getLength());
        }
Esempio n. 28
0
 public void setArrowOnPosition(int x, int y, int height)
 {
     PacketBuilder pb = new PacketBuilder().setId(217);
     int offset = pb.curLength;
     pb.addByte((byte)2);
     pb.addByte((byte)0);
     pb.addUShort(x);
     pb.addUShort(y);
     pb.addByte((byte)height);
     pb.addUShort(65535);
     for (int i = (pb.curLength - offset); i < 9; i++)
     {
         pb.addByte((byte)0);
     }
     connection.SendPacket(pb.toPacket());
 }
        public void loadSaveThread()
        {
            while (true)
            {
                try
                {
                    Thread.Sleep(30);
                }
                catch (ThreadInterruptedException)
                {
                    forceSaveAllPlayers();
                    break;
                }

                lock(playersToLoad) {
				    if(playersToLoad.Count > 0) {

                        Connection connection = null;
					    while(playersToLoad.Count > 0) {
                            connection = playersToLoad.Dequeue();
                            if (connection != null) {
                                ReturnCode returnCode = loadPlayer(connection);
						        PacketBuilder pb = new PacketBuilder().setSize(Packet.Size.Bare);
						        int slot = -1;
                                if (returnCode == ReturnCode.LOGIN_OK)
                                {
                                    slot = Server.register(connection);
							        if(slot == -1) {
                                        returnCode = ReturnCode.WORLD_FULL;
							        }
						        }
						        pb.addByte((byte) returnCode);
                                if (returnCode == ReturnCode.LOGIN_OK) {
                                    pb.addByte((byte)connection.getPlayer().getRights()); // rights
                                    pb.addByte((byte)0); //1
                                    pb.addByte((byte)0);//Flagged, will genrate mouse packets
                                    pb.addByte((byte)0); //3
                                    pb.addByte((byte)0); //4
                                    pb.addByte((byte)0); //5
                                    pb.addByte((byte)0); // Generates packets
                                    pb.addUShort(slot);//PlayerID
                                    pb.addByte((byte)1); // membership flag #1?..this one enables all GE boxes
                                    pb.addByte((byte)1); // membership flag #2?
                                    connection.SendPacket(pb.toPacket());
                                    connection.getPlayer().getPackets().sendMapRegion();
                                    connection.getPlayer().setActive(true);
                                    Console.WriteLine("Loaded " + connection.getPlayer().getLoginDetails().getUsername() + "'s game: returncode = " + returnCode + ".");
                                } else {
                                    connection.SendPacket(pb.toPacket());
                                }
				            }
					    }
				    }
			    }
			    lock(playersToSave) {
				    if(playersToSave.Count > 0) {
					    Player p = null;
					    while(playersToSave.Count > 0) {
                            p = playersToSave.Dequeue();
                            if(p != null) {
						        if(savePlayer(p)) {
							        Console.WriteLine("Saved " + p.getLoginDetails().getUsername() + "'s game.");
						        } else {
							        Console.WriteLine("Could not save " +  p.getLoginDetails().getUsername() + "'s game.");
						        }
                            }
					    }
				    }
			    }
            }
        }