コード例 #1
0
        public async Task <FightOutputCollector> Fight(ulong mech1, ulong mech2, CommandContext ctx)
        {
            Console.WriteLine("fight1");
            if (!this.players.ContainsKey(mech1) || !this.players.ContainsKey(mech2))
            {
                return(null);
            }
            Console.WriteLine("fight2");
            FightOutputCollector outputCollector = new FightOutputCollector();

            Console.WriteLine("fight3");
            this.players[mech1].destroyed = false;
            this.players[mech2].destroyed = false;

            int rows1 = 0, rows2 = 0;

            outputCollector.playerInfoOutput1.Add(this.players[mech1].GetUpgradesList(out rows1));
            outputCollector.playerInfoOutput2.Add(this.players[mech2].GetUpgradesList(out rows2));
            Console.WriteLine("fight4");
            for (int i = 0; i < rows2 - rows1; i++)
            {
                outputCollector.playerInfoOutput1.Add(string.Empty);
            }

            for (int i = 0; i < rows1 - rows2; i++)
            {
                outputCollector.playerInfoOutput2.Add(string.Empty);
            }
            Console.WriteLine("fight5");
            CreatureData crData1 = this.players[mech1].creatureData.DeepCopy();
            CreatureData crData2 = this.players[mech2].creatureData.DeepCopy();

            outputCollector.playerInfoOutput1.Add("\n" + this.players[mech1].GetInfoForCombat(this));
            outputCollector.playerInfoOutput2.Add("\n" + this.players[mech2].GetInfoForCombat(this));

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

            Console.WriteLine("fight6");
            //false = mech1 wins, true = mech2 wins
            bool result;
            //for output purposes

            bool coinflip = false;

            Console.WriteLine("fight7");
            //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;
                }
            }
            Console.WriteLine("fight8");
            if (result == true)
            {
                ulong mid = mech1;
                mech1 = mech2;
                mech2 = mid;

                CreatureData midCrData = crData1.DeepCopy();
                crData1 = crData2.DeepCopy();
                crData2 = midCrData.DeepCopy();
            }
            Console.WriteLine("fight9");
            //-preCombat header

            if (!coinflip)
            {
                outputCollector.preCombatOutput.Add($"{this.players[mech1].name} has Attack Priority.");
                if (this.players[mech1].specificEffects.invertAttackPriority || this.players[mech2].specificEffects.invertAttackPriority)
                {
                    outputCollector.preCombatOutput.Add($"Because of a Trick Roomster, {this.players[mech2].name} has Attack Priority instead.");

                    ulong mid = mech1;
                    mech1 = mech2;
                    mech2 = mid;

                    CreatureData midCrData = crData1.DeepCopy();
                    crData1 = crData2.DeepCopy();
                    crData2 = midCrData.DeepCopy();
                }
            }
            else
            {
                outputCollector.preCombatOutput.Add($"{this.players[mech1].name} wins the coinflip for Attack Priority.");
            }

            Console.WriteLine("fight10");

            outputCollector.goingFirst = mech1;

            //need to trigger Start of Combat here

            for (int multiplier = 0; multiplier < this.players[mech1].specificEffects.multiplierStartOfCombat; multiplier++)
            {
                ExtraEffectInfo.StartOfCombatInfo SOCInfo = new ExtraEffectInfo.StartOfCombatInfo(ctx, mech1);

                await Effect.CallEffects(this.players[mech1].effects, Effect.EffectType.StartOfCombat, null, this, mech1, mech2, SOCInfo);

                for (int i = 0; i < SOCInfo.output.Count(); i++)
                {
                    outputCollector.preCombatOutput.Add(SOCInfo.output[i]);
                }

                //need to do something about effects that trigger whenever a start of combat triggers
            }
            Console.WriteLine("fight11");
            for (int multiplier = 0; multiplier < this.players[mech2].specificEffects.multiplierStartOfCombat; multiplier++)
            {
                ExtraEffectInfo.StartOfCombatInfo SOCInfo = new ExtraEffectInfo.StartOfCombatInfo(ctx, mech2);

                await Effect.CallEffects(this.players[mech2].effects, Effect.EffectType.StartOfCombat, null, this, mech2, mech1, SOCInfo);

                for (int i = 0; i < SOCInfo.output.Count(); i++)
                {
                    outputCollector.preCombatOutput.Add(SOCInfo.output[i]);
                }

                //need to do something about effects that trigger whenever a start of combat triggers
            }
            Console.WriteLine("fight12");
            //-preCombat header


            //combat header
            for (int curAttacker = 0; this.players[mech1].IsAlive() && this.players[mech2].IsAlive(); curAttacker++)
            {
                Console.WriteLine("attacking1");
                ulong attacker, defender;
                if (curAttacker % 2 == 0)
                {
                    attacker = mech1;
                    defender = mech2;
                }
                else
                {
                    attacker = mech2;
                    defender = mech1;
                }
                Console.WriteLine("attacking2");
                // If needed to change the attack mech method to
                var damageInfo = await this.players[attacker].AttackMech(this, attacker, defender, ctx);
                Console.WriteLine("attacking3");
                outputCollector.combatOutput.Add(damageInfo.output);
                Console.WriteLine("attacking4");

                if (!this.players[mech1].IsAlive() || !this.players[mech2].IsAlive())
                {
                    break;
                }
                //should stop when a player is dead
                Console.WriteLine("attacking5");
                var combatInfo = new ExtraEffectInfo.AfterAttackInfo(ctx, damageInfo.dmg);
                Console.WriteLine("attacking6");
                await Effect.CallEffects(this.players[attacker].effects, Effect.EffectType.AfterThisAttacks, null, this, attacker, defender, combatInfo);

                Console.WriteLine("attacking7");
                //should stop when a player is dead
                combatInfo.calledEffect = Effect.EffectType.AfterTheEnemyAttacks;
                await Effect.CallEffects(this.players[attacker].effects, Effect.EffectType.AfterTheEnemyAttacks, null, this, defender, attacker, combatInfo);

                Console.WriteLine("attacking8");
            }
            Console.WriteLine("fight13");

            if (this.players[mech1].IsAlive())
            {
                outputCollector.combatOutput.Add($"{this.players[mech1].name} has won!");

                if (this.players[mech1].specificEffects.invertAttackPriority || this.players[mech2].specificEffects.invertAttackPriority)
                {
                    this.players[mech1].lives++;
                }
                else
                {
                    this.players[mech2].lives--;
                }

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

                if (this.players[mech1].specificEffects.invertAttackPriority || this.players[mech2].specificEffects.invertAttackPriority)
                {
                    this.players[mech2].lives++;
                }
                else
                {
                    this.players[mech1].lives--;
                }

                this.pairsHandler.playerResults[this.pairsHandler.playerResults.Count - 1][mech1] = FightResult.LOSS;
                this.pairsHandler.playerResults[this.pairsHandler.playerResults.Count - 1][mech2] = FightResult.WIN;
            }
            Console.WriteLine("fight14");
            //-combat header

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

            this.players[mech1].destroyed = false;
            this.players[mech2].destroyed = false;
            Console.WriteLine("fight15");
            return(outputCollector);
        }