static int GetEventTime(IntPtr L)
    {
        int count = LuaDLL.lua_gettop(L);

        if (count == 1)
        {
            Player    arg0 = (Player)LuaScriptMgr.GetNetObject(L, 1, typeof(Player));
            IM.Number o    = PlayerState_Rebound.GetEventTime(arg0);
            LuaScriptMgr.PushValue(L, o);
            return(1);
        }
        else if (count == 2)
        {
            Player    arg0 = (Player)LuaScriptMgr.GetNetObject(L, 1, typeof(Player));
            string    arg1 = LuaScriptMgr.GetLuaString(L, 2);
            IM.Number o    = PlayerState_Rebound.GetEventTime(arg0, arg1);
            LuaScriptMgr.PushValue(L, o);
            return(1);
        }
        else
        {
            LuaDLL.luaL_error(L, "invalid arguments to method: PlayerState_Rebound.GetEventTime");
        }

        return(0);
    }
    static int OnExit(IntPtr L)
    {
        LuaScriptMgr.CheckArgsCount(L, 1);
        PlayerState_Rebound obj = (PlayerState_Rebound)LuaScriptMgr.GetNetObjectSelf(L, 1, "PlayerState_Rebound");

        obj.OnExit();
        return(0);
    }
    static int GetDefaultMaxDist(IntPtr L)
    {
        LuaScriptMgr.CheckArgsCount(L, 1);
        Player arg0 = (Player)LuaScriptMgr.GetNetObject(L, 1, typeof(Player));

        IM.Number o = PlayerState_Rebound.GetDefaultMaxDist(arg0);
        LuaScriptMgr.PushValue(L, o);
        return(1);
    }
    static int Update(IntPtr L)
    {
        LuaScriptMgr.CheckArgsCount(L, 2);
        PlayerState_Rebound obj = (PlayerState_Rebound)LuaScriptMgr.GetNetObjectSelf(L, 1, "PlayerState_Rebound");

        IM.Number arg0 = (IM.Number)LuaScriptMgr.GetNetObject(L, 2, typeof(IM.Number));
        obj.Update(arg0);
        return(0);
    }
    static int OnEnter(IntPtr L)
    {
        LuaScriptMgr.CheckArgsCount(L, 2);
        PlayerState_Rebound obj  = (PlayerState_Rebound)LuaScriptMgr.GetNetObjectSelf(L, 1, "PlayerState_Rebound");
        PlayerState         arg0 = (PlayerState)LuaScriptMgr.GetNetObject(L, 2, typeof(PlayerState));

        obj.OnEnter(arg0);
        return(0);
    }
