bool _IsDefended(Player target)
    {
        IM.Number fDistance = GameUtils.HorizonalDistance(m_player.position, target.position);
        if (fDistance > m_defenseDist)
        {
            return(false);
        }
        PlayerState.State curState = target.m_StateMachine.m_curState.m_eState;
        if (curState != State.eRun && curState != State.eRush)
        {
            return(false);
        }
        IM.Vector3 lhs = m_player.position + m_player.right * m_defenseRadius;
        IM.Vector3 rhs = m_player.position - m_player.right * m_defenseRadius;

        IM.Vector3 playerToLhs = GameUtils.HorizonalNormalized(lhs, target.position);
        IM.Vector3 playerToRhs = GameUtils.HorizonalNormalized(rhs, target.position);

        if (IM.Vector3.Dot(target.forward, m_player.forward) > IM.Number.zero)
        {
            return(false);
        }

        IM.Number fCrossRet1 = IM.Vector3.Cross(playerToLhs, target.moveDirection).y;
        IM.Number fCrossRet2 = IM.Vector3.Cross(playerToRhs, target.moveDirection).y;
        if (fCrossRet1 * fCrossRet2 > IM.Number.zero)
        {
            return(false);
        }

        return(true);
    }
Esempio n. 2
0
 public void ToggleShooter(PlayerState.State state)
 {
     if (state == PlayerState.State.normal)
     {
         mainShooter.gameObject.SetActive(true);
         secondaryShooter.gameObject.SetActive(false);
         AssignInputListener(mainShooter, secondaryShooter);
         //swap from focus to main if holding z while swapping
         if (Input.GetKey(KeyCode.Z))
         {
             mainShooter.StartAuto();
         }
     }
     else if (state == PlayerState.State.focus)
     {
         mainShooter.gameObject.SetActive(false);
         secondaryShooter.gameObject.SetActive(true);
         AssignInputListener(secondaryShooter, mainShooter);
         //swap from main to focus if holding z while swapping
         if (Input.GetKey(KeyCode.Z))
         {
             secondaryShooter.StartAuto();
         }
     }
 }
Esempio n. 3
0
    public void SetGameState(PlayerState.State newState)
    {
        switch (newState)
        {
        case PlayerState.State.Default:
            m_alarmLightsController.StopAlarm();
            break;

        case PlayerState.State.Alarm:
            if (m_alarmLightsController)
            {
                m_alarmLightsController.StartAlarm();
            }
            if (m_alarmEnemySpawner)
            {
                m_alarmEnemySpawner.StartAlarm();
            }
            AlarmActivated?.Invoke();
            break;

        case PlayerState.State.PoliceArrive:
            break;
        }
        playerState.currentState = newState;
    }
    static int IntToEnum(IntPtr L)
    {
        int arg0 = (int)LuaDLL.lua_tonumber(L, 1);

        PlayerState.State o = (PlayerState.State)arg0;
        LuaScriptMgr.Push(L, o);
        return(1);
    }
 public PlayerState GetState(PlayerState.State state)
 {
     if ((int)state > (int)PlayerState.State.eMax)
     {
         return(null);
     }
     return(m_arStateList[(int)state]);
 }
Esempio n. 6
0
 public IM.Number GetRatio(PlayerState.State state)
 {
     IM.Number ratio;
     if (ratios.TryGetValue(state, out ratio))
     {
         return(ratio);
     }
     return(IM.Number.zero);
 }
Esempio n. 7
0
    void Start()
    {
        // 获取组件
        _rigidbody          = GetComponent <Rigidbody>();
        _speedRegulator     = GetComponent <SpeedRegulator>();
        _directionRegulator = GetComponent <DirectionRegulator>();

        State = new PlayerState.Debug(this);
    }
Esempio n. 8
0
 public void ToggleMovement(PlayerState.State state)
 {
     if (state == PlayerState.State.normal)
     {
         currentSpeed = moveSpeed;
     }
     else if (state == PlayerState.State.focus)
     {
         currentSpeed = focusSpeed;
     }
 }
    static int GetState(IntPtr L)
    {
        LuaScriptMgr.CheckArgsCount(L, 2);
        PlayerStateMachine obj = (PlayerStateMachine)LuaScriptMgr.GetNetObjectSelf(L, 1, "PlayerStateMachine");

        PlayerState.State arg0 = (PlayerState.State)LuaScriptMgr.GetNetObject(L, 2, typeof(PlayerState.State));
        PlayerState       o    = obj.GetState(arg0);

        LuaScriptMgr.PushObject(L, o);
        return(1);
    }
Esempio n. 10
0
    public void SetState(PlayerState.State state)
    {
        if (currentState != null)
        {
            currentState.EndState();
        }

        currentState = stateDictionary[state];
        currentState.StartState();
        currentStateEnum = state;
    }
Esempio n. 11
0
 public static void Close(PlayerState.State state = PlayerState.State.Inventory)
 {
     GetInstance().Visible = false;
     if (state == PlayerState.State.Inventory)
     {
         PlayerState.SetState(PlayerState.prec_state);
     }
     else
     {
         PlayerState.SetState(state);
     }
 }
