示例#1
0
        private void Buy(int itemID)
        {
            ConsoleKey key      = ConsoleKey.Applications;
            string     numToBuy = "0";

            while (true)
            {
                DrawSelections();
                Item   item       = Data._itemInfo.items.Find(theItem => theItem.id == itemID);
                int    itemPrice  = _shop.sellPrices [_shop.sellItemIDs.IndexOf(itemID)];
                string totalPrice = (Convert.ToInt64(numToBuy) * itemPrice).ToString();
                string line2      = "Total Price" + " " + totalPrice;
                string line1      = "# to Buy   " + " " + new string (' ', totalPrice.Length - numToBuy.Length) + numToBuy;
                DrawAmountBox(new List <string> {
                    line1, line2
                }, new string (' ', totalPrice.Length - numToBuy.Length) + numToBuy, 0);
                key      = Console.ReadKey(true).Key;
                numToBuy = HandleKey(key, numToBuy);

                if (item.unlimited)
                {
                    if (numToBuy != "0" && numToBuy != "1")
                    {
                        numToBuy = "1";
                    }
                }

                if (key == ConsoleKey.Enter)
                {
                    if (numToBuy != "0")
                    {
                        if (Convert.ToInt64(totalPrice) <= GameFile._money)
                        {
                            GameFile._money = (int)((long)GameFile._money - Convert.ToInt64(totalPrice));
                            TypeWrite(BuildText(_shop.boughtText, item, numToBuy), ConsoleColor.DarkYellow, true, false, true);

                            for (int i = 0; i < Convert.ToInt64(numToBuy); i++)
                            {
                                GameFile.AddItem(item.id);
                            }

                            break;
                        }
                        else
                        {
                            TypeWrite(BuildText(_shop.cannotAffordText, item, numToBuy), ConsoleColor.DarkYellow, true, false, true);
                            TypeWrite(item.desc, ConsoleColor.DarkYellow, false, false, false);
                        }
                    }
                }
                else if (key == ConsoleKey.Escape)
                {
                    break;              //Pressed escape
                }
            }
        }
示例#2
0
        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]);
                }
            }
        }
示例#3
0
        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);
        }