//return the child of type _spellColliderType or null if he doesn't exist public SpellTreeNode getChildOfType(SpellColliderType _spellColliderType) { foreach (SpellTreeNode child in children) { if (child.spellColliderType == _spellColliderType) { return(child); } } return(null); }
//true if on children is of type _spellColliderType public bool hasColliderChildOfType(SpellColliderType _spellColliderType) { foreach (SpellTreeNode child in children) { if (child.spellColliderType == _spellColliderType) { return(true); } } return(false); }
public void AddSortCollider(SpellColliderType col) { if (this.spellTree.advance(col)) { string spell = this.spellTree.isSpell(); if (spell != null) { launchSpell(spell); spellTree.resetActualNode(); } } else { failSpellParticule.Play(); spellTree.resetActualNode(); } }
public SpellTreeNode(List <SpellColliderType> spellDefinition, string spellName) { SpellColliderType _spellColliderType = spellDefinition[0]; spellDefinition.RemoveAt(0); this.spellColliderType = _spellColliderType; if (spellDefinition.Count != 0) { children = new List <SpellTreeNode>(); this.spellName = null; children.Add(new SpellTreeNode(spellDefinition, spellName)); } else { children = null; this.spellName = spellName; } }
//use to move the actualNode (where we are) public bool advance(SpellColliderType type) { bool isFind = false; if (actualNode == null) { foreach (SpellTreeNode child in children) { if (child.isColliderType(type)) { isFind = true; actualNode = child; //Debug.Log("actual is " + actualNode.spellColliderType); break; } } //if(!isFind) //Debug.Log("can't Advance to " + type); return(isFind); } else { if (actualNode.spellColliderType != type) { SpellTreeNode newNode = actualNode.getChildOfType(type); if (newNode == null) { //Debug.Log("can't Advance to " + type); return(false); } else { actualNode = newNode; //Debug.Log("actual is " + actualNode.spellColliderType); return(true); } } return(true); } }
//use to add a spell, a spell is an order of ColliderType and a name public void addSpell(List <SpellColliderType> spellDef, string spellName) { SpellColliderType type = spellDef[0]; bool isFind = false; foreach (SpellTreeNode child in children) { if (child.isColliderType(type)) { isFind = true; spellDef.RemoveAt(0); child.addChild(spellDef, spellName); break; } } if (!isFind) { children.Add(new SpellTreeNode(spellDef, spellName)); } }
//use to add more spell public void addChild(List <SpellColliderType> spellDefinition, string spellName) { if (spellDefinition.Count != 0) { SpellColliderType newChildType = spellDefinition[0]; bool isFind = false; foreach (SpellTreeNode child in children) { if (child.spellColliderType == newChildType) { child.addChild(spellDefinition, spellName); spellDefinition.RemoveAt(0); isFind = true; break; } } if (!isFind) { children.Add(new SpellTreeNode(spellDefinition, spellName)); } } }
public void initSpell() { Game_Manager gm = GameObject.Find("GameManager").GetComponent <Game_Manager>(); Debug.Log(gm.spell); if (gm.spell != null) { Debug.Log("arf"); spellList.Clear(); List <string> list = gm.spell.Shot.Collider; SpellColliderType[] array = new SpellColliderType[list.Count]; int i = 0; foreach (string s in list) { Debug.Log(s); array[i] = (SpellColliderType)Enum.Parse(typeof(SpellColliderType), s); i++; } SpellDefinition def = new SpellDefinition("shot", array); spellList.Add(def); list = gm.spell.Holohomora.Collider; array = new SpellColliderType[list.Count]; i = 0; foreach (string s in list) { Debug.Log(s); array[i] = (SpellColliderType)Enum.Parse(typeof(SpellColliderType), s); i++; } def = new SpellDefinition("holohomora", array); spellList.Add(def); list = gm.spell.Lave.Collider; array = new SpellColliderType[list.Count]; i = 0; foreach (string s in list) { Debug.Log(s); array[i] = (SpellColliderType)Enum.Parse(typeof(SpellColliderType), s); i++; } def = new SpellDefinition("lave", array); spellList.Add(def); list = gm.spell.Protego.Collider; array = new SpellColliderType[list.Count]; i = 0; foreach (string s in list) { Debug.Log(s); array[i] = (SpellColliderType)Enum.Parse(typeof(SpellColliderType), s); i++; } def = new SpellDefinition("protego", array); spellList.Add(def); Debug.Log("def " + spellList.Count); } foreach (SpellDefinition spell in spellList) { spellTree.addSpell(new List <SpellColliderType>(spell.colliderOrder), spell.spellName); } spellTree.DebugTree(); }
//return true of the node is of type _spellColliderType public bool isColliderType(SpellColliderType _spellColliderType) { return(this.spellColliderType == _spellColliderType); }