Esempio n. 12
0
    public override void Update(IM.Number fDeltaTime)
    {
        base.Update(fDeltaTime);

        Player defenseTarget = m_player.m_defenseTarget;

        PlayerState.State defenseTargetState = defenseTarget.m_StateMachine.m_curState.m_eState;
        switch (defenseTargetState)
        {
        case PlayerState.State.eBackToBack:
        case PlayerState.State.eBackToBackForward:
        case PlayerState.State.eBackCompete:
            /*
             *      if (defenseTarget.m_StateMachine.m_curState is PlayerState_BackToBackForward)
             *      {
             *              DefenseBackMoving();
             *              defenderWasMoving = true;
             *      }
             *      else
             *      {
             *              DefenseBackToBack();
             *              toDefenseMoving = false;
             *      }
             */
            DefenseBackMoving();
            defenderWasMoving = true;
            break;

        case PlayerState.State.eBackToStand:
            DefenseBackToStand();
            break;

        case PlayerState.State.eBackTurnRun:
            DefenseBackCrossing();
            break;

        default:
            m_system.SetTransaction(AIState.Type.eDefense);
            break;
        }

        if (defenseTargetState != PlayerState.State.eBackToBackForward)
        {
            defenderWasMoving = false;
            toDefenseMoving   = false;
        }
        if (defenseTargetState != PlayerState.State.eBackTurnRun)
        {
            toBlockCrossing   = false;
            toDefenseCrossing = false;
        }
    }
Esempio n. 13
0
    public void Update(IM.Number deltaTime)
    {
        if (!enabled)
        {
            return;
        }
        //should be a parallel state, but not now
        GameMatch   match = GameSystem.Instance.mClient.mCurMatch;
        UBasketball ball  = match.mCurScene.mBall;

        if (ball == null || ball.m_actor == null)
        {
            return;
        }
        Player passer = ball.m_actor;

        PlayerState.State curState = passer.m_StateMachine.m_curState.m_eState;
        if (!_player.m_bToCatch || curState == PlayerState.State.eCatch)
        {
            return;
        }

        //进入一定距离范围内后,才开始计算何时开始进入Catch状态播动画
        IM.Number fDistance = GameUtils.HorizonalDistance(ball.position, _player.position);
        if (fDistance > _detectorSize)
        {
            return;
        }

        if (IM.Number.Approximately(_targetAnimTime, IM.Number.zero))
        {
            if (curState == PlayerState.State.eStand)
            {
                _targetAnimTime = _CalcAnimBeginTime("standCatchBallLRChest", ball);
            }
            else if (curState == PlayerState.State.eRun)
            {
                _targetAnimTime = _CalcAnimBeginTime("runCatchBallRHead", ball);
            }
        }

        if (_timeCnt > _targetAnimTime)
        {
            _player.m_StateMachine.SetState(PlayerState.State.eCatch);
            _timeCnt = IM.Number.zero;
        }
        else
        {
            _timeCnt += deltaTime;
        }
    }
    static int SetState(IntPtr L)
    {
        int count = LuaDLL.lua_gettop(L);

        if (count == 2 && LuaScriptMgr.CheckTypes(L, 1, typeof(PlayerStateMachine), typeof(PlayerState.State)))
        {
            PlayerStateMachine obj  = (PlayerStateMachine)LuaScriptMgr.GetNetObjectSelf(L, 1, "PlayerStateMachine");
            PlayerState.State  arg0 = (PlayerState.State)LuaScriptMgr.GetLuaObject(L, 2);
            bool o = obj.SetState(arg0);
            LuaScriptMgr.Push(L, o);
            return(1);
        }
        else if (count == 2 && LuaScriptMgr.CheckTypes(L, 1, typeof(PlayerStateMachine), typeof(PlayerState)))
        {
            PlayerStateMachine obj  = (PlayerStateMachine)LuaScriptMgr.GetNetObjectSelf(L, 1, "PlayerStateMachine");
            PlayerState        arg0 = (PlayerState)LuaScriptMgr.GetLuaObject(L, 2);
            bool o = obj.SetState(arg0);
            LuaScriptMgr.Push(L, o);
            return(1);
        }
        else if (count == 3 && LuaScriptMgr.CheckTypes(L, 1, typeof(PlayerStateMachine), typeof(PlayerState), typeof(bool)))
        {
            PlayerStateMachine obj  = (PlayerStateMachine)LuaScriptMgr.GetNetObjectSelf(L, 1, "PlayerStateMachine");
            PlayerState        arg0 = (PlayerState)LuaScriptMgr.GetLuaObject(L, 2);
            bool arg1 = LuaDLL.lua_toboolean(L, 3);
            bool o    = obj.SetState(arg0, arg1);
            LuaScriptMgr.Push(L, o);
            return(1);
        }
        else if (count == 3 && LuaScriptMgr.CheckTypes(L, 1, typeof(PlayerStateMachine), typeof(PlayerState.State), typeof(bool)))
        {
            PlayerStateMachine obj  = (PlayerStateMachine)LuaScriptMgr.GetNetObjectSelf(L, 1, "PlayerStateMachine");
            PlayerState.State  arg0 = (PlayerState.State)LuaScriptMgr.GetLuaObject(L, 2);
            bool arg1 = LuaDLL.lua_toboolean(L, 3);
            bool o    = obj.SetState(arg0, arg1);
            LuaScriptMgr.Push(L, o);
            return(1);
        }
        else
        {
            LuaDLL.luaL_error(L, "invalid arguments to method: PlayerStateMachine.SetState");
        }

        return(0);
    }
    public void OnStateChanged()
    {
        PlayerState.State newState = playerState.GetState();

        if (newState != currentState)
        {
            SetBoolAnimParam(animConfig.isIdleParam, false);
            SetBoolAnimParam(animConfig.isRunningParam, false);
            SetBoolAnimParam(animConfig.isJumpingParam, false);

            switch (newState)
            {
            case PlayerState.State.idle:
                SetBoolAnimParam(animConfig.isIdleParam, true);
                break;

            case PlayerState.State.moving:
                SetBoolAnimParam(animConfig.isRunningParam, true);
                break;

            case PlayerState.State.jumping:
                SetBoolAnimParam(animConfig.isJumpingParam, true);
                break;

            case PlayerState.State.falling:
                SetBoolAnimParam(animConfig.isJumpingParam, true);
                break;

            case PlayerState.State.stunned:
                playerAnimator.SetTrigger(animConfig.doStunParam);
                break;

            case PlayerState.State.frozen:
                playerAttackAnimator.SetBool(animConfig.didHit, true);
                break;

            default:
                break;
            }
            currentState = newState;
        }

        //playerAnimator.SetBool(animConfig.isIdleParam, newState == PlayerState.State.idle);
    }
