Beispiel #1
0
        public void ExecutePushGlobalAlly(Pushable pushable, Push push)
        {
            Vector2Int[] targetCellCoords = new Vector2Int[4];

            Cell[] targetCells = new Cell[4];

            int pushMaximum = 0;

            if (push == Push.west)
            {
                print("pushing west");
                for (var i = 4 - 1; i > 0; i--)
                {
                    targetCellCoords[i] = new Vector2Int(pushable.GetGridPos().x + i, pushable.GetGridPos().y);

                    if (!combatController.ListOfPlayerCells.ContainsKey(targetCellCoords[i]))
                    {
                        continue;
                    }

                    targetCells[i] = combatController.ListOfPlayerCells[targetCellCoords[i]];

                    if (targetCells[i].isOccupied)
                    {
                        print("continuing, targetCell is occupied");
                        continue;
                    }
                    if (targetCells[i].isEnemyCell)
                    {
                        print("continuing, targetCell is enemyCell");
                        continue;
                    }
                    if (targetCells[i] == null)
                    {
                        print("continuing, targetCell doesn't exist");
                        continue;
                    }

                    pushMaximum = i;

                    print("reverse side push maximum is " + pushMaximum);

                    break;
                }


                for (var i = 0; i < 4; i++)
                {
                    targetCellCoords[i] = new Vector2Int(pushable.GetGridPos().x + i, pushable.GetGridPos().y);

                    if (!combatController.ListOfPlayerCells.ContainsKey(targetCellCoords[i]))
                    {
                        continue;
                    }

                    targetCells[i] = combatController.ListOfPlayerCells[targetCellCoords[i]];

                    if (targetCells[i].hasObstacle == true)
                    {
                        if (combatController.ListOfPlayerCells[new Vector2Int(pushable.GetGridPos().x + 1, pushable.GetGridPos().y)].isOccupied)
                        {
                            pushMaximum = 0;
                            break;
                        }

                        if (pushMaximum > i - 1)
                        {
                            pushMaximum = i - 1;
                            print("subtracting from pushMaximum due to Obstacle");
                        }
                    }

                    if (targetCells[i].isOccupied)
                    {
                        if (targetCells[i] == combatController.ListOfPlayerCells[pushable.GetGridPos()])
                        {
                            continue;
                        }

                        print("target cell is occupied");

                        if (pushMaximum > i - 1)
                        {
                            pushMaximum = i - 1;
                            print("subtracting from pushMaximum");
                        }
                    }
                }

                print("pushMaximum " + pushMaximum);
            }

            else if (push == Push.east)
            {
                for (var i = 4 - 1; i > 0; i--)
                {
                    targetCellCoords[i] = new Vector2Int(pushable.GetGridPos().x - i, pushable.GetGridPos().y);

                    if (!combatController.ListOfPlayerCells.ContainsKey(targetCellCoords[i]))
                    {
                        continue;
                    }

                    targetCells[i] = combatController.ListOfPlayerCells[targetCellCoords[i]];

                    if (targetCells[i].isOccupied || targetCells[i].isEnemyCell || targetCells[i] == null)
                    {
                        continue;
                    }

                    pushMaximum = i;

                    break;
                }


                for (var i = 0; i < 4; i++)
                {
                    targetCellCoords[i] = new Vector2Int(pushable.GetGridPos().x - i, pushable.GetGridPos().y);

                    if (!combatController.ListOfPlayerCells.ContainsKey(targetCellCoords[i]))
                    {
                        continue;
                    }

                    targetCells[i] = combatController.ListOfPlayerCells[targetCellCoords[i]];

                    if (targetCells[i].hasObstacle == true)
                    {
                        if (combatController.ListOfPlayerCells[new Vector2Int(pushable.GetGridPos().x - 1, pushable.GetGridPos().y)].isOccupied)
                        {
                            pushMaximum = 0;
                            break;
                        }

                        if (pushMaximum > i - 1)
                        {
                            pushMaximum = i - 1;
                        }
                    }

                    if (targetCells[i].isOccupied)
                    {
                        if (targetCells[i] == combatController.ListOfPlayerCells[pushable.GetGridPos()])
                        {
                            continue;
                        }

                        print("target cell is occupied");

                        if (pushMaximum > i - 1)
                        {
                            pushMaximum = i - 1;
                            print("subtracting from pushMaximum");
                        }
                    }
                }
            }

            else if (push == Push.north)
            {
                for (var i = 4 - 1; i > 0; i--)
                {
                    targetCellCoords[i] = new Vector2Int(pushable.GetGridPos().x, pushable.GetGridPos().y + i);

                    if (!combatController.ListOfPlayerCells.ContainsKey(targetCellCoords[i]))
                    {
                        continue;
                    }

                    targetCells[i] = combatController.ListOfPlayerCells[targetCellCoords[i]];

                    if (targetCells[i].isOccupied || targetCells[i].isEnemyCell || targetCells[i] == null)
                    {
                        continue;
                    }

                    pushMaximum = i;

                    break;
                }


                for (var i = 0; i < 4; i++)
                {
                    targetCellCoords[i] = new Vector2Int(pushable.GetGridPos().x, pushable.GetGridPos().y + i);

                    if (!combatController.ListOfPlayerCells.ContainsKey(targetCellCoords[i]))
                    {
                        continue;
                    }

                    targetCells[i] = combatController.ListOfPlayerCells[targetCellCoords[i]];

                    if (targetCells[i].hasObstacle == true)
                    {
                        if (combatController.ListOfPlayerCells[new Vector2Int(pushable.GetGridPos().x, pushable.GetGridPos().y + 1)].isOccupied)
                        {
                            pushMaximum = 0;
                            break;
                        }

                        if (pushMaximum > i - 1)
                        {
                            pushMaximum = i - 1;
                        }
                    }

                    if (targetCells[i].isOccupied)
                    {
                        if (targetCells[i] == combatController.ListOfPlayerCells[pushable.GetGridPos()])
                        {
                            continue;
                        }

                        print("target cell is occupied");

                        if (pushMaximum > i - 1)
                        {
                            pushMaximum = i - 1;
                            print("subtracting from pushMaximum");
                        }
                    }
                }
            }

            else
            {
                for (var i = 4 - 1; i > 0; i--)
                {
                    targetCellCoords[i] = new Vector2Int(pushable.GetGridPos().x, pushable.GetGridPos().y - i);

                    if (!combatController.ListOfPlayerCells.ContainsKey(targetCellCoords[i]))
                    {
                        continue;
                    }

                    targetCells[i] = combatController.ListOfPlayerCells[targetCellCoords[i]];

                    if (targetCells[i].isOccupied || targetCells[i].isEnemyCell || targetCells[i] == null)
                    {
                        continue;
                    }

                    pushMaximum = i;

                    break;
                }


                for (var i = 0; i < 4; i++)
                {
                    targetCellCoords[i] = new Vector2Int(pushable.GetGridPos().x, pushable.GetGridPos().y - i);

                    if (!combatController.ListOfPlayerCells.ContainsKey(targetCellCoords[i]))
                    {
                        continue;
                    }

                    targetCells[i] = combatController.ListOfPlayerCells[targetCellCoords[i]];

                    if (targetCells[i].hasObstacle == true)
                    {
                        if (combatController.ListOfPlayerCells[new Vector2Int(pushable.GetGridPos().x, pushable.GetGridPos().y - 1)].isOccupied)
                        {
                            pushMaximum = 0;
                            break;
                        }

                        if (pushMaximum > i - 1)
                        {
                            pushMaximum = i - 1;
                        }
                    }

                    if (targetCells[i].isOccupied)
                    {
                        if (targetCells[i] == combatController.ListOfPlayerCells[pushable.GetGridPos()])
                        {
                            continue;
                        }

                        print("target cell is occupied");

                        if (pushMaximum > i - 1)
                        {
                            pushMaximum = i - 1;
                            print("subtracting from pushMaximum");
                        }
                    }
                }
            }

            if (pushMaximum > 0)
            {
                pushable.GetComponent <Mover>().Pathfind(targetCells[pushMaximum]);
                pushable.GetComponent <Mover>().isBeingPushed = true;
                targetCells[pushMaximum].isOccupied           = true;
            }
            else
            {
                print("pushMaximum is 0");
            }
        }
