From 3c7e67b59b50c000bb088fa82a9ce991bebd906e Mon Sep 17 00:00:00 2001 From: "oskar.wiksten@gmail.com" Date: Tue, 15 Mar 2011 20:07:47 +0000 Subject: [PATCH] Player respawns on last place of rest. Resting resets respawn place. git-svn-id: https://andors-trail.googlecode.com/svn/trunk@58 08aca716-68be-ccc6-4d58-36f5abd142ac --- AndorsTrail/res/xml/crossglen_hall.tmx | 56 +++++++++---------- AndorsTrail/res/xml/fallhaven_tavern.tmx | 52 ++++++++--------- AndorsTrail/res/xml/home.tmx | 51 +++++++++-------- .../AndorsTrail/AndorsTrailApplication.java | 4 +- .../src/com/gpl/rpg/AndorsTrail/Dialogs.java | 7 ++- .../com/gpl/rpg/AndorsTrail/WorldSetup.java | 2 +- .../AndorsTrail/controller/Controller.java | 16 ++++-- .../controller/MovementController.java | 13 +++-- .../model/map/LayeredWorldMap.java | 2 +- .../AndorsTrail/model/map/MapCollection.java | 9 +++ .../rpg/AndorsTrail/model/map/MapObject.java | 4 +- .../AndorsTrail/model/map/TMXMapReader.java | 2 +- 12 files changed, 116 insertions(+), 102 deletions(-) diff --git a/AndorsTrail/res/xml/crossglen_hall.tmx b/AndorsTrail/res/xml/crossglen_hall.tmx index ec3068d0d..8714b4a00 100644 --- a/AndorsTrail/res/xml/crossglen_hall.tmx +++ b/AndorsTrail/res/xml/crossglen_hall.tmx @@ -1,71 +1,71 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - H4sIAAAAAAAAAwtiZGBoxIKDgJiTATsOwqMHhCdiwYTMw6UHhB0ZMHEQI36MTw82OWz+QcakmofNP8iYVPPIwcjmNUIxtcyjtvvIwRtxmIcuPhT8G0gA4zIPV9rElddgGKTmJQsDQz4Qv2KBphFG3GmTGPN+As0pAOJfUPNAZqH7AcYmZB6ucAAA3NS0n7AEAAA= + + eJwLYmRgaMSCg4CYkwE7DsKjB4QnYsGEzMOlB4QdGTBxECN+jE8PNjls/kHGpJqHzT/ImFTzyMHI5jVCMbXMo7b7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sJlBSA05GAD9cUNrsAQAAA== + + eJwTZGBgEBwCmAGNptQsZECOHnR9tDKPkB5i7UVWQy4g5A5cbieknlB4EGMeMeFLCiA2zigxk5B9pIYPsWYRsp8c87CZQUgNORgAXCMLoA== @@ -75,10 +75,10 @@ - - - - + + + + diff --git a/AndorsTrail/res/xml/fallhaven_tavern.tmx b/AndorsTrail/res/xml/fallhaven_tavern.tmx index a17915a68..c18361169 100644 --- a/AndorsTrail/res/xml/fallhaven_tavern.tmx +++ b/AndorsTrail/res/xml/fallhaven_tavern.tmx @@ -1,71 +1,71 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - H4sIAAAAAAAAA62S3Q2DMAyEr/xJDMRDX1oxAozRl46QGZiHDledoghkHEgcHk5RbOeTdZf5Acw361vdo8BbOi9X2cX3gTciX0MNfLCJtRKeplRe8EPOvlrg3frTst9+9ixf9tcG+DXbvLxLXixfnpb9tIzZd4k85nnlDfsTjhqV2qT4p/F6pCslDysvloeVF8vDyovlUeJfKW//V+W/fda+lsOjR3wX/JP7uUye9iel/lQWwuXwBQAA + + eJytkt0NgzAMhK/8SQzEQ19aMQKM0ZeOkBmYhw5XnaIIZBxIHB5OUWznk3WX+QHMN+tb3aPAWzovV9nF94E3Il9DDXywibUSnqZUXvBDzr5a4N3607LffvYsX/bXBvg127y8S14sX56W/bSM2XeJPOZ55Q37E44aldqk+KfxeqQrJQ8rL5aHlRfLw8qL5VHiXylv/1flv33WvpbDo0d8F/yT+7lMnvYnpf4tlmRN - - H4sIAAAAAAAAA2NgoAwoseOX52RhYNgMVBPAimDnsCPYyGpAwIiAeZJAtS3sCHYmMwNDFjOEjawGBpywmLeQDYJFoXJTgHQ1M4RdCaSroOxsZlR9yVBzO1gh+mHgGxvDoAO/0dwkyo6bDwsPUoAQVL8IlBYGxSmSmX9wmAeK+81obgGZcRoYtmdYMPkiBNIDNgByiyoWfTCxMGZMOWRwAej2u1SI0ylIbnhLgXkbWSl3CzI4iGQeKC5yyQhjZHCRyu5DB5TERwsOv5EbH8hx+pANgpNZcKsnBmDTP4XCOMEFAPWS7JjwBQAA + + eJxjYKAMKLHjl+dkYWDYDFQTwIpg57Aj2MhqQMCIgHmSQLUt7Ah2JjMDQxYzhI2sBgacsJi3kA2CRaFyU4B0NTOEXQmkq6DsbGZUfclQcztYIfph4Bsbw6ADv9HcJMqOmw8LD1KAEFS/CJQWBsUpkpl/cJgHivvNaG4BmXEaGLZnWDD5IgTSAzYAcosqFn0wsTBmTDlkcAHo9rtUiNMpSG54S4F5G1kpdwsyOIhkHigucskIY2RwkcruQweUxEcLDr+RGx/IcfqQDYKTWXCrJwZg0z+FwjjBBQBLRCQn - - H4sIAAAAAAAAA2NgoD74z4xd3IeVuuaRC2DmJbNQ1zxqAWqYh+w3UswjRu1gN+89mea1sBOvjxjzqAFA5rFRwV3I5lETDCXzLrJBMLXMo0baQU6rpKRbcgEA5Xi8NfAFAAA= + + eJxjYKA++M+MXdyHlbrmkQtg5iWzUNc8agFqmIfsN1LMI0btYDfvPZnmtbATr48Y86gBQOaxUcFdyOZREwwl8y6yQTC1zKNG2kFOq6SkW3IBAKIeGu8= - - H4sIAAAAAAAAAxNkYGAQHMGYgQCbAQcbmzmUAmLNwmUvPj+Sah4pYUYKn1zzGHDIk+NnQupISTO47CUlfsi1a7iahw6o5UZqmYuul1I3YnMfNcMUGQMAKrZNJfAFAAA= + + eJwTZGBgEBzBmIEAmwEHG5s5lAJizcJlLz4/kmoeKWFGCp9c8xhwyJPjZ0LqSEkzuOwlJX7ItWu4mocOqOVGapmLrpdSN2JzHzXDFBkDAMrPEsw= @@ -75,8 +75,8 @@ - - + + diff --git a/AndorsTrail/res/xml/home.tmx b/AndorsTrail/res/xml/home.tmx index bd0b1becf..1767a4e06 100644 --- a/AndorsTrail/res/xml/home.tmx +++ b/AndorsTrail/res/xml/home.tmx @@ -1,71 +1,71 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - H4sIAAAAAAAAAwtiZGAIIhI3EsAwdRMJYJg6Rwb8mBJ1L1kYGPKh+BULbnV5QDkYyEVS10iEukaof5DV/QTKFUDxL6g6kJpABgR2ZEDlI2MAxi8HupABAAA= + + eJwLYmRgCCISNxLAMHUTCWCYOkcG/JgSdS9ZGBjyofgVC251eUA5GMhFUtdIhLpGqH+Q1f0EyhVA8S+oOpCaQAYEdmRA5SNjAIJFJI8= - - H4sIAAAAAAAAA2NgIB7ksjMweLEg+DD2TzZMtVFAuWKgeAs7hK3FysCgCcSerAg1d4HyzED5ZiA9BUj3AOWskDAMvMViPjZwkUh1D9kgGAR0gPbsBrpvDwuEjQw2ovFxqbuIxAfJnQaqOQMNm19EugkGAGc0HW+QAQAA + + eJxjYCAe5LIzMHixIPgw9k82TLVRQLlioHgLO4StxcrAoAnEnqwINXeB8sxA+WYgPQVI9wDlrJAwDLzFYj42cJFIdQ/ZIBgEdID27Aa6bw8LhI0MNqLxcam7iMQHyZ0GqjkDDZtfRLoJBgCErxNf - - H4sIAAAAAAAAAxNkYGAQHOSYECBWLS5zcfHRzaOGOkEcYjAMAKpaHhWQAQAA + + eJwTZGBgEBzkmBAgVi0uc3Hx0c2jhjpBHGIwDAAZbASn - - H4sIAAAAAAAAA2NgIB58YCZO3X8kdfj0IKt7T6Q6QvZeZCNOHQgks0Boblbi7eVkJ07dMhxmEgIAugjLAZABAAA= + + eJxjYCAefGAmTt1/JHX49CCre0+kOkL2XmQjTh0IJLNAaG5W4u3lZCdO3TIcZhICAOWWC/A= @@ -75,8 +75,7 @@ - - + diff --git a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/AndorsTrailApplication.java b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/AndorsTrailApplication.java index 5225ebd09..d43082b77 100644 --- a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/AndorsTrailApplication.java +++ b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/AndorsTrailApplication.java @@ -14,9 +14,9 @@ import android.view.WindowManager; public final class AndorsTrailApplication extends Application { public static final boolean DEVELOPMENT_DEBUGRESOURCES = false; - public static final boolean DEVELOPMENT_FORCE_STARTNEWGAME = true; + public static final boolean DEVELOPMENT_FORCE_STARTNEWGAME = false; public static final boolean DEVELOPMENT_FORCE_CONTINUEGAME = false; - public static final boolean DEVELOPMENT_DEBUGBUTTONS = false; + public static final boolean DEVELOPMENT_DEBUGBUTTONS = true; public static final boolean DEVELOPMENT_VALIDATEDATA = true; public static final boolean DEVELOPMENT_DEBUGMESSAGES = true; public static final int CURRENT_VERSION = 17; diff --git a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/Dialogs.java b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/Dialogs.java index 41880842a..9744f67f8 100644 --- a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/Dialogs.java +++ b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/Dialogs.java @@ -36,6 +36,7 @@ import com.gpl.rpg.AndorsTrail.controller.ItemController; import com.gpl.rpg.AndorsTrail.model.actor.Monster; import com.gpl.rpg.AndorsTrail.model.item.ItemType; import com.gpl.rpg.AndorsTrail.model.item.Loot; +import com.gpl.rpg.AndorsTrail.model.map.MapObject; import com.gpl.rpg.AndorsTrail.resource.TileStore; import com.gpl.rpg.AndorsTrail.view.ItemContainerAdapter; @@ -203,9 +204,9 @@ public final class Dialogs { currentActivity.startActivityForResult(intent, MainActivity.INTENTREQUEST_LEVELUP); } - public static void showRest(final Activity currentActivity, final ViewContext viewContext) { + public static void showRest(final Activity currentActivity, final ViewContext viewContext, final MapObject area) { if (!viewContext.preferences.confirmRest) { - Controller.ui_playerRested(currentActivity, viewContext); + Controller.ui_playerRested(currentActivity, viewContext, area); return; } Dialog d = new AlertDialog.Builder(currentActivity) @@ -214,7 +215,7 @@ public final class Dialogs { .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { - Controller.ui_playerRested(currentActivity, viewContext); + Controller.ui_playerRested(currentActivity, viewContext, area); } }) .setNegativeButton(android.R.string.no, null) diff --git a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/WorldSetup.java b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/WorldSetup.java index 2d7f8f05d..1cf3f42f4 100644 --- a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/WorldSetup.java +++ b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/WorldSetup.java @@ -110,7 +110,7 @@ public final class WorldSetup { private void createNewWorld() { world.model = new ModelContainer(); world.model.player.initializeNewPlayer_(world.itemTypes, world.dropLists, newHeroName); - Controller.playerRested(world); + Controller.playerRested(world, null); MovementController.respawnPlayer(world); } diff --git a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/controller/Controller.java b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/controller/Controller.java index be661ab8a..0f9799196 100644 --- a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/controller/Controller.java +++ b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/controller/Controller.java @@ -37,10 +37,10 @@ public final class Controller { if (o.map == null || o.place == null) return; int offset_x = position.x - o.position.topLeft.x; int offset_y = position.y - o.position.topLeft.y; - view.movementController.placePlayerAt(o.map, o.place, offset_x, offset_y); + view.movementController.placePlayerAt(MapObject.MAPEVENT_NEWMAP, o.map, o.place, offset_x, offset_y); break; case MapObject.MAPEVENT_REST: - Dialogs.showRest(view.mainActivity, view); + Dialogs.showRest(view.mainActivity, view, o); break; } } @@ -66,7 +66,7 @@ public final class Controller { if (lostExp < 0) lostExp = 0; // Shouldn't happen, but just to be sure. player.addExperience(-lostExp); model.statistics.addPlayerDeath(lostExp); - playerRested(world); + playerRested(world, null); MovementController.respawnPlayer(world); final MainActivity act = view.mainActivity; act.updateStatus(); @@ -74,19 +74,23 @@ public final class Controller { act.message(act.getResources().getString(R.string.combat_hero_dies, lostExp)); } - public static void playerRested(final WorldContext world) { + public static void playerRested(final WorldContext world, MapObject area) { final Player player = world.model.player; ActorStatsController.removeAllTemporaryConditions(player); ActorStatsController.recalculatePlayerCombatTraits(player); player.setMaxAP(); player.setMaxHP(); + if (area != null) { + player.spawnPlace = area.id; + player.spawnMap = world.model.currentMap.name; + } for (LayeredWorldMap m : world.maps.predefinedMaps) { if (m.visited) m.spawnAll(world); } } - public static void ui_playerRested(final Activity currentActivity, final ViewContext viewContext) { - playerRested(viewContext); + public static void ui_playerRested(final Activity currentActivity, final ViewContext viewContext, MapObject area) { + playerRested(viewContext, area); viewContext.mainActivity.updateStatus(); Dialogs.showRested(currentActivity, viewContext); } diff --git a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/controller/MovementController.java b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/controller/MovementController.java index 37c1fba6a..a7b08d9eb 100644 --- a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/controller/MovementController.java +++ b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/controller/MovementController.java @@ -24,21 +24,22 @@ public final class MovementController { this.model = world.model; } - public void placePlayerAt(String mapName, String placeName, int offset_x, int offset_y) { - placePlayerAt(world, mapName, placeName, offset_x, offset_y); + public void placePlayerAt(int objectType, String mapName, String placeName, int offset_x, int offset_y) { + placePlayerAt(world, objectType, mapName, placeName, offset_x, offset_y); view.mainActivity.clearMessages(); view.mainActivity.mainview.notifyMapChanged(); } - public static void placePlayerAt(final WorldContext world, String mapName, String placeName, int offset_x, int offset_y) { + + public static void placePlayerAt(final WorldContext world, int objectType, String mapName, String placeName, int offset_x, int offset_y) { if (mapName == null || placeName == null) return; LayeredWorldMap newMap = world.maps.findPredefinedMap(mapName); if (newMap == null) { L.log("Cannot find map " + mapName); return; } - MapObject place = newMap.findEventObject(MapObject.MAPEVENT_NEWMAP, placeName); + MapObject place = newMap.findEventObject(objectType, placeName); if (place == null) { - L.log("Cannot find place " + placeName + " in map " + mapName); + L.log("Cannot find place " + placeName + " of type " + objectType + " in map " + mapName); return; } final ModelContainer model = world.model; @@ -173,7 +174,7 @@ public final class MovementController { } public static void respawnPlayer(final WorldContext world) { - placePlayerAt(world, world.model.player.spawnMap, world.model.player.spawnPlace, 0, 0); + placePlayerAt(world, MapObject.MAPEVENT_REST, world.model.player.spawnMap, world.model.player.spawnPlace, 0, 0); } public static void moveBlockedActors(final WorldContext world) { diff --git a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/model/map/LayeredWorldMap.java b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/model/map/LayeredWorldMap.java index 5af490e50..3bc782fbd 100644 --- a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/model/map/LayeredWorldMap.java +++ b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/model/map/LayeredWorldMap.java @@ -82,7 +82,7 @@ public final class LayeredWorldMap { public MapObject findEventObject(int objectType, String name) { for (MapObject o : eventObjects) { - if (o.type == objectType && o.id.equals(name)) return o; + if (o.type == objectType && name.equals(o.id)) return o; } return null; } diff --git a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/model/map/MapCollection.java b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/model/map/MapCollection.java index 2800dc1da..2833b31ef 100644 --- a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/model/map/MapCollection.java +++ b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/model/map/MapCollection.java @@ -79,6 +79,15 @@ public final class MapCollection { continue; } world.conversations.getPhrase(o.id); // Will warn inside if not available. + } else if (o.type == MapObject.MAPEVENT_REST) { + if (o.id == null || o.id.length() <= 0) { + L.log("WARNING: Map \"" + m.name + "\" contains rest area without id."); + continue; + } + if (m.findEventObject(MapObject.MAPEVENT_REST, o.id) != o) { + L.log("WARNING: Map \"" + m.name + "\" contains duplicate rest area with id \"" + o.id + "\"."); + continue; + } } } diff --git a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/model/map/MapObject.java b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/model/map/MapObject.java index 3f72bde88..767666d9b 100644 --- a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/model/map/MapObject.java +++ b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/model/map/MapObject.java @@ -35,8 +35,8 @@ public final class MapObject { public static MapObject createNewMapEvent(final CoordRect position, final String thisMapTitle, final String destinationMap, final String destinationPlace) { return new MapObject(position, MAPEVENT_NEWMAP, thisMapTitle, destinationMap, destinationPlace, null, null); } - public static MapObject createNewRest(final CoordRect position) { - return new MapObject(position, MAPEVENT_REST, null, null, null, null, null); + public static MapObject createNewRest(final CoordRect position, final String placeId) { + return new MapObject(position, MAPEVENT_REST, placeId, null, null, null, null); } public static MapObject createNewKeyArea(final CoordRect position, final String phraseID, final QuestProgress requireQuestStage) { return new MapObject(position, MAPEVENT_KEYAREA, phraseID, null, null, requireQuestStage, null); diff --git a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/model/map/TMXMapReader.java b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/model/map/TMXMapReader.java index 8d65f5ea3..936acc6a6 100644 --- a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/model/map/TMXMapReader.java +++ b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/model/map/TMXMapReader.java @@ -355,7 +355,7 @@ public final class TMXMapReader { mapObjects.add(MapObject.createNewKeyArea(position, phraseID, requireQuestStage)); } else if (object.type.equals("rest")) { - mapObjects.add(MapObject.createNewRest(position)); + mapObjects.add(MapObject.createNewRest(position, object.name)); } else if (object.type.equals("container")) { DropList dropList = dropLists.getDropList(object.name); if (dropList == null) continue;