Esempio n. 16
0
    public bool CanIntercept(SkillInstance intercept, Player passer, Player catcher, out IM.Vector3 ballPosWhenIntercepted)
    {
        ballPosWhenIntercepted = IM.Vector3.zero;

        PlayerState.State curState = m_player.m_StateMachine.m_curState.m_eState;
        if (curState != State.eRun && curState != State.eStand && curState != State.eDefense && curState != State.eRush)
        {
            return(false);
        }

        IM.Vector3 dirPasserToCatcher = GameUtils.HorizonalNormalized(catcher.position, passer.position);
        IM.Vector3 dirOriginFace      = m_player.forward;

        m_player.forward = -dirPasserToCatcher;

        string action = _ParseAction(intercept.curAction.action_id, intercept.matchedKeyIdx);

        PlayerAnimAttribute.AnimAttr animAttr = m_player.m_animAttributes.GetAnimAttrById(Command.Interception, action);
        if (animAttr == null)
        {
            Debug.LogError("Can not find animAttr: " + m_curAction);
        }

        PlayerAnimAttribute.KeyFrame keyFrame = animAttr.GetKeyFrame("OnBlock");
        IM.Number frameRate          = m_player.animMgr.GetFrameRate(action);
        IM.Number fEventTime         = keyFrame.frame / frameRate;
        IM.Number fBallFlyDistance   = passer.m_speedPassBall * fEventTime;
        IM.Number fDistPlayer2Passer = GameUtils.HorizonalDistance(passer.position, m_player.position);
        if (fDistPlayer2Passer < fBallFlyDistance)
        {
            m_player.forward = dirOriginFace;
            return(false);
        }

        if (!m_player.GetNodePosition(SampleNode.Ball, action, fEventTime, out ballPosWhenIntercepted))
        {
            m_player.forward = dirOriginFace;
            return(false);
        }

        m_player.forward = dirOriginFace;
        return(true);
    }
 private void OnPlayerStateChanged(PlayerState oldState, PlayerState newState)
 {
     ValidateCondition(PractiseStepCondition.EnterState, (param) =>
     {
         int index = (int)(param[0]);
         if (newState.m_player != GetPlayer(index))
         {
             return(false);
         }
         PlayerState.State state = (PlayerState.State)(param[1]);
         return(state == newState.m_eState);
     });
     if (newState.m_eState == PlayerState.State.eHold && newState.m_player.m_bMovedWithBall)
     {
         ValidateCondition(PractiseStepCondition.DoubleDribble, (param) =>
         {
             int index = (int)(param[0]);
             return(newState.m_player == GetPlayer(index));
         });
     }
 }
    public override void GameUpdate(IM.Number deltaTime)
    {
        base.GameUpdate(deltaTime);

        if (match.mainRole.m_StateMachine.m_curState.m_eState == PlayerState.State.eRebound)
        {
            if (curr_state != PlayerState.State.eRebound)
            {
                player_rebounding = true;
            }
        }
        else
        {
            if (player_rebounding)
            {
                OnPlayerReboundOver();
            }
            player_rebounding = false;
        }

        curr_state = match.mainRole.m_StateMachine.m_curState.m_eState;

        if (step == Step.Shoot && match.mCurScene.mBall.m_ballState == BallState.eRebound)
        {
            Vector3 velocity = (Vector3)match.mCurScene.mBall.curVel;
            if (velocity.y < 0f && InReboundRange())
            {
                Tip1();
            }
        }

        match.HighlightButton(0, in_tutorial && IsCommandValid(Command.Rebound));

        //if (Input.GetKey(KeyCode.R))
        //{
        //	OnStart();
        //	Shoot();
        //	Pause(false);
        //}
    }
