示例#1
0
        public override int use(PlayerBase user, WorldBase world, Vector2 location, GameTime time, BinaryInputManager inputManager)
        {
            base.use(user, world, location, time, inputManager);

            int used = 0;

            Item_Arrow item_arrow = (Item_Arrow)user.inventory.getItemOfType(new Item_Arrow(1));

            if (item_arrow != null)
            {
                user.inventory.consume(item_arrow, 1);

                EntityArrow arrow = new EntityArrow(user.location + new Vector2(0, -15), world, user);
                arrow.velocity += Vector2.Normalize(location - user.location) * 30;
                world.addEntity(arrow);
                used = 1;

                SoundManager.getSound("bow-throw").playWithVariance(0, .2f, 0, SoundType.MONSTER);
            }
            else
            {
                user.speechManager.addSpeechBubble(Game1.texture_entity_arrow);
            }



            return(used);
        }
示例#2
0
 /// <summary>
 /// returns EntityDamageSourceIndirect of an arrow
 /// </summary>
 public static DamageSource CauseArrowDamage(EntityArrow par0EntityArrow, Entity par1Entity)
 {
     return((new EntityDamageSourceIndirect("arrow", par0EntityArrow, par1Entity)).SetProjectile());
 }
        /// <summary>
        /// called when the player releases the use item button. Args: itemstack, world, entityplayer, itemInUseCount
        /// </summary>
        public override void OnPlayerStoppedUsing(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer, int par4)
        {
            bool flag = par3EntityPlayer.Capabilities.IsCreativeMode || EnchantmentHelper.GetEnchantmentLevel(Enchantment.Infinity.EffectId, par1ItemStack) > 0;

            if (flag || par3EntityPlayer.Inventory.HasItem(Item.Arrow.ShiftedIndex))
            {
                int   i = GetMaxItemUseDuration(par1ItemStack) - par4;
                float f = (float)i / 20F;
                f = (f * f + f * 2.0F) / 3F;

                if ((double)f < 0.10000000000000001D)
                {
                    return;
                }

                if (f > 1.0F)
                {
                    f = 1.0F;
                }

                EntityArrow entityarrow = new EntityArrow(par2World, par3EntityPlayer, f * 2.0F);

                if (f == 1.0F)
                {
                    entityarrow.ArrowCritical = true;
                }

                int j = EnchantmentHelper.GetEnchantmentLevel(Enchantment.Power.EffectId, par1ItemStack);

                if (j > 0)
                {
                    entityarrow.SetDamage(entityarrow.GetDamage() + (double)j * 0.5D + 0.5D);
                }

                int k = EnchantmentHelper.GetEnchantmentLevel(Enchantment.Punch.EffectId, par1ItemStack);

                if (k > 0)
                {
                    entityarrow.Func_46023_b(k);
                }

                if (EnchantmentHelper.GetEnchantmentLevel(Enchantment.Flame.EffectId, par1ItemStack) > 0)
                {
                    entityarrow.SetFire(100);
                }

                par1ItemStack.DamageItem(1, par3EntityPlayer);
                par2World.PlaySoundAtEntity(par3EntityPlayer, "random.bow", 1.0F, 1.0F / (ItemRand.NextFloat() * 0.4F + 1.2F) + f * 0.5F);

                if (!flag)
                {
                    par3EntityPlayer.Inventory.ConsumeInventoryItem(Item.Arrow.ShiftedIndex);
                }
                else
                {
                    entityarrow.DoesArrowBelongToPlayer = false;
                }

                if (!par2World.IsRemote)
                {
                    par2World.SpawnEntityInWorld(entityarrow);
                }
            }
        }