static bool InFrontOfBallOwner(Player player, UBasketball ball, IM.Number distThreshold)
    {
        if (ball.m_owner == null)
        {
            return(false);
        }

        //distance
        IM.Number dist = GameUtils.HorizonalDistance(player.position, ball.position);
        if (dist > distThreshold)
        {
            Debug.Log("Steal distance: " + dist + " greater than " + distThreshold);
            return(false);
        }

        //is in front of target
        IM.Vector3 dir = player.position - ball.m_owner.position;
        dir.Normalize();
        IM.Number angle = IM.Vector3.Angle(ball.m_owner.forward, dir);
        if (angle > new IM.Number(90))
        {
            Debug.Log("Steal angle " + angle);
            return(false);
        }

        return(true);
    }
示例#2
0
 static int Normalize(IntPtr L)
 {
     LuaScriptMgr.CheckArgsCount(L, 1);
     IM.Vector3 obj = (IM.Vector3)LuaScriptMgr.GetNetObjectSelf(L, 1, "IM.Vector3");
     obj.Normalize();
     LuaScriptMgr.SetValueObject(L, 1, obj);
     return(0);
 }
 public void Constraint(ref IM.Vector3 pos)
 {
     IM.Number  limitDist    = m_match.RADIAL_FAR;
     IM.Vector3 basketCenter = m_match.basketCenter;
     IM.Vector3 dir          = pos - basketCenter;
     if (dir.magnitude <= limitDist)
     {
         return;
     }
     dir.Normalize();
     pos = basketCenter + dir * limitDist;
 }
	public override bool ResetPlayerPos()
	{
		IM.Number angle = IM.Random.Range(new IM.Number(90), new IM.Number(270));
		IM.Vector3 dir = IM.Quaternion.AngleAxis(angle, IM.Vector3.up) * IM.Vector3.forward;
        match.mainRole.position = GameSystem.Instance.MatchPointsConfig.ThreePTCenter.transform.position + dir * IM.Number.two;
		basketCenter = match.mCurScene.mBasket.m_vShootTarget;
		basketCenter.y = IM.Number.zero;
		dir = match.mainRole.position - basketCenter;
		dir.Normalize();
		defenser.position = basketCenter + dir * IM.Number.two;
		defenser.forward = dir;
		match.mainRole.forward = -dir;
		return true;
	}
    public int DetectZone(IM.Vector3 pos)
    {
        int zone = 0;

        IM.Vector3 dir = pos - basketCenter;
        dir.y = IM.Number.zero;
        IM.Number radialDist = dir.magnitude;
        IM.Number horiDist   = IM.Math.Abs(pos.x);
        dir.Normalize();
        IM.Number angle         = IM.Vector3.Angle(IM.Vector3.right, dir);
        int       radialSection = ((angle - ANGLE_SEG_SIDE) / ANGLE_SEG).floorToInt + 1;

        Debug.Log("player standing on section: " + radialSection);
        if (radialSection == 0 || radialSection == 4)
        {
            if (horiDist <= HORI_NEAR)
            {
                zone = 1;
            }
            else if (horiDist <= HORI_MIDDLE)
            {
                zone = pos.x > 0 ? 2 : 10;
            }
            else if (horiDist <= HORI_FAR)
            {
                zone = pos.x > 0 ? 3 : 11;
            }
        }
        else if (radialSection == 1 || radialSection == 2 || radialSection == 3)
        {
            if (radialDist <= RADIAL_NEAR)
            {
                zone = 1;
            }
            else if (radialDist <= RADIAL_MIDDLE)
            {
                zone = (radialSection + 1) * 2;
            }
            else if (radialDist <= RADIAL_FAR)
            {
                zone = (radialSection + 1) * 2 + 1;
            }
        }
        return(zone);
    }