Esempio n. 19
0
    public void Freeze(float frozenTime)
    {
        if (state.GetState() != PlayerState.State.frozen)
        {
            state.frozenTime = Time.time + frozenTime;
            recoverState     = state.GetState();
            state.SetState(PlayerState.State.frozen);
            state.velocityHold     = rigidBody.velocity;
            rigidBody.velocity     = Vector2.zero;
            state.gravityScaleHold = rigidBody.gravityScale;
            rigidBody.gravityScale = 0;
            // Need to increase timers by the freeze time
            // so they continue as if nothing happened
            startJumpTime          += frozenTime;
            state.invulnerableTime += frozenTime;

            PlayerAttack pa = GetComponent <PlayerAttack>();
            if (pa != null)
            {
                pa.Freeze(frozenTime);
            }
        }
    }
Esempio n. 20
0
    void ReadRatio()
    {
        string text = ResourceLoadManager.Instance.GetConfigText(name);

        if (text == null)
        {
            UnityEngine.Debug.LogError("LoadConfig failed: " + name);
            return;
        }

        XmlDocument doc  = CommonFunction.LoadXmlConfig(GlobalConst.DIR_XML_STEAL_STATE_RATIO, text);
        XmlNode     root = doc.SelectSingleNode("Data");

        foreach (XmlNode line in root.SelectNodes("Line"))
        {
            if (CommonFunction.IsCommented(line))
            {
                continue;
            }
            PlayerState.State state = (PlayerState.State)(int.Parse(line.SelectSingleNode("state").InnerText));
            IM.Number         ratio = IM.Number.Parse(line.SelectSingleNode("ratio").InnerText);
            ratios.Add(state, ratio);
        }
    }
Esempio n. 21
0
    public void Update()
    {
        if (m_timerHideName != null)
        {
            m_timerHideName.Update(Time.deltaTime);
        }

        if (m_owner == null || m_goPlayerInfo == null)
        {
            return;
        }

        PlayerState.State playerState = m_owner.m_StateMachine.m_curState.m_eState;
        if (m_owner.m_bWithBall && m_uiState != null)
        {
            //m_uiState.gameObject.SetActive(true);
            //m_uiState.spriteName = "Ball";
        }
        else if (playerState == PlayerState.State.eStolen ||
                 playerState == PlayerState.State.eCrossed)
        {
            m_uiState.gameObject.SetActive(true);
            m_uiState.spriteName = "Exclam";
        }
        else
        {
            m_uiState.gameObject.SetActive(false);
            m_uiState.spriteName = "None";
        }

        if (!m_bWithBall && m_owner.m_bWithBall)                // Player get ball
        {
            // Show
            m_uiPosition.transform.localPosition = m_oriPositionPos;
            NGUITools.SetActive(m_uiName.gameObject, true);
            m_uiName.alpha         = 1f;
            m_nameFadeAway.enabled = false;
            // Begin countdown
            m_timerHideName.Reset();
            m_timerHideName.stop = false;
        }
        else if (m_bWithBall && !m_owner.m_bWithBall)           // Player lose ball
        {
            // Fade away instantly
            m_timerHideName.stop = true;
            OnTimerHideName();
        }

        m_bWithBall = m_owner.m_bWithBall;

        UIManager uiMgr = GameSystem.Instance.mClient.mUIManager;

        if (uiMgr == null || uiMgr.m_uiCamera == null)
        {
            return;
        }

        GameMatch curMatch = GameSystem.Instance.mClient.mCurMatch;

        if (curMatch != null && curMatch.m_uiInGamePanel != null)
        {
            {
                m_goPlayerInfo.transform.parent        = curMatch.m_uiInGamePanel.transform;
                m_goPlayerInfo.transform.localPosition = Vector3.zero;
                m_goPlayerInfo.transform.localScale    = Vector3.one;
            }

            {
                m_goState.transform.parent        = curMatch.m_uiInGamePanel.transform;
                m_goState.transform.localPosition = Vector3.zero;
                m_goState.transform.localScale    = Vector3.one;
            }
        }

        Vector3 viewPos     = Camera.main.WorldToViewportPoint(m_owner.transform.position);
        Vector3 viewHeadPos = Camera.main.WorldToViewportPoint(m_owner.model.head.position);

        Vector3 worldPos = uiMgr.m_uiCamera.GetComponent <Camera>().ViewportToWorldPoint(viewPos);
        Vector3 posHead  = Vector3.zero;

        Vector3 worldHeadPos = uiMgr.m_uiCamera.GetComponent <Camera>().ViewportToWorldPoint(viewHeadPos);

        m_goPlayerInfo.transform.position = worldHeadPos;
        posHead = m_goPlayerInfo.transform.localPosition;

        m_goPlayerInfo.transform.position = worldPos;
        Vector3 pos = m_goPlayerInfo.transform.localPosition;

        pos.x = Mathf.FloorToInt(pos.x);
        pos.y = Mathf.FloorToInt(pos.y);
        pos.z = 0.0f;
        m_goPlayerInfo.transform.localPosition = pos;

        m_YState = (posHead.y - pos.y) + 50.0f;

        m_goState.transform.position      = worldPos;
        m_uiState.transform.localPosition = Vector3.up * m_YState;

        pos   = m_goState.transform.localPosition;
        pos.x = Mathf.FloorToInt(pos.x);
        pos.y = Mathf.FloorToInt(pos.y);
        pos.z = 2.0f;
        m_goState.transform.localPosition = pos;
    }
