Ejemplo n.º 1
0
 static public void RegisterState(ELifeState state, Type type)
 {
     if (null == m_StateFactory)
     {
         m_StateFactory = new Dictionary<ELifeState, Type>();
     }
     m_StateFactory.Add(state, type);
 }
Ejemplo n.º 2
0
 static public void RegisterState(ELifeState state, Type type)
 {
     if (null == m_StateFactory)
     {
         m_StateFactory = new Dictionary <ELifeState, Type>();
     }
     m_StateFactory.Add(state, type);
 }
Ejemplo n.º 3
0
    private void OnTriggerChangeState(MessageObject obj)
    {
        if (!(obj.msgValue is ELifeState))
        {
            return;
        }
        ELifeState newState = (ELifeState)(obj.msgValue);

        TryEnterState(newState, false);
    }
Ejemplo n.º 4
0
 void SetLifeState()
 {
     if (isAlive)
     {
         LifeState = ELifeState.ALIVE;
     }
     else
     {
         LifeState = ELifeState.DEAD;
     }
 }
Ejemplo n.º 5
0
 void SetLifeState()
 {
     if (m_AIHealth.m_IsAlive)
     {
         LifeState = ELifeState.ALIVE;
     }
     else
     {
         LifeState = ELifeState.DEAD;
     }
 }
Ejemplo n.º 6
0
    private static IState CreateStateInstance(ELifeState stateId, Ilife unit)
    {
        if (null == m_StateFactory)
        {
            StateDefine.RegisterState();
        }
        IState result = null;
        Type   type   = null;

        if (m_StateFactory.TryGetValue(stateId, out type))
        {
            result = Activator.CreateInstance(type, unit, stateId) as IState;
        }
        return(result);
    }
Ejemplo n.º 7
0
    private IState StateFactory(ELifeState stateId)
    {
        IState result = null;

        if (null != m_StateUsingStore && m_StateUsingStore.TryGetValue(stateId, out result))
        {
            return(result);
        }
        result = CreateStateInstance(stateId, m_lifeInstance);
        if (null == m_StateUsingStore)
        {
            m_StateUsingStore = new Dictionary <ELifeState, IState>();
        }
        m_StateUsingStore.Add(stateId, result);

        return(result);
    }
Ejemplo n.º 8
0
    public List <StateConflictConfigElement> GetStateConflicList(int uid, ELifeState state)
    {
        //get table
        StateConflictTable config =
            TryGetConfig <StateConflictTable>(ConfigPath_StateConflictConfig);

        if (null != config)
        {
            //match uid to sate conflict table
            StateConflictConfig res = null;
            if (config.StateConflictConfigMap.TryGetValue(uid, out res))
            {
                //get state
                List <StateConflictConfigElement> result = null;
                if (res.StateConflictMap.TryGetValue((int)(state), out result))
                {
                    return(result);
                }
            }
        }
        return(null);
    }
Ejemplo n.º 9
0
 public IState(Ilife unit, ELifeState state)
 {
     this.unit  = unit;
     this.state = state;
 }
Ejemplo n.º 10
0
    public bool TryEnterState(ELifeState newStateID, bool force,object param = null)
    {
        if (null != m_CurrentState && m_CurrentState.GetState() == newStateID)
        {
            //do nothing
            return true;
        }
        IState newState = StateFactory(newStateID);
        if (null == newState)
        {
            return false;
        }

        if (null == m_CurrentState)
        {
            if (!newState.CanEnter())
            {
                return false;
            }
            //reset state
            m_CurrentState = newState;
            m_CurrentState.DoEnter(param);
            return true;
        }
        if (!force )
        {
            List<StateConflictConfigElement> stateClash = null;
            /*if (m_CurrentCharStateConflictMap.StateConflictMap.TryGetValue((int)(m_CurrentState.GetState()), out stateClash))
            {
                foreach (StateConflictConfigElement s in stateClash)
                {
                    //与当前状态冲突
                    if (s.StateId == (int)newStateID)
                    {
                        if (s.IsConflict)
                        {
                            Debuger.LogWarning(string.Format("current state:{0} can't enter new state:{1}",
                                m_CurrentState.GetState(), newStateID));
                            return false;
                        }
                        else
                        {
                            break;
                        }
                    }
                }
            }*/

            if (!m_CurrentState.CanExit())
            {
                return false;
            }

            if (!newState.CanEnter())
            {
                return false;
            }
        }

        m_CurrentState.DoExit();

        //reset state
        m_CurrentState = newState;
        m_CurrentState.DoEnter(param);
        return true;
    }