Beispiel #6
0
    public void OnRebound()
    {
        PlayerState_Rebound rebound = _owner.m_StateMachine.m_curState as PlayerState_Rebound;

        if (rebound == null)
        {
            return;
        }
        rebound.OnRebound();
    }
    static int GetMaxDist(IntPtr L)
    {
        LuaScriptMgr.CheckArgsCount(L, 2);
        Player        arg0 = (Player)LuaScriptMgr.GetNetObject(L, 1, typeof(Player));
        SkillInstance arg1 = (SkillInstance)LuaScriptMgr.GetNetObject(L, 2, typeof(SkillInstance));

        IM.Number o = PlayerState_Rebound.GetMaxDist(arg0, arg1);
        LuaScriptMgr.PushValue(L, o);
        return(1);
    }
    static int GetDefaultHeightRange(IntPtr L)
    {
        LuaScriptMgr.CheckArgsCount(L, 3);
        Player arg0 = (Player)LuaScriptMgr.GetNetObject(L, 1, typeof(Player));

        IM.Number arg1;
        IM.Number arg2;
        PlayerState_Rebound.GetDefaultHeightRange(arg0, out arg1, out arg2);
        LuaScriptMgr.PushValue(L, arg1);
        LuaScriptMgr.PushValue(L, arg2);
        return(2);
    }
 protected override void OnMatchSetted()
 {
     match.mainRole.m_StateMachine.ReplaceState(new PlayerState_Stand_Simple(match.mainRole.m_StateMachine, match));
     match.mainRole.m_alwaysForbiddenPickup = true;
     attacker = match.m_homeTeam.GetMember(1);
     attacker.m_alwaysForbiddenPickup   = true;
     match.mCurScene.mBall.onHitGround += OnBallHitGround;
     match.mCurScene.mBall.onRebound   += OnRebound;
     match.mCurScene.mBall.onGrab      += OnGrab;
     PlayerState_Rebound.GetDefaultHeightRange(match.mainRole, out minHeight, out maxHeight);
     eventTime = PlayerState_Rebound.GetEventTime(match.mainRole);
 }
    static int GetHeightRange(IntPtr L)
    {
        LuaScriptMgr.CheckArgsCount(L, 4);
        Player arg0 = (Player)LuaScriptMgr.GetNetObject(L, 1, typeof(Player));

        IM.Number     arg1;
        IM.Number     arg2;
        SkillInstance arg3 = (SkillInstance)LuaScriptMgr.GetNetObject(L, 4, typeof(SkillInstance));

        PlayerState_Rebound.GetHeightRange(arg0, out arg1, out arg2, arg3);
        LuaScriptMgr.PushValue(L, arg1);
        LuaScriptMgr.PushValue(L, arg2);
        return(2);
    }
    static int _CreatePlayerState_Rebound(IntPtr L)
    {
        int count = LuaDLL.lua_gettop(L);

        if (count == 2)
        {
            PlayerStateMachine  arg0 = (PlayerStateMachine)LuaScriptMgr.GetNetObject(L, 1, typeof(PlayerStateMachine));
            GameMatch           arg1 = (GameMatch)LuaScriptMgr.GetNetObject(L, 2, typeof(GameMatch));
            PlayerState_Rebound obj  = new PlayerState_Rebound(arg0, arg1);
            LuaScriptMgr.PushObject(L, obj);
            return(1);
        }
        else
        {
            LuaDLL.luaL_error(L, "invalid arguments to method: PlayerState_Rebound.New");
        }

        return(0);
    }
    static int set_rootMotionScale(IntPtr L)
    {
        object o = LuaScriptMgr.GetLuaObject(L, 1);
        PlayerState_Rebound obj = (PlayerState_Rebound)o;

        if (obj == null)
        {
            LuaTypes types = LuaDLL.lua_type(L, 1);

            if (types == LuaTypes.LUA_TTABLE)
            {
                LuaDLL.luaL_error(L, "unknown member name rootMotionScale");
            }
            else
            {
                LuaDLL.luaL_error(L, "attempt to index rootMotionScale on a nil value");
            }
        }

        obj.rootMotionScale = (IM.Number)LuaScriptMgr.GetNetObject(L, 3, typeof(IM.Number));
        return(0);
    }
    static int get_tooLate(IntPtr L)
    {
        object o = LuaScriptMgr.GetLuaObject(L, 1);
        PlayerState_Rebound obj = (PlayerState_Rebound)o;

        if (obj == null)
        {
            LuaTypes types = LuaDLL.lua_type(L, 1);

            if (types == LuaTypes.LUA_TTABLE)
            {
                LuaDLL.luaL_error(L, "unknown member name tooLate");
            }
            else
            {
                LuaDLL.luaL_error(L, "attempt to index tooLate on a nil value");
            }
        }

        LuaScriptMgr.Push(L, obj.tooLate);
        return(1);
    }
    static int set_m_toReboundBall(IntPtr L)
    {
        object o = LuaScriptMgr.GetLuaObject(L, 1);
        PlayerState_Rebound obj = (PlayerState_Rebound)o;

        if (obj == null)
        {
            LuaTypes types = LuaDLL.lua_type(L, 1);

            if (types == LuaTypes.LUA_TTABLE)
            {
                LuaDLL.luaL_error(L, "unknown member name m_toReboundBall");
            }
            else
            {
                LuaDLL.luaL_error(L, "attempt to index m_toReboundBall on a nil value");
            }
        }

        obj.m_toReboundBall = LuaScriptMgr.GetBoolean(L, 3);
        return(0);
    }
    public void Update(IM.Number deltaTime)
    {
        if (rebounders.Count == 0)
        {
            return;
        }

        GameMatch   match = GameSystem.Instance.mClient.mCurMatch;
        UBasketball ball  = match.mCurScene.mBall;

        if (!closed)
        {
            validTime -= deltaTime;
            if (validTime < IM.Number.zero)                     //close
            {
                closed = true;

                //select rebounder
                rebounders.Sort((info1, info2) =>
                {
                    if (info1.reboundValue < info2.reboundValue)
                    {
                        return(-1);
                    }
                    else if (info1.reboundValue > info2.reboundValue)
                    {
                        return(1);
                    }
                    else
                    {
                        return(0);
                    }
                });

                Info selectedRebounder = null;
                if (rebounders.Count > 0)
                {
                    uint totalValue = 0;
                    foreach (Info info in rebounders)
                    {
                        totalValue += info.reboundValue;
                    }
                    uint value = (uint)IM.Random.Range(0, totalValue);
                    Debug.Log("rebound value: " + value);
                    foreach (Info pl in rebounders)
                    {
                        Debug.Log("player :" + pl.player.m_id + " rebound : " + pl.reboundValue);
                    }

                    uint finalOdd = 0;
                    foreach (Info pl in rebounders)
                    {
                        finalOdd += pl.reboundValue;
                        if (value < finalOdd)
                        {
                            selectedRebounder = pl;
                            break;
                        }
                    }
                }

                if (selectedRebounder != null)
                {
                    foreach (Info info in rebounders)
                    {
                        bool canPick = (selectedRebounder == info && ball.m_ballState == BallState.eRebound && ball.m_picker == null);
                        if (canPick)
                        {
                            ball.m_picker = selectedRebounder.player;

                            PlayerState_Rebound stateRebound = ball.m_picker.m_StateMachine.GetState(PlayerState.State.eRebound) as PlayerState_Rebound;
                            if (ball.m_picker.m_StateMachine.m_curState.m_eState == PlayerState.State.eRebound && !stateRebound.m_toReboundBall)
                            {
                                stateRebound.m_toReboundBall = true;
                            }
                            else
                            {
                                MatchState.State eCurState = match.m_stateMachine.m_curState.m_eState;
                                if (eCurState == MatchState.State.ePlaying || eCurState == MatchState.State.eTipOff)
                                {
                                    if (ball.m_owner != null)
                                    {
                                        Debug.LogError("can not grab ball.");
                                    }
                                    ball.m_picker.GrabBall(ball);
                                }
                            }
                        }

                        string trace = "Rebound: player: " + info.player.m_id + " " + info.player.m_name +
                                       " value:" + info.reboundValue + " canPick:" + canPick;
                        Debugger.Instance.m_steamer.message += "\n" + trace + "\n";
                        Debug.Log(trace);
                    }
                }
            }
        }

        if (ball.m_ballState != BallState.eRebound)
        {
            rebounders.Clear();
            closed = false;
        }
    }
    override public void OnEnter(PlayerState lastState)
    {
        base.OnEnter(lastState);

        tooLate = false;

        //Debug.Log("rebound action is: " + m_curAction );

        m_heightScale = IM.Number.one;
        m_success     = true;
        if (m_ball.m_bGoal)
        {
            m_success = false;
        }
        if (m_ball.m_picker != null)
        {
            m_success = false;
        }
        if (m_ball.m_ballState != BallState.eRebound)
        {
            m_success = false;
        }

        Dictionary <string, uint> skillAttr = m_player.GetSkillAttribute();
        Dictionary <string, uint> data      = m_player.m_finalAttrs;

        if (data == null)
        {
            Debug.LogError("Can not find data.");
            m_success = false;
        }
        if (!m_match.m_ruler.CanRebound() || m_ball.m_owner != null)
        {
            m_success = false;
            tooLate   = false;
            Debug.Log(m_player.m_name + " Rebound failed, ball haven't been reached the highest position or ball has owner");
        }

        //Debug.Log("Rebound distance:" + m_player.m_fReboundDist);
        IM.Number fDistPlayer2Ball = GameUtils.HorizonalDistance(m_player.position, m_ball.position);

        IM.Number reboundDist = PlayerState_Rebound.GetMaxDist(m_player);
        if (fDistPlayer2Ball > reboundDist)
        {
            m_success = false;
            Debug.Log("player to ball distance: " + fDistPlayer2Ball + " farther than rebound distance: " + reboundDist);
        }

        IM.Number minHeight, maxHeight;
        GetHeightRange(m_player, out minHeight, out maxHeight);

        IM.Number fEventTime = GetEventTime(m_player, m_curAction);

        if (m_success)
        {
            IM.Vector3 vBallPosRebound;
            IM.Number  fCurTime     = m_ball.m_fTime;
            IM.Number  fHighestTime = m_ball.CompleteLastCurve().GetHighestTime();
            if (fCurTime + fEventTime < fHighestTime)   //������
            {
                m_success = false;
                tooLate   = false;
                Debug.Log("Rebound failed, ball not in falling.");
            }
            else if (m_ball.GetPositionInAir((fCurTime + fEventTime), out vBallPosRebound))
            {
                if (vBallPosRebound.y > minHeight && vBallPosRebound.y < maxHeight)
                {
                    //Debugger.Instance.DrawSphere("Rebound", vBallPosRebound, Color.red);
                    m_player.FaceTo(vBallPosRebound);
                    IM.Vector3 reboundAnimBall;
                    m_player.GetNodePosition(SampleNode.Ball, m_curAction, fEventTime, out reboundAnimBall);
                    m_heightScale = vBallPosRebound.y / reboundAnimBall.y;

                    IM.Vector3 root;
                    m_player.GetNodePosition(SampleNode.Root, m_curAction, fEventTime, out root);
                    IM.Vector3 root2Ball = reboundAnimBall - root;

                    IM.Number fDistPlayerToReboundPos = GameUtils.HorizonalDistance(vBallPosRebound - root2Ball, m_player.position);
                    IM.Number fDistOrigReboundPos     = GameUtils.HorizonalDistance(root, m_player.position);
                    rootMotionScale = fDistPlayerToReboundPos / fDistOrigReboundPos;
                    //Debug.Log("root motion scale: " + m_player.m_rootMotion.m_scale);
                }
                else
                {
                    m_success = false;
                    tooLate   = vBallPosRebound.y <= minHeight;
                    Debug.Log("Rebound failed, ball height: " + m_ball.transform.position.y + " height range: min: " + minHeight + " ,max: " + maxHeight);
                }
            }
            else
            {
                m_success = false;
                tooLate   = true;
                Debug.Log("reboundTime out of the curve, too slow");
            }
        }
        else
        {
            m_player.FaceTo(m_ball.position);
        }

        //m_curAction = m_mapAnimType[m_animType];
        IM.Vector3 vRoundScale = new IM.Vector3(rootMotionScale, m_heightScale, rootMotionScale);

        uint skillValue = 0;

        m_player.m_skillSystem.HegdingToValue("addn_rebound", ref skillValue);
        if (m_success)
        {
            m_match.reboundHelper.AddRebounder(m_player, m_curExecSkill);
        }

        ++m_player.mStatistics.data.rebound_times;
        if (m_success)
        {
            ++m_player.mStatistics.data.valid_rebound_times;
        }

        GameSystem.Instance.mClient.mPlayerManager.IsolateCollision(m_player, true);
        m_fEventTime = GetEventTime(m_player, m_curAction);
        IM.RootMotion rootMotion = m_player.animMgr.Play(m_curAction, true).rootMotion;
        rootMotion.scale = rootMotionScale;
        rootMotion.Reset();
    }
    public override void GameUpdate(IM.Number deltaTime)
    {
        base.GameUpdate(deltaTime);

        if (curStep != null)
        {
            stepRunningTime += (float)deltaTime;

            if (HasCondition(PractiseStepCondition.OnGround))
            {
                ValidateCondition(PractiseStepCondition.OnGround, (param) =>
                {
                    int index     = (int)(param[0]);
                    Player player = GetPlayer(index);
                    return(player.m_bOnGround);
                });
            }
            if (HasCondition(PractiseStepCondition.Wait))
            {
                ValidateCondition(PractiseStepCondition.Wait, (param) =>
                {
                    float waitTime = (float)(param[0]);
                    return(stepRunningTime >= waitTime);
                });
            }
            if (HasCondition(PractiseStepCondition.InDist))
            {
                ValidateCondition(PractiseStepCondition.InDist, (param) =>
                {
                    int index      = (int)(param[0]);
                    Player player  = GetPlayer(index);
                    GameObject obj = GetSceneObject((string)(param[1]));
                    float dist     = (float)(param[2]);
                    bool value     = (bool)(param[3]);
                    return((GameUtils.HorizonalDistance(obj.transform.position, (Vector3)player.position) <= dist) == value);
                });
            }
            if (HasCondition(PractiseStepCondition.EnterRow))
            {
                ValidateCondition(PractiseStepCondition.EnterRow, (param) =>
                {
                    int index     = (int)(param[0]);
                    int rowStart  = (int)(param[1]);
                    int rowEnd    = (int)(param[2]);
                    Player player = GetPlayer(index);
                    int secIdx    = RoadPathManager.Instance.CalcSectorIdx(player.position);
                    if (secIdx == -1)
                    {
                        return(false);
                    }
                    int rowIdx = secIdx / RoadPathManager.Instance.m_angleNum;
                    return(rowStart <= rowIdx && rowIdx <= rowEnd);
                });
            }
            if (HasCondition(PractiseStepCondition.EnterArea))
            {
                ValidateCondition(PractiseStepCondition.EnterArea, (param) =>
                {
                    int index     = (int)(param[0]);
                    Player player = GetPlayer(index);
                    Area area     = (Area)(param[1]);
                    return(match.mCurScene.mGround.GetArea(player) == area);
                });
            }
            if (HasCondition(PractiseStepCondition.EnterState))
            {
                ValidateCondition(PractiseStepCondition.EnterState, (param) =>
                {
                    int index               = (int)(param[0]);
                    Player player           = GetPlayer(index);
                    PlayerState.State state = (PlayerState.State)(param[1]);
                    return(state == player.m_StateMachine.m_curState.m_eState);
                });
            }
            if (HasCondition(PractiseStepCondition.BlockTiming))
            {
                ValidateCondition(PractiseStepCondition.BlockTiming, (param) =>
                {
                    Player attacker = ball.m_owner;
                    if (attacker == null)
                    {
                        attacker = ball.m_actor;
                    }
                    if (attacker.m_StateMachine.m_curState.m_eState != PlayerState.State.eShoot &&
                        attacker.m_StateMachine.m_curState.m_eState != PlayerState.State.eLayup &&
                        attacker.m_StateMachine.m_curState.m_eState != PlayerState.State.eDunk)
                    {
                        return(false);
                    }
                    if (!PlayerState_Block.InBlockArea(attacker, attacker.m_defenseTarget, match.mCurScene.mBasket.m_vShootTarget))
                    {
                        return(false);
                    }
                    return(attacker.m_blockable.blockable);
                });
            }
            if (HasCondition(PractiseStepCondition.Blocked))
            {
                ValidateCondition(PractiseStepCondition.Blocked, (param) =>
                {
                    int index     = (int)(param[0]);
                    Player player = GetPlayer(index);
                    if (player.m_StateMachine.m_curState.m_eState != PlayerState.State.eBlock)
                    {
                        return(false);
                    }
                    PlayerState_Block blockState = player.m_StateMachine.m_curState as PlayerState_Block;
                    bool success = (bool)(param[1]);
                    return(blockState.m_success == success);
                });
            }
            if (HasCondition(PractiseStepCondition.BlockInArea))
            {
                ValidateCondition(PractiseStepCondition.BlockInArea, (param) =>
                {
                    int index       = (int)(param[0]);
                    Player player   = GetPlayer(index);
                    Player attacker = ball.m_owner;
                    if (attacker == null)
                    {
                        attacker = ball.m_actor;
                    }
                    bool inArea = (bool)(param[1]);
                    return(PlayerState_Block.InBlockArea(attacker, player, match.mCurScene.mBasket.m_vShootTarget) == inArea);
                });
            }
            if (HasCondition(PractiseStepCondition.BlockTooLate))
            {
                ValidateCondition(PractiseStepCondition.BlockTooLate, (param) =>
                {
                    int index     = (int)(param[0]);
                    Player player = GetPlayer(index);
                    if (player.m_StateMachine.m_curState.m_eState != PlayerState.State.eBlock)
                    {
                        return(false);
                    }
                    PlayerState_Block blockState = player.m_StateMachine.m_curState as PlayerState_Block;
                    if (blockState.m_success)
                    {
                        return(false);
                    }
                    Player attacker = ball.m_owner;
                    if (attacker == null)
                    {
                        attacker = ball.m_actor;
                    }
                    bool tooLate = (bool)(param[1]);
                    if (tooLate)
                    {
                        return(blockState.m_failReason == PlayerState_Block.FailReason.TooLate);
                    }
                    else
                    {
                        return(blockState.m_failReason == PlayerState_Block.FailReason.TooEarly);
                    }
                });
            }
            if (HasCondition(PractiseStepCondition.ReboundTiming))
            {
                ValidateCondition(PractiseStepCondition.ReboundTiming, (param) =>
                {
                    if (ball.m_ballState == BallState.eRebound)
                    {
                        IM.Vector3 velocity = ball.curVel;
                        if (velocity.y < IM.Number.zero)
                        {
                            int index           = (int)(param[0]);
                            Player player       = GetPlayer(index);
                            IM.Number eventTime = PlayerState_Rebound.GetEventTime(player);
                            IM.Vector3 pos;
                            ball.GetPositionInAir(ball.m_fTime + eventTime, out pos);
                            IM.Number ball_height = pos.y;
                            IM.Number minHeight, maxHeight;
                            PlayerState_Rebound.GetDefaultHeightRange(player, out minHeight, out maxHeight);
                            return(minHeight < ball_height && ball_height < maxHeight);
                        }
                    }
                    return(false);
                });
            }
            if (HasCondition(PractiseStepCondition.Rebound))
            {
                ValidateCondition(PractiseStepCondition.Rebound, (param) =>
                {
                    int index     = (int)(param[0]);
                    Player player = GetPlayer(index);
                    if (player.m_StateMachine.m_curState.m_eState != PlayerState.State.eRebound)
                    {
                        return(false);
                    }
                    PlayerState_Rebound reboundState = player.m_StateMachine.m_curState as PlayerState_Rebound;
                    bool success = (bool)(param[1]);
                    if (success)
                    {
                        reboundState.m_toReboundBall = true;
                    }
                    return(reboundState.m_success == success);
                });
            }
            if (HasCondition(PractiseStepCondition.ReboundInArea))
            {
                ValidateCondition(PractiseStepCondition.ReboundInArea, (param) =>
                {
                    int index           = (int)(param[0]);
                    Player player       = GetPlayer(index);
                    IM.Number dist2Ball = GameUtils.HorizonalDistance(player.position, ball.position);
                    IM.Number maxDist   = PlayerState_Rebound.GetDefaultMaxDist(player);
                    bool inArea         = (bool)(param[1]);
                    return((dist2Ball <= maxDist) == inArea);
                });
            }
            if (HasCondition(PractiseStepCondition.ReboundTooLate))
            {
                ValidateCondition(PractiseStepCondition.ReboundTooLate, (param) =>
                {
                    int index     = (int)(param[0]);
                    Player player = GetPlayer(index);
                    if (player.m_StateMachine.m_curState.m_eState != PlayerState.State.eRebound)
                    {
                        return(false);
                    }
                    PlayerState_Rebound reboundState = player.m_StateMachine.m_curState as PlayerState_Rebound;
                    if (reboundState.m_success)
                    {
                        return(false);
                    }
                    bool tooLate = (bool)(param[1]);
                    return(reboundState.tooLate == tooLate);
                });
            }
            if (HasCondition(PractiseStepCondition.Undefended))
            {
                ValidateCondition(PractiseStepCondition.Undefended, (param) =>
                {
                    int index     = (int)(param[0]);
                    Player player = GetPlayer(index);
                    return(!player.IsDefended());
                });
            }
            if (HasCondition(PractiseStepCondition.Defended))
            {
                ValidateCondition(PractiseStepCondition.Defended, (param) =>
                {
                    int index     = (int)(param[0]);
                    Player player = GetPlayer(index);
                    return(player.IsDefended());
                });
            }
        }

        if (stepFinished)
        {
            EndStep();
        }

        if (readyStepID != 0)
        {
            curStep     = GameSystem.Instance.PractiseStepConfig.GetStep(readyStepID);
            readyStepID = 0;
            RunStep();
            return;
        }
    }