Esempio n. 22
0
    void _OnTriggerStay(Player player)
    {
        GameMatch match = GameSystem.Instance.mClient.mCurMatch;

        if (match == null)
        {
            return;
        }

        if (match.GetMatchType() != GameMatch.Type.eBullFight &&
            match.GetMatchType() != GameMatch.Type.eCareer3On3 &&
            match.GetMatchType() != GameMatch.Type.eAsynPVP3On3 &&
            match.GetMatchType() != GameMatch.Type.e3AIOn3AI &&
            match.GetMatchType() != GameMatch.Type.e3On3 &&
            match.GetMatchType() != GameMatch.Type.ePVP_3On3 &&
            match.GetMatchType() != GameMatch.Type.ePVP_1PLUS &&
            match.GetMatchType() != GameMatch.Type.eUltimate21 &&
            match.GetMatchType() != GameMatch.Type.eGrabZone &&
            match.GetMatchType() != GameMatch.Type.ePractise)
        {
            return;
        }
        //if( match.m_mainRole != m_Owner && !m_Owner.m_bIsAI )
        //    return;

        if (m_Owner.m_StateMachine.m_curState.m_eState == PlayerState.State.eFallLostBall ||
            m_Owner.m_StateMachine.m_curState.m_eState == PlayerState.State.eKnocked)
        {
            return;
        }

        if (m_Owner.m_aiMgr != null && m_Owner.m_aiMgr.m_curState != null)
        {
            m_Owner.m_aiMgr.m_curState.OnPlayerCollided(player);
        }

        if (match.GetMatchType() == GameMatch.Type.eGrabZone ||
            match.GetMatchType() == GameMatch.Type.ePractise)
        {
            return;
        }

        bool isStayed = false;

        isColliderStayed.TryGetValue(player, out isStayed);
        if (isStayed)
        {
            return;
        }
        isColliderStayed[player] = true;

        PlayerState.State curPlayerState        = m_Owner.m_StateMachine.m_curState.m_eState;
        PlayerState.State curCollidePlayerState = player.m_StateMachine.m_curState.m_eState;
        IM.Vector3        dirPlayerToCollide    = GameUtils.HorizonalNormalized(m_Owner.position, player.position);
        IM.Number         fAngle = IM.Vector3.Angle(m_Owner.forward, dirPlayerToCollide);
        if (fAngle < new IM.Number(60) &&
            m_Owner.m_team.m_side != player.m_team.m_side
            )
        {
            if (
                curPlayerState == PlayerState.State.eBackTurnRun ||
                curPlayerState == PlayerState.State.eCutIn ||
                curPlayerState == PlayerState.State.eRush)
            {
                //突破/空切倒地几率=0.2+(防守者身体强度-突破者身体强度)*0.0004
                Dictionary <string, uint> playerData    = m_Owner.m_finalAttrs;
                Dictionary <string, uint> colPlayerData = player.m_finalAttrs;
                if (playerData == null || colPlayerData == null)
                {
                    Debug.LogError("Can not build player: " + m_Owner.m_name + " ,can not fight state by id: " + m_Owner.m_id);
                    Debug.LogError("Can not build player: " + player.m_name + " ,can not fight state by id: " + player.m_id);
                    return;
                }

                GameMatch curMatch = GameSystem.Instance.mClient.mCurMatch;
                uint      strength = 0;
                player.m_skillSystem.HegdingToValue("addn_strength", ref strength);
                IM.Number colPlayerStrength = (colPlayerData["strength"] + strength) * curMatch.GetAttrReduceScale("strength", player);

                m_Owner.m_skillSystem.HegdingToValue("addn_strength", ref strength);
                IM.Number playerStrength = (playerData["strength"] + strength) * curMatch.GetAttrReduceScale("strength", m_Owner);
                IM.Number fRate          = hedging.Calc(playerStrength, colPlayerStrength);
                fRate = IM.Number.one - fRate;

                IM.Number fRandom = IM.Random.value;
                if (curPlayerState == PlayerState.State.eBackTurnRun)
                {
                    IM.Number uRate    = fRate;
                    bool      sumValue = random.AdjustRate(ref uRate);
                    m_Owner.m_StateMachine.SetState(fRandom < fRate ? PlayerState.State.eFallLostBall : PlayerState.State.eKnocked);
                    if (fRandom < fRate && sumValue)
                    {
                        random.SumValue();
                    }
                }
                else if (curPlayerState == PlayerState.State.eCutIn)
                {
                    fRate *= IM.Number.half;
                    m_Owner.m_StateMachine.SetState(fRandom < fRate ? PlayerState.State.eFallGround : PlayerState.State.eKnocked);
                }
                else if (curPlayerState == PlayerState.State.eRush)
                {
                    fRate *= new IM.Number(0, 300);
                    //防守者不被撞,无人持球时不被撞
                    if (match.mCurScene.mBall.m_owner != null && m_Owner.m_team.m_role == GameMatch.MatchRole.eOffense)
                    {
                        if (fRandom < fRate)
                        {
                            m_Owner.m_StateMachine.SetState(m_Owner.m_bWithBall ? PlayerState.State.eFallLostBall : PlayerState.State.eFallGround);
                        }
                        else
                        {
                            m_Owner.m_StateMachine.SetState(PlayerState.State.eKnocked);
                        }
                    }
                }

                //Debugger.Instance.m_steamer.message = "Player: " + m_Owner.m_name + " strength: " + playerData["strength"];
                //Debugger.Instance.m_steamer.message += " Collided Player: " + colPlayer.m_Owner.m_name + " strength: " + colPlayerData["strength"];
                //Debugger.Instance.m_steamer.message += " Collide fall down rate: " + fRate + " Random: " + fRandom;
            }
        }
    }
