예제 #1
0
		public virtual void SendNPCCreate(GameNPC npc)
		{
			if (m_gameClient.Player == null || npc.IsVisibleTo(m_gameClient.Player) == false)
				return;

			if (npc is GameMovingObject)
			{
				SendMovingObjectCreate(npc as GameMovingObject);
				return;
			}

			using (var pak = new GSTCPPacketOut(GetPacketCode(eServerPackets.NPCCreate)))
			{
				int speed = 0;
				ushort speedZ = 0;
				if (npc.IsMoving && !npc.IsAtTargetPosition)
				{
					speed = npc.CurrentSpeed;
					speedZ = (ushort) npc.TickSpeedZ;
				}
				pak.WriteShort((ushort) npc.ObjectID);
				pak.WriteShort((ushort) speed);
				pak.WriteShort(npc.Heading);
				pak.WriteShort((ushort) npc.Z);
				pak.WriteInt((uint) npc.X);
				pak.WriteInt((uint) npc.Y);
				pak.WriteShort(speedZ);
				pak.WriteShort(npc.Model);
				pak.WriteByte(npc.Size);
				pak.WriteByte(npc.GetDisplayLevel(m_gameClient.Player));

				var flags = (byte) (GameServer.ServerRules.GetLivingRealm(m_gameClient.Player, npc) << 6);
				if ((npc.Flags & GameNPC.eFlags.GHOST) != 0) flags |= 0x01;
				if (npc.Inventory != null)
					flags |= 0x02; //If mob has equipment, then only show it after the client gets the 0xBD packet
				if ((npc.Flags & GameNPC.eFlags.PEACE) != 0) flags |= 0x10;
				if ((npc.Flags & GameNPC.eFlags.FLYING) != 0) flags |= 0x20;

				pak.WriteByte(flags);
				pak.WriteByte(0x20); //TODO this is the default maxstick distance

				string add = "";
				if (m_gameClient.Account.PrivLevel > 1)
				{
					if ((npc.Flags & GameNPC.eFlags.CANTTARGET) != 0)
						add += "-DOR"; // indicates DOR flag for GMs
					if ((npc.Flags & GameNPC.eFlags.DONTSHOWNAME) != 0)
						add += "-NON"; // indicates NON flag for GMs
				}

                DBLanguageNPC translation = npc.GetTranslation(m_gameClient);

                string name = translation.Name;/*npc.Name;*/
				if (name.Length + add.Length + 2 > 47) // clients crash with too long names
					name = name.Substring(0, 47 - add.Length - 2);
				if (add.Length > 0)
					name = string.Format("[{0}]{1}", name, add);

				pak.WritePascalString(name);

                //if (npc.GuildName.Length > 47)
                //    pak.WritePascalString(npc.GuildName.Substring(0, 47));
                //else pak.WritePascalString(npc.GuildName);

                string guildName = translation.GuildName;
                if (guildName.Length > 47)
                    guildName = guildName.Substring(0, 47);

                pak.WritePascalString(guildName);
				pak.WriteByte(0x00);

				SendTCP(pak);
			}
		}
예제 #2
0
		public override void SendNPCCreate(GameNPC npc)
		{

			if (m_gameClient.Player == null || npc.IsVisibleTo(m_gameClient.Player) == false)
				return;

			//Added by Suncheck - Mines are not shown to enemy players
			if (npc is GameMine)
			{
				if (GameServer.ServerRules.IsAllowedToAttack((npc as GameMine).Owner, m_gameClient.Player, true))
				{
					return;
				}
			}

			if (npc is GameMovingObject)
			{
				SendMovingObjectCreate(npc as GameMovingObject);
				return;
			}

			GSTCPPacketOut pak = new GSTCPPacketOut(GetPacketCode(eServerPackets.NPCCreate));
			int speed = 0;
			ushort speedZ = 0;
			if (npc == null)
				return;
			if (!npc.IsAtTargetPosition)
			{
				speed = npc.CurrentSpeed;
				speedZ = (ushort)npc.TickSpeedZ;
			}
			pak.WriteShort((ushort)npc.ObjectID);
			pak.WriteShort((ushort)(speed));
			pak.WriteShort(npc.Heading);
			pak.WriteShort((ushort)npc.Z);
			pak.WriteInt((uint)npc.X);
			pak.WriteInt((uint)npc.Y);
			pak.WriteShort(speedZ);
			pak.WriteShort(npc.Model);
			pak.WriteByte(npc.Size);
			byte level = npc.GetDisplayLevel(m_gameClient.Player);
			if((npc.Flags&GameNPC.eFlags.STATUE)!=0)
			{
				level |= 0x80;
			}
			pak.WriteByte(level);

			byte flags = (byte)(GameServer.ServerRules.GetLivingRealm(m_gameClient.Player, npc) << 6);
			if ((npc.Flags & GameNPC.eFlags.GHOST) != 0) flags |= 0x01;
			if (npc.Inventory != null) flags |= 0x02; //If mob has equipment, then only show it after the client gets the 0xBD packet
			if ((npc.Flags & GameNPC.eFlags.PEACE) != 0) flags |= 0x10;
			if ((npc.Flags & GameNPC.eFlags.FLYING) != 0) flags |= 0x20;
			if((npc.Flags & GameNPC.eFlags.TORCH) != 0) flags |= 0x04;
			
			pak.WriteByte(flags);
			pak.WriteByte(0x20); //TODO this is the default maxstick distance

			string add = "";
			byte flags2 = 0x00;
			IControlledBrain brain = npc.Brain as IControlledBrain;
			if (m_gameClient.Version >= GameClient.eClientVersion.Version187)
			{
				if (brain != null)
				{
					flags2 |= 0x80; // have Owner
				}
			}
			if ((npc.Flags & GameNPC.eFlags.CANTTARGET) != 0)
				if (m_gameClient.Account.PrivLevel > 1) add += "-DOR"; // indicates DOR flag for GMs
			else flags2 |= 0x01;
			if ((npc.Flags & GameNPC.eFlags.DONTSHOWNAME) != 0)
				if (m_gameClient.Account.PrivLevel > 1) add += "-NON"; // indicates NON flag for GMs
			else flags2 |= 0x02;

			if( ( npc.Flags & GameNPC.eFlags.STEALTH ) > 0 )
				flags2 |= 0x04;

			if( npc.ShowQuestIndicator( m_gameClient.Player ) )
				flags2 |= 0x08;

			pak.WriteByte(flags2); // 4 high bits seems unused (new in 1.71)
			pak.WriteShort(0x00); // new in 1.71
			pak.WriteByte(0x00); // new in 1.71 (region instance ID from StoC_0x20)

            DBLanguageNPC translation = npc.GetTranslation(m_gameClient);

            string name = translation.Name;/*GameServer.ServerRules.GetNPCName(m_gameClient.Player, npc);*/
			if (name.Length + add.Length + 2 > 47) // clients crash with too long names
				name = name.Substring(0, 47 - add.Length - 2);
			if (add.Length > 0)
				name = string.Format("[{0}]{1}", name, add);

			pak.WritePascalString(name);

            string l_npcGuildname = translation.GuildName;/*GameServer.ServerRules.GetNPCGuildName(m_gameClient.Player, npc);;*/
			if (l_npcGuildname.Length > 47)
				pak.WritePascalString(l_npcGuildname.Substring(0, 47));
			else pak.WritePascalString(l_npcGuildname);

			pak.WriteByte(0x00);
			SendTCP(pak);
		}