示例#6
0
    void ShowCollisionSpark(UBasketball ball)
    {
        if (m_collisionSpark == null)
        {
            Object prefab = ResourceLoadManager.Instance.LoadPrefab("Prefab/Effect/E_Spark1");
            m_collisionSpark = (Object.Instantiate(prefab) as GameObject).GetComponent <ParticleSystem>();
            m_collisionSpark.transform.parent        = transform;
            m_collisionSpark.transform.localScale    = Vector3.one;
            m_collisionSpark.transform.localRotation = Quaternion.identity;
        }

        IM.Vector3 dirRimToBall = ball.position - m_rim.center;
        dirRimToBall.Normalize();
        dirRimToBall.y = IM.Number.zero;
        IM.Vector3 sparkPos = m_rim.center + dirRimToBall * m_rim.radius;
        m_collisionSpark.transform.position = (Vector3)sparkPos;
        m_collisionSpark.Play();
    }
示例#7
0
    void _DoCollision_Rim(IM.Vector3 vBounceRim, ShootSolution.SShootCurve shootCurve, IM.Number fTime, ref IM.Vector3 vecResultPos, ref IM.Vector3 vecResultVel)
    {
        fTime -= new IM.Number(0, 001);
        IM.Vector3 vecBallPos = new IM.Vector3(
            shootCurve.fX_a * fTime * fTime + shootCurve.fX_b * fTime + shootCurve.fX_c,
            shootCurve.fY_a * fTime * fTime + shootCurve.fY_b * fTime + shootCurve.fY_c,
            shootCurve.fZ_a * fTime * fTime + shootCurve.fZ_b * fTime + shootCurve.fZ_c);
        fTime += new IM.Number(0, 001);

        IM.Vector3 vecBallVel = new IM.Vector3(
            IM.Number.two * shootCurve.fX_a * fTime + shootCurve.fX_b,
            IM.Number.two * shootCurve.fY_a * fTime + shootCurve.fY_b,
            IM.Number.two * shootCurve.fZ_a * fTime + shootCurve.fZ_b);

        IM.Vector3 vecRim2Ball     = vecBallPos - m_basket.m_rim.center;
        IM.Vector3 vecRim2BallHori = vecRim2Ball;
        vecRim2BallHori.y = IM.Number.zero;
        vecRim2BallHori.Normalize();

        IM.Vector3 vecContactPos = m_basket.m_rim.center + m_basket.m_rim.radius * vecRim2BallHori;
        IM.Vector3 vecForce      = vecBallPos - vecContactPos;
        vecForce.Normalize();

        /*
         * if(vecForce.y > 0.7f)
         * {
         *      vecForce.y = 1.0f;
         *      vecForce.x = vecForce.z = IM.Number.zero;
         * }
         */
        IM.Number fDotProd = IM.Vector3.Dot(vecBallVel, vecForce);
        vecResultVel = vecBallVel - vecForce * fDotProd;

        vecResultVel.x *= vBounceRim.x;
        vecResultVel.y *= vBounceRim.y;
        vecResultVel.z *= vBounceRim.z;

        vecResultPos = vecBallPos;
    }
