Exemple #1
0
        public static CreatureData operator +(CreatureData a, CreatureData b)
        {
            CreatureData ret = new CreatureData(a.attack + b.attack, a.health + b.health)
            {
                staticKeywords = a.staticKeywords
            };

            foreach (var kw in b.staticKeywords)
            {
                if (ret.staticKeywords.ContainsKey(kw.Key))
                {
                    ret.staticKeywords[kw.Key] += kw.Value;
                }
                else
                {
                    ret.staticKeywords.Add(kw.Key, kw.Value);
                }
            }

            return(ret);
        }
Exemple #2
0
 public Player()
 {
     this.creatureData      = new CreatureData();
     this.shop              = new Shop();
     this.hand              = new Hand();
     this.name              = "No name";
     this.attachedMechs     = new List <Upgrade>();
     this.curMana           = 10;
     this.destroyed         = false;
     this.aftermathMessages = new List <string>();
     this.overloaded        = 0;
     this.ready             = false;
     this.lives             = 0;
     this.playHistory       = new List <List <Card> >();
     this.playHistory.Add(new List <Card>());
     this.boughtThisTurn      = new List <Upgrade>();
     this.specificEffects     = new SpecificEffects();
     this.extraUpgradeEffects = new List <Upgrade>();
     this.nextRoundEffects    = new List <Upgrade>();
     this.pool    = new MinionPool();
     this.maxMana = 10;
 }
Exemple #3
0
        public async Task AttachMech(Upgrade mech, GameHandler gameHandler, int curPlayer, int enemy)
        {
            await mech.OnPlay(gameHandler, curPlayer, enemy);

            foreach (var extraEffect in mech.extraUpgradeEffects)
            {
                await extraEffect.OnPlay(gameHandler, curPlayer, enemy);
            }

            if (mech.creatureData.staticKeywords[StaticKeyword.Magnetic] > 0)
            {
                for (int i = 0; i < mech.creatureData.staticKeywords[StaticKeyword.Magnetic]; i++)
                {
                    await PlayerInteraction.ActivateMagneticAsync(gameHandler, curPlayer, enemy);
                }
            }

            if (mech.creatureData.staticKeywords[StaticKeyword.Echo] > 0)
            {
                gameHandler.players[curPlayer].shop.AddUpgrade(mech.BasicCopy(gameHandler.players[curPlayer].pool));
            }

            if (mech.creatureData.staticKeywords[StaticKeyword.Binary] > 0)
            {
                mech.creatureData.staticKeywords[StaticKeyword.Binary]--;

                Upgrade binaryLessCopy = mech.BasicCopy(gameHandler.players[curPlayer].pool);
                binaryLessCopy.cardText += " (No Binary)";
                binaryLessCopy.creatureData.staticKeywords[StaticKeyword.Binary]--;

                //the copy should have basic stats
                gameHandler.players[curPlayer].hand.AddCard(binaryLessCopy);
            }
            mech.creatureData.staticKeywords[StaticKeyword.Binary] = 0;

            this.creatureData += mech.creatureData;

            this.creatureData.staticKeywords[StaticKeyword.Echo]     = 0;
            this.creatureData.staticKeywords[StaticKeyword.Magnetic] = 0;
            this.creatureData.staticKeywords[StaticKeyword.Freeze]   = 0;
            this.creatureData.staticKeywords[StaticKeyword.Binary]   = 0;

            await mech.Battlecry(gameHandler, curPlayer, enemy);

            foreach (var extraEffect in mech.extraUpgradeEffects)
            {
                await extraEffect.Battlecry(gameHandler, curPlayer, enemy);
            }

            if (gameHandler.players[curPlayer].playHistory[gameHandler.players[curPlayer].playHistory.Count() - 1].Count() > 0)
            {
                mech.Combo(gameHandler, curPlayer, enemy);

                foreach (var extraEffect in mech.extraUpgradeEffects)
                {
                    extraEffect.Combo(gameHandler, curPlayer, enemy);
                }
            }

            this.attachedMechs.Add((Upgrade)mech.DeepCopy());

            foreach (var extraEffect in mech.extraUpgradeEffects)
            {
                this.extraUpgradeEffects.Add((Upgrade)extraEffect.DeepCopy());
            }
        }
