Merging 1.7.5 Source: actors/buffs changes

This commit is contained in:
Evan Debenham 2015-01-30 17:16:05 -05:00
parent d50c566579
commit 9e79aab869
8 changed files with 82 additions and 38 deletions

View File

@ -56,19 +56,29 @@ public class Buff extends Actor {
public int icon() {
return BuffIndicator.NONE;
}
public static<T extends Buff> T append( Char target, Class<T> buffClass ) {
try {
T buff = buffClass.newInstance();
buff.attachTo( target );
return buff;
} catch (Exception e) {
return null;
}
}
public static<T extends FlavourBuff> T append( Char target, Class<T> buffClass, float duration ) {
T buff = append( target, buffClass );
buff.spend( duration );
return buff;
}
public static<T extends Buff> T affect( Char target, Class<T> buffClass ) {
T buff = target.buff( buffClass );
if (buff != null) {
return buff;
} else {
try {
buff = buffClass.newInstance();
buff.attachTo( target );
return buff;
} catch (Exception e) {
return null;
}
return append( target, buffClass );
}
}

View File

@ -20,25 +20,26 @@ package com.shatteredpixel.shatteredpixeldungeon.actors.buffs;
import com.shatteredpixel.shatteredpixeldungeon.actors.Char;
import com.shatteredpixel.shatteredpixeldungeon.items.rings.RingOfElements.Resistance;
import com.shatteredpixel.shatteredpixeldungeon.ui.BuffIndicator;
import com.watabou.utils.Bundle;
public class Charm extends FlavourBuff {
public int object = 0;
private static final String OBJECT = "object";
@Override
public boolean attachTo( Char target ) {
if (super.attachTo( target )) {
target.pacified = true;
return true;
} else {
return false;
}
public void storeInBundle( Bundle bundle ) {
super.storeInBundle( bundle );
bundle.put( OBJECT, object );
}
@Override
public void detach() {
target.pacified = false;
super.detach();
public void restoreFromBundle( Bundle bundle ) {
super.restoreFromBundle( bundle );
object = bundle.getInt( OBJECT );
}
@Override
public int icon() {
return BuffIndicator.HEART;

View File

@ -17,7 +17,7 @@
*/
package com.shatteredpixel.shatteredpixeldungeon.actors.buffs;
//Special kind of buff, that doesn't perform any kind actions
//buff which does not need to act, used as a flag for other logic.
public class FlavourBuff extends Buff {
@Override

View File

@ -56,8 +56,8 @@ public class Frost extends FlavourBuff {
@Override
public void detach() {
target.paralysed = false;
super.detach();
Paralysis.unfreeze( target );
}
@Override

View File

@ -29,7 +29,6 @@ public class Light extends FlavourBuff {
@Override
public boolean attachTo( Char target ) {
if (super.attachTo( target )) {
// When a level is loading, do nothing
if (Dungeon.level != null) {
target.viewDistance = Math.max( Dungeon.level.viewDistance, DISTANCE );
Dungeon.observe();

View File

@ -37,8 +37,8 @@ public class Paralysis extends FlavourBuff {
@Override
public void detach() {
target.paralysed = false;
super.detach();
unfreeze(target);
}
@Override
@ -55,4 +55,12 @@ public class Paralysis extends FlavourBuff {
Resistance r = ch.buff( Resistance.class );
return r != null ? r.durationFactor() * DURATION : DURATION;
}
public static void unfreeze( Char ch ) {
if (ch.buff( Paralysis.class ) == null &&
ch.buff( Frost.class ) == null) {
ch.paralysed = false;
}
}
}

View File

@ -18,9 +18,28 @@
package com.shatteredpixel.shatteredpixeldungeon.actors.buffs;
import com.shatteredpixel.shatteredpixeldungeon.ui.BuffIndicator;
import com.watabou.utils.Bundle;
//TODO: consider refactoring this
public class SnipersMark extends FlavourBuff {
public int object = 0;
private static final String OBJECT = "object";
@Override
public void storeInBundle( Bundle bundle ) {
super.storeInBundle( bundle );
bundle.put( OBJECT, object );
}
@Override
public void restoreFromBundle( Bundle bundle ) {
super.restoreFromBundle( bundle );
object = bundle.getInt( OBJECT );
}
@Override
public int icon() {
return BuffIndicator.MARK;
@ -28,6 +47,6 @@ public class SnipersMark extends FlavourBuff {
@Override
public String toString() {
return "Sniper's mark";
return "Zeroed in";
}
}

View File

@ -17,7 +17,6 @@
*/
package com.shatteredpixel.shatteredpixeldungeon.actors.buffs;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.actors.Char;
import com.shatteredpixel.shatteredpixeldungeon.ui.BuffIndicator;
import com.watabou.utils.Bundle;
@ -25,20 +24,28 @@ import com.watabou.utils.Bundle;
public class Terror extends FlavourBuff {
public static final float DURATION = 10f;
public Char source;
public int object = 0;
private static final String OBJECT = "object";
@Override
public void storeInBundle( Bundle bundle ) {
super.storeInBundle(bundle);
bundle.put(OBJECT, object);
}
@Override
public void restoreFromBundle( Bundle bundle ) {
super.restoreFromBundle( bundle );
object = bundle.getInt( OBJECT );
}
@Override
public int icon() {
return BuffIndicator.TERROR;
}
@Override
public void restoreFromBundle( Bundle bundle ) {
super.restoreFromBundle( bundle );
// It's not really correct...
source = Dungeon.hero;
}
@Override
public String toString() {
return "Terror";