Пример #1
0
        public unsafe void Test()
        {
            var customEffect = new CustomEffect();

            // Test int
            var getInt = Utilities.BuildPropertyGetter<int>(typeof(CustomEffect), typeof(CustomEffect).GetProperty("Int"));
            var setInt = Utilities.BuildPropertySetter<int>(typeof(CustomEffect), typeof(CustomEffect).GetProperty("Int"));

            int intValue = 5;
            setInt(customEffect, ref intValue);
            getInt(customEffect, out intValue);
            Assert.AreEqual(intValue, 5);

            var getFloat = Utilities.BuildPropertyGetter<float>(typeof(CustomEffect), typeof(CustomEffect).GetProperty("Float"));
            var setFloat = Utilities.BuildPropertySetter<float>(typeof(CustomEffect), typeof(CustomEffect).GetProperty("Float"));

            float floatValue = 5.0f;
            setFloat(customEffect, ref floatValue);
            getFloat(customEffect, out floatValue);
            Assert.AreEqual(floatValue, 5);
            
            var getDouble = Utilities.BuildPropertyGetter<double>(typeof(CustomEffect), typeof(CustomEffect).GetProperty("Double"));
            var setDouble = Utilities.BuildPropertySetter<double>(typeof(CustomEffect), typeof(CustomEffect).GetProperty("Double"));

            double doubleValue = 5.0;
            setDouble(customEffect, ref doubleValue);
            getDouble(customEffect, out doubleValue);
            Assert.AreEqual(doubleValue, 5);

            var getVector2 = Utilities.BuildPropertyGetter<Vector2>(typeof(CustomEffect), typeof(CustomEffect).GetProperty("Vector2"));
            var setVector2 = Utilities.BuildPropertySetter<Vector2>(typeof(CustomEffect), typeof(CustomEffect).GetProperty("Vector2"));

            var Vector2Value = new Vector2(1,2);
            setVector2(customEffect, ref Vector2Value);
            getVector2(customEffect, out Vector2Value);
            Assert.AreEqual(Vector2Value, new Vector2(1, 2));

            var getTestEnum = Utilities.BuildPropertyGetter<int>(typeof(CustomEffect), typeof(CustomEffect).GetProperty("TestEnum"));
            var setTestEnum = Utilities.BuildPropertySetter<int>(typeof(CustomEffect), typeof(CustomEffect).GetProperty("TestEnum"));

            int TestEnumValue = (int)TestEnum.Value2;
            setTestEnum(customEffect, ref TestEnumValue);
            getTestEnum(customEffect, out TestEnumValue);
            Assert.AreEqual(TestEnumValue, (int)TestEnum.Value2);

            var getBlob = Utilities.BuildPropertyGetter<IntPtr>(typeof(CustomEffect), typeof(CustomEffect).GetProperty("Blob"));
            var setBlob = Utilities.BuildPropertySetter<IntPtr>(typeof(CustomEffect), typeof(CustomEffect).GetProperty("Blob"));

            var BlobValue = new IntPtr(5);
            setBlob(customEffect, ref BlobValue);
            getBlob(customEffect, out BlobValue);
            Assert.AreEqual(BlobValue, new IntPtr(5));
        }
Пример #2
0
		public void EffectsClearDetachesEffect ()
		{
			var effect = new CustomEffect ();
			var element = new Label ();

			((IVisualElementController)element).EffectControlProvider = new EffectControlProvider ();
			element.Effects.Add (effect);

			element.Effects.Clear ();

			Assert.True (effect.OnDetachedCalled);
		}
Пример #3
0
		public void EffectLifecyclePostProvider ()
		{
			var effect = new CustomEffect ();
			var element = new Label ();

			((IVisualElementController)element).EffectControlProvider = new EffectControlProvider ();
			element.Effects.Add (effect);

			Assert.True (effect.IsAttached);
			Assert.True (effect.OnAttachedCalled);
			Assert.True (effect.Registered);
			Assert.False (effect.OnDetachedCalled);

			element.Effects.Remove (effect);
			Assert.True (effect.OnDetachedCalled);
		}
            protected override void OnTarget( Mobile from, object o )
            {
                if ( o is DrinkPotion )
                {
                    DrinkPotion potion = o as DrinkPotion;
                    if ( potion.RootParent != from )
                        from.SendMessage( "The potion must be in your pack." );
                    else if ( potion.Enhanced )
                        from.SendMessage( "This potion has already been enhanced." );
                    else if ( potion.Effects.Count == 0 )
                        from.SendMessage( "There is no substance present to enhance." );
                    else
                    {
                        if ( Utility.RandomBool() ) // 50% chance to succeed
                        {
                            double bonusFactor;

                            bonusFactor = 1 + ( 0.2 * ((PlayerMobile)from).Feats.GetFeatLevel(FeatList.EnhancePotion) ); // 30% increase, change this to accomodate feat levels

                            CustomEffect[] keyarray = new CustomEffect[potion.Effects.Count];
                            int k = 0;
                            foreach ( KeyValuePair<CustomEffect, int> kvp in potion.Effects )
                                keyarray[k++] = kvp.Key;
                            foreach ( CustomEffect key in keyarray )
                                potion.Effects[key] = (int)(potion.Effects[key] * bonusFactor);

                            potion.Enhanced = true;
                            from.SendMessage( "You successfully enhance the potion." );
                        }
                        else
                        {
                            Bottle emptybottle = new Bottle();
                            from.AddToBackpack( emptybottle );
                            potion.Consume( 1 );
                            from.SendMessage( "You have failed in your attempt at enhancing the potion, and have thus rendered it worthless." );
                        }
                    }
                }
                else
                    from.SendMessage( "You can only enhance drinkable potions." );
            }
