mirror of
https://github.com/OMGeeky/andors-trail.git
synced 2026-02-23 15:38:29 +01:00
Bugfix: Do not display double loot msgs about picked up gold.
* Also, refactor the loot popups to display toast even when the monster does not drop anything. (Should still display the exp)
This commit is contained in:
@@ -120,34 +120,46 @@ public final class Dialogs {
|
||||
context.startActivity(intent);
|
||||
}
|
||||
|
||||
public static String getGroundLootMessage(final Context ctx, final Loot loot) {
|
||||
public static String getGroundLootFoundMessage(final Context ctx, final Loot loot) {
|
||||
StringBuilder sb = new StringBuilder(60);
|
||||
if (!loot.items.isEmpty()) {
|
||||
sb.append(ctx.getString(R.string.dialog_groundloot_message));
|
||||
}
|
||||
if (loot.gold > 0) {
|
||||
sb.append(' ');
|
||||
sb.append(ctx.getString(R.string.dialog_loot_foundgold, loot.gold));
|
||||
}
|
||||
appendLootMessage(ctx, loot, sb);
|
||||
appendGoldPickedUpMessage(ctx, loot, sb);
|
||||
return sb.toString();
|
||||
}
|
||||
public static String getMonsterLootMessage(final Context ctx, final Loot combinedLoot, final int exp) {
|
||||
public static String getGroundLootPickedUpMessage(final Context ctx, final Loot loot) {
|
||||
StringBuilder sb = new StringBuilder(60);
|
||||
appendLootPickedUpMessage(ctx, loot, sb);
|
||||
return sb.toString();
|
||||
}
|
||||
public static String getMonsterLootFoundMessage(final Context ctx, final Loot combinedLoot, final int exp) {
|
||||
StringBuilder sb = new StringBuilder(60);
|
||||
appendMonsterEncounterSurvivedMessage(ctx, sb, exp);
|
||||
appendGoldPickedUpMessage(ctx, combinedLoot, sb);
|
||||
return sb.toString();
|
||||
}
|
||||
public static String getMonsterLootPickedUpMessage(final Context ctx, final Loot combinedLoot, final int exp) {
|
||||
StringBuilder sb = new StringBuilder(60);
|
||||
appendMonsterEncounterSurvivedMessage(ctx, sb, exp);
|
||||
appendLootPickedUpMessage(ctx, combinedLoot, sb);
|
||||
return sb.toString();
|
||||
}
|
||||
private static void appendMonsterEncounterSurvivedMessage(final Context ctx, final StringBuilder sb, final int exp) {
|
||||
sb.append(ctx.getString(R.string.dialog_monsterloot_message));
|
||||
|
||||
if (exp > 0) {
|
||||
sb.append(' ');
|
||||
sb.append(ctx.getString(R.string.dialog_monsterloot_gainedexp, exp));
|
||||
}
|
||||
appendLootMessage(ctx, combinedLoot, sb);
|
||||
return sb.toString();
|
||||
}
|
||||
private static void appendLootMessage(final Context ctx, final Loot loot, final StringBuilder sb) {
|
||||
private static void appendGoldPickedUpMessage(final Context ctx, final Loot loot, final StringBuilder sb) {
|
||||
if (loot.gold > 0) {
|
||||
sb.append(' ');
|
||||
sb.append(ctx.getString(R.string.dialog_loot_foundgold, loot.gold));
|
||||
}
|
||||
}
|
||||
private static void appendLootPickedUpMessage(final Context ctx, final Loot loot, final StringBuilder sb) {
|
||||
appendGoldPickedUpMessage(ctx, loot, sb);
|
||||
int numItems = loot.items.countItems();
|
||||
if (numItems == 1) {
|
||||
sb.append(' ');
|
||||
|
||||
@@ -262,6 +262,8 @@ public final class MainActivity extends Activity implements PlayerMovementListen
|
||||
}
|
||||
|
||||
private void showToast(String msg, int duration) {
|
||||
if (msg == null) return;
|
||||
if (msg.length() == 0) return;
|
||||
Toast t = null;
|
||||
if (lastToast != null) t = lastToast.get();
|
||||
if (t == null) {
|
||||
@@ -366,7 +368,7 @@ public final class MainActivity extends Activity implements PlayerMovementListen
|
||||
|
||||
@Override
|
||||
public void onPlayerSteppedOnGroundLoot(Loot loot) {
|
||||
final String msg = Dialogs.getGroundLootMessage(this, loot);
|
||||
final String msg = Dialogs.getGroundLootFoundMessage(this, loot);
|
||||
Dialogs.showGroundLoot(this, controllers, world, loot, msg);
|
||||
}
|
||||
|
||||
@@ -374,14 +376,14 @@ public final class MainActivity extends Activity implements PlayerMovementListen
|
||||
public void onPlayerPickedUpGroundLoot(Loot loot) {
|
||||
if (controllers.preferences.displayLoot == AndorsTrailPreferences.DISPLAYLOOT_NONE) return;
|
||||
|
||||
final String msg = Dialogs.getGroundLootMessage(this, loot);
|
||||
final String msg = Dialogs.getGroundLootPickedUpMessage(this, loot);
|
||||
showToast(msg, Toast.LENGTH_LONG);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerFoundMonsterLoot(Collection<Loot> loot, int exp) {
|
||||
final Loot combinedLoot = Loot.combine(loot);
|
||||
final String msg = Dialogs.getMonsterLootMessage(this, combinedLoot, exp);
|
||||
final String msg = Dialogs.getMonsterLootFoundMessage(this, combinedLoot, exp);
|
||||
Dialogs.showMonsterLoot(this, controllers, world, loot, combinedLoot, msg);
|
||||
}
|
||||
|
||||
@@ -390,7 +392,7 @@ public final class MainActivity extends Activity implements PlayerMovementListen
|
||||
if (controllers.preferences.displayLoot == AndorsTrailPreferences.DISPLAYLOOT_NONE) return;
|
||||
|
||||
final Loot combinedLoot = Loot.combine(loot);
|
||||
final String msg = Dialogs.getMonsterLootMessage(this, combinedLoot, exp);
|
||||
final String msg = Dialogs.getMonsterLootPickedUpMessage(this, combinedLoot, exp);
|
||||
showToast(msg, Toast.LENGTH_LONG);
|
||||
}
|
||||
|
||||
|
||||
@@ -59,14 +59,12 @@ public final class CombatController implements VisualEffectCompletedCallback {
|
||||
currentActiveMonster = null;
|
||||
world.model.uiSelections.selectedPosition = null;
|
||||
world.model.uiSelections.selectedMonster = null;
|
||||
if (killedMonsterBags.isEmpty()) {
|
||||
controllers.gameRoundController.resume();
|
||||
if (pickupLootBags && totalExpThisFight > 0) {
|
||||
controllers.itemController.lootMonsterBags(killedMonsterBags, totalExpThisFight);
|
||||
} else {
|
||||
if (pickupLootBags) {
|
||||
controllers.itemController.lootMonsterBags(killedMonsterBags, totalExpThisFight);
|
||||
}
|
||||
killedMonsterBags.clear();
|
||||
}
|
||||
controllers.gameRoundController.resume();
|
||||
}
|
||||
killedMonsterBags.clear();
|
||||
totalExpThisFight = 0;
|
||||
}
|
||||
|
||||
@@ -204,7 +202,7 @@ public final class CombatController implements VisualEffectCompletedCallback {
|
||||
loot.exp = 0;
|
||||
controllers.actorStatsController.applyKillEffectsToPlayer(player);
|
||||
|
||||
if (!loot.hasItems()) {
|
||||
if (!loot.hasItemsOrGold()) {
|
||||
world.model.currentMap.removeGroundLoot(loot);
|
||||
} else if (world.model.uiSelections.isInCombat) {
|
||||
killedMonsterBags.add(loot);
|
||||
@@ -235,6 +233,7 @@ public final class CombatController implements VisualEffectCompletedCallback {
|
||||
return false;
|
||||
}
|
||||
private void playerActionCompleted() {
|
||||
if (!world.model.uiSelections.isInCombat) return;
|
||||
if (canExitCombat()) {
|
||||
exitCombat(true);
|
||||
return;
|
||||
|
||||
@@ -108,7 +108,7 @@ public final class ItemController {
|
||||
}
|
||||
|
||||
public void lootMonsterBags(Collection<Loot> killedMonsterBags, int totalExpThisFight) {
|
||||
if (pickupLootBagWithoutConfirmation()) {
|
||||
if (pickupLootBagWithoutConfirmation() || !Loot.hasItems(killedMonsterBags)) {
|
||||
controllers.mapController.worldEventListeners.onPlayerPickedUpMonsterLoot(killedMonsterBags, totalExpThisFight);
|
||||
pickupAll(killedMonsterBags);
|
||||
removeLootBagIfEmpty(killedMonsterBags);
|
||||
@@ -207,7 +207,7 @@ public final class ItemController {
|
||||
}
|
||||
}
|
||||
public boolean removeLootBagIfEmpty(final Loot loot) {
|
||||
if (loot.hasItems()) return false;
|
||||
if (loot.hasItemsOrGold()) return false;
|
||||
|
||||
world.model.currentMap.removeGroundLoot(loot);
|
||||
controllers.mapController.mapLayoutListeners.onLootBagRemoved(world.model.currentMap, loot.position);
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.gpl.rpg.AndorsTrail.model.item;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
|
||||
import com.gpl.rpg.AndorsTrail.context.WorldContext;
|
||||
import com.gpl.rpg.AndorsTrail.savegames.LegacySavegameFormatReaderForItemContainer;
|
||||
@@ -33,11 +34,14 @@ public final class Loot {
|
||||
}
|
||||
|
||||
public boolean hasItemsOrExp() {
|
||||
return exp != 0 || hasItems();
|
||||
return exp != 0 || hasItemsOrGold();
|
||||
}
|
||||
public boolean hasItemsOrGold() {
|
||||
return gold != 0 || hasItems();
|
||||
}
|
||||
public boolean hasItems() {
|
||||
return gold != 0 || !items.isEmpty();
|
||||
}
|
||||
return !items.isEmpty();
|
||||
}
|
||||
public boolean isContainer() {
|
||||
return !isVisible;
|
||||
}
|
||||
@@ -48,6 +52,14 @@ public final class Loot {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public static boolean hasItems(Collection<Loot> lootBags) {
|
||||
if (lootBags == null) return false;
|
||||
if (lootBags.isEmpty()) return false;
|
||||
for (Loot loot : lootBags) {
|
||||
if (loot.hasItems()) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public void clear() {
|
||||
|
||||
Reference in New Issue
Block a user