Пример #1
0
 private static void WinSpell(ref Character character, GameState gameState, GameConfig config)
 {
     AddR(character.Spells, config.Spells[gameState.RandomLow(Math.Min(character.GetStat("WIS") + character.Traits.Level, config.Spells.Length))], 1);
 }
Пример #2
0
        private static void Dequeue(Character character, GameState gameState, GameConfig config)
        {
            while (TaskDone(gameState))
            {
                if (Split(gameState.Task, 0) == "kill")
                {
                    if (Split(gameState.Task, 3) == "*")
                    {
                        WinItem(ref character, gameState, config);
                    }
                    else if (Split(gameState.Task, 3) != "")
                    {
                        AddInventory(character, LowerCase(Split(gameState.Task, 1) + " " +
                                                          ProperCase(Split(gameState.Task, 3))), 1);
                    }
                }
                else if (gameState.Task == "buying")
                {
                    AddInventory(character, "Gold", -EquipPrice(character));
                    WinEquip(ref character, gameState, config);
                }
                else if ((gameState.Task == "market") || (gameState.Task == "sell"))
                {
                    if (gameState.Task == "sell")
                    {
                        var firstItem = character.Inventory.ToArray()[1];
                        var amt       = firstItem.Value * character.Traits.Level;
                        if (Pos(" of ", firstItem.Key) > 0)
                        {
                            amt *= (1 + gameState.RandomLow(10)) * (1 + gameState.RandomLow(character.Traits.Level));
                        }
                        character.Inventory.Remove(firstItem.Key);
                        AddInventory(character, "Gold", amt);
                    }
                    if (character.Inventory.Count > 1)
                    {
                        // character.Inventory.scrollToTop();
                        // Debug.Assert(firstItem == "");
                        var firstItem = character.Inventory.ToArray()[1];
                        Task("Selling " + Indefinite(firstItem.Key, firstItem.Value),
                             1 * 1000, gameState);
                        gameState.Task = "sell";
                        break;
                    }
                }

                var old = gameState.Task;
                gameState.Task = "";
                if (gameState.Q.Count > 0)
                {
                    var a = Split(gameState.Q.Peek(), 0);
                    var n = StrToInt(Split(gameState.Q.Peek(), 1));
                    var s = Split(gameState.Q.Peek(), 2);
                    if (a == "task" || a == "plot")
                    {
                        gameState.Q.Dequeue();
                        if (a == "plot")
                        {
                            CompleteAct(character, gameState, config);
                            s = "Loading " + gameState.BestPlot;
                        }
                        Task(s, n * 1000, gameState);
                    }
                    else
                    {
                        throw new Exception("bah!" + a);
                    }
                }
                else if (character.EncumBar.Done())
                {
                    Task("Heading to market to sell loot", 4 * 1000, gameState);
                    gameState.Task = "market";
                }
                else if ((Pos("kill|", old) <= 0) && (old != "heading"))
                {
                    if (character.Inventory["Gold"] > EquipPrice(character))
                    {
                        Task("Negotiating purchase of better equipment", 5 * 1000, gameState);
                        gameState.Task = "buying";
                    }
                    else
                    {
                        Task("Heading to the killing fields", 4 * 1000, gameState);
                        gameState.Task = "heading";
                    }
                }
                else
                {
                    var nn = character.Traits.Level;
                    var t  = MonsterTask(nn, gameState, config);
                    var InventoryLabelAlsoGameStyleTag = 3;
                    // nn = Math.floor((2 * InventoryLabelAlsoGameStyleTag * t.level * 1000) / nn);
                    nn = (2 * InventoryLabelAlsoGameStyleTag * t.level * 1000) / nn;
                    Task("Executing " + t.description, nn, gameState);
                }
            }
        }
Пример #3
0
 private static string InterestingItem(GameState gameState, GameConfig config)
 {
     return(Pick(config.ItemAttrib, gameState) + " " + Pick(config.Specials, gameState));
 }
