Ejemplo n.º 1
0
        private static void SetAlterItemDropNextFlags(PacketWriter alterItemDrop, CustomWeapon weapon)
        {
            alterItemDrop.PackByte(GetAlterEndFlags(weapon));

            if (weapon.DropAreaWidth != null)
            {
                alterItemDrop.PackInt16((short)weapon.DropAreaWidth);
            }

            if (weapon.DropAreaHeight != null)
            {
                alterItemDrop.PackInt16((short)weapon.DropAreaHeight);
            }

            if (weapon.Scale != null)
            {
                alterItemDrop.PackSingle((float)weapon.Scale);
            }

            if (weapon.AmmoIdentifier != null)
            {
                alterItemDrop.PackInt16((short)weapon.AmmoIdentifier);
            }

            if (weapon.UseAmmoIdentifier != null)
            {
                alterItemDrop.PackInt16((short)weapon.UseAmmoIdentifier);
            }

            if (weapon.NotAmmo != null)
            {
                alterItemDrop.PackByte((byte)(((bool)weapon.NotAmmo) ? 1 : 0));
            }
        }
Ejemplo n.º 2
0
 public bool Equals(CustomWeapon other)
 {
     if (other == null)
     {
         return(false);
     }
     return(ItemNetId == other.ItemNetId);
 }
Ejemplo n.º 3
0
        public override bool Equals(object obj)
        {
            CustomWeapon custwep = obj as CustomWeapon;

            if (custwep == null)
            {
                return(false);
            }
            return(Equals(custwep));
        }
Ejemplo n.º 4
0
        private static byte[] GetAlterItemDropPacket(CustomWeapon weapon, int itemIndex)
        {
            var flags1        = GetAlterStartFlags(weapon);
            var alterItemDrop = new PacketWriter()
                                .SetType(88)
                                .PackInt16((short)itemIndex)
                                .PackByte(flags1);

            if (weapon.Color != null)
            {
                var color = 0xFF000000;
                color += (uint)weapon.Color?.R;
                color += (uint)weapon.Color?.G << 8;
                color += (uint)weapon.Color?.B << 16;
                alterItemDrop.PackUInt32(color);
            }

            if (weapon.Damage != null)
            {
                alterItemDrop.PackUInt16((ushort)weapon.Damage);
            }

            if (weapon.Knockback != null)
            {
                alterItemDrop.PackSingle((float)weapon.Knockback);
            }

            if (weapon.UseAnimation != null)
            {
                alterItemDrop.PackUInt16((ushort)weapon.UseAnimation);
            }

            if (weapon.UseTime != null)
            {
                alterItemDrop.PackUInt16((ushort)weapon.UseTime);
            }

            if (weapon.ShootProjectileId != null)
            {
                alterItemDrop.PackInt16((short)weapon.ShootProjectileId);
            }

            if (weapon.ShootSpeed != null)
            {
                alterItemDrop.PackSingle((float)weapon.ShootSpeed);
            }

            if ((flags1 & 128) != 0)
            {
                SetAlterItemDropNextFlags(alterItemDrop, weapon);
            }

            return(alterItemDrop.GetByteData());
        }
Ejemplo n.º 5
0
        private static byte GetAlterStartFlags(CustomWeapon weapon)
        {
            byte flagByte = 0;

            if (weapon.Color != null)
            {
                flagByte += 1;
            }

            if (weapon.Damage != null)
            {
                flagByte += 2;
            }

            if (weapon.Knockback != null)
            {
                flagByte += 4;
            }

            if (weapon.UseAnimation != null)
            {
                flagByte += 8;
            }

            if (weapon.UseTime != null)
            {
                flagByte += 16;
            }

            if (weapon.ShootProjectileId != null)
            {
                flagByte += 32;
            }

            if (weapon.ShootSpeed != null)
            {
                flagByte += 64;
            }

            var nextFlags = weapon.DropAreaWidth != null || weapon.DropAreaHeight != null || weapon.Scale != null ||
                            weapon.AmmoIdentifier != null || weapon.UseAmmoIdentifier != null || weapon.NotAmmo != null;

            if (nextFlags)
            {
                flagByte += 128;
            }

            return(flagByte);
        }
Ejemplo n.º 6
0
        public static void DropItem(TSPlayer player, CustomWeapon weapon)
        {
            int freeIndex = 400;

            for (int i = 0; i < 400; ++i)
            {
                if (!Main.item[i].active && Main.timeItemSlotCannotBeReusedFor[i] == 0)
                {
                    freeIndex = i;
                    break;
                }
            }

            Main.timeItemSlotCannotBeReusedFor[freeIndex] = 0;

            Main.item[freeIndex]        = new Item();
            Main.item[freeIndex].active = true;

            var itemDrop = new PacketWriter()
                           .SetType((int)PacketTypes.UpdateItemDrop)
                           .PackInt16((short)freeIndex)
                           .PackSingle(player.TPlayer.position.X - short.MaxValue / 2f) //This line of code was modified from the API
                           .PackSingle(player.TPlayer.position.Y - short.MaxValue / 2f) //This line of code was modified from the API
                           .PackSingle(0)
                           .PackSingle(0)
                           .PackInt16(weapon.Stack ?? 1)
                           .PackByte(weapon.Prefix ?? 0)
                           .PackByte(0)
                           .PackInt16(weapon.ItemNetId)
                           .GetByteData();
            var itemOwner = new PacketWriter()
                            .SetType((int)PacketTypes.ItemOwner)
                            .PackInt16((short)freeIndex)
                            .PackByte((byte)player.Index)
                            .GetByteData();

            player.SendRawData(itemDrop);
            player.SendRawData(GetAlterItemDropPacket(weapon, freeIndex));
            player.SendRawData(itemOwner);
        }
Ejemplo n.º 7
0
        public CustomWeapon(CustomWeapon weapon)
        {
            Prefix    = weapon.Prefix;
            ItemNetId = weapon.ItemNetId;
            if (weapon.Color != null)
            {
                Color = new Color(((Color)weapon.Color).R, ((Color)weapon.Color).G, ((Color)weapon.Color).B);
            }

            Stack             = weapon.Stack;
            Damage            = weapon.Damage;
            Knockback         = weapon.Knockback;
            UseAnimation      = weapon.UseAnimation;
            UseTime           = weapon.UseTime;
            ShootProjectileId = weapon.ShootProjectileId;
            ShootSpeed        = weapon.ShootSpeed;
            Scale             = weapon.Scale;
            AmmoIdentifier    = weapon.AmmoIdentifier;
            UseAmmoIdentifier = weapon.UseAmmoIdentifier;
            NotAmmo           = weapon.NotAmmo;
            DropAreaHeight    = weapon.DropAreaHeight;
            DropAreaWidth     = weapon.DropAreaHeight;
        }
Ejemplo n.º 8
0
        private static byte GetAlterEndFlags(CustomWeapon weapon)
        {
            byte flagByte = 0;

            if (weapon.DropAreaWidth != null)
            {
                flagByte += 1;
            }

            if (weapon.DropAreaHeight != null)
            {
                flagByte += 2;
            }

            if (weapon.Scale != null)
            {
                flagByte += 4;
            }

            if (weapon.AmmoIdentifier != null)
            {
                flagByte += 8;
            }

            if (weapon.UseAmmoIdentifier != null)
            {
                flagByte += 16;
            }

            if (weapon.NotAmmo != null)
            {
                flagByte += 32;
            }

            return(flagByte);
        }