Exemple #1
0
    static int AngleToDir(IntPtr L)
    {
        int count = LuaDLL.lua_gettop(L);

        if (count == 3 && LuaScriptMgr.CheckTypes(L, 1, typeof(float), null, null))
        {
            float      arg0 = (float)LuaDLL.lua_tonumber(L, 1);
            EDirection arg1;
            Vector3    arg2;
            GameUtils.AngleToDir(arg0, out arg1, out arg2);
            LuaScriptMgr.Push(L, arg1);
            LuaScriptMgr.Push(L, arg2);
            return(2);
        }
        else if (count == 3 && LuaScriptMgr.CheckTypes(L, 1, typeof(IM.Number), null, null))
        {
            IM.Number  arg0 = (IM.Number)LuaScriptMgr.GetLuaObject(L, 1);
            int        arg1;
            IM.Vector3 arg2;
            GameUtils.AngleToDir(arg0, out arg1, out arg2);
            LuaScriptMgr.Push(L, arg1);
            LuaScriptMgr.PushValue(L, arg2);
            return(2);
        }
        else
        {
            LuaDLL.luaL_error(L, "invalid arguments to method: GameUtils.AngleToDir");
        }

        return(0);
    }
Exemple #2
0
    public override void Update(IM.Number fDeltaTime)
    {
        if (m_player.m_StateMachine.assistAI.curCommand != Command.TraceBall ||
            m_ball.m_ballState != BallState.eLoseBall)
        {
            m_player.m_StateMachine.assistAI.Disable();
        }

        IM.Vector3 targetPos         = m_ball.position;
        IM.Vector3 vecPlayerToTarget = targetPos - m_player.position;
        vecPlayerToTarget.y = IM.Number.zero;
        if (vecPlayerToTarget.magnitude < new IM.Number(0, 100))
        {
            m_player.moveDirection = IM.Vector3.zero;
            m_player.m_moveType    = MoveType.eMT_Stand;
        }
        else
        {
            int        dir;
            IM.Vector3 vel;
            IM.Number  angle = IM.Vector3.FromToAngle(IM.Vector3.forward, vecPlayerToTarget.normalized);
            GameUtils.AngleToDir(angle, out dir, out vel);
            m_player.m_dir      = dir;
            m_player.m_moveType = MoveType.eMT_Rush;
        }
    }
    public void Update(IM.Number deltaTime)
    {
        if (!_bMoveToTarget || !_owner.m_enableMovement)
        {
            Debugger.Instance.DrawSphere("move target " + _owner.m_id, (Vector3)targetPosition, Color.green);
            return;
        }

        Debugger.Instance.DrawSphere("move target " + _owner.m_id, (Vector3)targetPosition, Color.red);

        //calculate by delta time
        IM.Number distance   = GameUtils.HorizonalDistance(targetPosition, _owner.position);
        IM.Number movingTime = IM.Number.zero;
        if (!IM.Number.Approximately(distance, IM.Number.zero))
        {
            if (movingSpeed == IM.Number.zero)
            {
                movingTime = IM.Number.max;
            }
            else
            {
                movingTime = distance / movingSpeed;
            }
        }
        if (deltaTime > movingTime)
        {
            targetPosition = _owner.position;
            _bMoveToTarget = false;
            _owner.m_dir   = -1;

            if (onMoveToTarget != null)
            {
                onMoveToTarget();
            }
            else
            {
                Debug.LogError("no move to msg received.");
            }
        }
        else
        {
            IM.Vector3 dirMove = GameUtils.HorizonalNormalized(targetPosition, _owner.position);
            IM.Number  angle   = IM.Vector3.FromToAngle(IM.Vector3.forward, dirMove);
            IM.Vector3 vel;
            int        dir;
            GameUtils.AngleToDir(angle, out dir, out vel);

            /*
             * Logger.Log(string.Format("MoveHelper, calc dir, {0} {1}, pos:{2}->{3} angle:{4} dir:{5}",
             *  _owner.m_team.m_side, _owner.m_id, _owner.position, targetPosition, angle, dir));
             */
            _owner.m_dir = dir;
        }
    }
    public override void Update(IM.Number fDeltaTime)
    {
        if (m_player.m_StateMachine.assistAI.curCommand != Command.Defense)
        {
            m_player.m_StateMachine.assistAI.Disable();
        }

        Player target = m_player.m_defenseTarget;

        IM.Vector3 dirTargetToBasket      = GameUtils.HorizonalNormalized(m_match.mCurScene.mBasket.m_vShootTarget, target.position);
        IM.Number  fDistDefTargetToBasket = GameUtils.HorizonalDistance(target.position, m_match.mCurScene.mBasket.m_vShootTarget);
        IM.Number  fDistDefToBasket       = GameUtils.HorizonalDistance(m_player.position, m_match.mCurScene.mBasket.m_vShootTarget);

        IM.Vector3 targetPos         = target.position + dirTargetToBasket * IM.Math.Max(fDistDefTargetToBasket / new IM.Number(3, 500), IM.Number.half);
        IM.Vector3 vecPlayerToTarget = targetPos - m_player.position;
        IM.Number  distToTargetPos   = vecPlayerToTarget.magnitude;
        if (distToTargetPos < new IM.Number(0, 100))
        {
            m_player.m_dir = -1;
            m_player.m_moveHelper.StopMove(MoveType.eMT_Defense);
        }
        else
        {
            int        dir;
            IM.Vector3 vel;
            //IM.Number angle = IM.Quaternion.FromToRotation(IM.Vector3.forward, vecPlayerToTarget.normalized).eulerAngles.y;
            IM.Number angle = IM.Vector3.FromToAngle(IM.Vector3.forward, vecPlayerToTarget.normalized);
            GameUtils.AngleToDir(angle, out dir, out vel);
            m_player.m_dir      = dir;
            m_player.m_moveType = distToTargetPos < new IM.Number(4) ? MoveType.eMT_Run : MoveType.eMT_Rush;
        }

        if (target.m_AOD.GetStateByPos(m_player.position) == AOD.Zone.eInvalid)
        {
            m_player.m_toSkillInstance = null;
        }
        else if (m_player.m_inputDispatcher != null &&
                 m_player.m_inputDispatcher._autoDefTakeOver.InTakeOver &&
                 AIUtils.IsAttacking(target) &&
                 m_player.m_StateMachine.m_curState.m_eState != PlayerState.State.eDisturb &&
                 !(m_player.m_StateMachine.m_curState is PlayerState_Skill) &&
                 target.m_blockable.blockable)
        {
            m_player.m_StateMachine.SetState(PlayerState.State.eDisturb);
        }
    }