public override List <EffectData> Apply(FieldManager manager, Random random, GameMatch match, int playerUserIndex, Combo combo, Block block)
        {
            Field  playerField = playerUserIndex == 1 ? match.Field1 : match.Field2;
            Player enemy       = playerUserIndex == 1 ? match.Player2 : match.Player1;
            Field  enemyField  = playerUserIndex == 1 ? match.Field2 : match.Field1;

            List <EffectData> data = new List <EffectData>();

            if (enemyField.TryBlock(out var effect))
            {
                data.Add(EffectDataHelper.GlobalEffectRemovedData(enemy, effect));
            }
            else
            {
                enemy.TakeDamage(DamageToEnemyHealth);
                data.Add(EffectDataHelper.HealthData(enemy, DamageToEnemyHealth));

                List <Block> blocks = manager.GetRandomNonDestroyedBlocks(enemyField, ShotsAmount).ToList();
                foreach (Block blockToDestroy in blocks)
                {
                    manager.DestroyBlocks(enemyField, blocks, BlockState.DestroyedByDamage);
                    data.Add(EffectDataHelper.UniqueShotData(playerField, enemyField, block, blockToDestroy, "ShotgunEffect"));
                }
            }

            return(data);
        }
示例#2
0
        public override List <EffectData> Apply(FieldManager manager, UpgradeManager upgradeManager, Random random, GameMatch match, int playerUserIndex, Combo combo)
        {
            Player       player             = playerUserIndex == 1 ? match.Player1 : match.Player2;
            Field        playerField        = playerUserIndex == 1 ? match.Field1 : match.Field2;
            Player       enemy              = playerUserIndex == 1 ? match.Player2 : match.Player1;
            Field        enemyField         = playerUserIndex == 1 ? match.Field2 : match.Field1;
            UpgradesInfo playerUpgradesInfo = playerUserIndex == 1 ? match.Player1Upgrades : match.Player2Upgrades;

            int effectsCount = Math.Max(1, combo.Blocks.Count - FieldManager.MinComboCount);

            List <EffectData> data = new List <EffectData>();

            if (enemyField.TryBlock(out var effect))
            {
                data.Add(EffectDataHelper.GlobalEffectRemovedData(enemy, effect.Type));
            }
            else
            {
                float damage = DamageToEnemyHealth * combo.EffectScale
                               * upgradeManager.GetAttackBlockUpgradeBonus(playerUpgradesInfo);
                data.Add(EffectDataHelper.HealthData(enemy, -damage * effectsCount));
                for (int i = 0; i < effectsCount; i++)
                {
                    enemy.TakeDamage(damage);

                    for (int j = 0; j < BlocksToAttackCount; j++)
                    {
                        Block block = manager.GetRandomNonDestroyedBlocks(enemyField).FirstOrDefault();
                        if (block != null)
                        {
                            manager.DestroyBlocks(enemyField, new List <Block> {
                                block
                            }, BlockState.DestroyedByDamage);
                            data.Add(EffectDataHelper.ShotData(playerField, enemyField, combo.Blocks.First(), block, -DamageToBlockHealth));
                        }
                    }
                }
            }

            if (combo.Blocks.Count > 3)
            {
                data.AddRange(BlockEffectsHelper.CreateUniqueBlock(manager, random, playerField, player, combo, ComboEffectType));
            }

            return(data);
        }
        public override List <EffectData> Apply(FieldManager manager, Random random, GameMatch match, int playerUserIndex, Combo combo, Block block)
        {
            Field  playerField = playerUserIndex == 1 ? match.Field1 : match.Field2;
            Player enemy       = playerUserIndex == 1 ? match.Player2 : match.Player1;
            Field  enemyField  = playerUserIndex == 1 ? match.Field2 : match.Field1;

            List <EffectData> data = new List <EffectData>();

            if (enemyField.TryBlock(out var effect))
            {
                data.Add(EffectDataHelper.GlobalEffectRemovedData(enemy, effect));
            }
            else
            {
                Block toBlock = manager.GetRandomNonDestroyedBlockExceptBorders(enemyField);
                manager.DestroyBlocks(enemyField, manager.GetNeighbours(enemyField, toBlock), BlockState.DestroyedByDamage);
                data.Add(EffectDataHelper.UniqueShotData(playerField, enemyField, block, toBlock, "BoulderEffect"));
            }

            return(data);
        }
