예제 #1
0
        public override void InitSkillsOnMonster(SkillSet set, ActiveSkill meleeSkill, int level)
        {
            if (OldTemplate != null)
            {
                OldTemplate.InitSkillsOnMonster(set, meleeSkill, level);
            }

            FieldInfo field;

            foreach (SkillModifyInfo info in SkillModifyInfo)
            {
                string key   = info.key;
                string value = info.value;
                Skill  sk    = set.GetSkill(info.id);

                field = sk.GetType().GetField(key, BindingFlags.Public | BindingFlags.Instance);

                if (field != null)
                {
                    if (field.FieldType == typeof(int))
                    {
                        field.SetValue(sk, Int32.Parse(value));
                    }
                    else if (field.FieldType == typeof(float))
                    {
                        field.SetValue(sk, float.Parse(value));
                    }
                    else if (field.FieldType == typeof(double))
                    {
                        field.SetValue(sk, Double.Parse(value));
                    }
                    else if (field.FieldType == typeof(bool))
                    {
                        field.SetValue(sk, Boolean.Parse(value));
                    }
                    else if (field.FieldType == typeof(string))
                    {
                        field.SetValue(sk, value);
                    }
                    else
                    {
                        throw new ArgumentException("invalid custom skill field " + key + " - has unknown type (not int, float, double or string)");
                    }
                }
                else
                {
                    Debug.LogError("Cant write to property " + key + " in " + sk.GetType().Name + " (property is null)");
                }
            }

            if (MeleeSkill != null)
            {
                foreach (SkillModifyInfo info in AutoattackSkillModifyInfos)
                {
                    string key   = info.key;
                    string value = info.value;

                    field = meleeSkill.GetType().GetField(key, BindingFlags.Public | BindingFlags.Instance);

                    if (field != null)
                    {
                        if (field.FieldType == typeof(int))
                        {
                            field.SetValue(meleeSkill, Int32.Parse(value));
                        }
                        else if (field.FieldType == typeof(float))
                        {
                            field.SetValue(meleeSkill, float.Parse(value));
                        }
                        else if (field.FieldType == typeof(double))
                        {
                            field.SetValue(meleeSkill, Double.Parse(value));
                        }
                        else if (field.FieldType == typeof(bool))
                        {
                            field.SetValue(meleeSkill, Boolean.Parse(value));
                        }
                        else if (field.FieldType == typeof(string))
                        {
                            field.SetValue(meleeSkill, value);
                        }
                        else
                        {
                            throw new ArgumentException("invalid custom autoattack skill field " + key + " - has unknown type (not int, float, double or string)");
                        }
                    }
                    else
                    {
                        Debug.LogError("Cant write to property " + key + " in " + meleeSkill.GetType().Name + " (property is null)");
                    }
                }
            }

            if (DisabledEffects.Count > 0)
            {
                foreach (SkillId id in DisabledEffects)
                {
                    Skill sk = set.GetSkill(id);
                    sk.DisableOriginalEffects();
                }
            }

            if (DisabledMeleeEffects)
            {
                if (meleeSkill != null)
                {
                    meleeSkill.DisableOriginalEffects();
                }
            }

            if (SkillAddEffects.Count > 0)
            {
                foreach (SkillEffectInfo info in SkillAddEffects)
                {
                    Skill  sk   = set.GetSkill(info.id);
                    string name = info.effectName;

                    object[] parameters;

                    SkillEffect effect = null;
                    foreach (Type t in Utils.GetTypesInNamespace("Assets.scripts.Skills.SkillEffects", true, typeof(SkillEffect)))
                    {
                        if (t.Name.Equals("Effect" + name, StringComparison.InvariantCultureIgnoreCase))
                        {
                            foreach (ConstructorInfo ci in t.GetConstructors())
                            {
                                parameters = new object[ci.GetParameters().Length];

                                bool matches = true;

                                // pro dany konstruktor zjistit, jestli jsou jeho parametry definovane
                                for (int i = 0; i < ci.GetParameters().Length; i++)
                                {
                                    ParameterInfo pi = ci.GetParameters()[i];
                                    string        val;
                                    if (!info.parameters.TryGetValue(pi.Name, out val))
                                    {
                                        matches = false;
                                        break;
                                    }
                                    else
                                    {
                                        if (pi.ParameterType == typeof(int))
                                        {
                                            parameters[i] = Int32.Parse(val);
                                        }
                                        else if (pi.ParameterType == typeof(float))
                                        {
                                            parameters[i] = float.Parse(val);
                                        }
                                        else if (pi.ParameterType == typeof(double))
                                        {
                                            parameters[i] = Double.Parse(val);
                                        }
                                        else if (pi.ParameterType == typeof(bool))
                                        {
                                            parameters[i] = Boolean.Parse(val);
                                        }
                                        else if (pi.ParameterType == typeof(string))
                                        {
                                            parameters[i] = val;
                                        }
                                        else
                                        {
                                            throw new ArgumentException("invalid param when constructing skill effect " + pi.ParameterType + " - cant parse");
                                        }
                                    }
                                }

                                // this constructor will be used
                                if (matches)
                                {
                                    effect = (SkillEffect)ci.Invoke(parameters);
                                    break;
                                }
                            }

                            break;
                        }
                    }

                    if (effect != null)
                    {
                        sk.AddAdditionalEffect(effect);
                    }
                    else
                    {
                        Debug.LogError("couldnt create instance of " + name + " with parameters " + info.parameters);
                    }
                }
            }



            if (MeleeAddEffects.Count > 0 && meleeSkill != null)
            {
                foreach (SkillEffectInfo info in MeleeAddEffects)
                {
                    string name = info.effectName;

                    object[] parameters;

                    SkillEffect effect = null;
                    foreach (Type t in Utils.GetTypesInNamespace("Assets.scripts.Skills.SkillEffects", true, typeof(SkillEffect)))
                    {
                        if (t.Name.Equals("Effect" + name, StringComparison.InvariantCultureIgnoreCase))
                        {
                            foreach (ConstructorInfo ci in t.GetConstructors())
                            {
                                parameters = new object[ci.GetParameters().Length];

                                bool matches = true;

                                // pro dany konstruktor zjistit, jestli jsou jeho parametry definovane
                                for (int i = 0; i < ci.GetParameters().Length; i++)
                                {
                                    ParameterInfo pi = ci.GetParameters()[i];
                                    string        val;
                                    if (!info.parameters.TryGetValue(pi.Name, out val))
                                    {
                                        matches = false;
                                        break;
                                    }
                                    else
                                    {
                                        if (pi.ParameterType == typeof(int))
                                        {
                                            parameters[i] = Int32.Parse(val);
                                        }
                                        else if (pi.ParameterType == typeof(float))
                                        {
                                            parameters[i] = float.Parse(val);
                                        }
                                        else if (pi.ParameterType == typeof(double))
                                        {
                                            parameters[i] = Double.Parse(val);
                                        }
                                        else if (pi.ParameterType == typeof(bool))
                                        {
                                            parameters[i] = Boolean.Parse(val);
                                        }
                                        else if (pi.ParameterType == typeof(string))
                                        {
                                            parameters[i] = val;
                                        }
                                        else
                                        {
                                            throw new ArgumentException("invalid param when constructing skill effect " + pi.ParameterType + " - cant parse");
                                        }
                                    }
                                }

                                // this constructor will be used
                                if (matches)
                                {
                                    effect = (SkillEffect)ci.Invoke(parameters);
                                    break;
                                }
                            }

                            break;
                        }
                    }

                    if (effect != null)
                    {
                        meleeSkill.AddAdditionalEffect(effect);
                    }
                    else
                    {
                        Debug.LogError("couldnt create instance of " + name + " with parameters " + info.parameters);
                    }
                }
            }
        }