Пример #4
0
        private static void WinEquip(ref Character character, GameState gameState, GameConfig config)
        {
            var posn = gameState.Random(character.Equips.Count);

            string[] stuff;
            string[] better;
            string[] worse;

            if (posn == 0)
            {
                stuff  = config.Weapons;
                better = config.OffenseAttrib;
                worse  = config.OffenseBad;
            }
            else
            {
                better = config.DefenseAttrib;
                worse  = config.DefenseBad;
                stuff  = (posn == 1) ? config.Shields : config.Armors;
            }

            var name = LPick(stuff, character.Traits.Level, gameState);
            var qual = StrToInt(Split(name, 1));

            name = Split(name, 0);
            var plus = character.Traits.Level - qual;

            if (plus < 0)
            {
                better = worse;
            }
            var count = 0;

            while (count < 2 && plus != 0)
            {
                var modifier = Pick(better, gameState);
                qual     = StrToInt(Split(modifier, 1));
                modifier = Split(modifier, 0);
                if (Pos(modifier, name) > 0)
                {
                    break;                         // no repeats
                }
                if (Math.Abs(plus) < Math.Abs(plus))
                {
                    break;                                 // too much
                }
                name  = modifier + " " + name;
                plus -= qual;
                ++count;
            }
            if (plus != 0)
            {
                name = plus + " " + name;
            }
            if (plus > 0)
            {
                name = "+" + name;
            }

            // character.Equips[posn] = name;
            var keys   = character.Equips.Keys.ToArray();
            var values = character.Equips.Values.ToArray();

            character.Equips[keys[posn]] = name;
            character.BestEquip          = name;
            if (posn > 1)
            {
                character.BestEquip += " " + values[posn];
            }
        }
Пример #5
0
 private static void WinItem(ref Character character, GameState gameState, GameConfig config)
 {
     AddInventory(character, SpecialItem(gameState, config), 1);
 }
Пример #6
0
 private static string SpecialItem(GameState gameState, GameConfig config)
 {
     return(InterestingItem(gameState, config) + " of " + Pick(config.ItemOfs, gameState));
 }
Пример #7
0
        private static void CompleteQuest(ref Character character, ref GameState gameState, GameConfig config)
        {
            gameState.QuestBar.Reset(50 + gameState.RandomLow(1000));
            if (gameState.Quests.Count != 0)
            {
                // Log("Quest complete: " + gameState.BestQuest);
                gameState.CheckAll(gameState.Quests);

                switch (gameState.Random(4))
                {
                case 0: WinSpell(ref character, gameState, config); break;

                case 1: WinEquip(ref character, gameState, config); break;

                case 2: WinStat(ref character, gameState, config); break;

                case 3: WinItem(ref character, gameState, config); break;
                }
            }

            while (gameState.Quests.Count > 99)
            {
                gameState.Quests.RemoveAt(0);
            }

            gameState.QuestMonster = "";

            string caption = "";

            switch (gameState.Random(5))
            {
            case 0:
                var level = character.Traits.Level;
                var lev   = 0;
                for (var i = 1; i <= 4; ++i)
                {
                    var montag = gameState.Random(config.Monsters.Length);
                    var m      = config.Monsters[montag];
                    var l      = StrToInt(Split(m, 1));
                    if (i == 1 || Math.Abs(l - level) < Math.Abs(lev - level))
                    {
                        lev = l;
                        gameState.QuestMonster      = m;
                        gameState.QuestMonsterIndex = montag;
                    }
                }
                caption = "Exterminate " + Definite(Split(gameState.QuestMonster, 0), 2);
                break;

            case 1:
                caption = "Seek " + Definite(InterestingItem(gameState, config), 1);
                break;

            case 2:
                caption = "Deliver this " + BoringItem(gameState, config);
                break;

            case 3:
                caption = "Fetch me " + Indefinite(BoringItem(gameState, config), 1);
                break;

            case 4:
                var mlev = 0;
                level = character.Traits.Level;
                for (var ii = 1; ii <= 2; ++ii)
                {
                    var montag = gameState.Random(config.Monsters.Length);
                    var m      = config.Monsters[montag];
                    var l      = StrToInt(Split(m, 1));
                    if ((ii == 1) || (Math.Abs(l - level) < Math.Abs(mlev - level)))
                    {
                        mlev = l;
                        gameState.QuestMonster = m;
                    }
                }
                caption = "Placate " + Definite(Split(gameState.QuestMonster, 0), 2);
                gameState.QuestMonster = "";      // We're trying to placate them, after all
                break;
            }

            // if (!game.Quests) game.Quests = [];
            while (gameState.Quests.Count > 99)
            {
                gameState.Quests.RemoveAt(0);                                 // shift();
            }
            // Debug.Assert(caption == "");
            gameState.Quests.Add((caption, false));
            gameState.BestQuest = caption;
            // Quests.AddUI(caption);


            // Log('Commencing quest: ' + caption);

            // SaveGame();
        }
