v3.0.0: refactored cleric spells to better support variable functions
This commit is contained in:
@@ -21,54 +21,21 @@
|
||||
|
||||
package com.shatteredpixel.shatteredpixeldungeon.actors.hero.spells;
|
||||
|
||||
import com.shatteredpixel.shatteredpixeldungeon.actors.Char;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.items.artifacts.HolyTome;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.mechanics.Ballistica;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.scenes.CellSelector;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.ui.HeroIcon;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public abstract class ClericSpell {
|
||||
|
||||
public void use(HolyTome tome, Hero hero ){
|
||||
if (targetingPrompt() == null){
|
||||
activate(tome, hero, hero.pos);
|
||||
} else {
|
||||
GameScene.selectCell(new CellSelector.Listener() {
|
||||
@Override
|
||||
public void onSelect(Integer cell) {
|
||||
activate(tome, hero, cell);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String prompt() {
|
||||
return targetingPrompt();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
//leave null for no targeting
|
||||
public String targetingPrompt(){
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean useTargeting(){
|
||||
return targetingPrompt() != null;
|
||||
}
|
||||
|
||||
public int targetedPos(Char user, int dst ){
|
||||
return new Ballistica( user.pos, dst, Ballistica.PROJECTILE ).collisionPos;
|
||||
}
|
||||
public abstract void onCast(HolyTome tome, Hero hero );
|
||||
|
||||
public float chargeUse( Hero hero ){
|
||||
return 1;
|
||||
}
|
||||
|
||||
protected abstract void activate( HolyTome tome, Hero hero, Integer target );
|
||||
|
||||
public String name(){
|
||||
return Messages.get(this, "name");
|
||||
}
|
||||
@@ -85,4 +52,14 @@ public abstract class ClericSpell {
|
||||
return HeroIcon.NONE;
|
||||
}
|
||||
|
||||
public static ArrayList<ClericSpell> getSpellList(Hero cleric){
|
||||
ArrayList<ClericSpell> spells = new ArrayList<>();
|
||||
|
||||
spells.add(GuidingLight.INSTANCE);
|
||||
spells.add(HolyWeapon.INSTANCE);
|
||||
spells.add(HolyWard.INSTANCE);
|
||||
|
||||
return spells;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -38,9 +38,9 @@ import com.watabou.noosa.audio.Sample;
|
||||
import com.watabou.utils.Callback;
|
||||
import com.watabou.utils.Random;
|
||||
|
||||
public class GuidingLight extends ClericSpell {
|
||||
public class GuidingLight extends TargetedClericSpell {
|
||||
|
||||
public static GuidingLight INSTANCE = new GuidingLight();
|
||||
public static final GuidingLight INSTANCE = new GuidingLight();
|
||||
|
||||
@Override
|
||||
public int icon() {
|
||||
@@ -48,12 +48,7 @@ public class GuidingLight extends ClericSpell {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String targetingPrompt() {
|
||||
return Messages.get(this, "prompt");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void activate(HolyTome tome, Hero hero, Integer target) {
|
||||
protected void onTargetSelected(HolyTome tome, Hero hero, Integer target) {
|
||||
if (target == null){
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ import com.watabou.noosa.audio.Sample;
|
||||
|
||||
public class HolyWard extends ClericSpell {
|
||||
|
||||
public static HolyWard INSTANCE = new HolyWard();
|
||||
public static final HolyWard INSTANCE = new HolyWard();
|
||||
|
||||
@Override
|
||||
public int icon() {
|
||||
@@ -41,7 +41,7 @@ public class HolyWard extends ClericSpell {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void activate(HolyTome tome, Hero hero, Integer target) {
|
||||
public void onCast(HolyTome tome, Hero hero) {
|
||||
|
||||
Buff.affect(hero, HolyArmBuff.class, 50f);
|
||||
Item.updateQuickslot();
|
||||
|
||||
@@ -33,7 +33,7 @@ import com.watabou.noosa.audio.Sample;
|
||||
|
||||
public class HolyWeapon extends ClericSpell {
|
||||
|
||||
public static HolyWeapon INSTANCE = new HolyWeapon();
|
||||
public static final HolyWeapon INSTANCE = new HolyWeapon();
|
||||
|
||||
@Override
|
||||
public int icon() {
|
||||
@@ -46,7 +46,7 @@ public class HolyWeapon extends ClericSpell {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void activate(HolyTome tome, Hero hero, Integer target) {
|
||||
public void onCast(HolyTome tome, Hero hero) {
|
||||
|
||||
Buff.affect(hero, HolyWepBuff.class, 50f);
|
||||
Item.updateQuickslot();
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Pixel Dungeon
|
||||
* Copyright (C) 2012-2015 Oleg Dolya
|
||||
*
|
||||
* Shattered Pixel Dungeon
|
||||
* Copyright (C) 2014-2024 Evan Debenham
|
||||
*
|
||||
* 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.actors.hero.spells;
|
||||
|
||||
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.items.Item;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.items.artifacts.HolyTome;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.items.bags.Bag;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.windows.WndBag;
|
||||
|
||||
public abstract class InventoryClericSpell extends ClericSpell {
|
||||
|
||||
@Override
|
||||
public void onCast(HolyTome tome, Hero hero) {
|
||||
GameScene.selectItem(new WndBag.ItemSelector() {
|
||||
|
||||
@Override
|
||||
public String textPrompt() {
|
||||
return inventoryPrompt();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<? extends Bag> preferredBag() {
|
||||
return InventoryClericSpell.this.preferredBag();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean itemSelectable(Item item) {
|
||||
return usableOnItem(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSelect(Item item) {
|
||||
onItemSelected(tome, hero, item);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected String inventoryPrompt(){
|
||||
return Messages.get(this, "prompt");
|
||||
}
|
||||
|
||||
protected Class<? extends Bag> preferredBag() {
|
||||
return null; //defaults to no preference
|
||||
}
|
||||
|
||||
protected boolean usableOnItem( Item item ){
|
||||
return true;
|
||||
}
|
||||
|
||||
protected abstract void onItemSelected( HolyTome tome, Hero hero, Item item );
|
||||
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Pixel Dungeon
|
||||
* Copyright (C) 2012-2015 Oleg Dolya
|
||||
*
|
||||
* Shattered Pixel Dungeon
|
||||
* Copyright (C) 2014-2024 Evan Debenham
|
||||
*
|
||||
* 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.actors.hero.spells;
|
||||
|
||||
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.items.artifacts.HolyTome;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.scenes.CellSelector;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
|
||||
|
||||
public abstract class TargetedClericSpell extends ClericSpell {
|
||||
|
||||
@Override
|
||||
public void onCast(HolyTome tome, Hero hero ){
|
||||
GameScene.selectCell(new CellSelector.Listener() {
|
||||
@Override
|
||||
public void onSelect(Integer cell) {
|
||||
onTargetSelected(tome, hero, cell);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String prompt() {
|
||||
return targetingPrompt();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected String targetingPrompt(){
|
||||
return Messages.get(this, "prompt");
|
||||
}
|
||||
|
||||
protected abstract void onTargetSelected(HolyTome tome, Hero hero, Integer target);
|
||||
|
||||
}
|
||||
@@ -25,9 +25,7 @@ import com.shatteredpixel.shatteredpixeldungeon.Chrome;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.spells.ClericSpell;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.spells.GuidingLight;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.spells.HolyWard;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.spells.HolyWeapon;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.spells.TargetedClericSpell;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.items.artifacts.HolyTome;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
|
||||
import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
|
||||
@@ -72,11 +70,7 @@ public class WndClericSpells extends Window {
|
||||
msg.setPos(0, title.bottom()+4);
|
||||
add(msg);
|
||||
|
||||
//TODO build spell list
|
||||
ArrayList<ClericSpell> spells = new ArrayList<>();
|
||||
spells.add(GuidingLight.INSTANCE);
|
||||
spells.add(HolyWeapon.INSTANCE);
|
||||
spells.add(HolyWard.INSTANCE);
|
||||
ArrayList<ClericSpell> spells = ClericSpell.getSpellList(cleric);
|
||||
|
||||
ArrayList<IconButton> spellBtns = new ArrayList<>();
|
||||
|
||||
@@ -139,10 +133,10 @@ public class WndClericSpells extends Window {
|
||||
GameScene.show(new WndTitledMessage(new HeroIcon(spell), Messages.titleCase(spell.name()), spell.desc()));
|
||||
} else {
|
||||
hide();
|
||||
spell.use(tome, Dungeon.hero);
|
||||
spell.onCast(tome, Dungeon.hero);
|
||||
|
||||
//TODO, probably need targeting logic here
|
||||
if (spell.useTargeting() && Dungeon.quickslot.contains(tome)){
|
||||
if (spell instanceof TargetedClericSpell && Dungeon.quickslot.contains(tome)){
|
||||
QuickSlotButton.useTargeting(Dungeon.quickslot.getSlot(tome));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user