Esempio n. 23
0
 public PlayerState GetState(PlayerState.State state)
 {
     return(stateDictionary[state]);
 }
Esempio n. 24
0
    bool _StealBall(out bool bVaild)
    {
        bVaild = false;

        if (m_ball.m_owner == null)
        {
            return(false);
        }
        stealTarget = m_ball.m_owner;
        if (!stealTarget.m_bOnGround)
        {
            return(false);
        }
        PlayerState.State ps = stealTarget.m_StateMachine.m_curState.m_eState;
        ratio = GameSystem.Instance.StealConfig.GetRatio(ps);
        if (ratio == IM.Number.zero)
        {
            Debug.Log("Steal failed, state: " + ps);
            return(false);
        }

        if (m_ball.m_ballState != BallState.eUseBall)
        {
            return(false);
        }
        Dictionary <string, uint> targetData = stealTarget.m_finalAttrs;
        Dictionary <string, uint> playerData = m_player.m_finalAttrs;

        //if (m_ball.m_owner == stealTarget)
        //{
        //    //ÔÚÉÈÐÎÇøÓòÄÚÀ­½üµ½³ÖÇòÕßÉíÇ°
        //    AOD.Zone zone = stealTarget.m_AOD.GetStateByPos(m_player.position);
        //    if (zone != AOD.Zone.eInvalid)
        //    {
        //        //Vector3 newPos = new Vector3(stealTarget.position.x,stealTarget.position.y,stealTarget.position.z);
        //        //Vector3 newPos;
        //        //newPos.x = stealTarget.position.x + 1.5f * stealTarget.forward.normalized.x;
        //        //newPos.y = stealTarget.position.y + 1.5f * stealTarget.forward.normalized.y;
        //        //newPos.z = stealTarget.position.z + 1.5f * stealTarget.forward.normalized.z;
        //        //m_player.position = newPos;
        //        m_player.m_moveHelper.MoveTo(stealTarget.position);
        //    }
        //}

        if (!InStealPosition(m_player, m_ball))
        {
            Debug.Log("Steal failed.");
            return(false);
        }

        uint stealValue = 0;

        m_player.m_skillSystem.HegdingToValue("addn_steal", ref stealValue);

        uint control = 0;

        stealTarget.m_skillSystem.HegdingToValue("addn_control", ref control);

        IM.Number antiStealRate   = (targetData["control"] + control) * m_match.GetAttrReduceScale("control", stealTarget);
        IM.Number playerStealRate = (playerData["steal"] + stealValue) * m_match.GetAttrReduceScale("steal", m_player);
        IM.Number stealRate       = hedging.Calc(playerStealRate, antiStealRate);

        SkillSpec skillSpec = m_player.GetSkillSpecialAttribute(SkillSpecParam.eSteal_rate);

        if (skillSpec.paramOp == SkillSpecParamOp.eAdd)
        {
            stealRate += skillSpec.value;
        }
        else if (skillSpec.paramOp == SkillSpecParamOp.eMulti)
        {
            stealRate *= skillSpec.value;
        }
        stealRate = stealRate * ratio;
        bool sumValue = random[stealTarget].AdjustRate(ref stealRate);

        Debugger.Instance.m_steamer.message = " Steal ball: stealRate: " + stealRate;

        IM.Number fRandomValue = IM.Random.value;
        Debugger.Instance.m_steamer.message += " Random value: " + fRandomValue;

        bVaild = true;
        if (fRandomValue > stealRate)
        {
            Debugger.Instance.m_steamer.message += "steal failed.";
            return(false);
        }

        if (sumValue)
        {
            random[stealTarget].SumValue();
        }
        Debugger.Instance.m_steamer.message += ", steal success.";

        return(true);
    }
