]> www.infradead.org Git - users/mchehab/andors-trail.git/commitdiff
Persist inventories of vendors in savegame file. Restock merchants when map respawns.
authorOskar Wiksten <oskar.wiksten@gmail.com>
Wed, 1 Aug 2012 20:51:02 +0000 (22:51 +0200)
committerOskar Wiksten <oskar.wiksten@gmail.com>
Wed, 1 Aug 2012 20:51:02 +0000 (22:51 +0200)
1  2 
AndorsTrail/src/com/gpl/rpg/AndorsTrail/AndorsTrailApplication.java
AndorsTrail/src/com/gpl/rpg/AndorsTrail/activity/ConversationActivity.java
AndorsTrail/src/com/gpl/rpg/AndorsTrail/activity/DebugInterface.java
AndorsTrail/src/com/gpl/rpg/AndorsTrail/activity/ShopActivity.java
AndorsTrail/src/com/gpl/rpg/AndorsTrail/model/actor/Monster.java
AndorsTrail/src/com/gpl/rpg/AndorsTrail/model/map/PredefinedMap.java

index 4f7ad4bedd5be59d6d763b44731109c49baa00c6,b2d3751c1ef54608b9f260b1790d27d3e812e067..f11ee4c8299cc5d15b8014b9e3b5182df3538588
@@@ -16,12 -16,11 +16,12 @@@ public final class AndorsTrailApplicati
        public static final boolean DEVELOPMENT_DEBUGRESOURCES = false;\r
        public static final boolean DEVELOPMENT_FORCE_STARTNEWGAME = false;\r
        public static final boolean DEVELOPMENT_FORCE_CONTINUEGAME = false;\r
 -      public static final boolean DEVELOPMENT_DEBUGBUTTONS = true;\r
 +      public static final boolean DEVELOPMENT_DEBUGBUTTONS = false;\r
        public static final boolean DEVELOPMENT_VALIDATEDATA = true;\r
        public static final boolean DEVELOPMENT_DEBUGMESSAGES = true;\r
 -      public static final int CURRENT_VERSION = 24;\r
 -      public static final String CURRENT_VERSION_DISPLAY = "0.6.10dev";\r
 +      public static final boolean DEVELOPMENT_INCOMPATIBLE_SAVEGAMES = DEVELOPMENT_DEBUGRESOURCES || true;\r
-       public static final int CURRENT_VERSION = DEVELOPMENT_INCOMPATIBLE_SAVEGAMES ? 999 : 30;\r
++      public static final int CURRENT_VERSION = DEVELOPMENT_INCOMPATIBLE_SAVEGAMES ? 999 : 31;\r
 +      public static final String CURRENT_VERSION_DISPLAY = "0.7.0dev";\r
        \r
        public final WorldContext world = new WorldContext();\r
        public final WorldSetup setup = new WorldSetup(world, this);\r
index f9d9b34f74231d2497b964deecd4a2a8895eb0ed,ed6232af19df4ae6006c40f79c2d01edb009ca6e..a6dd4d403637c30efcda26ee91d0c3612f8ea05a
@@@ -213,6 -133,6 +213,7 @@@ public final class ConversationActivit
                intent.setData(Uri.parse("content://com.gpl.rpg.AndorsTrail/shop"));
                Dialogs.addMonsterIdentifiers(intent, npc);
                startActivityForResult(intent, MainActivity.INTENTREQUEST_SHOP);
