Esempio n. 1
0
        private void FindConnectedRuleBlocks(Vector2Int originPosition, Vector2Int direction, RuleCategory[] targetRuleCategories, List <Block> resultBlocks)
        {
            var position = originPosition + direction;

            while (m_logicGameManager.InMap(position))
            {
                var mapBlocks = m_logicGameManager.Map[position.x, position.y];

                var hasTargetRuleBlock = false;
                foreach (var block in mapBlocks)
                {
                    var hasTargetRuleCategory = false;
                    foreach (var targetRuleCategory in targetRuleCategories)
                    {
                        if (IsTargetRuleBlock(block, targetRuleCategory))
                        {
                            hasTargetRuleCategory = true;
                            break;
                        }
                    }
                    if (hasTargetRuleCategory)
                    {
                        hasTargetRuleBlock = true;
                        resultBlocks.Add(block);
                    }
                }

                if (!hasTargetRuleBlock)
                {
                    break;
                }

                position += direction;

                if (!m_logicGameManager.InMap(position))
                {
                    break;
                }

                mapBlocks = m_logicGameManager.Map[position.x, position.y];

                var hasAndKeyWordRuleBlock = false;
                foreach (var block in mapBlocks)
                {
                    if (IsTargetKeyWordRuleBlock(block, KeyWordCategory.And))
                    {
                        hasAndKeyWordRuleBlock = true;
                    }
                }

                if (!hasAndKeyWordRuleBlock)
                {
                    break;
                }

                position += direction;
            }
        }
Esempio n. 2
0
        private void HandleDirectionYou(Direction moveDirection, Vector2Int negativeEndPosition, Vector2Int positiveEndPosition, Stack <Command> tickCommands)
        {
            var displacement = DirectionUtils.DirectionToDisplacement(moveDirection);

            var impactBlocks = DictionaryPool <Block, int> .Get();

            for (var position = negativeEndPosition + displacement; position != positiveEndPosition; position += displacement)
            {
                var hasYou = false;
                {
                    var blocks = m_logicGameManager.Map[position.x, position.y];
                    foreach (var block in blocks)
                    {
                        if (HasAttribute(block, AttributeCategory.You))
                        {
                            impactBlocks[block] = impactBlocks.GetOrDefault(block, 0) | 1;
                            hasYou = true;
                        }
                    }
                }
                if (hasYou)
                {
                    for (var pullPosition = position - displacement; m_logicGameManager.InMap(pullPosition); pullPosition -= displacement)
                    {
                        var blocks  = m_logicGameManager.Map[pullPosition.x, pullPosition.y];
                        var hasPull = false;
                        foreach (var block in blocks)
                        {
                            if (HasAttribute(block, AttributeCategory.Pull))
                            {
                                impactBlocks[block] = impactBlocks.GetOrDefault(block, 0) | 1;
                                hasPull             = true;
                            }
                        }
                        if (!hasPull)
                        {
                            break;
                        }
                    }
                    for (var pushPosition = position + displacement; m_logicGameManager.InMap(pushPosition); pushPosition += displacement)
                    {
                        var blocks  = m_logicGameManager.Map[pushPosition.x, pushPosition.y];
                        var hasPush = false;
                        foreach (var block in blocks)
                        {
                            if (HasAttribute(block, AttributeCategory.Push))
                            {
                                impactBlocks[block] = impactBlocks.GetOrDefault(block, 0) | 1;
                                hasPush             = true;
                            }
                        }
                        if (!hasPush)
                        {
                            break;
                        }
                    }
                }
            }

            HandlePreMove(impactBlocks, displacement, tickCommands);

            {
                var stopPosition = positiveEndPosition - displacement;
                {
                    var blocks = m_logicGameManager.Map[stopPosition.x, stopPosition.y];
                    foreach (var block in blocks)
                    {
                        var impact = 0;
                        if (impactBlocks.TryGetValue(block, out impact))
                        {
                            impactBlocks[block] = 0;
                        }
                    }
                }
            }
            for (var position = positiveEndPosition - displacement; position != negativeEndPosition + displacement; position -= displacement)
            {
                var hasStop = false;
                {
                    var blocks = m_logicGameManager.Map[position.x, position.y];
                    foreach (var block in blocks)
                    {
                        if (HasAttribute(block, AttributeCategory.Stop) || HasAttribute(block, AttributeCategory.Pull) || HasAttribute(block, AttributeCategory.Push))
                        {
                            if (impactBlocks.GetOrDefault(block, 0) == 0)
                            {
                                hasStop = true;
                                break;
                            }
                        }
                    }
                }
                if (hasStop)
                {
                    var stopPosition = position - displacement;
                    {
                        var blocks = m_logicGameManager.Map[stopPosition.x, stopPosition.y];
                        foreach (var block in blocks)
                        {
                            var impact = 0;
                            if (impactBlocks.TryGetValue(block, out impact))
                            {
                                impactBlocks[block] = 0;
                            }
                        }
                    }
                }
            }

            foreach (var impactBlockPair in impactBlocks)
            {
                var block  = impactBlockPair.Key;
                var impact = impactBlockPair.Value;

                if (impact == 1)
                {
                    PerformMoveBlockCommand(block, moveDirection, 1, tickCommands);
                }
            }

            DictionaryPool <Block, int> .Release(impactBlocks);
        }