public static Spirit GenerateSpirit(SpiritType t, int level, AttackLibrary atklib = null) { var spirit = new Spirit(t) { Level = level, Name = t.Name, HP = t.HP + t.PL_HP * level, DEF = t.DEF + t.PL_DEF * level, SPEED = t.SPEED + t.PL_SPEED * level, DMG = t.DMG + t.PL_DMG * level, CRIT = t.CRIT, ACC = t.ACC, }; /*foreach(var attr in t.Attributes) { * bool b = attr.Key.Contains("Level"); * var Key = b ? attr.Key.Substring(5) : attr.Key; * float Val = b ? attr.Value * level : attr.Value; * * if (spirit.Attribute.ContainsKey(Key)) * spirit.Attribute[Key] = spirit.Attribute[Key] + Val; * else * spirit.Attribute.Add(Key, Val); * }*/ atklib = atklib ?? Game.Instance.AttackLibrary; spirit.currentHP = spirit.HP * SpiritType.PP_HP; for (int x = 0, i = t.Attacks.List.Length - 1; x < 4 && i >= 0; --i) { if (t.Attacks.List[i].Level > level) { continue; } ++x; var atk = atklib.Attacks.First(a => a.Name == t.Attacks.List[i].Attack); spirit.Attacks.Add(atk); } return(spirit); }
public Spirit(SpiritType type) { Type = type; }
public void LoadFromCSV(TextAsset file) { List <SpiritType> csvLib = new List <SpiritType>(); string[,] grid = CSVReader.SplitCsvGrid(file.text); HashSet <string> fieldnotfound = new HashSet <string>(); for (int y = 1; y < grid.GetUpperBound(1); y++) { if (grid[1, y] == "") { continue; } //SpiritType t = new SpiritType(); SpiritType t = ScriptableObject.CreateInstance <SpiritType>(); Type type = typeof(SpiritType); //if (!elements.ContainsKey(grid[2, y])) //elements.Add(grid[2, y], new ElementType(grid[2, y])); //t.type = elements[grid[2, y]]; t.Name = grid[1, y]; for (int x = 3; x < grid.GetUpperBound(0); x++) { if (grid[x, 0] != "") { FieldInfo field = type.GetField(grid[x, 0]); if (field == null) { fieldnotfound.Add(grid[x, 0]); continue; } if (field.FieldType == typeof(int)) { field.SetValue(t, int.Parse(grid[x, y])); } else if (field.FieldType == typeof(float)) { field.SetValue(t, float.Parse(grid[x, y])); } else if (field.FieldType == typeof(bool)) { field.SetValue(t, bool.Parse(grid[x, y])); } else { field.SetValue(t, grid[x, y]); } // string } //t.Attributes.Add(, float.Parse()); } csvLib.Add(t); } Spirits = csvLib.ToArray(); foreach (var t in Spirits) { t.name = t.Name; // dont confuse SpiritType 'Name' with Scriptableobject 'Name' ... AssetDatabase.AddObjectToAsset(t, this); t.hideFlags = HideFlags.HideInHierarchy; AssetDatabase.SaveAssets(); AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(this)); } foreach (var v in fieldnotfound) { Debug.Log("field " + v + " not found"); } }