private void GetTrainers() { XmlNodeList trainers = _xml ["data"]["trainers"].ChildNodes; foreach (XmlNode trainerN in trainers) { Trainer trainer = new Trainer(); trainer.id = Convert.ToInt32(trainerN.Attributes ["id"].Value); trainer.name = trainerN.Attributes ["name"].Value; trainer.units = new List <Unit> { }; List <string> idsAndLevels = trainerN.Attributes ["units"].Value.Split(new string [] { "," }, StringSplitOptions.None).ToList(); foreach (string s in idsAndLevels) { int id = Convert.ToInt32(s.Substring(0, s.IndexOf("-"))); int level = Convert.ToInt32(s.Substring(s.IndexOf("-") + 1)); trainer.units.Add(UnitMaster.MakeUnit(id, level)); } trainer.encounterText = trainerN.Attributes ["encounterText"].Value; trainer.sendOutUnitText = trainerN.Attributes ["sendOutUnitText"].Value; trainer.unitDiedText = trainerN.Attributes ["unitDiedText"].Value; trainer.allUnitsDiedText = trainerN.Attributes ["allUnitsDiedText"].Value; trainer.playerLoseText = trainerN.Attributes ["playerLoseText"].Value; trainer.playerWinText = trainerN.Attributes ["playerWinText"].Value; trainer.moneyGainText = trainerN.Attributes ["moneyGainText"].Value; trainer.moneyLoseText = trainerN.Attributes ["moneyLoseText"].Value; trainer.moneyGain = Convert.ToInt32(trainerN.Attributes ["moneyGain"].Value); trainer.moneyLose = Convert.ToInt32(trainerN.Attributes ["moneyLose"].Value); _trainers.Add(trainer); } }
public static void IncreaseEXP(Unit unit, int exp, bool instant) { decimal expLeft = exp; int expBase = Data._unitInfo.expNextBase; decimal expMult = Data._unitInfo.expNextMult; decimal expPrev = (int)(expBase * (decimal)(1 - Math.Pow((double)expMult, unit.level - 1)) / (1 - expMult)); decimal increment = (unit.expNext - expPrev) / 100; int intervals = (int)Math.Ceiling(expLeft / increment); for (int i = 0; i < intervals; i++) { if (expLeft < increment) { increment = expLeft; } if (unit.exp + increment >= unit.expNext) { expLeft -= unit.expNext - unit.exp; if (unit.level < Data._unitInfo.maxLevel) { LevelUpUnit(unit); UnitMaster.IncreaseEXP(unit, (int)expLeft, instant); } else { unit.exp = unit.expNext - 1; } break; } else { unit.exp += increment; expLeft -= increment; } IncreaseEXPEvent(unit); if (expLeft <= 0) { break; } if (!instant) { Thread.Sleep(3); } } }
public Trainer Clone() { Trainer clone = (Trainer)this.MemberwiseClone(); clone.units = new List <Unit> { }; for (int i = 0; i < this.units.Count(); i++) { clone.units.Add(UnitMaster.MakeUnit(this.units [i].id, this.units [i].level)); } return(clone); }
private void onUseItem(Item item, int unitIndex, ref bool usedItem) { usedItem = true; if (item.effect == Item.Effect.HealHP) { IncreaseHP(GameFile._units [unitIndex], (int)item.effectNum); } else if (item.effect == Item.Effect.Revive) { IncreaseHP(GameFile._units [unitIndex], (int)(GameFile._units [unitIndex].stats ["HP"] * item.effectNum)); } else if (item.effect == Item.Effect.TeachMove) { usedItem = UnitMaster.LearnMove(this, GameFile._units [unitIndex], Data._moveInfo.moves.Find(m => m.id == (int)item.effectNum)); } else if (item.effect == Item.Effect.Cure) { GameFile._units [unitIndex].ailment.turns = 0; new MenuUnitsScreen(unitIndex); } else if (item.effect == Item.Effect.GiveEXP) { decimal expBefore = GameFile._units [unitIndex].exp; UnitMaster.IncreaseEXPEvent -= onIncreaseEXP; UnitMaster.IncreaseEXPEvent += onIncreaseEXP; UnitMaster.LevelUpEvent -= onLevelUp; UnitMaster.LevelUpEvent += onLevelUp; UnitMaster.IncreaseEXP(GameFile._units [unitIndex], (int)item.effectNum, true); if (GameFile._units [unitIndex].exp - expBefore < (decimal)item.effectNum) { TypeWrite(BuildText(Data._unitInfo.cannotLevelUpText, GameFile._units [unitIndex]), ConsoleColor.DarkYellow, true, false, true); } } else if (item.effect == Item.Effect.GiveLevel) { if (GameFile._units [unitIndex].level == Data._unitInfo.maxLevel) { TypeWrite(BuildText(Data._unitInfo.cannotLevelUpText, GameFile._units [unitIndex]), ConsoleColor.DarkYellow, true, false, true); GameFile._units [unitIndex].exp = GameFile._units [unitIndex].expNext - 1; } else { UnitMaster.LevelUpEvent -= onLevelUp; UnitMaster.LevelUpEvent += onLevelUp; UnitMaster.LevelUpUnit(GameFile._units [unitIndex]); } } }
public static void LoadFile(XmlDocument file) { _fileName = file ["data"].Attributes ["fileName"].Value; XmlNode playerInfo = file ["data"]["playerInfo"]; _roomID = Convert.ToInt32(playerInfo.Attributes ["roomID"].Value); _spawnRoomID = Convert.ToInt32(playerInfo.Attributes ["spawnRoomID"].Value); _money = Convert.ToInt32(playerInfo.Attributes ["money"].Value); _lastBattleWon = Boolean.Parse(playerInfo.Attributes ["lastBattleWon"].Value); _lastGetUnitID = Convert.ToInt32(playerInfo.Attributes ["lastGetUnitID"].Value); _lastGetItemID = Convert.ToInt32(playerInfo.Attributes ["lastGetItemID"].Value); _lastTeachMoveID = Convert.ToInt32(playerInfo.Attributes ["lastTeachMoveID"].Value); _lastTeachUnitID = Convert.ToInt32(playerInfo.Attributes ["lastTeachUnitID"].Value); XmlNode unitsInBag = file ["data"]["unitsInBag"]; foreach (XmlNode unitN in unitsInBag) { Unit p = UnitMaster.MakeUnit(Convert.ToInt32(unitN.Attributes ["id"].Value), Convert.ToInt32(unitN.Attributes ["level"].Value)); p.name = unitN.Attributes ["name"].Value; p.hpLeft = Convert.ToDecimal(unitN.Attributes ["hpLeft"].Value); p.exp = Convert.ToDecimal(unitN.Attributes ["exp"].Value); p.moves = new List <Move> (); string [] moves = unitN.Attributes ["moves"].Value.Split(new char [] { ',' }); foreach (string moveS in moves) { int id = Convert.ToInt32(moveS.Substring(0, moveS.IndexOf("-"))); int usesLeft = Convert.ToInt32(moveS.Substring(moveS.IndexOf("-") + 1)); Move move = DataCloner.CloneMove(Data._moveInfo.moves.Find(theMove => theMove.id == id)); move.usesLeft = usesLeft; p.moves.Add(move); } GameFile._units.Add(p); } XmlNode itemsInBag = file ["data"]["itemsInBag"]; foreach (XmlNode itemN in itemsInBag) { for (int i = 0; i < Convert.ToInt32(itemN.Attributes ["amount"].Value); i++) { AddItem(Convert.ToInt32(itemN.Attributes ["id"].Value)); } } }
public static void CreateFile() { _roomID = Data._startInfo.roomID; _spawnRoomID = Data._startInfo.spawnRoomID; _money = Data._startInfo.money; for (int i = 0; i < Data._startInfo.unitIDs.Count(); i++) { _units.Add(UnitMaster.MakeUnit(Data._startInfo.unitIDs [i], Data._startInfo.unitLevels [i])); } for (int i = 0; i < Data._startInfo.itemIDs.Count(); i++) { for (int j = 0; j < Data._startInfo.itemAmounts [i]; j++) { GameFile.AddItem(Data._startInfo.itemIDs [i]); } } }
private void onLevelUp(Unit unit) { TypeWrite(BuildText(Data._unitInfo.levelUpText, unit), ConsoleColor.DarkYellow, false); if (Console.KeyAvailable) { Console.ReadKey(true); } Console.ReadKey(true); Clear(ClearType.AboveDialog); for (int i = 0; i < unit.nativeMoveLevels.Count(); i++) { if (unit.nativeMoveLevels [i] == unit.level) { UnitMaster.LearnMove(this, unit, unit.nativeMoves [i]); } } }
private void IncreaseHP(Unit unit, int amount) { UnitMaster.IncreaseHPEvent -= onIncreaseHP; UnitMaster.IncreaseHPEvent += onIncreaseHP; UnitMaster.IncreaseHP(unit, amount, false); }
private bool HandleOptionItem(OptionItem ifAction, List <OptionItem> ifActionList) { if (ifAction.GetType() == typeof(Loop)) { Loop loop = (Loop)ifAction; for (int i = 0; i < loop.repeat; i++) { ifActionList.InsertRange(ifActionList.IndexOf(ifAction) + 1, loop.items); } return(false); } else if (ifAction.GetType() == typeof(OptionCondition)) { OptionCondition condition = (OptionCondition)ifAction; bool isTrue = false; switch (condition.comparison) { case OptionCondition.Comparison.MoneyGreaterThan: if (GameFile._money > Convert.ToInt32(condition.expression)) { isTrue = true; } break; case OptionCondition.Comparison.MoneyLessThan: if (GameFile._money < Convert.ToInt32(condition.expression)) { isTrue = true; } break; case OptionCondition.Comparison.AllUnitsDead: if (UnitMaster.AllDead()) { isTrue = true; } break; case OptionCondition.Comparison.LastBattleWon: if (GameFile._lastBattleWon) { isTrue = true; } break; case OptionCondition.Comparison.HasItem: if (GameFile._items.Exists(item => item.itemId == Convert.ToInt32(condition.expression.Substring(0, condition.expression.IndexOf("-"))))) { List <ItemStack> stacks = GameFile._items.FindAll(item => item.itemId == Convert.ToInt32(condition.expression.Substring(0, condition.expression.IndexOf("-")))); int count = 0; foreach (ItemStack stack in stacks) { count += stack.amount; if (count >= Convert.ToInt32(condition.expression.Substring(condition.expression.IndexOf("-") + 1))) { isTrue = true; break; } } } break; case OptionCondition.Comparison.HasUnit: if (GameFile._units.Exists(unit => unit.id == Convert.ToInt32(condition.expression))) { isTrue = true; } break; case OptionCondition.Comparison.HasLevelRange: if (GameFile._units.Exists(unit => unit.level >= Convert.ToInt32(condition.expression.Substring(0, condition.expression.IndexOf("-"))) && unit.level <= Convert.ToInt32(condition.expression.Substring(condition.expression.IndexOf("-") + 1)))) { isTrue = true; } break; } if (isTrue) { ifActionList.InsertRange(ifActionList.IndexOf(ifAction) + 1, condition.trueItems); } else { ifActionList.InsertRange(ifActionList.IndexOf(ifAction) + 1, condition.falseItems); } return(false); } else if (ifAction.GetType() == typeof(Action)) { Action action = (Action)ifAction; switch (action.type) { case Action.Type.GetUnit: Unit unit = UnitMaster.MakeUnit(Convert.ToInt32(action.vars ["unitID"]), Convert.ToInt32(action.vars ["unitLevel"])); new GetUnitScreen(unit, action.vars ["text"], Boolean.Parse(action.vars ["canRename"])); return(false); case Action.Type.GetItem: for (int i = 0; i < Convert.ToInt32(action.vars ["amount"]); i++) { GameFile.AddItem(Convert.ToInt32(action.vars ["itemID"])); } return(false); case Action.Type.GetMoney: GameFile._money += Convert.ToInt32(action.vars ["amount"]); return(false); case Action.Type.LoseItem: for (int i = 0; i < Convert.ToInt32(action.vars ["amount"]); i++) { GameFile.RemoveItem(Convert.ToInt32(action.vars ["itemID"])); } return(false); case Action.Type.LoseMoney: if (GameFile._money <= Convert.ToInt32(action.vars ["amount"])) { GameFile._money = 0; } else { GameFile._money -= Convert.ToInt32(action.vars ["amount"]); } return(false); case Action.Type.UnitGainEXP: if (GameFile._units.Count() > 0) { if (GameFile._units [0].level == Data._unitInfo.maxLevel && GameFile._units [0].exp == GameFile._units [0].expNext - 1) { TypeWrite(BuildText(Data._unitInfo.cannotLevelUpText, GameFile._units [0]), ConsoleColor.DarkYellow, true, false, true); break; } else { decimal expBefore = GameFile._units [0].exp; UnitMaster.IncreaseEXPEvent -= onIncreaseEXP; UnitMaster.IncreaseEXPEvent += onIncreaseEXP; UnitMaster.LevelUpEvent -= onLevelUp; UnitMaster.LevelUpEvent += onLevelUp; if (GameFile._units [0].hpLeft > 0) { UnitMaster.IncreaseEXP(GameFile._units [0], Convert.ToInt32(action.vars ["amount"]), true); if (GameFile._units [0].exp - expBefore < Convert.ToDecimal(action.vars ["amount"])) { TypeWrite(BuildText(Data._unitInfo.cannotLevelUpText, GameFile._units [0]), ConsoleColor.DarkYellow, true, false, true); } } } return(false); } else { TypeWrite(Data._battleInfo.noUnitsText, ConsoleColor.DarkYellow, true, false, true); return(true); } case Action.Type.AllUnitsGainEXP: if (GameFile._units.Count() > 0) { UnitMaster.IncreaseEXPEvent -= onIncreaseEXP; UnitMaster.IncreaseEXPEvent += onIncreaseEXP; UnitMaster.LevelUpEvent -= onLevelUp; UnitMaster.LevelUpEvent += onLevelUp; foreach (Unit u in GameFile._units) { if (u.level == Data._unitInfo.maxLevel && u.exp == u.expNext - 1) { TypeWrite(BuildText(Data._unitInfo.cannotLevelUpText, u), ConsoleColor.DarkYellow, true, false, true); break; } else { if (u.hpLeft > 0) { decimal expBefore = u.exp; UnitMaster.IncreaseEXP(u, Convert.ToInt32(action.vars ["amount"]), true); if (u.exp - expBefore < Convert.ToDecimal(action.vars ["amount"])) { TypeWrite(BuildText(Data._unitInfo.cannotLevelUpText, u), ConsoleColor.DarkYellow, true, false, true); } } } } return(false); } else { TypeWrite(Data._battleInfo.noUnitsText, ConsoleColor.DarkYellow, true, false, true); return(true); } case Action.Type.UnitLevelUp: if (GameFile._units.Count() > 0) { UnitMaster.LevelUpEvent -= onLevelUp; UnitMaster.LevelUpEvent += onLevelUp; for (int i = 0; i < Convert.ToInt32(action.vars ["amount"]); i++) { if (GameFile._units [0].level == Data._unitInfo.maxLevel) { TypeWrite(BuildText(Data._unitInfo.cannotLevelUpText, GameFile._units [0]), ConsoleColor.DarkYellow, true, false, true); GameFile._units [0].exp = GameFile._units [0].expNext - 1; break; } else { if (GameFile._units [0].hpLeft > 0) { UnitMaster.LevelUpUnit(GameFile._units [0]); } } } return(false); } else { TypeWrite(Data._battleInfo.noUnitsText, ConsoleColor.DarkYellow, true, false, true); return(true); } case Action.Type.AllUnitsLevelUp: if (GameFile._units.Count() > 0) { UnitMaster.LevelUpEvent -= onLevelUp; UnitMaster.LevelUpEvent += onLevelUp; foreach (Unit u in GameFile._units) { for (int i = 0; i < Convert.ToInt32(action.vars ["amount"]); i++) { if (u.level == Data._unitInfo.maxLevel) { TypeWrite(BuildText(Data._unitInfo.cannotLevelUpText, u), ConsoleColor.DarkYellow, true, false, true); u.exp = u.expNext - 1; break; } else { if (u.hpLeft > 0) { UnitMaster.LevelUpUnit(u); } } } } return(false); } else { TypeWrite(Data._battleInfo.noUnitsText, ConsoleColor.DarkYellow, true, false, true); return(true); } case Action.Type.FightWild: if (Convert.ToDouble(action.vars ["chance"]) >= PreGameScreen._rand.NextDouble()) { if (GameFile._units.Exists(theUnit => theUnit.hpLeft > 0)) { int [] unitIDs = Array.ConvertAll <string, int> (action.vars ["unitIDs"].Split(new char [] { ',' }), delegate(string s) { return(Convert.ToInt32(s)); }); int minLevel = Convert.ToInt32(action.vars ["minLevel"]); int maxLevel = Convert.ToInt32(action.vars ["maxLevel"]); Unit bad = UnitMaster.MakeUnit(unitIDs [PreGameScreen._rand.Next(0, unitIDs.Count())], PreGameScreen._rand.Next(minLevel, maxLevel + 1)); new BattleScreen(bad, Boolean.Parse(action.vars ["canEscape"]), Boolean.Parse(action.vars ["canCatch"])); DrawScreenTitle(_roomName); return(false); } else { TypeWrite(Data._battleInfo.noUnitsText, ConsoleColor.DarkYellow, true, false, true); _nextRoomId = _roomId; return(true); } } return(false); case Action.Type.FightTrainer: if (Convert.ToDouble(action.vars ["chance"]) >= PreGameScreen._rand.NextDouble()) { if (GameFile._units.Exists(theUnit => theUnit.hpLeft > 0)) { new BattleScreen(Data._trainers.Find(t => t.id == Convert.ToInt32(action.vars ["trainerID"])).Clone(), Boolean.Parse(action.vars ["canEscape"]), Boolean.Parse(action.vars ["canCatch"])); DrawScreenTitle(_roomName); return(false); } else { TypeWrite(Data._battleInfo.noUnitsText, ConsoleColor.DarkYellow, true, false, true); _nextRoomId = _roomId; return(true); } } return(false); case Action.Type.SetUnitHP: if (GameFile._units.Count() > 0) { GameFile._units [0].hpLeft = (decimal)(Convert.ToDouble(action.vars ["percent"]) * GameFile._units [0].stats ["HP"]); return(false); } else { TypeWrite(Data._battleInfo.noUnitsText, ConsoleColor.DarkYellow, true, false, true); return(true); } case Action.Type.SetAllUnitsHP: if (GameFile._units.Count() > 0) { foreach (Unit p in GameFile._units) { p.hpLeft = (decimal)(Convert.ToDouble(action.vars ["percent"]) * p.stats ["HP"]); } return(false); } else { TypeWrite(Data._battleInfo.noUnitsText, ConsoleColor.DarkYellow, true, false, true); return(true); } case Action.Type.ChargeUnitMoves: if (GameFile._units.Count() > 0) { for (int i = 0; i < GameFile._units [0].moves.Count(); i++) { Move move = GameFile._units [0].moves [i]; move.usesLeft = move.uses; GameFile._units [0].moves [i] = move; } return(false); } else { TypeWrite(Data._battleInfo.noUnitsText, ConsoleColor.DarkYellow, true, false, true); return(true); } case Action.Type.ChargeAllUnitsMoves: if (GameFile._units.Count() > 0) { for (int j = 0; j < GameFile._units.Count(); j++) { for (int i = 0; i < GameFile._units [j].moves.Count(); i++) { Move move = GameFile._units [j].moves [i]; move.usesLeft = move.uses; GameFile._units [j].moves [i] = move; } } return(false); } else { TypeWrite(Data._battleInfo.noUnitsText, ConsoleColor.DarkYellow, true, false, true); return(true); } case Action.Type.TeachUnitMove: if (GameFile._units.Count() > 0) { UnitMaster.LearnMove(this, GameFile._units [0], Data._moveInfo.moves.Find(m => m.id == Convert.ToInt32(action.vars ["moveID"]))); return(false); } else { TypeWrite(Data._battleInfo.noUnitsText, ConsoleColor.DarkYellow, true, false, true); return(true); } case Action.Type.TeachAllUnitMove: if (GameFile._units.Count() > 0) { foreach (Unit p in GameFile._units) { UnitMaster.LearnMove(this, p, Data._moveInfo.moves.Find(m => m.id == Convert.ToInt32(action.vars ["moveID"]))); } return(false); } else { TypeWrite(Data._battleInfo.noUnitsText, ConsoleColor.DarkYellow, true, false, true); return(true); } case Action.Type.Text: TypeWrite(action.vars ["text"], ConsoleColor.DarkYellow, true); return(false); case Action.Type.Move: _nextRoomId = Convert.ToInt32(action.vars ["roomID"]); DrawScreenTitle(Data._rooms.Find(r => r.id == _nextRoomId).name); return(false); case Action.Type.ItemShop: new ItemShopScreen(Convert.ToInt32(action.vars ["shopID"])); Clear(ClearType.Both); DrawScreenTitle(_roomName); return(false); case Action.Type.SetAsSpawn: GameFile._spawnRoomID = GameFile._roomID; return(false); case Action.Type.Options: HandleOptionList(action.options, action.vars ["dialog"]); return(false); case Action.Type.Break: _breaksLeft = Convert.ToInt32(action.vars ["amount"]); return(true); case Action.Type.SwapRoomIDs: Room r1 = Data._rooms.Find(r => r.id == Convert.ToInt32(action.vars ["room1ID"])); Room r2 = Data._rooms.Find(r => r.id == Convert.ToInt32(action.vars ["room2ID"])); int r1Index = Data._rooms.IndexOf(r1); int r2Index = Data._rooms.IndexOf(r2); int tempID = r1.id; r1.id = r2.id; r2.id = tempID; Data._rooms [r1Index] = r1; Data._rooms [r2Index] = r2; return(false); } } return(true); }