Exemple #1
0
 public PickWeaponTarget( OilPotion potion )
     : base(15, false, TargetFlags.None)
 {
     m_Potion = potion;
 }
        public int AttemptCraft()
        {
            Bottle emptyBottle = m_Brewer.Backpack.FindItemByType( typeof( Bottle ) ) as Bottle;
            if ( m_Ingredients.Count == 0 )
                return -3;	// there's nothing to craft

            else if ( emptyBottle == null )
                return -5;	// the bottle must be in your pack

            else if ( Type == PotionType.Bomb && m_Range < 0 )
                return -6;	// not enough bomb in this bomb potion, MISTAR
            else if ( Type == PotionType.Oil && m_Duration <= 0 )
                return -7;

            object bottleParent = emptyBottle.Parent;
            Type[] types = new Type[m_Ingredients.Count];
            int[] amounts = new int[m_Ingredients.Count];
            int i = 0;

            foreach ( KeyValuePair<Type, int> kvp in m_Ingredients ) // build the ingredients list so we can remove them faster
            {
                types[i] = kvp.Key;
                amounts[i] = kvp.Value;
                i++;
            }

            if ( m_Brewer.Backpack.ConsumeTotal( types, amounts ) != -1 ) // couldn't find them
                return -1; // not enough resources

            if ( CraftChance() > Utility.RandomDouble() )
            {
                CustomPotion potion;

                if ( Type == PotionType.Bomb )
                {
                    potion = new BombPotion( m_Bottle );
                    ((BombPotion)potion).ExplosionRange = m_Range;
                    ((BombPotion)potion).InstantExplosion = m_InstantExplosion;
                }
                else if ( Type == PotionType.Oil )
                {
                    potion = new OilPotion( m_Bottle );
                    ((OilPotion)potion).Duration = m_Duration;
                    ((OilPotion)potion).Corrosivity = m_Corrosivity;
                }
                else
                    potion = new DrinkPotion( m_Bottle );

                emptyBottle.Consume( 1 );
                potion.Name = m_Name;
                //potion.Hue = GetFinalHue(); // This has been disabled since the ingredient hues look funny on bottles

                foreach (KeyValuePair<CustomEffect, int> kvp in m_PotionEffects)
                {
                    if (kvp.Value != 0)
                    {
                        if (m_Brewer is PlayerMobile && (kvp.Key.GetType() == typeof(MadnessEffect) || kvp.Key.GetType() == typeof(ConfusionEffect) || kvp.Key.GetType() == typeof(OintmentEffect)))
                        {
                            PlayerMobile pm = m_Brewer as PlayerMobile;
                            int effectBonus = 0;
                            switch (pm.Feats.GetFeatLevel(FeatList.Pathology))
                            {
                                case 0: break;
                                case 1: break;
                                case 2: effectBonus = (int)(kvp.Value * 0.1); break;
                                case 3: effectBonus = (int)(kvp.Value * 0.3); break;
                                default: break;
                            }
                            potion.AddEffect(kvp.Key, kvp.Value + effectBonus);
                        }
                        else
                            potion.AddEffect(kvp.Key, kvp.Value);
                    }
                }

                if ( !( bottleParent is BaseContainer ) || !((BaseContainer)bottleParent).TryDropItem( m_Brewer, potion, false ) )
                    m_Brewer.AddToBackpack( potion );

                return 1; // craft succeeded
            }

            else
                return -2; // craft failed
        }