++              ConversationActivity.this.finish();
                return;
        } else if (phraseID.equalsIgnoreCase(ConversationCollection.PHRASE_ATTACK)) {
                ConversationActivity.this.setResult(ACTIVITYRESULT_ATTACK);
index 03ff00baaeb4c5aa654d88f88a987e3ea90ba28c,0a41f667315eb97511a77bfadbc7b662ce7237b4..b3734576d966977bf6f3cd21558ee497bab925c0
@@@ -11,10 -11,10 +11,11 @@@ import com.gpl.rpg.AndorsTrail.AndorsTr
  import com.gpl.rpg.AndorsTrail.R;
  import com.gpl.rpg.AndorsTrail.context.ViewContext;
  import com.gpl.rpg.AndorsTrail.context.WorldContext;
+ import com.gpl.rpg.AndorsTrail.model.map.PredefinedMap;
  
 +@SuppressWarnings("unused")
  public final class DebugInterface {
 -      //private final ViewContext viewContext;
 +      private final ViewContext viewContext;
        private final MainActivity mainActivity;
        private final Resources res;
        private final WorldContext world;
                                mainActivity.showToast("DEBUG: given 10000 exp", Toast.LENGTH_SHORT);
                                }
                        })*/
 -                      ,new DebugButton("hp=max", new OnClickListener() {
+                       ,new DebugButton("reset", new OnClickListener() {
+                       @Override
+                               public void onClick(View arg0) {
+                               for(PredefinedMap map : world.maps.predefinedMaps) {
+                                       map.lastVisitTime = 1;
+                                       map.resetIfNotRecentlyVisited();
+                               }
+                               mainActivity.showToast("DEBUG: maps respawned", Toast.LENGTH_SHORT);
+                               }
+                       })
 +                      ,new DebugButton("hp", new OnClickListener() {
                        @Override
                                public void onClick(View arg0) {
 -                              world.model.player.traits.maxHP = 200;
 -                              world.model.player.health.max = world.model.player.traits.maxHP;
 +                              world.model.player.actorTraits.maxHP = 200;
 +                              world.model.player.health.max = world.model.player.actorTraits.maxHP;
                                world.model.player.health.setMax();
                                world.model.player.conditions.clear();
                                mainActivity.updateStatus();
index 59b84154ffc49c28b88b42fd605f3ff94a2f9bb5,49c61185e2bcfc69bfc172aa0dfbaf4285808e28..03f9a85462e0baa3ef658b363762b7523a7c8032
@@@ -21,8 -19,6 +21,7 @@@ import com.gpl.rpg.AndorsTrail.model.ac
  import com.gpl.rpg.AndorsTrail.model.actor.Player;
  import com.gpl.rpg.AndorsTrail.model.item.ItemContainer;
  import com.gpl.rpg.AndorsTrail.model.item.ItemType;
- import com.gpl.rpg.AndorsTrail.model.item.Loot;
 +import com.gpl.rpg.AndorsTrail.resource.tiles.TileCollection;
  import com.gpl.rpg.AndorsTrail.view.ShopItemContainerAdapter;
  import com.gpl.rpg.AndorsTrail.view.ShopItemContainerAdapter.OnContainerItemClickedListener;
  
@@@ -70,17 -63,22 +69,15 @@@ public final class ShopActivity extend
          shoplist_buy = (ListView) h.findViewById(R.id.shop_buy_list);
          shoplist_sell = (ListView) h.findViewById(R.id.shop_sell_list);
          
-         Loot merchantLoot = new Loot();
-         npc.dropList.createRandomLoot(merchantLoot, player);
-         container_buy = merchantLoot.items;
+         container_buy = npc.getShopItems(player);
          
 -              shoplist_buy.setAdapter(new ShopItemContainerAdapter(
 -                              this
 -                              , world.tileStore
 -                              , player
 -                              , container_buy
 -                              , this
 -                              , false));
 -        shoplist_sell.setAdapter(new ShopItemContainerAdapter(
 -                      this
 -                      , world.tileStore
 -                      , player
 -                              , player.inventory
 -                      , this
 -                      , true));
 +        HashSet<Integer> iconIDs = world.tileManager.getTileIDsFor(container_buy);
 +        iconIDs.addAll(world.tileManager.getTileIDsFor(player.inventory));
 +        TileCollection tiles = world.tileManager.loadTilesFor(iconIDs, res);
 +        buyListAdapter = new ShopItemContainerAdapter(this, tiles, world.tileManager, player, container_buy, this, false);
 +        sellListAdapter = new ShopItemContainerAdapter(this, tiles, world.tileManager, player, player.inventory, this, true);
 +              shoplist_buy.setAdapter(buyListAdapter);
 +        shoplist_sell.setAdapter(sellListAdapter);
          
          update();
      }
index c4e73ea707b778d218515dfc18edccd0458861c6,06d2143e9197038e6511a73221e485f6d0043cb7..e35c2340b7244609b4aefaa32603be7e1f83ab3a
@@@ -24,11 -25,10 +25,12 @@@ public final class Monster extends Acto
        public final String phraseID;
        public final int exp;
        public final DropList dropList;
 +      public final String faction;
+       private ItemContainer shopItems = null;
 +      public final int monsterClass;
        
        public Monster(MonsterType monsterType, Coord position) {
 -              super(monsterType, false);
 +              super(monsterType, false, monsterType.isImmuneToCriticalHits());
                this.monsterTypeID = monsterType.id;
                this.position.set(position);
                this.millisecondsPerMove = Constants.MONSTER_MOVEMENT_TURN_DURATION_MS / monsterType.getMovesPerTurn();
                        monsterTypeId = monsterTypeId.replace(' ', '_').replace("\\'", "").toLowerCase();
                }
                MonsterType monsterType = world.monsterTypes.getMonsterType(monsterTypeId);
 +              
 +              if (fileversion < 25) return readFromParcel_pre_v0610(src, fileversion, monsterType);
 +              
 +              return new Monster(src, world, fileversion, monsterType);
 +      }
 +
 +      public Monster(DataInputStream src, WorldContext world, int fileversion, MonsterType monsterType) throws IOException {
 +              super(src, world, fileversion, false, monsterType.isImmuneToCriticalHits(), monsterType);
 +              this.monsterTypeID = monsterType.id;
 +              this.millisecondsPerMove = Constants.MONSTER_MOVEMENT_TURN_DURATION_MS / monsterType.getMovesPerTurn();
 +              this.nextPosition = new CoordRect(new Coord(), actorTraits.tileSize);
 +              this.phraseID = monsterType.phraseID;
 +              this.exp = monsterType.exp;
 +              this.dropList = monsterType.dropList;
 +              this.forceAggressive = src.readBoolean();
 +              this.faction = monsterType.faction;
 +              this.monsterClass = monsterType.monsterClass;
++              if (fileversion >= 31) {
++                      if (src.readBoolean()) {
++                              this.shopItems = new ItemContainer(src, world, fileversion);
++                      }
++              }
 +      }
 +
 +      private static Monster readFromParcel_pre_v0610(DataInputStream src, int fileversion, MonsterType monsterType) throws IOException {
                Coord position = new Coord(src, fileversion);
                Monster m = new Monster(monsterType, position);
                m.ap.current = src.readInt();
                if (fileversion >= 12) {
                        m.forceAggressive = src.readBoolean();
                }
 -              
 -              if (fileversion >= 25) {
 -                      if (src.readBoolean()) {
 -                              m.shopItems = new ItemContainer(src, world, fileversion);
 -                      }
 -              }
                return m;
        }
 -      
 +
        public void writeToParcel(DataOutputStream dest, int flags) throws IOException {
                dest.writeUTF(monsterTypeID);
 -              position.writeToParcel(dest, flags);
 -              dest.writeInt(ap.current);
 -              dest.writeInt(health.current);
 +              super.writeToParcel(dest, flags);
                dest.writeBoolean(forceAggressive);
+               if (shopItems != null) {
+                       dest.writeBoolean(true);
+                       shopItems.writeToParcel(dest, flags);
+               } else {
+                       dest.writeBoolean(false);
+               }
        }
  }
index 0b70cef99038690380ab39d163cee94ed4d5b007,8198198e83801318a18e6a75a88f79962514f002..5a1a5bc1664bf28980da94e8cab2d4a0b78aca30
@@@ -232,9 -223,9 +232,10 @@@ public final class PredefinedMap 
                
                // We reset all non-unique spawn areas. This keeps the savegame file smaller, thus reducing load and save times. Also keeps the running memory usage slightly lower.
                for(MonsterSpawnArea a : spawnAreas) {
-                       if (!a.isUnique) a.reset();
+                       if (a.isUnique) a.resetShops();
+                       else a.reset();
                }
 +              splatters.clear();
                lastVisitTime = VISIT_RESET;
        }