Esempio n. 25
0
 void InitialiseState(PlayerState.State stateEnum, PlayerState state)
 {
     state.Initialize(playerRef, playerData);
     stateDictionary.Add(stateEnum, state);
 }
 public bool SetState(PlayerState.State eNewState, bool bForceChange)
 {
     return(SetState(m_arStateList[(int)eNewState], bForceChange));
 }
 public bool SetState(PlayerState.State eNewState)
 {
     return(SetState(m_arStateList[(int)eNewState], false));
 }
Esempio n. 28
0
    public void Update(float deltaTime)
    {
        Player defenseTarget = match.mainRole.m_defenseTarget;

        if (defenseTarget != null && defenseTarget.m_bWithBall &&
            defenseTarget.m_AOD.GetStateByPos(match.mainRole.position) == AOD.Zone.eInvalid)
        {
            if (!revisingDefense)
            {
                ShowTip(CommonFunction.GetConstString("MATCH_GUIDE_ReviseDefense"));
                revisingDefense = true;
            }
        }
        else
        {
            revisingDefense = false;
        }

        PlayerState curState = match.mainRole.m_StateMachine.m_curState;

        if (lastMainRoleState != PlayerState.State.eRebound && curState.m_eState == PlayerState.State.eRebound)
        {
            IM.Number curDist = GameUtils.HorizonalDistance(match.mainRole.position, match.mCurScene.mBall.position);
            if (curDist > match.mainRole.m_fReboundDist)
            {
                ShowTip(CommonFunction.GetConstString("MATCH_GUIDE_ReviseDistance"));
            }
            else if (!(curState as PlayerState_Rebound).m_success)
            {
                ShowTip(CommonFunction.GetConstString("MATCH_GUIDE_ReviseRebound"));
            }
        }
        else if (lastMainRoleState != PlayerState.State.eSteal && curState.m_eState == PlayerState.State.eSteal)
        {
            if (defenseTarget.m_AOD.GetStateByPos(match.mainRole.position) == AOD.Zone.eInvalid)
            {
                ShowTip(CommonFunction.GetConstString("MATCH_GUIDE_ReviseDistance"));
            }
        }
        else if (lastMainRoleState != PlayerState.State.eBlock && curState.m_eState == PlayerState.State.eBlock)
        {
            IM.Number curDist = GameUtils.HorizonalDistance(match.mainRole.position, match.mCurScene.mBall.position);
            if (curDist < IM.Number.one || curDist > new IM.Number(5))
            {
                ShowTip(CommonFunction.GetConstString("MATCH_GUIDE_ReviseDistance"));
            }
            else if (!match.mainRole.m_defenseTarget.m_blockable.blockable)
            {
                ShowTip(CommonFunction.GetConstString("MATCH_GUIDE_ReviseBlockTimming"));
            }
        }
        else if (lastMainRoleState != PlayerState.State.eBodyThrowCatch && curState.m_eState == PlayerState.State.eBodyThrowCatch)
        {
            IM.Number maxDist = PlayerState_BodyThrowCatch.GetMaxDistance(match.mainRole);
            IM.Number curDist = GameUtils.HorizonalDistance(match.mainRole.position, match.mCurScene.mBall.position);
            if (curDist > maxDist)
            {
                ShowTip(CommonFunction.GetConstString("MATCH_GUIDE_ReviseDistance"));
            }
        }

        lastMainRoleState = curState.m_eState;
    }
