//Helper method to de-cluter our XML reader method private void SpellHelper(string tag, string value, ActionSpell spell) { switch (tag) { case "name": spell.spellName = value; break; case "area": spell.spellArea = int.Parse(value); break; case "range": spell.spellRange = int.Parse(value); break; case "modTarget": spell.spellTargetAttribute = value; break; case "modAmount": spell.spellValue = int.Parse(value); break; case "modOperation": spell.spellOp = value; break; default: break; } }
private void loadSpellMods() { for (int i = 0; i < spellMods.Length; i++) { reader = new XmlTextReader(spellMods[i]); string temp = ""; ActionSpell newSpell = new ActionSpell(); while (reader.Read()) { switch (reader.NodeType) { case XmlNodeType.Element: temp = reader.Name; break; case XmlNodeType.Text: //Display the text in each element. SpellHelper(temp, reader.Value, newSpell); break; case XmlNodeType.EndElement: //Display the end of the element. break; default: break; } } gmObject.Spells[newSpell.spellName] = newSpell; reader.Close(); } }
public ActionSpell GetActionSpells() { ActionSpell resArray = new ActionSpell(); resArray.spells = spells; return resArray; }
//console command for casting spells public void CastSpell(String[] tokens) { if (tokens.Length < 4) { output.text += "\n" + "Invalid number of arguments for <cast>. Expected 4, got " + tokens.Length + ".\nUsage: cast <spell> <caster> <target>"; } else { try { //get the componenets Unit caster = Units[tokens[2]]; Unit target = Units[tokens[3]]; ActionSpell spell = Spells[tokens[1]]; //RANGE CHECK if (caster.IsValidMove(spell.spellRange, target.CurrentLocation.x, target.CurrentLocation.y)) { //find which attribute the spell is targeting switch (spell.spellTargetAttribute) { case "health": if (spell.spellOp == "sub") { target.unitInfo.CurrentHealth -= spell.spellValue; } else if (spell.spellOp == "add") { target.unitInfo.CurrentHealth += spell.spellValue; } else if (spell.spellOp == "div") { target.unitInfo.CurrentHealth /= spell.spellValue; } else if (spell.spellOp == "multi") { target.unitInfo.CurrentHealth *= spell.spellValue; } break; case "movement": if (spell.spellOp == "sub") { target.unitInfo.Movement -= spell.spellValue; } else if (spell.spellOp == "add") { target.unitInfo.Movement += spell.spellValue; } else if (spell.spellOp == "div") { target.unitInfo.Movement /= spell.spellValue; } else if (spell.spellOp == "multi") { target.unitInfo.Movement *= spell.spellValue; } break; //the hard part. Dig through all the modable fields to find one we are looking for default: List <string> keyList = new List <string>(target.unitInfo.coreDict.Keys); for (int i = 0; i < keyList.Count; i++) { List <string> innerKeyList = new List <string>(target.unitInfo.coreDict[keyList[i]].Keys); for (int j = 0; j < innerKeyList.Count; j++) { if (innerKeyList[j] == spell.spellTargetAttribute) { if (spell.spellOp == "sub") { target.unitInfo.coreDict[keyList[i]][innerKeyList[j]] -= spell.spellValue; } else if (spell.spellOp == "add") { target.unitInfo.coreDict[keyList[i]][innerKeyList[j]] += spell.spellValue; } else if (spell.spellOp == "div") { target.unitInfo.coreDict[keyList[i]][innerKeyList[j]] /= spell.spellValue; } else if (spell.spellOp == "multi") { target.unitInfo.coreDict[keyList[i]][innerKeyList[j]] *= spell.spellValue; } output.text += "\n" + "Cast successful."; i = keyList.Count; j = innerKeyList.Count; } } if (i + 1 == keyList.Count) { output.text += "\n" + "Could not find the affected attribute on target. Cast failed."; } } break; } } else { output.text += "\n" + "The target is out of range."; } } catch (Exception e) { output.text += "\n" + "Caster, Target, or spell name incorrect. Check names." + e; } } }