Ejemplo n.º 1
0
Core::Core()
  : mGameRunning( false ),
    mGameMode( MODE_UNKNOWN ),
    mOutcome( OUTCOME_UNKNOWN ),
    mOrder( ORDER_UNKNOWN ),
    mOwnClass( CLASS_UNKNOWN ),
    mOpponentClass( CLASS_UNKNOWN ),
    mDuration( 0 ),
    mGameClientRestartRequired( false )
{
  mTimer = new QTimer( this );
  connect( mTimer, SIGNAL( timeout() ), this, SLOT( Tick() ) );
  mTimer->start( 1000 );

  // Connect log
  connect( &mLogTracker, SIGNAL( HandleOutcome(Outcome) ), this, SLOT( HandleOutcome(Outcome) ) );
  connect( &mLogTracker, SIGNAL( HandleOrder(GoingOrder) ), this, SLOT( HandleOrder(GoingOrder) ) );
  connect( &mLogTracker, SIGNAL( HandleOwnClass(Class) ), this, SLOT( HandleOwnClass(Class) ) ) ;
  connect( &mLogTracker, SIGNAL( HandleOpponentClass(Class) ), this, SLOT( HandleOpponentClass(Class) ) );
  connect( &mLogTracker, SIGNAL( HandleGameMode(GameMode) ), this, SLOT( HandleGameMode(GameMode) ) );

  connect( &mLogTracker, SIGNAL( HandleMatchStart() ), this, SLOT( HandleMatchStart() ) );
  connect( &mLogTracker, SIGNAL( HandleMatchEnd(const ::CardHistoryList&, bool) ), this, SLOT( HandleMatchEnd(const ::CardHistoryList&, bool) ) );

  ResetResult();
}
Ejemplo n.º 2
0
void HearthstoneLogTracker::HandleLogLine( const QString& line ) {
  if( line.trimmed().isEmpty() || line.startsWith( "(Filename:" )  ) {
    return;
  }

  // CardPlayed / CardReturned / PlayerDied
  static QRegExp regex( "ProcessChanges.*\\[.*id=(\\d+).*cardId=(\\w+|).*\\].*zone from (.*) ->\\s?(.*)" );
  if( regex.indexIn(line) != -1 ) {
    QStringList captures = regex.capturedTexts();
    int id = captures[1].toInt();
    QString cardId = captures[2];
    QString from = captures[3];
    QString to = captures[4];

    bool draw = from.contains( "DECK" ) && to.contains( "HAND" );
    bool mulligan = from.contains( "HAND" ) && to.contains( "DECK" );

    // Discarded cards by playing Soulfire, Doomguard etc.
    bool discard = from.contains( "HAND" ) && to.contains( "GRAVEYARD" );

    if( !draw && !mulligan && !discard ) {
      if( from.contains( "FRIENDLY HAND" ) ) {
        CardPlayed( PLAYER_SELF, cardId.toStdString(), id );
      } else if( from.contains( "OPPOSING HAND" ) ) {
        CardPlayed( PLAYER_OPPONENT, cardId.toStdString(), id );
      } else if( from.contains( "OPPOSING SECRET" ) && to.contains( "OPPOSING GRAVEYARD" ) ) {
        SecretResolved( PLAYER_OPPONENT, cardId.toStdString(), id );
      }
    }

    if( from.contains( "FRIENDLY PLAY" ) && to.contains( "FRIENDLY HAND" ) ) {
      CardReturned( PLAYER_SELF, cardId.toStdString() );
    }

    DBG( "Card %s from %s -> %s. (draw: %d, mulligan %d, discard %d) [%d]", qt2cstr( cardId ), qt2cstr( from ), qt2cstr( to ), draw, mulligan, discard, id );
  }

  // Outcome
  static QRegExp regexOutcome( "name=(victory|defeat)_screen_start" );
  if( regexOutcome.indexIn(line) != -1 ) {
    QStringList captures = regexOutcome.capturedTexts();
    QString outcome = captures[1];

    if( outcome == "victory" ) {
      emit HandleOutcome( OUTCOME_VICTORY );
    } else if( outcome == "defeat" ) {
      emit HandleOutcome( OUTCOME_DEFEAT );
    }
    emit HandleMatchEnd( mCardHistoryList );
    Reset();
  }

  // Coin
  static QRegExp regexCoin( "ProcessChanges.*zonePos=5.*zone from  -> (.*)" );  // unique because from is nothing -> " "
  if( regexCoin.indexIn(line) != -1 ) {
    QStringList captures = regexCoin.capturedTexts();
    QString to = captures[1];

    if( to.contains( "FRIENDLY HAND" ) ) {
      // I go second because I get the coin
      emit HandleOrder( ORDER_SECOND );
    } else if( to.contains( "OPPOSING HAND" ) ) {
      // Opponent got coin, so I go first
      emit HandleOrder( ORDER_FIRST );
    }
  }

  // Turn Info
  static QRegExp regexTurn( "change=powerTask.*tag=NEXT_STEP value=MAIN_ACTION" );
  if( regexTurn.indexIn(line) != -1 ) {
    mTurnCounter++;

    emit HandleTurn( mTurnCounter );

    // reset hero power usage on turn change
    mHeroPowerUsed = false;
  }

  // Hero Power
  static QRegExp regexHeroPowerEquip( "player=(\\d+).*-> FRIENDLY PLAY \\(Hero Power\\)" );
  if( regexHeroPowerEquip.indexIn(line) != -1 ) {
    QStringList captures = regexHeroPowerEquip.capturedTexts();
    QString playerId = captures[1];

    mHeroPlayerId = playerId.toInt();
    DBG( "Hero Power Equip -> My Player Id: %d", mHeroPlayerId );
  }

  static QRegExp regexHeroPower( "PowerProcessor\\.DoTaskListForCard.*cardId=(\\w+).*player=(\\d+)" );
  if( regexHeroPower.indexIn(line) != -1 ) {
    QStringList captures = regexHeroPower.capturedTexts();
    QString cardId = captures[1];
    int playerId = captures[2].toInt();
    Player player = ( playerId == mHeroPlayerId ) ? PLAYER_SELF : PLAYER_OPPONENT;

    bool isHeroPower = false;
    for( int i = 0; i < NUM_HERO_POWER_CARDS; i++ ) {
      if( cardId == HERO_POWER_CARD_IDS[ i ] ) {
        isHeroPower = true;
        break;
      }
    }

    // Power log line is emitted multiple times
    // Make sure we only account for first occurrence
    // Plus line is emitted when match starts, so ignore turn 0
    if( isHeroPower && !mHeroPowerUsed && CurrentTurn() > 0 ) {
      CardPlayed( player, cardId.toStdString() );
      mHeroPowerUsed = true;
    }
  }

  // Hero Equip
  static QRegExp regexHeroEquip( "cardId=(\\w+).*-> (\\w+) PLAY \\(Hero\\)" );
  if( regexHeroEquip.indexIn(line) != -1 ) {
    QStringList captures = regexHeroEquip.capturedTexts();
    QString cardId = captures[1];
    QString type = captures[2];

    // This log line can be emitted when hero swaps (Lord Jaraxxus)
    // So make sure we only account for the "initial" playable heroes
    Class hero = CLASS_UNKNOWN;
    for( int i = 0; i < NUM_HEROES; i++ ) {
      // startsWith instead of exact match to support
      // the new reasonably priced hero skins
      // (e.g. HERO_01a instead of HERO_01)
      if( cardId.startsWith( HERO_IDS[ i ] ) ) {
        hero = ( Class )i;
      }
    }

    // Set solo mode when encountering naxxramas/blackrock mountain heroes
    if( hero == CLASS_UNKNOWN ) {
      if( cardId.startsWith("NAX") || cardId.startsWith("BRM") ) {
        HandleGameMode( MODE_SOLO_ADVENTURES );
      }
    }

    if( hero != CLASS_UNKNOWN ) {
      if( type == "FRIENDLY" ) {
        emit HandleMatchStart();
        emit HandleOwnClass( hero );
      } else {
        emit HandleOpponentClass( hero );
      }
    }
  }

  // Game Mode
  // Practice, Casual/Ranked, ScreenForge
  static QRegExp regexMode( "---(\\w+)---" );
  if( regexMode.indexIn(line) != -1 ) {
    QStringList captures = regexMode.capturedTexts();
    QString screen = captures[1];

    if( screen == "RegisterScreenPractice" ) {
      HandleGameMode( MODE_SOLO_ADVENTURES );
    } else if( screen == "RegisterScreenTourneys") {
      HandleGameMode( MODE_CASUAL ); // or ranked resp.
    } else if( screen == "RegisterScreenForge" ) {
      HandleGameMode( MODE_ARENA );
    } else if( screen == "RegisterScreenFriendly" ) {
      HandleGameMode( MODE_FRIENDLY );
    }
  }

  // Tavern Brawl
  static QRegExp regexTavernBrawl( "SAVE --> NetCacheTavernBrawlRecord" );
  if( regexTavernBrawl.indexIn(line) != -1 ) {
    HandleGameMode( MODE_TAVERN_BRAWL );
  }

  // Rank
  // Rank events via log are unreliable

  // Legend
  // Emitted at the end of the game twice, make sure we capture only the first time
  static QRegExp regexLegend( "legend rank (\\d+)" );
  if( !mLegendTracked && regexLegend.indexIn(line) != -1 ) {
    QStringList captures = regexLegend.capturedTexts();
    int legend = captures[1].toInt();
    if( legend > 0 ) {
      mLegendTracked = true;
      HandleLegend( legend );
    }
  }

  // Casual/Ranked distinction
  static QRegExp regexRanked( "name=rank_window" );
  if( regexRanked.indexIn(line) != -1 ) {
    HandleGameMode( MODE_RANKED );
  }

  // flag current GAME as spectated
  static QRegExp regexBeginSpectating( "Start Spectator Game" );
  if( regexBeginSpectating.indexIn(line) != -1 ) {
    DBG( "Begin spectator game" );
    emit HandleSpectating( true );
  }

  // disable spectating flag if we leave the spectator MODE
  static QRegExp regexEndSpectating( "End Spectator Mode" );
  if( regexEndSpectating.indexIn(line) != -1 ) {
    DBG( "End spectator mode" );
    emit HandleSpectating( false );
  }
}