Esempio n. 29
0
 protected override void OnTick()
 {
     //持球进攻
     if (m_player.m_bWithBall)
     {
         PlayerState.State state = m_player.m_StateMachine.m_curState.m_eState;
         if (m_match.m_ruler.m_bToCheckBall)                 //带出三分线
         {
             if (state == PlayerState.State.eStand ||
                 state == PlayerState.State.eRun ||
                 state == PlayerState.State.eRush ||
                 state == PlayerState.State.eHold)
             {
                 bool inTakeOver = false;
                 if (m_player.m_inputDispatcher != null)
                 {
                     inTakeOver = m_player.m_inputDispatcher.inTakeOver;
                 }
                 if (!inTakeOver)
                 {
                     Player passTarget = AIUtils.ChoosePassTargetCheckBall(m_player, m_match);
                     if (passTarget != null)
                     {
                         AI_Pass pass = m_system.GetState(Type.ePass) as AI_Pass;
                         pass.m_toPass = passTarget;
                         m_system.SetTransaction(pass);
                     }
                     else
                     {
                         m_system.SetTransaction(AIState.Type.eCheckBall);
                     }
                 }
                 else
                 {
                     m_system.SetTransaction(AIState.Type.eCheckBall);
                 }
             }
         }
         else
         {
             if (state == PlayerState.State.eStand ||
                 state == PlayerState.State.eRun ||
                 state == PlayerState.State.eRush)
             {
                 Offense();
             }
             else if (state == PlayerState.State.eHold)
             {
                 if ((m_match.mCurScene.mGround.GetArea(m_player) == Area.eNear ||
                      !m_player.IsDefended(m_system.AI.devAngleAttacker, m_system.AI.devDistAOD)) &&
                     arriveFirstTarget)
                 {
                     Offense();
                 }
                 else
                 {
                     m_system.SetTransaction(AIState.Type.eIdle);
                 }
             }
         }
     }
     else            //非持球进攻
     {
         //空切
         if (arriveFirstTarget && m_ball.m_owner != null && IM.Random.value < new IM.Number(0, 250) &&
             m_player.IsDefended(m_system.AI.devAngleAttacker, m_system.AI.devDistAOD))
         {
             //if( !(m_match is GameMatch_PVP) )
             m_system.SetTransaction(AIState.Type.eCutIn);
         }
         //要球
         else if (m_ball.m_owner != null && m_ball.m_owner.m_team == m_player.m_team && m_system.m_bNotDefended && !m_match.m_ruler.m_bToCheckBall)
         {
             //if( !(m_match is GameMatch_PVP) )
             m_system.SetTransaction(AIState.Type.eRequireBall);
         }
         //靠近球6米,追球
         else if (AIUtils.ShouldTraceBall(m_ball, m_player))
         {
             m_system.SetTransaction(AIState.Type.eIdle);
         }
         //挡拆
         else
         {
             int result = AIUtils.CanPickAndRoll(m_player);
             if (result == 1 && m_player.m_StateMachine.m_curState.IsCommandValid(Command.PickAndRoll))
             {
                 m_system.SetTransaction(AIState.Type.ePickAndRoll);
             }
             else if (result == 2)
             {
                 positionForPR = true;
                 m_system.SetTransaction(AIState.Type.ePositioning, new IM.Number(100), true);
             }
         }
     }
 }
Esempio n. 30
0
    public override void _Process(float delta)
    {
        if (!playerInputActive)
        {
            return;
        }

        if (lastState != PlayerState.GetState() || lastSelectedUsable != Player.UsableSelected)
        {
            World.UIBlockTilemap.Clear();
            lastSelectedUsable = Player.UsableSelected;
            lastState          = PlayerState.GetState();
        }

        mousePos = Convertion.Location2WorldFloor(GetGlobalMousePosition());

        //Affichage
        if (PlayerState.GetState() == PlayerState.State.Normal)
        {
            NormalState();
        }
        else if (PlayerState.GetState() == PlayerState.State.Build)
        {
            BuildState();
        }


        /* Inventory Click */
        if (Input.IsActionJustPressed("inventory"))
        {
            InventoryClick();
        }

        /*Escape*/
        if (Input.IsActionJustPressed("escape"))
        {
            if (PlayerState.GetState() == PlayerState.State.Pause)
            {
                PlayerState.SetState(PlayerState.prec_state);
                PauseMenu.Close();
            }
            else if (PlayerState.GetState() == PlayerState.State.Normal)
            {
                PlayerState.SetState(PlayerState.State.Pause);
                PauseMenu.Open();
            }
            else if (PlayerState.GetState() == PlayerState.State.Inventory)
            {
                UI_PlayerInventory2.Close();
            }
            else if (PlayerState.GetState() == PlayerState.State.Build)
            {
                PlayerState.SetState(PlayerState.State.Normal);
            }
            else if (PlayerState.GetState() == PlayerState.State.BuildingInterface)
            {
                BuildingInterface.CloseInterface();
            }
            else if (PlayerState.GetState() == PlayerState.State.Link)
            {
                Link._Link();
                Link.Reset();
                PlayerState.SetState(PlayerState.State.Normal);
            }
        }

        //Inputs
        if (Input.IsActionJustPressed("mouse1"))
        {
            if (PlayerState.GetState() == PlayerState.State.Normal)
            {
                ClickNormalState();
            }
            else if (PlayerState.GetState() == PlayerState.State.Build)
            {
                ClickBuildState();
            }
            if (PlayerState.GetState() == PlayerState.State.Normal || PlayerState.GetState() == PlayerState.State.Build || PlayerState.GetState() == PlayerState.State.BuildingInterface)
            {
                if (Building.HasBuildingSelected)
                {
                    ClickOnBuilding();
                }

                if (SpaceShip.ShipSelected)
                {
                    SpaceShipClick();
                }
            }
            if (PlayerState.GetState() == PlayerState.State.Link)
            {
                if (Building.HasBuildingSelected)
                {
                    ClickOnBuilding2Link();
                }
            }
        }
    }