diff --git a/app/src/main/java/de/happycarl/geotown/app/gui/PlayingActivity.java b/app/src/main/java/de/happycarl/geotown/app/gui/PlayingActivity.java index 3cb5855..7d0bc04 100644 --- a/app/src/main/java/de/happycarl/geotown/app/gui/PlayingActivity.java +++ b/app/src/main/java/de/happycarl/geotown/app/gui/PlayingActivity.java @@ -187,10 +187,10 @@ protected void onCreate(Bundle savedInstanceState) { ButterKnife.inject(this); - if (GeotownApplication.getPreferences().getLong(AppConstants.PREF_PRNG_SEED, 0L) <= 0) { + /*if (GeotownApplication.getPreferences().getLong(AppConstants.PREF_PRNG_SEED, 0L) <= 0) { seed = System.currentTimeMillis(); GeotownApplication.getPreferences().edit().putLong(AppConstants.PREF_PRNG_SEED, seed).apply(); - } + }*/ doBindService(); @@ -280,7 +280,7 @@ public boolean onOptionsItemSelected(MenuItem item) { intent.putExtra("ENCODE_FORMAT", "QR_CODE"); intent.putExtra("ENCODE_TYPE", "TEXT_TYPE"); - String qrPayload = AppConstants.QR_CODE_PREFIX + ":" + GeotownApplication.getPreferences().getLong(AppConstants.PREF_CURRENT_ROUTE, 0L) + ":" + seed; + String qrPayload = AppConstants.QR_CODE_PREFIX + ":" + GeotownApplication.getPreferences().getLong(AppConstants.PREF_CURRENT_ROUTE, 0L) + ":" + GeotownApplication.getPreferences().getLong(AppConstants.PREF_PRNG_SEED, 0L); intent.putExtra("ENCODE_DATA", qrPayload); try { @@ -369,11 +369,12 @@ private void routeEnd(boolean finished) { .putLong(AppConstants.PREF_CURRENT_WAYPOINT, -1L).apply(); GeotownApplication.getPreferences().edit() .putLong(AppConstants.PREF_CURRENT_ROUTE, -1L).apply(); + GeotownApplication.getPreferences().edit() + .putLong(AppConstants.PREF_PRNG_SEED, 0L).apply(); if(finished) { //we finished the route - GeotownApplication.getPreferences().edit() - .putLong(AppConstants.PREF_PRNG_SEED, 0L).apply(); + GameUtil.publishRouteFinishToPlayGames(this, mGameHelper); Crouton.makeText(this, R.string.message_playing_route_finished, Style.CONFIRM).show(); diff --git a/app/src/main/java/de/happycarl/geotown/app/gui/RouteDetailActivity.java b/app/src/main/java/de/happycarl/geotown/app/gui/RouteDetailActivity.java index 6814a00..13da0b6 100644 --- a/app/src/main/java/de/happycarl/geotown/app/gui/RouteDetailActivity.java +++ b/app/src/main/java/de/happycarl/geotown/app/gui/RouteDetailActivity.java @@ -295,6 +295,7 @@ public void onClick(DialogInterface dialog, int which) { } else { //No current Route editor.putLong(AppConstants.PREF_CURRENT_ROUTE, mRoute.id); + editor.putLong(AppConstants.PREF_PRNG_SEED, 0L); editor.apply(); //if route was played before, reset it now diff --git a/app/src/main/java/de/happycarl/geotown/app/service/GameService.java b/app/src/main/java/de/happycarl/geotown/app/service/GameService.java index c0c0507..e3aa556 100644 --- a/app/src/main/java/de/happycarl/geotown/app/service/GameService.java +++ b/app/src/main/java/de/happycarl/geotown/app/service/GameService.java @@ -201,8 +201,14 @@ public void onCreate() { loadRoute(); long seed = GeotownApplication.getPreferences().getLong(AppConstants.PREF_PRNG_SEED, 0); + Log.d("Seed", "seed is " + seed + " : " + (seed != 0L)); - random = new Random((seed != 0L) ? seed : System.currentTimeMillis()); + if(seed == 0L) { + seed = System.currentTimeMillis(); + GeotownApplication.getPreferences().edit().putLong(AppConstants.PREF_PRNG_SEED, seed).apply(); + Log.d("seed", "put seed " + seed); + } + random = new Random(seed); } @Override @@ -329,6 +335,8 @@ private void sendMessage(int messageCode, int arg1, int arg2) { } private void reportDistanceToTarget() { + if(currentTarget == null) + return; if (distanceToTarget == -1) { Location oldGPS = LocationServices.FusedLocationApi.getLastLocation(mApiClient); if (oldGPS != null) { @@ -425,7 +433,7 @@ private void selectNewWaypoint() { .from(GeoTownWaypoint.class) .where("done = ?", false) .where("route = ?", currentRoute.getId()) - .orderBy("question") + .orderBy("RANDOM()") .execute(); Log.d("selectNewWaypoint", "new route null?: " + (currentWaypoint == null)); @@ -446,7 +454,8 @@ private void selectNewWaypoint() { Log.d("GameService", "NO TRACK UPLOAD"); } } else { - int index = random.nextInt(waypoints.size()); + int index = Math.abs(random.nextInt() % waypoints.size()); + Log.d("seed", "index: " + index + ": " + waypoints.size()); currentWaypoint = waypoints.get(index); currentWaypoint.save(); Log.d("selectNewWaypoint", "new ID: " + currentWaypoint.id);