Exemplo n.º 1
0
 public PlayerState()
 {
     mAllowSuperposition = SAME_STATE_OPERATE.SSO_COEXIST;
     mBuffStateType      = BUFF_STATE_TYPE.BST_NONE;
     mActive             = true;
     mStateTime          = -1.0f;
     mMutexID            = 0;
     mID = generateGUID();
 }
    protected bool canAddState(PlayerState state)
    {
        PlayerState existState = getFirstState(state.GetType());

        // 已经存在有一个同样的状态,并且该状态不允许叠加,则移除已经存在的状态
        if (existState != null)
        {
            SAME_STATE_OPERATE operate = existState.allowSuperposition();
            // 移除旧状态
            if (operate == SAME_STATE_OPERATE.SSO_REMOVE_OLD)
            {
                ;
            }
            // 不允许添加新状态
            else if (operate == SAME_STATE_OPERATE.SSO_CAN_NOT_ADD_NEW)
            {
                return(false);
            }
            // 相同的状态可以共存
            else if (operate == SAME_STATE_OPERATE.SSO_COEXIST)
            {
                ;
            }
            // 只保留优先级最高的状态
            else if (operate == SAME_STATE_OPERATE.SSO_USE_HIGH_PRIORITY)
            {
                // 移除优先级低的旧状态
                if (existState.getPriority() >= state.getPriority())
                {
                    return(false);
                }
            }
        }
        // 检查是否有跟要添加的状态互斥且不能移除的状态
        foreach (var itemList in mCurStateMap)
        {
            foreach (var item in itemList.Value)
            {
                if (item != state && item.isActive() && !allowAddStateByGroup(state, item))
                {
                    return(false);
                }
            }
        }
        // 检查自身限制条件
        if (!state.canEnter())
        {
            return(false);
        }
        return(true);
    }
    protected void removeMutexState(PlayerState state)
    {
        // 移除自身不可共存的状态
        PlayerState existState = getFirstState(state.GetType());

        if (existState != null)
        {
            SAME_STATE_OPERATE operate = existState.allowSuperposition();
            // 移除旧状态
            if (operate == SAME_STATE_OPERATE.SSO_REMOVE_OLD)
            {
                removeState(existState, true, null);
            }
            // 不允许添加新状态
            else if (operate == SAME_STATE_OPERATE.SSO_CAN_NOT_ADD_NEW)
            {
                ;
            }
            // 相同的状态可以共存
            else if (operate == SAME_STATE_OPERATE.SSO_COEXIST)
            {
                ;
            }
            // 只保留优先级最高的状态
            else if (operate == SAME_STATE_OPERATE.SSO_USE_HIGH_PRIORITY)
            {
                // 移除优先级低的旧状态
                if (existState.getPriority() < state.getPriority())
                {
                    removeState(existState, true, null);
                }
            }
        }
        // 移除状态组互斥的状态
        foreach (var itemList in mCurStateMap)
        {
            foreach (var item in itemList.Value)
            {
                if (item != state && item.isActive() && !allowKeepStateByGroup(state, item))
                {
                    removeState(item, true, null);
                }
            }
        }
    }