Пример #5
0
 /// <summary>
 /// Return a pointer to the unamanged version of this callback.
 /// </summary>
 /// <param name="callback">The callback.</param>
 /// <returns>A pointer to a shadow c++ callback</returns>
 public static IntPtr ToIntPtr(CustomEffect callback)
 {
     return ToIntPtr<CustomEffect>(callback);
 }
Пример #6
0
 public void AddEffect( CustomEffect ID, int intensity )
 {
     m_Effects.Add( ID, intensity );
 }
 void SetTextureParameters(CustomEffect effect)
 {
     effect.SampleOffset = new Vector2(1.0f / (float) TextureSize, 1.0f / (float) TextureSize);
     effect.TextureSize = new Vector2(TextureSize, TextureSize);
     effect.NormalMap = normalMapBackBuffer.GetRenderTarget();
 }
Пример #8
0
 public static void Register( CustomPotionEffect instance, CustomEffect id )
 {
     if ( m_Registry.ContainsKey( id ) )
         Console.WriteLine( "WARNING: CustomPotionEffect found with duplicate ID (Name: {0}, ID: {1}) -- The effect was NOT registered.", instance.Name, id );
     else
         m_Registry[id] = instance;
 }
Пример #9
0
 public static CustomPotionEffect GetEffect( CustomEffect id )
 {
     return m_Registry[id];
 }
Пример #10
0
        // also updates difficulty
        public void UpdateEffects()
        {
            if ( m_Ingredients.Count == 0 )
            {
                m_PotionEffects = new Dictionary<CustomEffect, int>();
                m_PotionBooster = m_Duration = m_Corrosivity = m_Range = m_Duration = 0;
                m_TotalEffects = 0;
                m_InstantExplosion = false;
                return;
            }

            m_PotionEffects.Clear();
            bool instantExplosion = true;
            int totalherbs=0;
            double potionbooster = 1.0;
            int range = 0;
            int corrosivity = 0;
            int duration = 0;

            foreach ( KeyValuePair<Type, int> kvp in m_Ingredients )
            {
                Item instance = (Item)Activator.CreateInstance(kvp.Key);
                if (!(instance is IAlchemyIngredient))
                    continue;

                IAlchemyIngredient ingredient = instance as IAlchemyIngredient;
                int amount = kvp.Value;
                totalherbs += amount;

                for (int i=1; i<=amount; i++)
                {
                    foreach ( KeyValuePair<CustomEffect, int> kvp2 in ingredient.Effects )
                    {
                        if ( !m_PotionEffects.ContainsKey( kvp2.Key ) )
                            m_PotionEffects[kvp2.Key] = 0;

                        m_PotionEffects[kvp2.Key] += (int)(kvp2.Value * (1.0/i));	// diminishing returns, 100% for first, 50% for second, 33% for third...
                    }
                    if (instance is IDrinkIngredient && m_Type == PotionType.Drink)
                        potionbooster += (((IDrinkIngredient)instance).PotionBooster * 0.01) * (1.0 / i); // also diminishing returns for potion boosters
                    else if (instance is IBombIngredient && m_Type == PotionType.Bomb)
                    {
                        range += ((IBombIngredient)instance).Range; // add up range of all ingredients together
                        // if any ingredient has InstantEffect = false, then the potion will NOT be instant
                        if (instantExplosion == true && ((IBombIngredient)instance).InstantEffect == false)
                            instantExplosion = false;
                    }
                    else if (instance is IOilIngredient && m_Type == PotionType.Oil)
                    {
                        corrosivity += ((IOilIngredient)instance).Corrosivity; // add up corrosivity of all ingredients together
                        duration += ((IOilIngredient)instance).Duration;
                    }
                }
            }

            CustomEffect[] keyarray = new CustomEffect [m_PotionEffects.Count]; // store keys to amplify later
            int k = 0;
            foreach ( KeyValuePair<CustomEffect, int> kvp in m_PotionEffects ) // build the keyarray, as we can't change values during enumeration
                keyarray[k++] = kvp.Key;

            m_TotalEffects = 0;

            for ( int j = 0; j < k; j++ ) // amplify values
            {
                m_PotionEffects[keyarray[j]] = (int)(m_PotionEffects[keyarray[j]] * potionbooster);

                if ( m_PotionEffects[keyarray[j]] < 0 && m_Type == PotionType.Drink && ((PlayerMobile)m_Brewer).Feats.GetFeatLevel(FeatList.LowerSideEffects) > 0 )
                {
                    double reduction = 0.1 * ((PlayerMobile)m_Brewer).Feats.GetFeatLevel(FeatList.LowerSideEffects); // adjust for different levels
                    m_PotionEffects[keyarray[j]] -= (int)(m_PotionEffects[keyarray[j]] * reduction);
                }

                if ( m_PotionEffects[keyarray[j]] > 0 || ( m_Type == PotionType.Bomb || m_Type == PotionType.Oil ) )
                { // only positive effects count towards difficulty increase, unless it's a bomb/oil in which case, both do.
                    m_TotalEffects+=Math.Abs( m_PotionEffects[keyarray[j]] );
                }
            }

            if ( m_Type == PotionType.Drink )
                m_PotionBooster = (int)(potionbooster - 1.0);
            else if ( m_Type == PotionType.Bomb )
            {
                m_Range = range / totalherbs;
                m_InstantExplosion = instantExplosion;
            }
            else if ( m_Type == PotionType.Oil )
            {
                m_Corrosivity = corrosivity / totalherbs;
                m_Duration = duration / totalherbs;
            }
        }
