public ConsumableItem(string n, string i, string g, int v, string d, Usage us, IUseEffect useEffect, BattleAction ba, string recip, bool reus) : base(n, i, g, v, d, us) { BattleAction = ba; UseEffect = useEffect; Recipie = recip; Reusable = reus; }
public Battler(Game g, string name) { var mod = new Modifier(); var data = XDocument.Load(g.Content.RootDirectory + g.PathSeperator + "Data" + g.PathSeperator + "Battlers.xml", LoadOptions.None); XElement el = null; foreach (XElement elem in data.Descendants("Battler")) { if (elem.Attribute("internal").Value == name) { el = elem; break; } } this.Name = g.LoadString("Battlers", el.Attribute("internal").Value); this.internalName = (string)el.Attribute("internal"); this.battlerGraphicsFolder = (string)el.Attribute("battlegraphics"); this.worldGraphicsFolder = (string)el.Attribute("worldgraphics"); useBossHealthBar = bool.Parse(el.Attribute("boss").Value); displayStats = !bool.Parse(el.Attribute("boss").Value); exp = int.Parse(el.Attribute("exp").Value); gold = int.Parse(el.Attribute("gold").Value); dropchance = int.Parse(el.Attribute("chance").Value); itemDrop = el.Attribute("item").Value; twoTurns = false; if (el.Attribute("twoturns") != null) { twoTurns = true; } if (el.Attribute("inorder") != null) { inOrder = true; } if (el.Attribute("behaviour") != null) { var args = el.Attribute("behaviour").Value.Split(','); for (int i = 0; i < args.Length; i++) { switch (args[i]) { case ("avoidlight"): { AddBehaviour(Behaviours.FreezeOnLight); break; } case ("flying"): { AddBehaviour(Behaviours.Flying); break; } case ("interactwithent"): { AddBehaviour(Behaviours.InteractWithEntity); break; } case ("sentry"): { AddBehaviour(Behaviours.Sentry); break; } case ("blind"): { AddBehaviour(Behaviours.Blind); break; } case ("wanders"): { AddBehaviour(Behaviours.Wanders); break; } } } } if (el.Element("Sprite") != null) { Width = (int)el.Attribute("width"); Height = (int)el.Attribute("height"); Duration = (float)el.Attribute("interval"); } if (el.Element("Sounds") != null) { if (el.Element("Sounds").Attribute("attack") != null) { Sounds.Add(BattlerAnimType.Attack, el.Element("Sounds").Attribute("attack").Value); } if (el.Element("Sounds").Attribute("die") != null) { Sounds.Add(BattlerAnimType.Die, el.Element("Sounds").Attribute("die").Value); } if (el.Element("Sounds").Attribute("recoil") != null) { Sounds.Add(BattlerAnimType.Recoil, el.Element("Sounds").Attribute("recoil").Value); } if (el.Element("Sounds").Attribute("spell") != null) { Sounds.Add(BattlerAnimType.CastSpell, el.Element("Sounds").Attribute("spell").Value); } } if (el.Element("ScaleFromPlayer") != null) { BattleStats = new BattleStats(this); var playerID = int.Parse(el.Element("ScaleFromPlayer").Attribute("id").Value); var pc = g.party.GetPlayerCharacter(playerID); BattleStats.MaxHP += pc.BattleStats.MaxHP; BattleStats.HP += pc.BattleStats.MaxHP; BattleStats.MaxSP += pc.BattleStats.MaxSP; BattleStats.SP += pc.BattleStats.MaxSP; BattleStats.baseLuck = pc.BattleStats.baseLuck; if (BattleStats.baseAttributes.Count == 0) { BattleStats.baseAttributes.Add(Attributes.Strength, 0); BattleStats.baseAttributes.Add(Attributes.Magic, 0); BattleStats.baseAttributes.Add(Attributes.Dexterity, 0); } BattleStats.baseAttributes[Attributes.Strength] += pc.BattleStats.Attributes[Attributes.Strength]; BattleStats.baseAttributes[Attributes.Magic] += pc.BattleStats.Attributes[Attributes.Magic]; BattleStats.baseAttributes[Attributes.Dexterity] += pc.BattleStats.Attributes[Attributes.Dexterity]; BattleStats.baseArmour += pc.BattleStats.Armour; BattleStats.baseLuck += pc.BattleStats.Luck; BattleStats.baseResistances.Add(DamageTypes.Physical, pc.BattleStats.Resistances[DamageTypes.Physical]); BattleStats.baseResistances.Add(DamageTypes.Fire, pc.BattleStats.Resistances[DamageTypes.Fire]); BattleStats.baseResistances.Add(DamageTypes.Electricity, pc.BattleStats.Resistances[DamageTypes.Electricity]); BattleStats.baseResistances.Add(DamageTypes.Cold, pc.BattleStats.Resistances[DamageTypes.Cold]); BattleStats.baseResistances.Add(DamageTypes.Light, pc.BattleStats.Resistances[DamageTypes.Light]); BattleStats.baseResistances.Add(DamageTypes.Poison, pc.BattleStats.Resistances[DamageTypes.Poison]); } if (el.Element("World") != null) { if (el.Element("World").Attribute("speed") != null) { worldMovementSpeed = int.Parse(el.Element("World").Attribute("speed").Value); } } else { worldMovementSpeed = 4; } if (BattleStats == null) { BattleStats = new BattleStats(this); } BattleStats.MaxHP += int.Parse(el.Element("Stats").Attribute("health").Value); BattleStats.HP += int.Parse(el.Element("Stats").Attribute("health").Value); BattleStats.MaxSP += int.Parse(el.Element("Stats").Attribute("mana").Value); BattleStats.SP += int.Parse(el.Element("Stats").Attribute("mana").Value); if (BattleStats.baseAttributes.Count == 0) { BattleStats.baseAttributes.Add(Attributes.Strength, 0); BattleStats.baseAttributes.Add(Attributes.Magic, 0); BattleStats.baseAttributes.Add(Attributes.Dexterity, 0); } BattleStats.baseAttributes[Attributes.Strength] += int.Parse(el.Element("Stats").Attribute("strength").Value); BattleStats.baseAttributes[Attributes.Magic] += int.Parse(el.Element("Stats").Attribute("magic").Value); BattleStats.baseAttributes[Attributes.Dexterity] += int.Parse(el.Element("Stats").Attribute("agility").Value); BattleStats.baseArmour += int.Parse(el.Element("Stats").Attribute("armour").Value); BattleStats.baseLuck += int.Parse(el.Element("Stats").Attribute("luck").Value); if (BattleStats.baseResistances.Count == 0) { BattleStats.baseResistances.Add(DamageTypes.Physical, int.Parse(el.Element("Resistances").Attribute("phys").Value)); BattleStats.baseResistances.Add(DamageTypes.Fire, int.Parse(el.Element("Resistances").Attribute("fire").Value)); BattleStats.baseResistances.Add(DamageTypes.Electricity, int.Parse(el.Element("Resistances").Attribute("elec").Value)); BattleStats.baseResistances.Add(DamageTypes.Cold, int.Parse(el.Element("Resistances").Attribute("cold").Value)); BattleStats.baseResistances.Add(DamageTypes.Light, int.Parse(el.Element("Resistances").Attribute("light").Value)); BattleStats.baseResistances.Add(DamageTypes.Poison, int.Parse(el.Element("Resistances").Attribute("poison").Value)); if (el.Element("Resistances").Attribute("raw") != null) { BattleStats.baseResistances.Add(DamageTypes.Raw, int.Parse(el.Element("Resistances").Attribute("raw").Value)); } else { BattleStats.baseResistances.Add(DamageTypes.Raw, 0); } } if (el.Element("Invulns") != null) { BattleStats.modInvulnerabilities = el.Element("Invulns").Value.Split(','); } if (el.Element("Vulns") != null) { BattleStats.modVulnerabilities = el.Element("Vulns").Value.Split(','); } battleActions = new List <BattleAction>(); var actions = el.Element("Actions").Value.Split(','); if (actions[0] == "copy_from_player") { for (int i = 0; i < g.party.PlayerCharacters[0].Spells.Count; i++) { if (g.party.PlayerCharacters[0].Spells[i].Usage == Usage.Battle || g.party.PlayerCharacters[0].Spells[i].Usage == Usage.BothSame) { if (g.party.PlayerCharacters[0].Spells[i].BattleAction.tag != "") { battleActions.Add(g.party.PlayerCharacters[0].Spells[i].BattleAction); } } } for (int i = 0; i < g.party.PlayerCharacters[0].Inventory.Count; i++) { if (g.party.PlayerCharacters[0].Inventory[i].Usage == Usage.Battle || g.party.PlayerCharacters[0].Inventory[i].Usage == Usage.BothSame) { if (g.party.PlayerCharacters[0].Inventory[i] is ConsumableItem) { var consum = (ConsumableItem)g.party.PlayerCharacters[0].Inventory[i]; if (consum.BattleAction.tag != "") { if (!battleActions.Contains(consum.BattleAction)) { battleActions.Add(consum.BattleAction); } } } } } } else { for (int i = 0; i < actions.Length; i++) { try { battleActions.Add(g.battleActions.Find(b => b.Name == actions[i])); } catch { Console.WriteLine("PANIC: BATTLER " + internalName + " IS SET TO HAVE ACTION " + actions[i] + " BUT THE ACTION WAS NOT FOUND"); } } } if (el.Element("DefaultAction") != null) { try { defaultAction = g.battleActions.Find(b => b.Name == el.Element("DefaultAction").Value); } catch { Console.WriteLine("PANIC: BATTLER " + internalName + " IS SET TO HAVE DEFAULT ACTION " + el.Element("DefaultAction").Value + " BUT THE ACTION WAS NOT FOUND"); } } if (el.Element("DeathAction") != null) { try { deathAction = g.battleActions.Find(b => b.Name == el.Element("DeathAction").Value); } catch { Console.WriteLine("PANIC: BATTLER " + internalName + " IS SET TO HAVE DEATH ACTION " + el.Element("DeathAction").Value + " BUT THE ACTION WAS NOT FOUND"); } } if (el.Attribute("behaviour").Value == "flying") { BattleStats.Modifiers.Add(g.modifiers.Find(m => m.Name == "mod_flying")); } if (el.Element("Modifiers") != null) { var args = el.Element("Modifiers").Value.Split(','); foreach (string arg in args) { var modi = g.modifiers.Find(m => m.Name == arg); if (modi != null) { BattleStats.Modifiers.Add(modi); } } } if (el.Attribute("tags") != null) { var args = el.Attribute("tags").Value.Split(','); for (int i = 0; i < args.Length; i++) { switch (args[i]) { case ("flying"): BattleStats.tags.Add(BattlerTags.Flying); break; case ("organic"): BattleStats.tags.Add(BattlerTags.Organic); break; case ("machine"): BattleStats.tags.Add(BattlerTags.Mechanic); break; case ("plant"): BattleStats.tags.Add(BattlerTags.Plant); break; case ("magical"): BattleStats.tags.Add(BattlerTags.Magical); break; default: Console.WriteLine("PANIC: ATTEMPTED TO ADD BATTLER TAG:" + args[i] + "TO " + internalName + ", BUT BATTLER TAG DOES NOT EXIST"); break; } } } }
//produces a new list of targets depending upon the entity that used the action and the action itself public static List <Battler> GetTargets(Battler caller, BattleAction action, Battle battle) { var Battlers = battle.Battlers; var team = caller.BattleStats.team; var battlers = new List <Battler>(); battlers.AddRange(Battlers); var targets = new List <Battler>(); for (int e = 0; e < battlers.Count; e++) { if (battlers[e].BattleStats.HP <= 0) { battlers.RemoveAt(e); e--; } } if (action.targetType == BattleAction.TargetType.Self) { var singleTarget = new List <Battler>(); singleTarget.Add(caller); return(singleTarget); } switch (action.bDirection) { case (BattleAction.Direction.Self): { for (int i = 0; i < battlers.Count; i++) { if (battlers[i].BattleStats.team == team) { targets.Add(battlers[i]); } } break; } case (BattleAction.Direction.Enemy): { for (int i = 0; i < battlers.Count; i++) { if (battlers[i].BattleStats.team != team) { targets.Add(battlers[i]); } } break; } case (BattleAction.Direction.Both): { for (int i = 0; i < battlers.Count; i++) { targets.Add(battlers[i]); } break; } } if (action.targetType == BattleAction.TargetType.Random) { return(GetRandomTarget(battle, targets, false).ReturnInList()); } if (action.targetType == BattleAction.TargetType.Single && team == Team.Enemy) { var singleTarget = new List <Battler>(); for (int i = 0; i < targets.Count; i++) { if (targets[i].BattleStats.canTarget == false) { targets.RemoveAt(i); } } if (action.tag == "HEAL") { int losthealth = 0; int target = 0; for (int i = 0; i < battlers.Count; i++) { if (targets[i].BattleStats.team == caller.BattleStats.team) { if (targets[i].BattleStats.HP < losthealth) { target = i; losthealth = targets[i].BattleStats.HP; } } } return(targets[target].ReturnInList()); } if (action.tag == "DAMAGE") { float damage = 0; for (int i = 0; i < action.actionEffects.Count; i++) { if (action.actionEffects[i] is DoDamage) { for (int b = 0; b < targets.Count; b++) { var dmg = (DoDamage)action.actionEffects[i]; damage += dmg.GetHighestResult(caller.BattleStats, targets[b].BattleStats); if (damage > targets[b].BattleStats.HP && targets[b].BattleStats.HP != targets[b].BattleStats.MaxHP) { singleTarget.Add(targets[b]); Console.WriteLine("BATTLE: single target chosen " + targets[b].Name + ", has low health"); return(singleTarget); } damage = 0; } } } singleTarget.Add(GetRandomTarget(battle, targets, false)); if (singleTarget[0] != null) { Console.WriteLine("BATTLE: single target chosen " + singleTarget[0].Name + " randomly"); } else { singleTarget.Clear(); } return(singleTarget); } for (int i = 0; i < action.actionEffects.Count; i++) { if (action.actionEffects[i] is DrainMana) { var drain = action.actionEffects[i] as DrainMana; Battler highest = null; for (int b = 0; b < targets.Count; b++) { //always be on the side of caution if (drain.lower <= targets[b].BattleStats.SP) { highest = targets[b]; } } var highestTarget = new List <Battler>(); highestTarget.Add(highest); if (highest != null) { return(highestTarget); } } } } return(targets); }
public static string ActionText(BattleAction action, Battler user) { return(user.Name + action.IntText); }
public static BattleAction GetEnemyBattleAction(Battle battle, Battler caller, List <Battler> battlers) //battlers is a list containing everyone EXCEPT the target battler { var actions = caller.battleActions.ToList(); var enemies = new List <int>(); var players = new List <int>(); BattleAction battleAction = null; BattleAction healAction = null; BattleAction manaAction = null; var callerHasLowHealth = false; var teamHasLowHealth = false; var callerHasLowMana = false; var teamHasLowMana = false; battlers.Remove(caller); for (int i = 0; i < battlers.Count; i++) { if (battlers[i].BattleStats.team == Team.Enemy) { enemies.Add(i); } else { players.Add(i); } } //first, get rid of actions we cant use for (int i = 0; i < actions.Count; i++) { if (actions[i] == null) { actions.RemoveAt(i); i--; i = MathHelper.Clamp(i--, 0, 999); } if (actions[i].ManaCost > caller.BattleStats.SP) { actions.RemoveAt(i); i--; continue; } } //if the battler has two turns, remove the previous action if (caller.twoTurns) { if (actions.Count > 1) { for (int i = 0; i < actions.Count; i++) { if (actions[i] == caller.lastAction) { actions.RemoveAt(i); i--; continue; } } } } //if the caller has in order, simply return with the chosen turn if (caller.inOrder) { battleAction = actions[MathHelper.Clamp(caller.actionNumber, 0, actions.Count - 1)]; goto ChooseTargets; } if (actions.Count == 0) { } //check if we can use dispel //check if we can heal anyone healAction = actions.Find(b => b.tag == "HEAL"); if (healAction != null) { if ((caller.BattleStats.MaxHP / 100) * 35 > caller.BattleStats.HP) { callerHasLowHealth = true; } for (int i = 0; i < battlers.Count; i++) { if (battlers[i].BattleStats.team == caller.BattleStats.team && (caller.BattleStats.MaxHP / 100) * 35 > caller.BattleStats.HP) { teamHasLowHealth = true; } } if (callerHasLowHealth && healAction != null) { battle.SetTargets(caller.ReturnInList()); return(healAction); } if (teamHasLowHealth) { if (healAction.targetType == BattleAction.TargetType.All) { battle.SetTargets(BattleMethods.GetTargets(caller, healAction, battle)); return(healAction); } goto End; } } //check if anyone needs mana manaAction = actions.Find(b => b.tag == "MANA"); if (manaAction != null) { if ((caller.BattleStats.MaxSP / 100) * 35 > caller.BattleStats.SP) { callerHasLowMana = true; } for (int i = 0; i < battlers.Count; i++) { if (battlers[i].BattleStats.team == caller.BattleStats.team && (caller.BattleStats.MaxSP / 100) * 35 > caller.BattleStats.SP) { teamHasLowMana = true; } } if (callerHasLowMana && manaAction != null) { battle.SetTargets(caller.ReturnInList()); return(manaAction); } if (teamHasLowMana) { if (healAction.targetType == BattleAction.TargetType.All) { battle.SetTargets(BattleMethods.GetTargets(caller, manaAction, battle)); return(manaAction); } goto End; } } //do we have a default action if (actions.Count == 0) { if (caller.defaultAction != null) { battleAction = caller.defaultAction; } } SelectAction: int stop = 0; while (battleAction == null) { if (actions.Count == 0) { return(battle.GetWaitAction()); } battleAction = actions[battle.Random.Next(0, actions.Count)]; if (battleAction.tag == "HEAL" || battleAction.tag == "DISPEL" || battleAction.tag == "MANA") { battleAction = null; stop += 1; if (stop > 500) { return(battle.GetWaitAction()); } } } ChooseTargets :; //prevents applying debuff if the debuff is already present on the character if (battleAction.tag == "DEBUFF" && battleAction.targetType == BattleAction.TargetType.Single) { for (int i = 0; i < battleAction.actionEffects.Count; i++) { if (battleAction.actionEffects[i] is ApplyModifier) { var applyModifier = (ApplyModifier)battleAction.actionEffects[i]; for (int e = 0; ;) { var random = players.ToList(); while (random.Count > 0) { e = battle.Random.Next(0, random.Count); if (battlers[players[e]].BattleStats.Modifiers.Find(m => m.Name == applyModifier.mod.Name) == null && battlers[players[e]].BattleStats.HP > 0) { battle.SetTargets(battlers[players[e]].ReturnInList()); return(battleAction); } random.RemoveAt(e); } if (random.Count == 0) { actions.Remove(battleAction); battleAction = null; goto SelectAction; } break; } } } } //the same, but inverse if (battleAction.tag == "BUFF" && battleAction.targetType == BattleAction.TargetType.Single) { for (int i = 0; i < battleAction.actionEffects.Count; i++) { if (battleAction.actionEffects[i] is ApplyModifier) { var applyModifier = (ApplyModifier)battleAction.actionEffects[i]; if (enemies.Count > 0) { var random = enemies.ToList(); for (int e = 0; ;) { e = battle.Random.Next(0, random.Count); if (battlers[enemies[e]].BattleStats.Modifiers.Find(m => m.Name == applyModifier.mod.Name) == null) { battle.SetTargets(battlers[enemies[e]].ReturnInList()); return(battleAction); } random.RemoveAt(e); if (random.Count == 0) { actions.Remove(battleAction); battleAction = null; goto SelectAction; } } } //to prevent casting it on self when the battler already has it if (caller.BattleStats.Modifiers.Find(m => m.Name == applyModifier.mod.Name) != null) { actions.Remove(battleAction); battleAction = null; goto SelectAction; } battle.SetTargets(caller.ReturnInList()); return(battleAction); } } } if (battleAction.tag == "BUFF" && battleAction.targetType == BattleAction.TargetType.Self) { for (int i = 0; i < battleAction.actionEffects.Count; i++) { if (battleAction.actionEffects[i] is ApplyModifier) { var applyModifier = (ApplyModifier)battleAction.actionEffects[i]; if (caller.BattleStats.Modifiers.Find(m => m.Name == applyModifier.mod.Name) == null) { battle.SetTargets(caller.ReturnInList()); return(battleAction); } actions.Remove(battleAction); battleAction = null; goto SelectAction; } } } End: Console.WriteLine("BATTLE: chosen action " + battleAction.Name); battle.SetTargets(BattleMethods.GetTargets(caller, battleAction, battle)); return(battleAction); }
public ConsumableItem(string n, string i, string g, int v, string d, Usage us, BattleAction ba, string recip) : base(n, i, g, v, d, us) { BattleAction = ba; Recipie = recip; }
public ConsumableItem(string n, string i, string g, int v, string d, Usage usage, BattleAction ba) : base(n, i, g, v, d, usage) { Recipie = ""; BattleAction = ba; }
public void SetBattleAction(BattleAction ba) { BattleAction = ba; manaCost = BattleAction.ManaCost; }