示例#8
0
    protected override void OnTick()
    {
        m_decidedOnHoldTime += m_system.AI.delay;
        if (m_player.m_defenseTarget != null)
        {
            GameMatch   match   = GameSystem.Instance.mClient.mCurMatch;
            UBasketball ball    = match.mCurScene.mBall;
            IM.Vector3  vBasket = match.mCurScene.mBasket.m_vShootTarget;

            if (ball.m_owner != null && ball.m_owner.m_StateMachine.m_curState.m_eState != PlayerState.State.ePrepareToShoot)
            {
                m_decidedOnPrepareShoot = false;
            }
            if (ball.m_owner != null && ball.m_owner.m_StateMachine.m_curState.m_eState != PlayerState.State.eBackToBackForward)
            {
                m_decidedOnBackToBack = false;
            }
            if (m_decidedOnHold && (ball.m_owner != null &&
                                    ball.m_owner.m_StateMachine.m_curState.m_eState != PlayerState.State.eHold &&
                                    ball.m_owner.m_StateMachine.m_curState.m_eState != PlayerState.State.eStand || m_decidedOnHoldTime > IM.Number.two))
            {
                m_decidedOnHold = false;
            }

            IM.Number distDef = GameUtils.HorizonalDistance(m_player.m_defenseTarget.position, m_player.position);

            if (AIUtils.ShouldTraceBall(ball, m_player))
            {
                m_system.SetTransaction(AIState.Type.eIdle);
                return;
            }

            if (m_player.m_team.m_role == GameMatch.MatchRole.eDefense)
            {
                //��ס����Ŀ��
                m_fDefenseDist = (m_player.m_defenseTarget.m_StateMachine.m_curState.m_eState == PlayerState.State.eHold ||
                                  m_player.m_defenseTarget.m_StateMachine.m_curState.m_eState == PlayerState.State.ePrepareToShoot) ? new IM.Number(1, 500) : new IM.Number(1, 500);
                IM.Vector3 defenseDirX = vBasket - m_player.m_defenseTarget.position;
                defenseDirX.y = IM.Number.zero;
                IM.Number distAttackerToBasket = defenseDirX.magnitude;
                defenseDirX.Normalize();

                if (m_defensePosition == DefensePosition.Left)
                {
                    defenseDirX = IM.Quaternion.AngleAxis(-m_player.m_defenseTarget.m_AOD.angle / 4, IM.Vector3.up) * defenseDirX;
                }
                else if (m_defensePosition == DefensePosition.Right)
                {
                    defenseDirX = IM.Quaternion.AngleAxis(m_player.m_defenseTarget.m_AOD.angle / 4, IM.Vector3.up) * defenseDirX;
                }

                IM.Vector3 targetToMove;
                if (m_defensePosition == DefensePosition.Inside && distAttackerToBasket > (new IM.Number(1, 900) + m_fDefenseDist))
                {
                    targetToMove = vBasket + (-defenseDirX) * new IM.Number(1, 900);
                }
                else
                {
                    targetToMove = m_player.m_defenseTarget.position + defenseDirX * m_fDefenseDist;
                }
                if (GameUtils.HorizonalDistance(m_player.position, targetToMove) > IM.Number.half)
                {
                    m_moveTarget = targetToMove;
                }
                //���ַ��ص���
                if (m_defensePosition == DefensePosition.Center)
                {
                    if (distAttackerToBasket > new IM.Number(2, 100))
                    {
                        IM.Number distMoveTargetToBasket = GameUtils.HorizonalDistance(vBasket, m_moveTarget);
                        if (distMoveTargetToBasket < new IM.Number(2, 100))
                        {
                            m_moveTarget = vBasket - defenseDirX * new IM.Number(2, 100);
                        }
                    }
                }

                if (m_player.m_defenseTarget.m_StateMachine.m_curState.m_eState == PlayerState.State.eBackToBackForward &&
                    distDef <= new IM.Number(2, 200))
                {
                    if (!m_decidedOnBackToBack)
                    {
                        IM.Number competeWeight = new IM.Number(50);
                        switch (m_player.m_position)
                        {
                        case PositionType.PT_SF:
                            competeWeight += new IM.Number(30);
                            break;

                        case PositionType.PT_PG:
                        case PositionType.PT_C:
                            competeWeight += new IM.Number(100);
                            break;
                        }
                        m_system.SetTransaction(AIState.Type.eDefenseBack, competeWeight);
                        m_system.SetTransaction(AIState.Type.eDefense, new IM.Number(50), true);
                        m_decidedOnBackToBack = true;
                        return;
                    }
                }
                else if (m_player.m_defenseTarget.m_bWithBall &&
                         (m_player.m_defenseTarget.m_StateMachine.m_curState.m_eState == PlayerState.State.eHold ||
                          m_player.m_defenseTarget.m_StateMachine.m_curState.m_eState == PlayerState.State.eStand))
                {
                    if (!m_decidedOnHold)
                    {
                        IM.Number stealRate = AIUtils.GetStealRate(m_player, m_player.m_defenseTarget, m_match);
                        if (stealRate > IM.Number.zero)
                        {
                            m_system.SetTransaction(AIState.Type.eSteal, stealRate * 100);
                        }
                        m_system.SetTransaction(AIState.Type.eDefense, (IM.Number.one - stealRate) * 100);
                        m_decidedOnHold     = true;
                        m_decidedOnHoldTime = IM.Number.zero;
                        return;
                    }
                }
                else if (ball.m_ballState != BallState.eLoseBall &&
                         IM.Vector3.Angle(m_player.forward, m_player.m_defenseTarget.forward) > new IM.Number(90) && distDef < IM.Number.two)
                {
                    List <SkillInstance> defenseSkill = m_player.m_skillSystem.GetBasicSkillsByCommand(Command.Defense);
                    m_player.m_toSkillInstance = defenseSkill[0];
                }

                //Э����ñ����
                IM.Number assistBlockRate = IM.Number.zero;
                switch (m_player.m_position)
                {
                case PositionType.PT_C:
                case PositionType.PT_PF:
                    assistBlockRate = new IM.Number(0, 750);
                    break;

                case PositionType.PT_SF:
                    assistBlockRate = new IM.Number(0, 600);
                    break;

                case PositionType.PT_PG:
                case PositionType.PT_SG:
                    assistBlockRate = new IM.Number(0, 400);
                    break;
                }

                if (m_ball.m_owner != null &&
                    (m_ball.m_owner == m_player.m_defenseTarget ||
                     (IM.Random.value < assistBlockRate && GameUtils.HorizonalDistance(m_ball.m_owner.position, m_player.position) < new IM.Number(3))) &&
                    AIUtils.IsAttacking(m_ball.m_owner))
                {
                    if (!m_decidedToBlock)
                    {
                        //m_devBlockTime = Random.Range(0f, m_system.AI.devTimeBlock);
                        m_devBlockTime = m_system.AI.devTimeBlock;
                        //m_blockTimingRatio = Random.value;
                        m_blockTimingRatio = IM.Number.zero;
                        //float toBlockRate = Mathf.Clamp(m_player.m_fightingCapacity / m_ball.m_owner.m_fightingCapacity * 0.2f, 0.05f, 0.5f);
                        IM.Number toBlockRate = IM.Number.half;
                        IM.Number value       = IM.Random.value;
                        m_bToBlock = value < toBlockRate;
                        Debug.Log(m_player.m_name + "Block time dev:" + m_devBlockTime +
                                  " To block rate: " + toBlockRate + " " + value + " " + m_bToBlock);
                        m_decidedToBlock = true;
                    }

                    IM.Vector3 owner2Player = m_player.position - m_ball.m_owner.position;
                    owner2Player.y = IM.Number.zero;
                    IM.Number fDistOwner2Player = owner2Player.magnitude;
                    fDistOwner2Player *= IM.Number.one - m_system.AI.devDistBlock;

                    if (m_ball.m_owner.m_AOD.GetStateByPos(m_player.position) == AOD.Zone.eInvalid)
                    {
                        m_moveTarget = m_ball.m_owner.position + m_ball.m_owner.forward * m_fDefenseDist;
                        m_system.SetTransaction(Type.eDefense);
                    }
                    else if (m_ball.m_owner.m_StateMachine.m_curState.m_eState == PlayerState.State.ePrepareToShoot)
                    {
                        if (!m_decidedOnPrepareShoot && !m_bToBlock)
                        {
                            if (m_player.m_defenseTarget == m_ball.m_owner)
                            {
                                IM.Number stealRate = AIUtils.GetStealRate(m_player, m_ball.m_owner, m_match);
                                Debug.Log(m_player.m_name + " Steal rate: " + stealRate);
                                if (stealRate > IM.Number.zero)
                                {
                                    m_system.SetTransaction(Type.eSteal, stealRate * 100);
                                }
                                m_system.SetTransaction(Type.eDefense, (IM.Number.one - stealRate) * 100);
                            }
                            m_decidedOnPrepareShoot = true;
                        }
                    }

                    if (m_bToBlock &&
                        m_player.m_StateMachine.m_curState.IsCommandValid(Command.Block) &&
                        AIUtils.CanBlock(m_player, m_ball.m_owner, m_devBlockTime, m_blockTimingRatio, m_basket.m_vShootTarget))
                    {
                        m_system.SetTransaction(Type.eBlock);
                    }
                }
                else
                {
                    if (m_decidedToBlock)
                    {
                        m_decidedToBlock = false;
                    }
                }
            }
            else
            {
                m_system.SetTransaction(AIState.Type.ePositioning);
            }
        }
    }