Esempio n. 1
0
 public void PickUp(GameObject obj)
 {
     if (aiMovementLogic.MoveTo(obj.transform.position))
     {
         aiMapLogic.LookAroundYourself();
     }
 }
Esempio n. 2
0
    public void KillPlayer(PlayerBase player)
    {
        Vector2 targetPlayerPosition = new Vector2(player.posX, player.posY);

        targetObject = player.gameObject;
        SwitchToBestWeapon();

        if (!safeFromMine)
        {
            safeFromMine = aiMovementLogic.MoveTo(safeLocation, 0.2f);
        }
        else
        {
            Vector2 bestShootSpot = GetBestShootSpot(targetPlayerPosition);

            if (aiBase.weaponHandling.activeWeapon.weaponType == WeaponEnum.mine)
            {
                DropMine();
            }
            else if (tankActive || aiBase.weaponHandling.activeWeapon.weaponType == WeaponEnum.specialDaVinci)
            {
                aiBase.weaponHandling.fire(aiBase.direction);
                aiMovementLogic.MoveTo(targetPlayerPosition, 0.2f);
                try
                {
                    WeaponSpecialDaVinciLogic tank = aiBase.gameObject.transform.parent.GetComponentInChildren <WeaponSpecialDaVinciLogic>();

                    tankActive = tank.update;
                }
                catch (Exception e)
                {
                    tankActive = false;
                }
            }
            else
            {
                if (aiMovementLogic.MoveTo(bestShootSpot))
                {
                    if (aiMapLogic.GetObjectDirection(player.gameObject) != aiBase.direction)
                    {
                        aiMapLogic.LookAt(player.gameObject);
                    }
                    else
                    {
                    }

                    if (aiWeaponLogic.CanShoot(aiBase.transform.position, aiBase.direction) &&
                        frameToShoot < Time.frameCount)
                    {
                        //if you fire last bullet, wait a second, then you can shoot again
                        if (aiBase.weaponHandling.activeWeapon.ammo == 1)
                        {
                            frameToShoot = Time.frameCount + 30;
                        }
                        aiBase.weaponHandling.fire(aiBase.direction);
                    }
                }
                else
                {
                }
            }
        }
    }
    public void AvoidBullet()
    {
        float verticalDistance   = aiBase.characterColliderHeight;
        float horizontalDistance = aiBase.characterColliderHeight;

        if (
            (decidedDirection == up && aiMovementLogic.CollidesBarrier(up, verticalDistance)) ||
            (decidedDirection == right && aiMovementLogic.CollidesBarrier(right, horizontalDistance)) ||
            (decidedDirection == down && aiMovementLogic.CollidesBarrier(down, verticalDistance)) ||
            (decidedDirection == left && aiMovementLogic.CollidesBarrier(left, horizontalDistance))
            )
        {
            decidedDirectionBool = false;
        }

        if (decidedDirectionBool)
        {
            if (decidedDirection == up)
            {
                aiMovementLogic.MoveTo(aiBase.posX, aiBase.posY + verticalDistance);
            }
            else if (decidedDirection == right)
            {
                aiMovementLogic.MoveTo(aiBase.posX + horizontalDistance, aiBase.posY);
            }
            else if (decidedDirection == down)
            {
                aiMovementLogic.MoveTo(aiBase.posX, aiBase.posY - verticalDistance);
            }
            else if (decidedDirection == left)
            {
                aiMovementLogic.MoveTo(aiBase.posX - horizontalDistance, aiBase.posY);
            }
            else
            {
            }
        }
        else
        {
            if (bulletFrom == up)
            {
                if (!aiMovementLogic.CollidesBarrier(left, horizontalDistance))
                {
                    aiMovementLogic.MoveTo(aiBase.posX - horizontalDistance, aiBase.posY);
                    decidedDirection = left;
                }
                else if (!aiMovementLogic.CollidesBarrier(right, horizontalDistance))
                {
                    aiMovementLogic.MoveTo(aiBase.posX + horizontalDistance, aiBase.posY);
                    decidedDirection = right;
                }
                else if (!aiMovementLogic.CollidesBarrier(down, verticalDistance))
                {
                    aiMovementLogic.MoveTo(aiBase.posX, aiBase.posY - verticalDistance);
                    decidedDirection = down;
                }
            }
            else if (bulletFrom == right)
            {
                if (!aiMovementLogic.CollidesBarrier(up, verticalDistance))
                {
                    aiMovementLogic.MoveTo(aiBase.posX, aiBase.posY + verticalDistance);
                    decidedDirection = up;
                }
                else if (!aiMovementLogic.CollidesBarrier(down, verticalDistance))
                {
                    aiMovementLogic.MoveTo(aiBase.posX, aiBase.posY - verticalDistance);
                    decidedDirection = down;
                }
                else if (!aiMovementLogic.CollidesBarrier(left, horizontalDistance))
                {
                    aiMovementLogic.MoveTo(aiBase.posX - horizontalDistance, aiBase.posY);
                    decidedDirection = left;
                }
                else
                {
                }
            }
            else if (bulletFrom == down)
            {
                if (!aiMovementLogic.CollidesBarrier(left, horizontalDistance))
                {
                    aiMovementLogic.MoveTo(aiBase.posX - horizontalDistance, aiBase.posY);
                    decidedDirection = left;
                }
                else if (!aiMovementLogic.CollidesBarrier(right, horizontalDistance))
                {
                    aiMovementLogic.MoveTo(aiBase.posX + horizontalDistance, aiBase.posY);
                    decidedDirection = right;
                }
                else if (!aiMovementLogic.CollidesBarrier(up, verticalDistance))
                {
                    aiMovementLogic.MoveTo(aiBase.posX, aiBase.posY + verticalDistance);
                    decidedDirection = up;
                }
            }
            else if (bulletFrom == left)
            {
                if (!aiMovementLogic.CollidesBarrier(up, verticalDistance))
                {
                    aiMovementLogic.MoveTo(aiBase.posX, aiBase.posY + verticalDistance);
                    decidedDirection = up;
                }
                else if (!aiMovementLogic.CollidesBarrier(down, verticalDistance))
                {
                    aiMovementLogic.MoveTo(aiBase.posX, aiBase.posY - verticalDistance);
                    decidedDirection = down;
                }
                else if (!aiMovementLogic.CollidesBarrier(right, horizontalDistance))
                {
                    aiMovementLogic.MoveTo(aiBase.posX + horizontalDistance, aiBase.posY);
                    decidedDirection = right;
                }
            }
            decidedDirectionBool = true;
        }

        //chek if you avoided
        if (!RegisterBullets())
        {
            decidedDirectionBool = false;
            decidedDirection     = down;
            aiPriorityLogic.SetAvoidBulletPriority(0);
            aiActionLogic.UpdateCurrentAction();
        }
    }