Пример #8
0
 private static string BoringItem(GameState gameState, GameConfig config)
 {
     return(Pick(config.BoringItems, gameState));
 }
Пример #9
0
 private static void Q(Character character, GameState gameState, GameConfig config, string s)
 {
     gameState.Q.Enqueue(s);
     Dequeue(character, gameState, config);
 }
Пример #10
0
 private static object ImpressiveGuy(GameState gameState, GameConfig config)
 {
     return(Pick(config.ImpressiveTitles, gameState) +
            (gameState.Random(2) == 1 ? " of the " + Pick(config.Races, gameState) : " of " + config.GenerateName()));
 }
Пример #11
0
        private static void InterplotCinematic(Character character, GameState gameState, GameConfig config)
        {
            switch (gameState.Random(3))
            {
            case 0:
                Q(character, gameState, config, "task|1|Exhausted, you arrive at a friendly oasis in a hostile land");
                Q(character, gameState, config, "task|2|You greet old friends and meet new allies");
                Q(character, gameState, config, "task|2|You are privy to a council of powerful do-gooders");
                Q(character, gameState, config, "task|1|There is much to be done. You are chosen!");
                break;

            case 1:
                Q(character, gameState, config, "task|1|Your quarry is in sight, but a mighty enemy bars your path!");
                var nemesis = NamedMonster(character.Traits.Level + 3, gameState, config);
                Q(character, gameState, config, "task|4|A desperate struggle commences with " + nemesis);
                var s = gameState.Random(3);
                for (var i = 1; i <= gameState.Random(1 + gameState.Act + 1); ++i)
                {
                    s += 1 + gameState.Random(2);
                    switch (s % 3)
                    {
                    case 0: Q(character, gameState, config, "task|2|Locked in grim combat with " + nemesis); break;

                    case 1: Q(character, gameState, config, "task|2|" + nemesis + " seems to have the upper hand"); break;

                    case 2: Q(character, gameState, config, "task|2|You seem to gain the advantage over " + nemesis); break;
                    }
                }
                Q(character, gameState, config, "task|3|Victory! " + nemesis + " is slain! Exhausted, you lose conciousness");
                Q(character, gameState, config, "task|2|You awake in a friendly place, but the road awaits");
                break;

            case 2:
                var nemesis2 = ImpressiveGuy(gameState, config);
                Q(character, gameState, config, "task|2|Oh sweet relief! You've reached the protection of the good " + nemesis2);
                Q(character, gameState, config, "task|3|There is rejoicing, and an unnerving encouter with " + nemesis2 + " in private");
                Q(character, gameState, config, "task|2|You forget your " + BoringItem(gameState, config) + " and go back to get it");
                Q(character, gameState, config, "task|2|What's this!? You overhear something shocking!");
                Q(character, gameState, config, "task|2|Could " + nemesis2 + " be a dirty double-dealer?");
                Q(character, gameState, config, "task|3|Who can possibly be trusted with this news!? ... Oh yes, of course");
                break;
            }
            Q(character, gameState, config, "plot|1|Loading");
        }
Пример #12
0
        internal static void Step(Character character, GameState gameState, GameConfig config)
        {
            if (gameState.TaskBar.Done())
            {
                gameState.Tasks += 1;
                // game.elapsed += TaskBar.Max().div(1000);

                // ClearAllSelections();

                if (gameState.Kill == "Loading....")
                {
                    gameState.TaskBar.Reset(0);  // Not sure if this is still the ticket
                }
                // gain XP / level up
                var gain = Pos("kill|", gameState.Task) == 1;
                if (gain)
                {
                    if (character.ExpBar.Done())
                    {
                        LevelUp(ref character, gameState, config);
                    }
                    else
                    {
                        character.ExpBar.Increment(gameState.TaskBar.Max / 1000);
                    }
                }

                // advance quest
                if (gain && gameState.Act >= 1)
                {
                    if (gameState.QuestBar.Done() || gameState.Quests.Count == 0)
                    {
                        CompleteQuest(ref character, ref gameState, config);
                    }
                    else
                    {
                        gameState.QuestBar.Increment(gameState.TaskBar.Max / 1000);
                    }
                }

                // advance plot
                if (gain || gameState.Act == 0)
                {
                    if (gameState.PlotBar.Done())
                    {
                        InterplotCinematic(character, gameState, config);
                    }
                    else
                    {
                        gameState.PlotBar.Increment(gameState.TaskBar.Max / 1000);
                    }
                }

                Dequeue(character, gameState, config);
            }
            else
            {
                // var elapsed = timeGetTime() - lasttick;
                // if (elapsed > 100) elapsed = 100;
                // if (elapsed < 0) elapsed = 0;
                // TaskBar.increment(elapsed);
                gameState.TaskBar.Increment(1000); // 1000 msec == 1 sec
            }
        }