示例#4
0
        /// <summary>
        /// Players turn processing
        /// </summary>
        /// <param name="player"></param>
        /// <param name="request"></param>
        public void ProcessBlockSwap(Player player, BlockSwapRequest request)
        {
            if (player.CurrentMatch == null)
            {
                Console.WriteLine($"Player {player.ClientID} is not in the game");
                return;
            }

            GameMatch         match       = player.CurrentMatch;
            Field             playerField = match.Player1 == player ? match.Field1 : match.Field2;
            Field             enemyField  = match.Player1 == player ? match.Field2 : match.Field1;
            Player            enemy       = match.Player1 == player ? match.Player2 : match.Player1;
            List <EffectData> effectsData = new List <EffectData>();

            FieldManager.RefreshGlobalEffects(playerField, player);
            FieldManager.RefreshGlobalEffects(enemyField, enemy);

            if (!player.TrySpendMana(player.BlockSwapCost))
            {
                SendError(player, ErrorType.NotEnoughMana);
                return;
            }
            else
            {
                EffectData hData = new EffectData();
                hData.EffectType     = EffectType.ManaChanged;
                hData.Data           = new Dictionary <string, object>();
                hData.Data["Target"] = player.InGameID;
                hData.Data["Value"]  = -player.BlockSwapCost;
                effectsData.Add(hData);
            }

            FieldManager.RefreshDurationEffects(playerField);
            FieldManager.RefreshDurationEffects(enemyField);

            if (!FieldManager.TryRebuildFieldFromSwap(playerField, new Swap(request.X, request.Y, request.Direction), out List <Block> blocks))
            {
                SendError(player, ErrorType.ImpossibleTurn);
            }

            List <Combo> combos = FieldManager.CheckForCombos(playerField, blocks);

            foreach (Combo combo in combos)
            {
                FieldManager.DestroyBlocks(enemyField, combo.Blocks, BlockState.DestroyedAsCombo);
                effectsData.AddRange(BlockEffectsManager.ApplyEffectsFromCombo(match, match.Player1 == player ? 1 : 2, combo));
            }

            effectsData.AddRange(FieldManager.ClearDestroyedBlocks(playerField, match, player));
            effectsData.AddRange(FieldManager.ClearDestroyedBlocks(enemyField, match, enemy));

            FieldManager.FillHoles(playerField);
            FieldManager.FillHoles(enemyField);

            GameStateResponse response = new GameStateResponse {
                GameState = GetPlayer1MatchStateData(match),
                Effects   = effectsData.ToArray()
            };

            Server.SendDataToClient(match.Player1.ClientID, (int)DataTypes.GameStateResponse, response);

            if (match.GameMode == GameMode.Practice)
            {
                FieldManager.SetDefaultState(playerField);
                FieldManager.SetDefaultState(enemyField);

                if (CheckForGameEnd(match, out GameEndResponse gameEndResponseDebug))
                {
                    GiveMatchReward(match, gameEndResponseDebug.PlayerWon);
                    RecalculateRating(match, gameEndResponseDebug.PlayerWon);
                    PlayersManager.UpdatePlayer(match.Player1);

                    MatchManager.DropMatch(player.CurrentMatch);

                    gameEndResponseDebug.PlayerStats = match.Player1.GetStatsData();
                    Server.SendDataToClient(match.Player1.ClientID, (int)DataTypes.GameEndResponse, gameEndResponseDebug);
                }
                return;
            }

            response = new GameStateResponse
            {
                GameState = GetPlayer2MatchStateData(match),
                Effects   = effectsData.ToArray()
            };
            Server.SendDataToClient(match.Player2.ClientID, (int)DataTypes.GameStateResponse, response);

            FieldManager.SetDefaultState(playerField);
            effectsData.AddRange(FieldManager.ClearDestroyedBlocks(playerField, match, player));
            FieldManager.SetDefaultState(enemyField);
            effectsData.AddRange(FieldManager.ClearDestroyedBlocks(enemyField, match, enemy));

            if (CheckForGameEnd(match, out GameEndResponse gameEndResponse))
            {
                GiveMatchReward(match, gameEndResponse.PlayerWon);
                RecalculateRating(match, gameEndResponse.PlayerWon);
                PlayersManager.UpdatePlayer(match.Player1);
                PlayersManager.UpdatePlayer(match.Player2);

                MatchManager.DropMatch(player.CurrentMatch);

                gameEndResponse.PlayerStats = match.Player1.GetStatsData();
                Server.SendDataToClient(match.Player1.ClientID, (int)DataTypes.GameEndResponse, gameEndResponse);

                gameEndResponse.PlayerStats = match.Player2.GetStatsData();
                Server.SendDataToClient(match.Player2.ClientID, (int)DataTypes.GameEndResponse, gameEndResponse);

                return;
            }
        }