Beispiel #1
0
 public void SkillEvent(Skills skill)
 {
     connector.cleanCells();
     connector.Skills(character, EventTypes.SKILL, SkillsCallBackParametrizedCallback(character, (character, selectedCell, result, targets) =>
     {
         foreach (CharacterScript target in targets)
         {
             var f = FormulaScript.Create("");
             foreach (Formula formula in skill.formulas)
             {
                 f.formula = formula.formula;
                 if (f.FormulaParser.IsValidExpression && target != null)
                 {
                     var r = f.FormulaParser.Evaluate(target.character.attributes);
                     AttributeValue attrbValue = target.character.attributesWithFormulas.Find(x => x.attribute.id == formula.attributeID);
                     if (attrbValue != null)
                     {
                         attrbValue.value += (int)r;
                         if (attrbValue.value > attrbValue.maxValue)
                         {
                             attrbValue.value = attrbValue.maxValue;
                         }
                     }
                 }
             }
         }
         objectCanvas.SetActive(false);
         Turn();
     }), skill);
 }
Beispiel #2
0
 public void Init()
 {
     tags       = new List <Tag>();
     slots      = new List <Slot>();
     formula    = ScriptableObject.CreateInstance <FormulaScript>();
     attributes = new List <AttributeValue>();
     skills     = new List <Skills>();
 }
Beispiel #3
0
    public void calculateFormulas()
    {
        var f = FormulaScript.Create("");

        // Copy attributes
        attributesWithFormulas = Extensions.Clone <AttributeValue>(attributes.Select(x => x.attribute).ToList()).ToList();
        foreach (AttributeValue attrb in attributesWithFormulas)
        {
            attrb.value    = attributes.Find(x => x.attribute == attrb.attribute).value;
            attrb.minValue = attributes.Find(x => x.attribute == attrb.attribute).minValue;
            attrb.maxValue = attributes.Find(x => x.attribute == attrb.attribute).maxValue;
        }

        // Formulas in slots
        foreach (Slot slot in Slots)
        {
            foreach (Formula formula in slot.modifier.formulas)
            {
                f.formula = formula.formula;
                if (f.FormulaParser.IsValidExpression)
                {
                    var            r          = f.FormulaParser.Evaluate(attributes);
                    AttributeValue attrbValue = attributesWithFormulas.Find(x => x.attribute.id == formula.attributeID);
                    if (attrbValue != null)
                    {
                        attrbValue.value += (int)r;
                        if (attrbValue.value > attrbValue.maxValue)
                        {
                            attrbValue.value = attrbValue.maxValue;
                        }
                    }
                }
            }
        }
        // Formulas in slots of specialized classes
        foreach (SpecializedClass specializedClass in specializedClasses)
        {
            foreach (Slot slot in specializedClass.slots)
            {
                foreach (Formula formula in slot.modifier.formulas)
                {
                    if (f.FormulaParser.IsValidExpression)
                    {
                        f.formula = formula.formula;
                        var            r          = f.FormulaParser.Evaluate(attributes);
                        AttributeValue attrbValue = attributesWithFormulas.Find(x => x.attribute.id == formula.attributeID);
                        attrbValue.value += (int)r;
                        if (attrbValue.value > attrbValue.maxValue)
                        {
                            attrbValue.value = attrbValue.maxValue;
                        }
                    }
                }
            }
        }
        specializedClassesCount = specializedClasses.Count;
    }