Пример #13
0
        private static (string description, int level) MonsterTask(int level, GameState gameState, GameConfig config)
        {
            var definite = false;
            int i;

            for (i = level; i >= 1; --i)
            {
                if (Odds(2, 5, gameState))
                {
                    level += RandSign(gameState);
                }
            }
            if (level < 1)
            {
                level = 1;
            }
            // level = level of puissance of opponent(s) we'll return

            string monster = "";
            int    lev;

            if (Odds(1, 25, gameState))
            {
                // Use an NPC every once in a while
                monster = " " + Split(Pick(config.Races, gameState), 0);
                if (Odds(1, 2, gameState))
                {
                    monster = "passing" + monster + " " + Split(Pick(config.Klasses, gameState), 0);
                }
                else
                {
                    monster  = PickLow(config.Titles, gameState) + " " + config.GenerateName() + " the" + monster;
                    definite = true;
                }
                lev     = level;
                monster = monster + "|" + IntToStr(level) + "|*";
            }
            else if (gameState.QuestMonster != "" && Odds(1, 4, gameState))
            {
                // Use the quest monster
                monster = config.Monsters[gameState.QuestMonsterIndex];
                lev     = StrToInt(Split(monster, 1));
            }
            else
            {
                // Pick the monster out of so many random ones closest to the level we want
                monster = Pick(config.Monsters, gameState);
                lev     = StrToInt(Split(monster, 1));
                for (var ii = 0; ii < 5; ++ii)
                {
                    var m1 = Pick(config.Monsters, gameState);
                    if (Math.Abs(level - StrToInt(Split(m1, 1))) < Math.Abs(level - lev))
                    {
                        monster = m1;
                        lev     = StrToInt(Split(monster, 1));
                    }
                }
            }

            var result = Split(monster, 0);

            gameState.Task = "kill|" + monster;

            var qty = 1;

            if (level - lev > 10)
            {
                // lev is too low. multiply...
                // qty = MathF.Floor((level + gameState.Random(Math.Max(lev,1))) / Math.Max(lev,1));
                qty = (level + gameState.Random(Math.Max(lev, 1))) / Math.Max(lev, 1);
                if (qty < 1)
                {
                    qty = 1;
                }
                // level = Math.Floor(level / qty);
                level = level / qty;
            }

            if ((level - lev) <= -10)
            {
                result = "imaginary " + result;
            }
            else if ((level - lev) < -5)
            {
                i      = 10 + (level - lev);
                i      = 5 - gameState.Random(i + 1);
                result = Sick(i, Young((lev - level) - i, result));
            }
            else if (((level - lev) < 0) && (gameState.Random(2) == 1))
            {
                result = Sick(level - lev, result);
            }
            else if (((level - lev) < 0))
            {
                result = Young(level - lev, result);
            }
            else if ((level - lev) >= 10)
            {
                result = "messianic " + result;
            }
            else if ((level - lev) > 5)
            {
                i      = 10 - (level - lev);
                i      = 5 - gameState.Random(i + 1);
                result = Big(i, Special((level - lev) - i, result));
            }
            else if (((level - lev) > 0) && (gameState.Random(2) == 1))
            {
                result = Big(level - lev, result);
            }
            else if (((level - lev) > 0))
            {
                result = Special(level - lev, result);
            }

            lev   = level;
            level = lev * qty;

            if (!definite)
            {
                result = Indefinite(result, qty);
            }
            return(result, level);
        }