/// <summary> /// 各パラメーターをデフォルトにします /// </summary> public void SetDefault() { Hidden = childChanged = lastOnMouse = mouseLeftDown = mouseRightDown = mouseMiddleDown = false; Scale = Vector2.One; lastMousePos = Position = RotationCenter = ScaleCenter = Vector2.Zero; Alpha = 1; Rotation = 0; PreScreenFilters.Clear(); PostScreenFilters.Clear(); ColorFilters.Clear(); RenderMasks.Clear(); }
/// <summary> /// Constructs the npc rendering packet. /// </summary> /// <param name="character">Character to send rendered npcs to.</param> /// <param name="allNpcs">A list of npcs that are spawned on the server.</param> public NpcRenderingPacketComposer(Character character, List <Npc> allNpcs) { SetOpcode(222); SetType(PacketType.Short); InitializeBit(); // The update block. Any updates that are pending will be added to this block. GenericPacketComposer updateBlock = new GenericPacketComposer(); AppendBits(8, character.LocalNpcs.Count); // A bin of npcs that have been removed during local npc updating. List <Npc> npcBin = new List <Npc>(); character.LocalNpcs.ForEach((npc) => { if (GameEngine.World.NpcManager.Spawns.Values.Contains(npc) && npc.Location.WithinDistance(character.Location) && !character.UpdateFlags.Teleporting) { UpdateMovement(npc, this); // Update the npc is required, since it is conditionally valid. if (npc.UpdateFlags.UpdateRequired) { RenderMasks.AppendMasks(npc, updateBlock); } } else { // Remove this npc, as it doesn't meet local standards. npcBin.Add(npc); // Signify the client that this npc needs to be removed. AppendBits(1, 1); AppendBits(2, 3); } }); // Remove all binned npcs. npcBin.ForEach((npc) => character.LocalNpcs.Remove(npc)); // Search for npcs that may qualify for locality. foreach (Npc npc in allNpcs) { // We cannot have more than 255 npcs in the client simultaneously. if (character.LocalNpcs.Count >= 255) { break; } if (character.LocalNpcs.Contains(npc) || !npc.Location.WithinDistance(character.Location)) { continue; } character.LocalNpcs.Add(npc); AddNewNpc(character, npc, this); // Update the npc if required. if (npc.UpdateFlags.UpdateRequired) { RenderMasks.AppendMasks(npc, updateBlock); } } // Finalize the composition. if (updateBlock.Position >= 3) { AppendBits(15, 32767); } FinishBit(); if (updateBlock.Position > 0) { AppendBytes(updateBlock.SerializeBuffer()); } }
/// <summary> /// Constructs the character rendering packet. /// </summary> /// <param name="character">The character to update.</param> /// <param name="allChars">A collection of characters that are checked against a few conditions.</param> public CharacterRenderingPacketComposer(Character character, List <Character> allChars) { if (character.UpdateFlags.MapRegionChanging) { Frames.SendMapRegion(character); } SetOpcode(216); SetType(PacketType.Short); InitializeBit(); // The update block. Any updates that are pending will be added to this block. GenericPacketComposer updateBlock = new GenericPacketComposer(); // Update this character's movement. UpdateThisMovement(character, this); if (character.UpdateFlags.UpdateRequired) { /* * No need to force appeal since appearance hasn't changed * (unless appearance update is requied in update flags). */ RenderMasks.AppendMasks(character, updateBlock, false); } AppendBits(8, character.LocalCharacters.Count); // Characters that have been binned during local characters updating. List <Character> charBin = new List <Character>(); character.LocalCharacters.ForEach((otherCharacter) => { if (GameEngine.World.CharacterManager.Contains(otherCharacter) && !otherCharacter.UpdateFlags.Teleporting && otherCharacter.Location.WithinDistance(character.Location) && otherCharacter.Session.Connection.Connected) { UpdateMovement(otherCharacter, this); if (otherCharacter.UpdateFlags.UpdateRequired) { RenderMasks.AppendMasks(otherCharacter, updateBlock, false); } } else { // Remove this character, as it doesn't meet local standards. charBin.Add(otherCharacter); // Signify the client that this character needs to be removed. AppendBits(1, 1); AppendBits(2, 3); } }); // Remove binned characters. charBin.ForEach((c) => character.LocalCharacters.Remove(c)); foreach (Character otherCharacter in allChars) { /* * If there is no more space in the local area for the main character to * see, then we will not show those other characters until some leave. */ if (character.LocalCharacters.Count > 255) { break; } if (otherCharacter == character || character.LocalCharacters.Contains(otherCharacter) || !otherCharacter.Location.WithinDistance(character.Location)) { continue; } character.LocalCharacters.Add(otherCharacter); AddNewCharacter(character, otherCharacter, this); RenderMasks.AppendMasks(otherCharacter, updateBlock, true); } /* * If there are masks that need updating, we will append a * special key identifying the start of the update masks, * and append the serialized update block. */ if (!updateBlock.Empty) { AppendBits(11, 2047); // Finish bit access so we can write bytes normally. FinishBit(); AppendBytes(updateBlock.SerializeBuffer()); } else { // Nothing else to write. FinishBit(); } }