Beispiel #4
0
        public static void DumpPowerFormulas(bool simple)
        {
            using (StreamWriter log = CreateDesktopLogFile(simple ? "simple_power_formulas" : "power_formulas"))
            {
                foreach (var powerEntry in MPQStorage.Data.Assets[SNOGroup.Power].Values)
                {
                    log.WriteLine("script formulas for {0}", Path.GetFileName(powerEntry.FileName));
                    Power power = (Power)powerEntry.Data;

                    var tagmaps = new Dictionary <string, TagMap>()
                    {
                        { "TagMap", power.Powerdef.TagMap },
                        { "GeneralTagMap", power.Powerdef.GeneralTagMap },
                        { "PVPGeneralTagMap", power.Powerdef.PVPGeneralTagMap },
                        { "ContactTagMap0", power.Powerdef.ContactTagMap0 },
                        { "ContactTagMap1", power.Powerdef.ContactTagMap1 },
                        { "ContactTagMap2", power.Powerdef.ContactTagMap2 },
                        { "ContactTagMap3", power.Powerdef.ContactTagMap3 },
                        { "PVPContactTagMap0", power.Powerdef.PVPContactTagMap0 },
                        { "PVPContactTagMap1", power.Powerdef.PVPContactTagMap1 },
                        { "PVPContactTagMap2", power.Powerdef.PVPContactTagMap2 },
                        { "PVPContactTagMap3", power.Powerdef.PVPContactTagMap3 },
                    };

                    foreach (var kv in tagmaps)
                    {
                        foreach (var tagEntry in kv.Value.OrderBy(e => e.TagID))
                        {
                            if (tagEntry.Type == 4)
                            {
                                string name = StringTagID(tagEntry.TagID);
                                log.WriteLine("{0}.\"{1}\"", kv.Key, name);
                                log.WriteLine("   tagid: {0}", tagEntry.TagID);

                                int   sf_n;
                                Match nameMatch = Regex.Match(name, "Script Formula (\\d+)");
                                if (nameMatch.Success)
                                {
                                    sf_n = int.Parse(nameMatch.Groups[1].Value);
                                }
                                else
                                {
                                    sf_n = -1;
                                }

                                if (sf_n != -1 && power.ScriptFormulaDetails.Count > sf_n)
                                {
                                    log.WriteLine("   detail 1: {0}", power.ScriptFormulaDetails[sf_n].CharArray1);
                                    log.WriteLine("   detail 2: {0}", power.ScriptFormulaDetails[sf_n].CharArray2);
                                }

                                log.WriteLine("   opname: {0}", tagEntry.ScriptFormula.OpCodeName);

                                if (!simple)
                                {
                                    log.WriteLine("   opbin: {0}", tagEntry.ScriptFormula.OpCodeArray.Aggregate("", (a, b) => a + " " + b));

                                    List <int> opcodes = new List <int>();
                                    while (opcodes.Count * 4 < tagEntry.ScriptFormula.OpCodeArray.Length)
                                    {
                                        opcodes.Add(BitConverter.ToInt32(tagEntry.ScriptFormula.OpCodeArray, opcodes.Count * 4));
                                    }

                                    log.WriteLine("   opdecode: {0}", FormulaScript.ToString(opcodes.ToArray()));
                                }
                                log.WriteLine("");
                            }
                        }
                    }
                    log.WriteLine("");
                    log.WriteLine("");
                }
            }
        }
Beispiel #5
0
    private void OnEnable()
    {
        // Remove button
        removeTexture = (Texture2D)Resources.Load("Buttons/remove", typeof(Texture2D));

        // Get Formulas
        listFormulas = new ReorderableList(serializedObject,
                                           serializedObject.FindProperty("_formulas"),
                                           true, true, true, true);

        // Draw formulas
        listFormulas.drawElementCallback =
            (Rect rect, int index, bool isActive, bool isFocused) => {
            //var element = listFormulas.serializedProperty.GetArrayElementAtIndex(index);
            var formula = item.formulas[index];
            rect.y += 2;

            indexFormula = Database.Instance.attributes.IndexOf(Database.Instance.attributes.Find(x => x.id == formula.attributeID));

            EditorGUI.BeginChangeCheck();
            indexFormula = EditorGUI.Popup(new Rect(rect.x, rect.y, 50, EditorGUIUtility.singleLineHeight), indexFormula, Database.Instance.attributes.Select(x => x.id).ToArray());

            EditorGUI.LabelField(new Rect(rect.x + 55, rect.y, 10, EditorGUIUtility.singleLineHeight), "=", EditorStyles.boldLabel);

            formula.formula = EditorGUI.TextField(new Rect(rect.x + 70, rect.y, rect.width - 98, EditorGUIUtility.singleLineHeight), formula.formula);

            bool removed = false;
            if (GUI.Button(new Rect(rect.width, rect.y, 16, 16), new GUIContent("", removeTexture), removeStyle))
            {
                item.formulas.Remove(item.formulas[index]);
                removed = true;
            }

            var f = FormulaScript.Create(formula.formula);
            if (!removed && !f.FormulaParser.IsValidExpression)
            {
                EditorGUI.LabelField(new Rect(rect.x + 70, rect.y + EditorGUIUtility.singleLineHeight + 2.0f, rect.width, EditorGUIUtility.singleLineHeight), f.FormulaParser.Error);
            }

            if (!removed && EditorGUI.EndChangeCheck())
            {
                formula.attributeID = Database.Instance.attributes[indexFormula].id;
            }
        };

        listFormulas.elementHeight = (EditorGUIUtility.singleLineHeight * 2) + 4.0f;

        // listFormulas header
        listFormulas.drawHeaderCallback = (Rect rect) => {
            EditorGUI.LabelField(rect, "Formulas");
        };

        // Add formula
        listFormulas.onAddDropdownCallback = (Rect buttonRect, ReorderableList l) => {
            item.formulas.Add(new Formula());
            serializedObject.ApplyModifiedProperties();
            EditorUtility.SetDirty(target);
        };

        // Remove formula
        listFormulas.onRemoveCallback = (ReorderableList l) => {
            item.formulas.Remove(item.formulas[l.index]);
            serializedObject.ApplyModifiedProperties();
        };
    }