v0.2.3e: added backend support for multiple quickslots (needs testing!)
This commit is contained in:
@@ -39,7 +39,9 @@ public class Belongings implements Iterable<Item> {
|
||||
|
||||
private Hero owner;
|
||||
|
||||
public Bag backpack;
|
||||
public Bag backpack;
|
||||
|
||||
public QuickSlot quickslot;
|
||||
|
||||
public KindOfWeapon weapon = null;
|
||||
public Armor armor = null;
|
||||
@@ -69,6 +71,8 @@ public class Belongings implements Iterable<Item> {
|
||||
bundle.put( ARMOR, armor );
|
||||
bundle.put( MISC1, misc1);
|
||||
bundle.put( MISC2, misc2);
|
||||
|
||||
quickslot.storePlaceholders( bundle );
|
||||
}
|
||||
|
||||
public void restoreFromBundle( Bundle bundle ) {
|
||||
@@ -92,6 +96,8 @@ public class Belongings implements Iterable<Item> {
|
||||
if (misc2 != null) {
|
||||
misc2.activate( owner );
|
||||
}
|
||||
|
||||
quickslot.restorePlaceholders(bundle);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
||||
@@ -878,7 +878,7 @@ public class Hero extends Char {
|
||||
if (wand.curCharges < wand.maxCharges && damage > 0) {
|
||||
|
||||
wand.curCharges++;
|
||||
if (Dungeon.quickslot == wand) {
|
||||
if (belongings.quickslot.contains(wand)) {
|
||||
QuickSlot.refresh();
|
||||
}
|
||||
|
||||
|
||||
@@ -136,9 +136,10 @@ public enum HeroClass {
|
||||
hero.STR = hero.STR + 1;
|
||||
|
||||
(hero.belongings.weapon = new ShortSword()).identify();
|
||||
new Dart( 8 ).identify().collect();
|
||||
Dart darts = new Dart( 8 );
|
||||
darts.identify().collect();
|
||||
|
||||
Dungeon.quickslot = Dart.class;
|
||||
hero.belongings.quickslot.setSlot(0, darts);
|
||||
|
||||
new PotionOfStrength().setKnown();
|
||||
}
|
||||
@@ -149,7 +150,7 @@ public enum HeroClass {
|
||||
WandOfMagicMissile wand = new WandOfMagicMissile();
|
||||
wand.identify().collect();
|
||||
|
||||
Dungeon.quickslot = wand;
|
||||
hero.belongings.quickslot.setSlot(0, wand);
|
||||
|
||||
new ScrollOfIdentify().setKnown();
|
||||
}
|
||||
@@ -161,10 +162,11 @@ public enum HeroClass {
|
||||
(hero.belongings.misc1 = cloak).identify();
|
||||
hero.belongings.misc1.activate( hero );
|
||||
|
||||
new Dart( 8 ).identify().collect();
|
||||
Dart darts = new Dart( 8 );
|
||||
darts.identify().collect();
|
||||
|
||||
|
||||
Dungeon.quickslot = cloak;
|
||||
hero.belongings.quickslot.setSlot(0, cloak);
|
||||
hero.belongings.quickslot.setSlot(1, darts);
|
||||
|
||||
new ScrollOfMagicMapping().setKnown();
|
||||
}
|
||||
@@ -177,7 +179,7 @@ public enum HeroClass {
|
||||
Boomerang boomerang = new Boomerang();
|
||||
boomerang.identify().collect();
|
||||
|
||||
Dungeon.quickslot = boomerang;
|
||||
hero.belongings.quickslot.setSlot(0, boomerang);
|
||||
}
|
||||
|
||||
public String title() {
|
||||
|
||||
@@ -0,0 +1,107 @@
|
||||
package com.shatteredpixel.shatteredpixeldungeon.actors.hero;
|
||||
|
||||
import com.shatteredpixel.shatteredpixeldungeon.items.Item;
|
||||
import com.watabou.utils.Bundlable;
|
||||
import com.watabou.utils.Bundle;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
/**
|
||||
* Created by debenhame on 16/01/2015.
|
||||
*/
|
||||
public class QuickSlot {
|
||||
|
||||
/**
|
||||
* Slots contain objects which are also in a player's inventory.
|
||||
* The one exception to this is when quantity is 0, which can
|
||||
* happen for a stackable item that has been 'used up', these are refered to a placeholders.
|
||||
*/
|
||||
private ArrayList<Item> slots = new ArrayList<Item>();
|
||||
|
||||
public void setSlot(int slot, Item item){
|
||||
slots.set(slot, item);
|
||||
}
|
||||
|
||||
public Item getItem(int slot){
|
||||
return slots.get(slot);
|
||||
}
|
||||
|
||||
//TODO: this will currently only get the first occurance of an item, even if it's in multiple slots
|
||||
//perhaps do not allow duplicate items in quickslots.
|
||||
public int getSlot(Item item) {
|
||||
return slots.indexOf(item);
|
||||
}
|
||||
|
||||
public Boolean isPlaceholder(int slot){
|
||||
return slots.get(slot) != null && slots.get(slot).quantity() == 0;
|
||||
}
|
||||
|
||||
public void clearSlot(int slot){
|
||||
setSlot(slot, null);
|
||||
}
|
||||
|
||||
public void clearItem(Item item){
|
||||
for (int i = 0; i < slots.size(); i++)
|
||||
if (slots.get(i) == item)
|
||||
clearSlot(i);
|
||||
}
|
||||
|
||||
public void clear(){
|
||||
slots = new ArrayList<Item>();
|
||||
}
|
||||
|
||||
public boolean contains(Item item){
|
||||
return slots.contains(item);
|
||||
}
|
||||
|
||||
public void replaceSimilar(Item item){
|
||||
for (int i = 0; i < slots.size(); i++)
|
||||
if (item.isSimilar(slots.get(i)))
|
||||
setSlot( i , item );
|
||||
}
|
||||
|
||||
public void convertToPlaceholder(Item item){
|
||||
Item placeholder = Item.virtual(item.getClass());
|
||||
|
||||
if (placeholder != null && slots.contains(item))
|
||||
for (int i = 0; i < slots.size(); i++)
|
||||
if (slots.get(i) == item)
|
||||
setSlot( i , placeholder );
|
||||
}
|
||||
|
||||
private final String PLACEHOLDERS = "placeholders";
|
||||
private final String PLACEMENTS = "placements";
|
||||
|
||||
public void storePlaceholders(Bundle bundle){
|
||||
ArrayList<Item> placeholders = new ArrayList<Item>(slots.size());
|
||||
boolean[] placements = new boolean[slots.size()];
|
||||
|
||||
for (int i = 0; i < slots.size(); i++)
|
||||
if (isPlaceholder(i)) {
|
||||
placeholders.add(slots.get(i));
|
||||
placements[i] = true;
|
||||
}
|
||||
bundle.put( PLACEHOLDERS, placeholders );
|
||||
bundle.put( PLACEMENTS, placements );
|
||||
}
|
||||
|
||||
//placements array is used as order is preserved while bundling, but exact index is not, so if we
|
||||
//bundle both the placeholders (which preserves their order) an an array telling us where the placeholders are,
|
||||
//we can reconstruct them perfectly.
|
||||
|
||||
public void restorePlaceholders(Bundle bundle){
|
||||
Collection<Bundlable> placeholders = bundle.getCollection(PLACEHOLDERS);
|
||||
boolean[] placements = bundle.getBooleanArray( PLACEMENTS );
|
||||
|
||||
int i = 0;
|
||||
for (Bundlable item : placeholders){
|
||||
while (placements[i] == false) i++;
|
||||
setSlot( i, (Item)item );
|
||||
i++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user