// Check event bool CheckEventCanRun( STAGE_EVENT evt ) { cTextArray sCond = new cTextArray( ); sCond.SetText( evt.s_CONDITION ); // check all line . if one line success . this event check return true int nCol = sCond.GetMaxCol(); for( int i= 0 ; i <nCol ; i++ ) { if( CheckEventCondition( sCond.GetTextLine( i ) ) ) { return true; } } return false; }
public bool IsLoopEvent( STAGE_EVENT evt ) { if (evt != null) { if ( (evt.n_TYPE & 1) > 0 ) // 1 is loop event { return true; } } return false; }
void GetEventToRun() { //if( IsRunningEvent() ) if( NextEvent != null ) // avoid double run return ; if( (EvtPool==null) ) return ; if( EvtPool.Count<=0) return ; List< int > removeLst = new List< int >(); // get next event to run foreach( KeyValuePair< int ,STAGE_EVENT > pair in EvtPool ) { if( CheckEventCanRun( pair.Value ) == true ){ // check if this event need run //NextEvent = pair.Value ; // run in next loop WaitPool.Add( pair.Value ); // check is loop event? if( IsLoopEvent( pair.Value )== false ) { removeLst.Add( pair.Key ); } } } // remove key , never check it again foreach( int key in removeLst ) { if( EvtPool.ContainsKey( key ) ) { EvtPool.Remove( key ); } } // prepare event to run if( WaitPool.Count > 0 ) { NextEvent = WaitPool[0]; WaitPool.RemoveAt( 0 ); PreEcecuteEvent(); // parser next event to run } // return (WaitPool.Count > 0 || NextEvent !=null); }
//==========Execute Event ================= // true : is running bool RunEvent( ) { // always check to wait list //GetEventToRun(); // get next event if( NextEvent == null ) { GetEventToRun(); // get next event to run } // if event is running //run event if( NextEvent != null ) { NextLine(); // execute one line //NextLine(); // parser event to run if( IsNextEventCompleted() ) { // record event comp //EvtCompletePool.Add( NextEvent.n_ID , GameDataManager.Instance.nRound ); if( GameDataManager.Instance.EvtDonePool.ContainsKey( NextEvent.n_ID ) ) { GameDataManager.Instance.EvtDonePool[ NextEvent.n_ID ] = GameDataManager.Instance.nRound; // update newest complete round } else{ GameDataManager.Instance.EvtDonePool.Add( NextEvent.n_ID , GameDataManager.Instance.nRound ); } // clear event for next NextEvent = null; IsEventEnd = true; // all end . check again for new condition status // if( WaitPool.Count <= 0 ){ if( IsRunningEvent() == false ) { GetEventToRun(); } // } } } // switch status // GameDataManager.Instance.nRound = 0; // GameDataManager.Instance.nActiveFaction = 0; return ( IsRunningEvent() ); }