v3.3.0: beacon of returning now uses a buff for tracking properties
This commit is contained in:
@@ -54,7 +54,7 @@ public class ScrollHolder extends Bag {
|
|||||||
public void onDetach( ) {
|
public void onDetach( ) {
|
||||||
super.onDetach();
|
super.onDetach();
|
||||||
for (Item item : items) {
|
for (Item item : items) {
|
||||||
if (item instanceof BeaconOfReturning) {
|
if (item instanceof BeaconOfReturning && ((BeaconOfReturning) item).returnDepth != -1) {
|
||||||
Notes.remove(Notes.Landmark.BEACON_LOCATION, ((BeaconOfReturning) item).returnDepth);
|
Notes.remove(Notes.Landmark.BEACON_LOCATION, ((BeaconOfReturning) item).returnDepth);
|
||||||
((BeaconOfReturning) item).returnDepth = -1;
|
((BeaconOfReturning) item).returnDepth = -1;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ import com.shatteredpixel.shatteredpixeldungeon.Assets;
|
|||||||
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
|
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.actors.Actor;
|
import com.shatteredpixel.shatteredpixeldungeon.actors.Actor;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.actors.Char;
|
import com.shatteredpixel.shatteredpixeldungeon.actors.Char;
|
||||||
|
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Buff;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Invisibility;
|
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Invisibility;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero;
|
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Talent;
|
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Talent;
|
||||||
@@ -56,6 +57,9 @@ public class BeaconOfReturning extends Spell {
|
|||||||
|
|
||||||
talentChance = 1/(float)Recipe.OUT_QUANTITY;
|
talentChance = 1/(float)Recipe.OUT_QUANTITY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//This class has a variety of code for compat with pre-v3.3.0 saves
|
||||||
|
//Previously the destination was an item property, but in 3.3.0 this was changed to use a buff
|
||||||
|
|
||||||
public int returnDepth = -1;
|
public int returnDepth = -1;
|
||||||
public int returnBranch = 0;
|
public int returnBranch = 0;
|
||||||
@@ -63,8 +67,10 @@ public class BeaconOfReturning extends Spell {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCast(final Hero hero) {
|
protected void onCast(final Hero hero) {
|
||||||
|
|
||||||
if (returnDepth == -1){
|
BeaconTracker tracker = hero.buff(BeaconTracker.class);
|
||||||
|
|
||||||
|
if (tracker == null && returnDepth == -1){
|
||||||
setBeacon(hero);
|
setBeacon(hero);
|
||||||
} else {
|
} else {
|
||||||
GameScene.show(new WndOptions(new ItemSprite(this),
|
GameScene.show(new WndOptions(new ItemSprite(this),
|
||||||
@@ -90,17 +96,21 @@ public class BeaconOfReturning extends Spell {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onThrow(int cell) {
|
protected void onThrow(int cell) {
|
||||||
if (Dungeon.hero.belongings.getItem(getClass()) == null){
|
if (returnDepth != -1) {
|
||||||
Notes.remove(Notes.Landmark.BEACON_LOCATION, returnDepth);
|
if (Dungeon.hero.belongings.getItem(getClass()) == null) {
|
||||||
|
Notes.remove(Notes.Landmark.BEACON_LOCATION, returnDepth);
|
||||||
|
}
|
||||||
|
returnDepth = -1;
|
||||||
}
|
}
|
||||||
returnDepth = -1;
|
|
||||||
super.onThrow(cell);
|
super.onThrow(cell);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void doDrop(Hero hero) {
|
public void doDrop(Hero hero) {
|
||||||
Notes.remove(Notes.Landmark.BEACON_LOCATION, returnDepth);
|
if (returnDepth != -1) {
|
||||||
returnDepth = -1;
|
Notes.remove(Notes.Landmark.BEACON_LOCATION, returnDepth);
|
||||||
|
returnDepth = -1;
|
||||||
|
}
|
||||||
super.doDrop(hero);
|
super.doDrop(hero);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -108,12 +118,17 @@ public class BeaconOfReturning extends Spell {
|
|||||||
if (returnDepth != -1){
|
if (returnDepth != -1){
|
||||||
Notes.remove(Notes.Landmark.BEACON_LOCATION, returnDepth);
|
Notes.remove(Notes.Landmark.BEACON_LOCATION, returnDepth);
|
||||||
}
|
}
|
||||||
|
if (hero.buff(BeaconTracker.class) != null){
|
||||||
|
Notes.remove(Notes.Landmark.BEACON_LOCATION,
|
||||||
|
hero.buff(BeaconTracker.class).returnDepth);
|
||||||
|
}
|
||||||
|
|
||||||
returnDepth = Dungeon.depth;
|
BeaconTracker tracker = Buff.affect(hero, BeaconTracker.class);
|
||||||
returnBranch = Dungeon.branch;
|
tracker.returnDepth = Dungeon.depth;
|
||||||
returnPos = hero.pos;
|
tracker.returnBranch = Dungeon.branch;
|
||||||
|
tracker.returnPos = hero.pos;
|
||||||
|
|
||||||
Notes.add(Notes.Landmark.BEACON_LOCATION, returnDepth);
|
Notes.add(Notes.Landmark.BEACON_LOCATION, tracker.returnDepth);
|
||||||
|
|
||||||
hero.spend( 1f );
|
hero.spend( 1f );
|
||||||
hero.busy();
|
hero.busy();
|
||||||
@@ -126,16 +141,28 @@ public class BeaconOfReturning extends Spell {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void returnBeacon( Hero hero ){
|
private void returnBeacon( Hero hero ){
|
||||||
|
|
||||||
if (returnDepth == Dungeon.depth && returnBranch == Dungeon.branch) {
|
|
||||||
|
|
||||||
Char existing = Actor.findChar(returnPos);
|
BeaconTracker tracker = hero.buff(BeaconTracker.class);
|
||||||
|
|
||||||
|
if (tracker == null){
|
||||||
|
if (returnDepth == -1){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
tracker = new BeaconTracker();
|
||||||
|
tracker.returnDepth = returnDepth;
|
||||||
|
tracker.returnBranch = returnBranch;
|
||||||
|
tracker.returnPos = returnPos;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tracker.returnDepth == Dungeon.depth && tracker.returnBranch == Dungeon.branch) {
|
||||||
|
|
||||||
|
Char existing = Actor.findChar(tracker.returnPos);
|
||||||
if (existing != null && existing != hero){
|
if (existing != null && existing != hero){
|
||||||
Char toPush = Char.hasProp(existing, Char.Property.IMMOVABLE) ? hero : existing;
|
Char toPush = Char.hasProp(existing, Char.Property.IMMOVABLE) ? hero : existing;
|
||||||
|
|
||||||
ArrayList<Integer> candidates = new ArrayList<>();
|
ArrayList<Integer> candidates = new ArrayList<>();
|
||||||
for (int n : PathFinder.NEIGHBOURS8) {
|
for (int n : PathFinder.NEIGHBOURS8) {
|
||||||
int cell = returnPos + n;
|
int cell = tracker.returnPos + n;
|
||||||
if (!Dungeon.level.solid[cell] && Actor.findChar( cell ) == null
|
if (!Dungeon.level.solid[cell] && Actor.findChar( cell ) == null
|
||||||
&& (!Char.hasProp(toPush, Char.Property.LARGE) || Dungeon.level.openSpace[cell])) {
|
&& (!Char.hasProp(toPush, Char.Property.LARGE) || Dungeon.level.openSpace[cell])) {
|
||||||
candidates.add( cell );
|
candidates.add( cell );
|
||||||
@@ -145,7 +172,7 @@ public class BeaconOfReturning extends Spell {
|
|||||||
|
|
||||||
if (!candidates.isEmpty()){
|
if (!candidates.isEmpty()){
|
||||||
if (toPush == hero){
|
if (toPush == hero){
|
||||||
returnPos = candidates.get(0);
|
tracker.returnPos = candidates.get(0);
|
||||||
} else {
|
} else {
|
||||||
Actor.add( new Pushing( toPush, toPush.pos, candidates.get(0) ) );
|
Actor.add( new Pushing( toPush, toPush.pos, candidates.get(0) ) );
|
||||||
toPush.pos = candidates.get(0);
|
toPush.pos = candidates.get(0);
|
||||||
@@ -171,7 +198,7 @@ public class BeaconOfReturning extends Spell {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//cannot return to mining level
|
//cannot return to mining level
|
||||||
if (returnDepth >= 11 && returnDepth <= 14 && returnBranch == 1){
|
if (tracker.returnDepth >= 11 && tracker.returnDepth <= 14 && tracker.returnBranch == 1){
|
||||||
GLog.w( Messages.get(ScrollOfTeleportation.class, "no_tele") );
|
GLog.w( Messages.get(ScrollOfTeleportation.class, "no_tele") );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -179,13 +206,14 @@ public class BeaconOfReturning extends Spell {
|
|||||||
Level.beforeTransition();
|
Level.beforeTransition();
|
||||||
Invisibility.dispel();
|
Invisibility.dispel();
|
||||||
InterlevelScene.mode = InterlevelScene.Mode.RETURN;
|
InterlevelScene.mode = InterlevelScene.Mode.RETURN;
|
||||||
InterlevelScene.returnDepth = returnDepth;
|
InterlevelScene.returnDepth = tracker.returnDepth;
|
||||||
InterlevelScene.returnBranch = returnBranch;
|
InterlevelScene.returnBranch = tracker.returnBranch;
|
||||||
InterlevelScene.returnPos = returnPos;
|
InterlevelScene.returnPos = tracker.returnPos;
|
||||||
Game.switchScene( InterlevelScene.class );
|
Game.switchScene( InterlevelScene.class );
|
||||||
}
|
}
|
||||||
if (quantity == 1){
|
if (quantity == 1){
|
||||||
Notes.remove(Notes.Landmark.BEACON_LOCATION, returnDepth);
|
Notes.remove(Notes.Landmark.BEACON_LOCATION, tracker.returnDepth);
|
||||||
|
if (tracker.target != null) tracker.detach();
|
||||||
}
|
}
|
||||||
detach(hero.belongings.backpack);
|
detach(hero.belongings.backpack);
|
||||||
Catalog.countUse(getClass());
|
Catalog.countUse(getClass());
|
||||||
@@ -197,8 +225,13 @@ public class BeaconOfReturning extends Spell {
|
|||||||
@Override
|
@Override
|
||||||
public String desc() {
|
public String desc() {
|
||||||
String desc = super.desc();
|
String desc = super.desc();
|
||||||
if (returnDepth != -1){
|
if (Dungeon.hero != null) {
|
||||||
desc += "\n\n" + Messages.get(this, "desc_set", returnDepth);
|
BeaconTracker tracker = Dungeon.hero.buff(BeaconTracker.class);
|
||||||
|
if (tracker != null){
|
||||||
|
desc += "\n\n" + Messages.get(this, "desc_set", tracker.returnDepth);
|
||||||
|
} else if (returnDepth != -1) {
|
||||||
|
desc += "\n\n" + Messages.get(this, "desc_set", returnDepth);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return desc;
|
return desc;
|
||||||
}
|
}
|
||||||
@@ -257,4 +290,37 @@ public class BeaconOfReturning extends Spell {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class BeaconTracker extends Buff {
|
||||||
|
|
||||||
|
{
|
||||||
|
revivePersists = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int returnDepth = -1;
|
||||||
|
public int returnBranch = 0;
|
||||||
|
public int returnPos;
|
||||||
|
|
||||||
|
private static final String DEPTH = "depth";
|
||||||
|
private static final String BRANCH = "branch";
|
||||||
|
private static final String POS = "pos";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void storeInBundle( Bundle bundle ) {
|
||||||
|
super.storeInBundle( bundle );
|
||||||
|
bundle.put( DEPTH, returnDepth );
|
||||||
|
bundle.put( BRANCH, returnBranch );
|
||||||
|
if (returnDepth != -1) {
|
||||||
|
bundle.put( POS, returnPos );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void restoreFromBundle( Bundle bundle ) {
|
||||||
|
super.restoreFromBundle(bundle);
|
||||||
|
returnDepth = bundle.getInt( DEPTH );
|
||||||
|
returnBranch = bundle.getInt( BRANCH );
|
||||||
|
returnPos = bundle.getInt( POS );
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user