use of POGOProtos.Data.Battle.BattleActionOuterClass.BattleAction in project PokeGOAPI-Java by Grover-c13.
the class Battle method updateLog.
/**
* Updates this battle with the given log
*
* @param handler to handle this battle
* @param log the log to update with
* @return if this battle should move on to the next defender
*/
private boolean updateLog(BattleHandler handler, BattleLog log) {
serverTimeOffset = log.getServerMs() - api.currentTimeMillis();
battleType = log.getBattleType();
startTime = log.getBattleStartTimestampMs();
endTime = log.getBattleEndTimestampMs();
if (log.getBattleActionsCount() > 0) {
long latestTime = Long.MIN_VALUE;
for (BattleAction action : log.getBattleActionsList()) {
if (action.getActionStartMs() > latestTime) {
lastRetrievedAction = action;
latestTime = action.getActionStartMs();
}
}
}
results = null;
for (BattleAction action : log.getBattleActionsList()) {
BattleResults results = action.getBattleResults();
if (results.hasGymState()) {
this.results = action.getBattleResults();
}
}
if (results != null) {
gym.updatePoints(results.getGymPointsDelta());
gymPointsDelta += results.getGymPointsDelta();
}
BattleState state = log.getState();
active = defenderIndex < defenderCount && !(state == BattleState.TIMED_OUT || state == BattleState.STATE_UNSET);
if (state != battleState) {
switch(state) {
case TIMED_OUT:
gym.clearDetails();
handler.onTimedOut(api, this);
break;
case DEFEATED:
gym.clearDetails();
handler.onDefeated(api, this);
break;
case VICTORY:
if (!active) {
gym.updateState(results.getGymState());
handler.onVictory(api, this, gymPointsDelta, gym.getPoints());
}
break;
default:
break;
}
if (!active) {
try {
api.inventories.updateInventories();
} catch (Exception e) {
handler.onException(api, this, e);
}
}
battleState = state;
}
for (BattleAction action : log.getBattleActionsList()) {
ServerAction serverAction = new ServerAction(action);
if (!handledActions.contains(serverAction)) {
serverActionQueue.add(serverAction);
handledActions.add(serverAction);
}
}
lastServerTime = log.getServerMs();
return battleState != BattleState.ACTIVE && battleState != BattleState.STATE_UNSET && battleState != BattleState.TIMED_OUT;
}
Aggregations