public PacketWriter UpdateObject(ref UpdateClass uc) { PacketWriter packet = new PacketWriter(Opcodes.SMSG_UPDATE_OBJECT); packet.WriteUInt32(1); //Number of transactions packet.WriteUInt8(0); packet.WriteUInt64(Guid); packet.WriteUInt8(GetUpdateMask()); packet.WriteBytes(uc.GetMask()); //Mask of updated fields uc.BuildPacket(ref packet, false); //Only appends updated values return(packet); }
public override PacketWriter BuildUpdate(UpdateTypes type = UpdateTypes.UPDATE_PARTIAL, bool self = false) { //Send update packet PacketWriter writer = CreateObject(false); UpdateClass uc = new UpdateClass(); //Object Fields uc.UpdateValue <ulong>(ObjectFields.OBJECT_FIELD_GUID, this.Guid); uc.UpdateValue <uint>(ObjectFields.OBJECT_FIELD_TYPE, (uint)this.ObjectType); // UpdateType, 0x9 - (Unit + Object) uc.UpdateValue <uint>(ObjectFields.OBJECT_FIELD_ENTRY, this.Entry); uc.UpdateValue <float>(ObjectFields.OBJECT_FIELD_SCALE_X, this.Scale); //Unit Fields uc.UpdateValue <uint>(UnitFields.UNIT_CHANNEL_SPELL, this.ChannelSpell); uc.UpdateValue <ulong>(UnitFields.UNIT_FIELD_CHANNEL_OBJECT, this.ChannelSpell); uc.UpdateValue <uint>(UnitFields.UNIT_FIELD_HEALTH, this.Health.Current); uc.UpdateValue <uint>(UnitFields.UNIT_FIELD_MAXHEALTH, this.Health.Maximum); uc.UpdateValue <uint>(UnitFields.UNIT_FIELD_LEVEL, this.Template.Level.Maximum); uc.UpdateValue <uint>(UnitFields.UNIT_FIELD_FACTIONTEMPLATE, this.Template.FactionA); uc.UpdateValue <uint>(UnitFields.UNIT_FIELD_FLAGS, this.Template.UnitFlags); uc.UpdateValue <float>(UnitFields.UNIT_FIELD_BASEATTACKTIME, this.Template.AttackTime); //Main hand uc.UpdateValue <float>(UnitFields.UNIT_FIELD_BASEATTACKTIME, 0f, 1); //Offhand uc.UpdateValue <uint>(UnitFields.UNIT_FIELD_RESISTANCES, this.Template.Armor.BaseAmount); uc.UpdateValue <uint>(UnitFields.UNIT_FIELD_RESISTANCES, this.Template.Holy.BaseAmount, 1); uc.UpdateValue <uint>(UnitFields.UNIT_FIELD_RESISTANCES, this.Template.Fire.BaseAmount, 2); uc.UpdateValue <uint>(UnitFields.UNIT_FIELD_RESISTANCES, this.Template.Nature.BaseAmount, 3); uc.UpdateValue <uint>(UnitFields.UNIT_FIELD_RESISTANCES, this.Template.Frost.BaseAmount, 4); uc.UpdateValue <uint>(UnitFields.UNIT_FIELD_RESISTANCES, this.Template.Shadow.BaseAmount, 5); uc.UpdateValue <float>(UnitFields.UNIT_FIELD_BOUNDINGRADIUS, this.Template.BoundingRadius); uc.UpdateValue <float>(UnitFields.UNIT_FIELD_COMBATREACH, this.Template.CombatReach); uc.UpdateValue <uint>(UnitFields.UNIT_FIELD_DISPLAYID, this.Template.ModelID); uc.UpdateValue <uint>(UnitFields.UNIT_FIELD_COINAGE, this.Money); uc.UpdateValue <float>(UnitFields.UNIT_MOD_CAST_SPEED, 1f); uc.UpdateValue <uint>(UnitFields.UNIT_FIELD_DAMAGE, ByteConverter.ConvertToUInt32((ushort)this.Template.Damage.Current, (ushort)this.Template.Damage.Maximum)); uc.UpdateValue <uint>(UnitFields.UNIT_DYNAMIC_FLAGS, this.DynamicFlags); uc.UpdateValue <uint>(UnitFields.UNIT_FIELD_BYTES_1, ByteConverter.ConvertToUInt32(this.StandState, this.NPCFlags, 0, 0)); uc.BuildPacket(ref writer, true); writer.Compress(); return(writer); }
public override PacketWriter BuildUpdate(UpdateTypes type = UpdateTypes.UPDATE_FULL, bool self = false) { PacketWriter packet = null; switch (type) { case UpdateTypes.UPDATE_FULL: packet = CreateObject(false); break; default: packet = new PacketWriter(Opcodes.SMSG_UPDATE_OBJECT); break; } UpdateClass uc = new UpdateClass(); uc.UpdateValue <ulong>(ObjectFields.OBJECT_FIELD_GUID, this.Guid); uc.UpdateValue <uint>(ObjectFields.OBJECT_FIELD_TYPE, (uint)this.ObjectType); uc.UpdateValue <uint>(ObjectFields.OBJECT_FIELD_ENTRY, this.Entry); uc.UpdateValue <float>(ObjectFields.OBJECT_FIELD_SCALE_X, 1f); uc.UpdateValue <uint>(ObjectFields.OBJECT_FIELD_PADDING, 0); uc.UpdateValue <ulong>(ItemFields.ITEM_FIELD_OWNER, this.Owner); uc.UpdateValue <ulong>(ItemFields.ITEM_FIELD_CREATOR, this.Creator); uc.UpdateValue <ulong>(ItemFields.ITEM_FIELD_CONTAINED, this.Contained); uc.UpdateValue <uint>(ItemFields.ITEM_FIELD_STACK_COUNT, this.StackCount); uc.UpdateValue <uint>(ItemFields.ITEM_FIELD_FLAGS, this.Template.Flags); for (int i = 0; i < 5; i++) { uc.UpdateValue <uint>(ItemFields.ITEM_FIELD_SPELL_CHARGES, this.SpellCharges[i], i); } if (this.IsContainer) //Is a container { var c = (Container)this; if (c.IsBackpack) //Just incase { return(null); } uc.UpdateValue <uint>(ContainerFields.CONTAINER_FIELD_NUM_SLOTS, c.TotalSlots); for (int i = 0; i < Container.MAX_BAG_SLOTS; i++) { ulong iguid = c.Slots.ContainsKey((uint)i) ? c.Slots[(uint)i] : 0; uc.UpdateValue <ulong>(ContainerFields.CONTAINER_FIELD_SLOT_1, iguid, i * 2); } } switch (type) { case UpdateTypes.UPDATE_PARTIAL: return(UpdateObject(ref uc)); case UpdateTypes.UPDATE_FULL: uc.BuildPacket(ref packet, true); return(packet); default: return(null); } }