Esempio n. 1
0
    void doorKeeperCathingBall(FBActor shooter, FBActor actor)
    {
        //球的轨迹和守门员的交点
        FixVector2 intersectPoint  = FixVector2.kZero;
        Fix64      intersectHeight = Fix64.One;
        Fix64      ballFlyTime     = Fix64.Zero;

        bool canHit = ball.estimateHit(actor.direction, -FixVector2.dot(actor.getPosition(), actor.direction), out ballFlyTime, out intersectPoint, out intersectHeight);

        if (!canHit)
        {
            Debuger.Log("Can not fly to doorkeeper");
            return;
        }

#if UNITY_EDITOR
        LogicEvent.fire("onDoorKeeperCatchingBallView", actor, intersectPoint, intersectHeight);
#endif

        FixVector2 toward           = intersectPoint - actor.getPosition();
        Fix64      distance         = toward.length;
        int        cathingZoneIndex = -1;
        if (distance < actor.configuration.dkcb_edgeLimit[0])
        {
            if (intersectHeight < actor.configuration.dkcb_edgeLimit[1])
            {
                //a区
                cathingZoneIndex = 0;
            }
            else if (intersectHeight < actor.configuration.dkcb_edgeLimit[2])
            {
                //b区
                cathingZoneIndex = 1;
            }
            else if (intersectHeight < actor.configuration.dkcb_edgeLimit[3])
            {
                //c区
                cathingZoneIndex = 2;
            }
            else
            {
                //H区,直接返回,不处理
                cathingZoneIndex = -1;
            }
        }
        else if (distance < actor.configuration.dkcb_edgeLimit[6])
        {
            if (intersectHeight < actor.configuration.dkcb_edgeLimit[4])
            {
                //fe区
                cathingZoneIndex = 4;
            }
            else if (intersectHeight < actor.configuration.dkcb_edgeLimit[5])
            {
                //gd区
                cathingZoneIndex = 3;
            }
            else
            {
                cathingZoneIndex = -1;
            }
        }
        else
        {
            //H区,直接返回,不处理
            cathingZoneIndex = -1;
        }

        bool pretendCatchingBall = false;

        if ((cathingZoneIndex == 3 || cathingZoneIndex == 4))
        {
            //修改获取球的区域
            Fix64      rightDoorV   = shooter.team == FBTeam.kBlue ? new Fix64(1) : new Fix64(-1);
            FixVector2 doorPosition = new FixVector2(config.worldSize.x * rightDoorV, Fix64.Zero);
            Fix64      s            = (shooter.getPosition() - doorPosition).length;
            if (s > shooter.configuration.maxGoalDistance)
            {
                s = shooter.configuration.maxGoalDistance;
            }

            Fix64 shootRate = ConstTable.ShootBall_GoalRate[(int)shooter.shootingType]
                              * ball.getEnergy().goalRate
                              *((Fix64)1.0f - s / shooter.configuration.maxGoalDistance);
            //失误计算
            Fix64 randV = this.randomUnit;
            pretendCatchingBall = randV >= shootRate;

            Debuger.Log("ShootBall GoalRate:" + (float)shootRate + " random:" + (float)randV);

            if (pretendCatchingBall)
            {
                if (cathingZoneIndex == 3)
                {
                    intersectHeight -= ConstTable.GoallKeeperPretendGetBallMissDistance;
                    if (intersectHeight < actor.configuration.dkcb_edgeLimit[4])
                    {
                        cathingZoneIndex = 4;
                    }
                }
                if (cathingZoneIndex == 4)
                {
                    intersectHeight += ConstTable.GoallKeeperPretendGetBallMissDistance;
                    if (intersectHeight > actor.configuration.dkcb_edgeLimit[4])
                    {
                        cathingZoneIndex = 3;
                    }
                }
            }
        }


        if (cathingZoneIndex != -1)
        {
            actor.doCathingGoalBall(new FixVector2(intersectPoint.x, intersectPoint.y), intersectHeight, ballFlyTime, cathingZoneIndex, pretendCatchingBall);
        }
    }