Exemplo n.º 1
0
        /// <summary>
        /// Removes a players projectile
        /// </summary>
        /// <param name="projectileId">The index of the projectile</param>
        public void RemoveProjectile(int projectileId)
        {
            var projectileDestroy = new PacketFactory()
                                    .SetType((int)PacketTypes.ProjectileDestroy)
                                    .PackInt16((short)projectileId)
                                    .PackByte((byte)TPlayer.whoAmI) // Owner
                                    .GetByteData();

            var projectileNew = new PacketFactory()
                                .SetType((int)PacketTypes.ProjectileNew)
                                .PackInt16((short)projectileId)
                                .PackSingle(0)                  // Position
                                .PackSingle(0)
                                .PackSingle(0)                  // Velocity
                                .PackSingle(0)
                                .PackSingle(0)                  // Knockback
                                .PackInt16(0)                   // Damage
                                .PackByte((byte)TPlayer.whoAmI) // Owner
                                .PackInt16((short)0)            // Type
                                .PackByte(0)                    // AI
                                .GetByteData();

            TshockPlayer.SendRawData(projectileDestroy);
            TshockPlayer.SendRawData(projectileNew);
        }
Exemplo n.º 2
0
 /**
  * Tells the player that the weapon they are using does not work in pvp.
  */
 public void TellWeaponIsIneffective()
 {
     if ((DateTime.Now - LastMessage).TotalSeconds > 2)
     {
         TshockPlayer.SendMessage("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++", Color.Red);
         TshockPlayer.SendMessage("That weapon does not work in PVP. Using it will cause you to do no damage!", Color.Red);
         TshockPlayer.SendMessage("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++", Color.Red);
         LastMessage = DateTime.Now;
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// Removes a projectile and tells the player that it does not work.
        /// </summary>
        /// <param name="hideDisallowedProjectiles">Whether or not to hide the projectile</param>
        /// <param name="projectileId">The index of the projectile</param>
        public void RemoveProjectileAndTellIsIneffective(int projectileId)
        {
            RemoveProjectile(projectileId);

            if ((DateTime.Now - LastMessage).TotalSeconds > 2)
            {
                TshockPlayer.SendMessage("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++", Color.Red);
                TshockPlayer.SendMessage("That projectile does not work in PVP. Using it will cause you to do no damage!", Color.Red);
                TshockPlayer.SendMessage("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++", Color.Red);
                LastMessage = DateTime.Now;
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Modifies a projectile based on the controller settings
        /// </summary>
        /// <param name="args">The information about the projectile</param>
        /// <returns></returns>
        internal bool ModifyProjectile(ProjectileArgs args)
        {
            int existingIndex = ProjectileUtils.FindProjectileIndex(args.Ident, TPlayer.whoAmI);
            var proj          = new Projectile();

            proj.SetDefaults(args.Type);

            Item weaponUsed = TshockPlayer.SelectedItem;

            weaponUsed = ProjectileMapper.DetermineWeaponUsed(args.Type, this);

            if (existingIndex > -1)
            {
                return(false);
            }

            // Apply buffs to user if weapon buffs exist
            if (Controller.Weapons.Count(p => p.netID == weaponUsed.netID && p.buffs.Count() > 0) > 0)
            {
                if (proj.ranged && args.Damage > 0)
                {
                    var weapon      = Controller.Weapons.FirstOrDefault(p => p.netID == TshockPlayer.SelectedItem.netID);
                    var weaponBuffs = weapon.buffs;
                    foreach (var weaponBuff in weaponBuffs)
                    {
                        TshockPlayer.SetBuff(weaponBuff.netID, Convert.ToInt32((weaponBuff.milliseconds / 1000f) * 60), true);
                    }
                }
            }

            // Load weapon modifications if this is a damaging projectile and the used weapon has modifications
            var modification = Controller.Projectiles.FirstOrDefault(p => p.netID == args.Type);

            StorageTypes.Weapon weaponModification = null;
            if (args.Damage > 0)
            {
                weaponModification = Controller.Weapons.FirstOrDefault(p => p.netID == TshockPlayer.SelectedItem.netID);
            }


            // Apply modifications and update if they exist
            if ((modification != null && modification.velocityRatio != 1f) || (weaponModification != null && weaponModification.velocityRatio != 1f))
            {
                int freeIndex = ProjectileUtils.FindFreeIndex();

                if (freeIndex > -1)
                {
                    proj = Main.projectile[freeIndex];
                    var velocity = args.Velocity;
                    if (modification != null)
                    {
                        velocity *= modification.velocityRatio;
                    }

                    if (weaponModification != null)
                    {
                        velocity *= weaponModification.velocityRatio;
                    }
                    proj.SetDefaults(args.Type);
                    proj.damage   = args.Damage;
                    proj.active   = true;
                    proj.identity = args.Ident;
                    proj.owner    = args.Owner;
                    proj.velocity = velocity;
                    proj.position = args.Position;
                    NetMessage.SendData((int)PacketTypes.ProjectileNew, -1, -1, NetworkText.FromLiteral(""), freeIndex);
                }

                return(true);
            }

            return(false);
        }