Beispiel #2
0
 //CC.AA
 public static int SortByY(Pushable pushable1, Pushable pushable2)
 {
     return(pushable1.GetGridPos().y.CompareTo(pushable2.GetGridPos().y));
 }
Beispiel #3
0
        public void ExecutePushGlobal(Pushable pushable, EnemyAttack ability)
        {
            Vector2Int[] targetCellCoords = new Vector2Int[ability.pushForce];
            Cell[]       targetCells      = new Cell[ability.pushForce];

            int pushMaximum = 0;

            if (ability.push == Push.west)
            {
                for (var i = ability.pushForce - 1; i > 0; i--)
                {
                    targetCellCoords[i] = new Vector2Int(pushable.GetGridPos().x + i, pushable.GetGridPos().y);

                    if (!combatController.ListOfPlayerCells.ContainsKey(targetCellCoords[i]))
                    {
                        continue;
                    }

                    targetCells[i] = combatController.ListOfPlayerCells[targetCellCoords[i]];

                    if (targetCells[i].isOccupied || targetCells[i].isEnemyCell || targetCells[i] == null)
                    {
                        continue;
                    }

                    pushMaximum = i;

                    break;
                }


                for (var i = 0; i < ability.pushForce; i++)
                {
                    targetCellCoords[i] = new Vector2Int(pushable.GetGridPos().x + i, pushable.GetGridPos().y);

                    if (!combatController.ListOfPlayerCells.ContainsKey(targetCellCoords[i]))
                    {
                        continue;
                    }

                    targetCells[i] = combatController.ListOfPlayerCells[targetCellCoords[i]];

                    if (targetCells[i].hasObstacle == true)
                    {
                        if (combatController.ListOfPlayerCells[new Vector2Int(pushable.GetGridPos().x + 1, pushable.GetGridPos().y)].isOccupied)
                        {
                            pushMaximum = 0;
                            break;
                        }

                        if (pushMaximum > i - 1)
                        {
                            pushMaximum = i - 1;
                        }
                    }
                }
            }

            else if (ability.push == Push.east)
            {
                for (var i = ability.pushForce - 1; i > 0; i--)
                {
                    targetCellCoords[i] = new Vector2Int(pushable.GetGridPos().x - i, pushable.GetGridPos().y);

                    if (!combatController.ListOfPlayerCells.ContainsKey(targetCellCoords[i]))
                    {
                        continue;
                    }

                    targetCells[i] = combatController.ListOfPlayerCells[targetCellCoords[i]];

                    if (targetCells[i].isOccupied || targetCells[i].isEnemyCell || targetCells[i] == null)
                    {
                        continue;
                    }

                    pushMaximum = i;

                    break;
                }


                for (var i = 0; i < ability.pushForce; i++)
                {
                    targetCellCoords[i] = new Vector2Int(pushable.GetGridPos().x - i, pushable.GetGridPos().y);

                    if (!combatController.ListOfPlayerCells.ContainsKey(targetCellCoords[i]))
                    {
                        continue;
                    }

                    targetCells[i] = combatController.ListOfPlayerCells[targetCellCoords[i]];

                    if (targetCells[i].hasObstacle == true)
                    {
                        if (combatController.ListOfPlayerCells[new Vector2Int(pushable.GetGridPos().x - 1, pushable.GetGridPos().y)].isOccupied)
                        {
                            pushMaximum = 0;
                            break;
                        }

                        if (pushMaximum > i - 1)
                        {
                            pushMaximum = i - 1;
                        }
                    }
                }
            }

            else if (ability.push == Push.north)
            {
                for (var i = ability.pushForce - 1; i > 0; i--)
                {
                    targetCellCoords[i] = new Vector2Int(pushable.GetGridPos().x, pushable.GetGridPos().y + i);

                    if (!combatController.ListOfPlayerCells.ContainsKey(targetCellCoords[i]))
                    {
                        continue;
                    }

                    targetCells[i] = combatController.ListOfPlayerCells[targetCellCoords[i]];

                    if (targetCells[i].isOccupied || targetCells[i].isEnemyCell || targetCells[i] == null)
                    {
                        continue;
                    }

                    pushMaximum = i;

                    break;
                }


                for (var i = 0; i < ability.pushForce; i++)
                {
                    targetCellCoords[i] = new Vector2Int(pushable.GetGridPos().x, pushable.GetGridPos().y + i);

                    if (!combatController.ListOfPlayerCells.ContainsKey(targetCellCoords[i]))
                    {
                        continue;
                    }

                    targetCells[i] = combatController.ListOfPlayerCells[targetCellCoords[i]];

                    if (targetCells[i].hasObstacle == true)
                    {
                        if (combatController.ListOfPlayerCells[new Vector2Int(pushable.GetGridPos().x, pushable.GetGridPos().y + 1)].isOccupied)
                        {
                            pushMaximum = 0;
                            break;
                        }

                        if (pushMaximum > i - 1)
                        {
                            pushMaximum = i - 1;
                        }
                    }
                }
            }

            else
            {
                for (var i = ability.pushForce - 1; i > 0; i--)
                {
                    targetCellCoords[i] = new Vector2Int(pushable.GetGridPos().x, pushable.GetGridPos().y - i);

                    if (!combatController.ListOfPlayerCells.ContainsKey(targetCellCoords[i]))
                    {
                        continue;
                    }

                    targetCells[i] = combatController.ListOfPlayerCells[targetCellCoords[i]];

                    if (targetCells[i].isOccupied || targetCells[i].isEnemyCell || targetCells[i] == null)
                    {
                        continue;
                    }

                    pushMaximum = i;

                    break;
                }


                for (var i = 0; i < ability.pushForce; i++)
                {
                    targetCellCoords[i] = new Vector2Int(pushable.GetGridPos().x, pushable.GetGridPos().y - i);

                    if (!combatController.ListOfPlayerCells.ContainsKey(targetCellCoords[i]))
                    {
                        continue;
                    }

                    targetCells[i] = combatController.ListOfPlayerCells[targetCellCoords[i]];

                    if (targetCells[i].hasObstacle == true)
                    {
                        if (combatController.ListOfPlayerCells[new Vector2Int(pushable.GetGridPos().x, pushable.GetGridPos().y - 1)].isOccupied)
                        {
                            pushMaximum = 0;
                            break;
                        }

                        if (pushMaximum > i - 1)
                        {
                            pushMaximum = i - 1;
                        }
                    }
                }
            }

            if (pushMaximum > 0)
            {
                pushable.GetComponent <Mover>().Pathfind(targetCells[pushMaximum]);
                pushable.GetComponent <Mover>().isBeingPushed = true;
                targetCells[pushMaximum].isOccupied           = true;
            }
        }
Beispiel #4
0
 public Cell CurrentCell()
 {
     return(combatController.ListOfPlayerCells[pushable.GetGridPos()]);
 }