Magic_Ling_Pixel_Dungeon/src/com/shatteredpixel/shatteredpixeldungeon/items/DewVial.java

164 lines
3.9 KiB
Java
Raw Normal View History

2014-07-27 13:39:07 +00:00
/*
* Pixel Dungeon
2015-06-12 20:44:04 +00:00
* Copyright (C) 2012-2015 Oleg Dolya
*
* Shattered Pixel Dungeon
* Copyright (C) 2014-2015 Evan Debenham
2014-07-27 13:39:07 +00:00
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
package com.shatteredpixel.shatteredpixeldungeon.items;
2014-07-27 13:39:07 +00:00
import com.shatteredpixel.shatteredpixeldungeon.Assets;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.HeroClass;
import com.shatteredpixel.shatteredpixeldungeon.effects.Speck;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.sprites.CharSprite;
import com.shatteredpixel.shatteredpixeldungeon.sprites.ItemSpriteSheet;
import com.shatteredpixel.shatteredpixeldungeon.utils.GLog;
import com.watabou.noosa.audio.Sample;
2014-07-27 13:39:07 +00:00
import com.watabou.utils.Bundle;
import java.util.ArrayList;
2014-07-27 13:39:07 +00:00
public class DewVial extends Item {
private static final int MAX_VOLUME = 10;
2014-08-13 04:24:18 +00:00
2014-07-27 13:39:07 +00:00
private static final String AC_DRINK = "DRINK";
2014-08-13 04:24:18 +00:00
2014-07-27 13:39:07 +00:00
private static final float TIME_TO_DRINK = 1f;
2014-08-13 04:24:18 +00:00
2014-07-27 13:39:07 +00:00
private static final String TXT_STATUS = "%d/%d";
2014-08-13 04:24:18 +00:00
2014-07-27 13:39:07 +00:00
{
image = ItemSpriteSheet.VIAL;
2014-08-13 04:24:18 +00:00
2014-07-27 13:39:07 +00:00
defaultAction = AC_DRINK;
2014-08-13 04:24:18 +00:00
2014-07-27 13:39:07 +00:00
unique = true;
}
2014-08-13 04:24:18 +00:00
2014-07-27 13:39:07 +00:00
private int volume = 0;
2014-08-13 04:24:18 +00:00
2014-07-27 13:39:07 +00:00
private static final String VOLUME = "volume";
2014-08-13 04:24:18 +00:00
2014-07-27 13:39:07 +00:00
@Override
public void storeInBundle( Bundle bundle ) {
super.storeInBundle( bundle );
bundle.put( VOLUME, volume );
}
2014-08-13 04:24:18 +00:00
2014-07-27 13:39:07 +00:00
@Override
public void restoreFromBundle( Bundle bundle ) {
super.restoreFromBundle( bundle );
volume = bundle.getInt( VOLUME );
}
2014-08-13 04:24:18 +00:00
2014-07-27 13:39:07 +00:00
@Override
public ArrayList<String> actions( Hero hero ) {
ArrayList<String> actions = super.actions( hero );
if (volume > 0) {
actions.add( AC_DRINK );
}
return actions;
}
2014-08-13 04:24:18 +00:00
2014-07-27 13:39:07 +00:00
@Override
public void execute( final Hero hero, String action ) {
if (action.equals( AC_DRINK )) {
2014-08-13 04:24:18 +00:00
2014-07-27 13:39:07 +00:00
if (volume > 0) {
int value = 1 + (Dungeon.depth - 1) / 5;
if (hero.heroClass == HeroClass.HUNTRESS) {
value++;
}
value *= volume;
value = (int)Math.max(volume*volume*.01*hero.HT, value);
2014-07-27 13:39:07 +00:00
int effect = Math.min( hero.HT - hero.HP, value );
if (effect > 0) {
hero.HP += effect;
hero.sprite.emitter().burst( Speck.factory( Speck.HEALING ), volume > 5 ? 2 : 1 );
2016-01-04 00:43:24 +00:00
hero.sprite.showStatus( CharSprite.POSITIVE, Messages.get(this, "value", effect) );
2014-07-27 13:39:07 +00:00
}
2014-08-13 04:24:18 +00:00
volume = 0;
2014-08-13 04:24:18 +00:00
2014-07-27 13:39:07 +00:00
hero.spend( TIME_TO_DRINK );
hero.busy();
2014-08-13 04:24:18 +00:00
2014-07-27 13:39:07 +00:00
Sample.INSTANCE.play( Assets.SND_DRINK );
hero.sprite.operate( hero.pos );
2014-08-13 04:24:18 +00:00
updateQuickslot();
2014-08-13 04:24:18 +00:00
2014-07-27 13:39:07 +00:00
} else {
2016-01-04 00:43:24 +00:00
GLog.w( Messages.get(this, "empty") );
2014-07-27 13:39:07 +00:00
}
2014-08-13 04:24:18 +00:00
2014-07-27 13:39:07 +00:00
} else {
2014-08-13 04:24:18 +00:00
2014-07-27 13:39:07 +00:00
super.execute( hero, action );
2014-08-13 04:24:18 +00:00
2014-07-27 13:39:07 +00:00
}
}
2014-08-13 04:24:18 +00:00
public void empty() {volume = 0; updateQuickslot();}
2014-08-13 04:24:18 +00:00
2014-07-27 13:39:07 +00:00
@Override
public boolean isUpgradable() {
return false;
}
2014-08-13 04:24:18 +00:00
2014-07-27 13:39:07 +00:00
@Override
public boolean isIdentified() {
return true;
}
2014-08-13 04:24:18 +00:00
2014-07-27 13:39:07 +00:00
public boolean isFull() {
return volume >= MAX_VOLUME;
}
2014-08-13 04:24:18 +00:00
2014-07-27 13:39:07 +00:00
public void collectDew( Dewdrop dew ) {
2014-08-13 04:24:18 +00:00
2016-01-04 00:43:24 +00:00
GLog.i( Messages.get(this, "collected") );
2014-07-27 13:39:07 +00:00
volume += dew.quantity;
if (volume >= MAX_VOLUME) {
volume = MAX_VOLUME;
2016-01-04 00:43:24 +00:00
GLog.p( Messages.get(this, "full") );
2014-07-27 13:39:07 +00:00
}
2014-08-13 04:24:18 +00:00
updateQuickslot();
2014-07-27 13:39:07 +00:00
}
2014-08-13 04:24:18 +00:00
2014-07-27 13:39:07 +00:00
public void fill() {
volume = MAX_VOLUME;
updateQuickslot();
2014-07-27 13:39:07 +00:00
}
2014-08-13 04:24:18 +00:00
2014-07-27 13:39:07 +00:00
@Override
public String status() {
return Messages.format( TXT_STATUS, volume, MAX_VOLUME );
2014-07-27 13:39:07 +00:00
}
@Override
public String toString() {
return super.toString() + " (" + status() + ")" ;
}
}