Пример #11
0
        public Effect ParseEffect(string effectConfig)
        {
            Effect effect = null;

            if (!string.IsNullOrEmpty(effectConfig) && effectConfig.Contains("="))
            {
                var arr        = effectConfig.Split('=');
                var effectType = arr[0];
                var effectId   = arr[1];
                if (effectType == "Damage")
                {
                    var damageEffectConfig = ConfigHelper.Get <SkillDamageEffectConfig>(int.Parse(effectId));
                    var damageEffect       = new DamageEffect();
                    effect = damageEffect;
                    damageEffect.DamageValueFormula = damageEffectConfig.ValueFormula;
                    damageEffect.TriggerProbability = damageEffectConfig.Probability;
                    if (damageEffectConfig.Target == "自身")
                    {
                        damageEffect.AddSkillEffectTargetType = AddSkillEffetTargetType.Self;
                    }
                    if (damageEffectConfig.Target == "技能目标")
                    {
                        damageEffect.AddSkillEffectTargetType = AddSkillEffetTargetType.SkillTarget;
                    }
                    if (damageEffectConfig.Type == "魔法伤害")
                    {
                        damageEffect.DamageType = DamageType.Magic;
                    }
                    if (damageEffectConfig.Type == "物理伤害")
                    {
                        damageEffect.DamageType = DamageType.Physic;
                    }
                    if (damageEffectConfig.Type == "真实伤害")
                    {
                        damageEffect.DamageType = DamageType.Real;
                    }
                }
                if (effectType == "AddStatus")
                {
                    var addStatusEffectConfig = ConfigHelper.Get <SkillAddStatusEffectConfig>(int.Parse(effectId));
                    var addStatusEffect       = new AddStatusEffect();
                    effect = addStatusEffect;
                    addStatusEffect.AddStatus = Resources.Load <StatusConfigObject>($"StatusConfigs/Status_{addStatusEffectConfig.StatusID}");
                    if (addStatusEffect.AddStatus == null)
                    {
                        addStatusEffect.AddStatus = Resources.Load <StatusConfigObject>($"StatusConfigs/BaseStatus/Status_{addStatusEffectConfig.StatusID}");
                    }
                    addStatusEffect.Duration = (uint)(float.Parse(addStatusEffectConfig.Duration) * 1000);
                    ParseParam(addStatusEffectConfig.Param1);
                    ParseParam(addStatusEffectConfig.Param2);
                    void ParseParam(string paramStr)
                    {
                        if (!string.IsNullOrEmpty(paramStr))
                        {
                            arr = paramStr.Split('=');
                            addStatusEffect.Params.Add(arr[0], arr[1]);
                        }
                    }
                }
            }
            else
            {
                effect = new CustomEffect()
                {
                    CustomEffectType = effectConfig
                };
            }
            return(effect);
        }