Exemple #4
0
        public static void StartBattle(GameHandler gameHandler, int mech1, int mech2)
        {
            //check for any exceptions

            if (Math.Max(mech1, mech2) >= gameHandler.players.Count())
            {
                return;
            }
            //if (mech1 == mech2) { Console.WriteLine($"{gameHandler.players[mech1].name} tried to fight itself."); return; }

            gameHandler.combatOutputCollector.Clear();

            gameHandler.players[mech1].destroyed = false;
            gameHandler.players[mech2].destroyed = false;

            //-introductionHeader output

            int rows1 = 0, rows2 = 0;

            gameHandler.combatOutputCollector.introductionHeader1.Add(gameHandler.players[mech1].GetUpgradesList(out rows1));
            gameHandler.combatOutputCollector.introductionHeader2.Add(gameHandler.players[mech2].GetUpgradesList(out rows2));

            for (int i = 0; i < rows2 - rows1; i++)
            {
                gameHandler.combatOutputCollector.introductionHeader1.Add(string.Empty);
            }

            for (int i = 0; i < rows1 - rows2; i++)
            {
                gameHandler.combatOutputCollector.introductionHeader2.Add(string.Empty);
            }

            //-introductionHeader output

            //save the data so it reverts after combat
            CreatureData crData1 = gameHandler.players[mech1].creatureData.DeepCopy();
            CreatureData crData2 = gameHandler.players[mech2].creatureData.DeepCopy();

            gameHandler.combatOutputCollector.introductionHeader1.Add("\n" + gameHandler.players[mech1].GetInfoForCombat(gameHandler));
            gameHandler.combatOutputCollector.introductionHeader2.Add("\n" + gameHandler.players[mech2].GetInfoForCombat(gameHandler));

            int prStat1 = crData1.staticKeywords[StaticKeyword.Rush] - crData1.staticKeywords[StaticKeyword.Taunt];
            int prStat2 = crData2.staticKeywords[StaticKeyword.Rush] - crData2.staticKeywords[StaticKeyword.Taunt];

            //false = mech1 wins, true = mech2 wins
            bool result;
            //for output purposes


            bool coinflip = false;

            //see who has bigger priority
            if (prStat1 > prStat2)
            {
                result = false;
            }
            else if (prStat1 < prStat2)
            {
                result = true;
            }
            //if tied, check the tiebreaker
            else if (crData1.staticKeywords[StaticKeyword.Tiebreaker] > crData2.staticKeywords[StaticKeyword.Tiebreaker])
            {
                result = false;
            }
            else if (crData1.staticKeywords[StaticKeyword.Tiebreaker] < crData2.staticKeywords[StaticKeyword.Tiebreaker])
            {
                result = true;
            }
            //roll random
            else
            {
                coinflip = true;
                if (GameHandler.randomGenerator.Next(0, 2) == 0)
                {
                    result = false;
                }
                else
                {
                    result = true;
                }
            }

            if (result == true)
            {
                GeneralFunctions.Swap <int>(ref mech1, ref mech2);
                CreatureData midCrData = crData1.DeepCopy();
                crData1 = crData2.DeepCopy();
                crData2 = midCrData.DeepCopy();
            }

            //-preCombat header

            if (!coinflip)
            {
                gameHandler.combatOutputCollector.preCombatHeader.Add($"{gameHandler.players[mech1].name} has Attack Priority.");
                if (gameHandler.players[mech1].specificEffects.invertAttackPriority || gameHandler.players[mech2].specificEffects.invertAttackPriority)
                {
                    gameHandler.combatOutputCollector.preCombatHeader.Add($"Because of a Trick Roomster, {gameHandler.players[mech2].name} has Attack Priority instead.");
                    GeneralFunctions.Swap <int>(ref mech1, ref mech2);
                    CreatureData midCrData = crData1.DeepCopy();
                    crData1 = crData2.DeepCopy();
                    crData2 = midCrData.DeepCopy();
                }
            }
            else
            {
                gameHandler.combatOutputCollector.preCombatHeader.Add($"{gameHandler.players[mech1].name} wins the coinflip for Attack Priority.");
            }

            gameHandler.combatOutputCollector.goingFirst = mech1;

            //trigger Start of Combat effects
            for (int multiplier = 0; multiplier < gameHandler.players[mech1].specificEffects.multiplierStartOfCombat; multiplier++)
            {
                for (int i = 0; i < gameHandler.players[mech1].attachedMechs.Count() && gameHandler.players[mech1].IsAlive() && gameHandler.players[mech2].IsAlive(); i++)
                {
                    gameHandler.players[mech1].attachedMechs[i].StartOfCombat(gameHandler, mech1, mech2);

                    //gameHandler.players[mech1].attachedMechs[i].GetType().GetMethod("StartOfCombat").DeclaringType

                    //var m = gameHandler.players[mech1].attachedMechs[i].S.GetType();


                    //m.DeclaringType

                    if (gameHandler.players[mech1].attachedMechs[i].GetType().GetMethod("StartOfCombat").DeclaringType != typeof(Upgrade).GetMethod("StartOfCombat").DeclaringType)
                    {
                        for (int j = 0; j < gameHandler.players[mech1].attachedMechs.Count(); j++)
                        {
                            gameHandler.players[mech1].attachedMechs[j].OnStartOfCombatTrigger(gameHandler, mech1, mech2);
                        }
                        foreach (var extraEffect in gameHandler.players[mech1].extraUpgradeEffects)
                        {
                            extraEffect.OnStartOfCombatTrigger(gameHandler, mech1, mech2);
                        }
                    }
                }

                foreach (var extraEffect in gameHandler.players[mech1].extraUpgradeEffects)
                {
                    extraEffect.StartOfCombat(gameHandler, mech1, mech2);
                    if (extraEffect.GetType().GetMethod("StartOfCombat").DeclaringType != typeof(Upgrade).GetMethod("StartOfCombat").DeclaringType)
                    {
                        for (int j = 0; j < gameHandler.players[mech1].attachedMechs.Count(); j++)
                        {
                            gameHandler.players[mech1].attachedMechs[j].OnStartOfCombatTrigger(gameHandler, mech1, mech2);
                        }
                        foreach (var extraEffect2 in gameHandler.players[mech1].extraUpgradeEffects)
                        {
                            extraEffect2.OnStartOfCombatTrigger(gameHandler, mech1, mech2);
                        }
                    }
                }
            }

            for (int multiplier = 0; multiplier < gameHandler.players[mech2].specificEffects.multiplierStartOfCombat; multiplier++)
            {
                for (int i = 0; i < gameHandler.players[mech2].attachedMechs.Count() && gameHandler.players[mech1].IsAlive() && gameHandler.players[mech2].IsAlive(); i++)
                {
                    gameHandler.players[mech2].attachedMechs[i].StartOfCombat(gameHandler, mech2, mech1);
                    if (gameHandler.players[mech2].attachedMechs[i].GetType().GetMethod("StartOfCombat").DeclaringType != typeof(Upgrade).GetMethod("StartOfCombat").DeclaringType)
                    {
                        for (int j = 0; j < gameHandler.players[mech2].attachedMechs.Count(); j++)
                        {
                            gameHandler.players[mech2].attachedMechs[j].OnStartOfCombatTrigger(gameHandler, mech2, mech2);
                        }
                        foreach (var extraEffect in gameHandler.players[mech2].extraUpgradeEffects)
                        {
                            extraEffect.OnStartOfCombatTrigger(gameHandler, mech2, mech1);
                        }
                    }
                }

                foreach (var extraEffect in gameHandler.players[mech2].extraUpgradeEffects)
                {
                    extraEffect.StartOfCombat(gameHandler, mech2, mech1);

                    if (extraEffect.GetType().GetMethod("StartOfCombat").DeclaringType != typeof(Upgrade).GetMethod("StartOfCombat").DeclaringType)
                    {
                        for (int j = 0; j < gameHandler.players[mech2].attachedMechs.Count(); j++)
                        {
                            gameHandler.players[mech2].attachedMechs[j].OnStartOfCombatTrigger(gameHandler, mech2, mech1);
                        }
                        foreach (var extraEffect2 in gameHandler.players[mech2].extraUpgradeEffects)
                        {
                            extraEffect2.OnStartOfCombatTrigger(gameHandler, mech2, mech1);
                        }
                    }
                }
            }
            //-preCombat header

            //-combat header
            //the fighting
            for (int curAttacker = 0; gameHandler.players[mech1].IsAlive() && gameHandler.players[mech2].IsAlive(); curAttacker++)
            {
                int attacker, defender;
                if (curAttacker % 2 == 0)
                {
                    attacker = mech1;
                    defender = mech2;
                }
                else
                {
                    attacker = mech2;
                    defender = mech1;
                }

                int dmg = gameHandler.players[attacker].AttackMech(gameHandler, attacker, defender);

                if (!gameHandler.players[mech1].IsAlive() || !gameHandler.players[mech2].IsAlive())
                {
                    break;
                }

                for (int i = 0; i < gameHandler.players[attacker].attachedMechs.Count() && gameHandler.players[mech1].IsAlive() && gameHandler.players[mech2].IsAlive(); i++)
                {
                    gameHandler.players[attacker].attachedMechs[i].AfterThisAttacks(dmg, gameHandler, attacker, defender);
                }
                foreach (var extraEffect in gameHandler.players[attacker].extraUpgradeEffects)
                {
                    if (!(gameHandler.players[mech1].IsAlive() && gameHandler.players[mech2].IsAlive()))
                    {
                        break;
                    }
                    extraEffect.AfterThisAttacks(dmg, gameHandler, attacker, defender);
                }

                for (int i = 0; i < gameHandler.players[defender].attachedMechs.Count() && gameHandler.players[mech1].IsAlive() && gameHandler.players[mech2].IsAlive(); i++)
                {
                    gameHandler.players[defender].attachedMechs[i].AfterTheEnemyAttacks(dmg, gameHandler, defender, attacker);
                }
                foreach (var extraEffect in gameHandler.players[defender].extraUpgradeEffects)
                {
                    if (!(gameHandler.players[mech1].IsAlive() && gameHandler.players[mech2].IsAlive()))
                    {
                        break;
                    }
                    extraEffect.AfterTheEnemyAttacks(dmg, gameHandler, defender, attacker);
                }
            }

            if (gameHandler.players[mech1].IsAlive())
            {
                gameHandler.combatOutputCollector.combatHeader.Add($"{gameHandler.players[mech1].name} has won!");
                gameHandler.players[mech2].lives--;

                gameHandler.pairsHandler.playerResults[gameHandler.pairsHandler.playerResults.Count - 1][mech1] = FightResult.WIN;
                gameHandler.pairsHandler.playerResults[gameHandler.pairsHandler.playerResults.Count - 1][mech2] = FightResult.LOSS;
            }
            else
            {
                gameHandler.combatOutputCollector.combatHeader.Add($"{gameHandler.players[mech2].name} has won!");
                gameHandler.players[mech1].lives--;

                gameHandler.pairsHandler.playerResults[gameHandler.pairsHandler.playerResults.Count - 1][mech1] = FightResult.LOSS;
                gameHandler.pairsHandler.playerResults[gameHandler.pairsHandler.playerResults.Count - 1][mech2] = FightResult.WIN;
            }

            //-combat header


            //revert to before the fight
            gameHandler.players[mech1].creatureData = crData1.DeepCopy();
            gameHandler.players[mech2].creatureData = crData2.DeepCopy();

            gameHandler.players[mech1].destroyed = false;
            gameHandler.players[mech2].destroyed = false;
        }