Ejemplo n.º 11
0
 private static IState CreateStateInstance(ELifeState stateId, Ilife unit)
 {
     if (null == m_StateFactory)
     {
         StateDefine.RegisterState();
     }
     IState result = null;
     Type type = null;
     if (m_StateFactory.TryGetValue(stateId, out type))
     {
         result = Activator.CreateInstance(type, unit,stateId) as IState;
     }
     return result;
 }
Ejemplo n.º 12
0
 private IState StateFactory(ELifeState stateId)
 {
     IState result = null;
     if (null != m_StateUsingStore && m_StateUsingStore.TryGetValue(stateId, out result))
     {
         return result;
     }
     result = CreateStateInstance(stateId, m_lifeInstance);
     if (null == m_StateUsingStore)
     {
         m_StateUsingStore = new Dictionary<ELifeState, IState>();
     }
     m_StateUsingStore.Add(stateId, result);
     
     return result;
 }
Ejemplo n.º 13
0
    public IState(Ilife unit,ELifeState state)
	{
		this.unit = unit;
        this.state = state;
	}
Ejemplo n.º 14
0
 public StateRun(Ilife unit, ELifeState state)
     : base(unit, state)
 {
 }
Ejemplo n.º 15
0
    public bool TryEnterState(ELifeState newStateID, bool force, object param = null)
    {
        if (null != m_CurrentState && m_CurrentState.GetState() == newStateID)
        {
            //do nothing
            return(true);
        }
        IState newState = StateFactory(newStateID);

        if (null == newState)
        {
            return(false);
        }

        if (null == m_CurrentState)
        {
            if (!newState.CanEnter())
            {
                return(false);
            }
            //reset state
            m_CurrentState = newState;
            m_CurrentState.DoEnter(param);
            return(true);
        }
        if (!force)
        {
            List <StateConflictConfigElement> stateClash = null;

            /*if (m_CurrentCharStateConflictMap.StateConflictMap.TryGetValue((int)(m_CurrentState.GetState()), out stateClash))
             * {
             *  foreach (StateConflictConfigElement s in stateClash)
             *  {
             *      //与当前状态冲突
             *      if (s.StateId == (int)newStateID)
             *      {
             *          if (s.IsConflict)
             *          {
             *              Debuger.LogWarning(string.Format("current state:{0} can't enter new state:{1}",
             *                  m_CurrentState.GetState(), newStateID));
             *              return false;
             *          }
             *          else
             *          {
             *              break;
             *          }
             *      }
             *  }
             * }*/

            if (!m_CurrentState.CanExit())
            {
                return(false);
            }

            if (!newState.CanEnter())
            {
                return(false);
            }
        }

        m_CurrentState.DoExit();

        //reset state
        m_CurrentState = newState;
        m_CurrentState.DoEnter(param);
        return(true);
    }
Ejemplo n.º 16
0
 public StateMove(Ilife unit, ELifeState state)
     : base(unit, state)
 {
 }
Ejemplo n.º 17
0
 public StateIdle(Ilife unit, ELifeState state) : base(unit, state)
 {
 }
Ejemplo n.º 18
0
 public StateRun(Ilife unit, ELifeState state)
     : base(unit, state)
 {
 }