v3.0.0: refactored cleric spells to better support variable functions

This commit is contained in:
Evan Debenham
2024-10-24 11:23:46 -04:00
parent ece5a7f3c4
commit 1a9310d368
7 changed files with 151 additions and 58 deletions

View File

@@ -21,54 +21,21 @@
package com.shatteredpixel.shatteredpixeldungeon.actors.hero.spells; package com.shatteredpixel.shatteredpixeldungeon.actors.hero.spells;
import com.shatteredpixel.shatteredpixeldungeon.actors.Char;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero; import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero;
import com.shatteredpixel.shatteredpixeldungeon.items.artifacts.HolyTome; import com.shatteredpixel.shatteredpixeldungeon.items.artifacts.HolyTome;
import com.shatteredpixel.shatteredpixeldungeon.mechanics.Ballistica;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages; 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 com.shatteredpixel.shatteredpixeldungeon.ui.HeroIcon;
import java.util.ArrayList;
public abstract class ClericSpell { public abstract class ClericSpell {
public void use(HolyTome tome, Hero hero ){ public abstract void onCast(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 float chargeUse( Hero hero ){ public float chargeUse( Hero hero ){
return 1; return 1;
} }
protected abstract void activate( HolyTome tome, Hero hero, Integer target );
public String name(){ public String name(){
return Messages.get(this, "name"); return Messages.get(this, "name");
} }
@@ -85,4 +52,14 @@ public abstract class ClericSpell {
return HeroIcon.NONE; 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;
};
} }

View File

@@ -38,9 +38,9 @@ import com.watabou.noosa.audio.Sample;
import com.watabou.utils.Callback; import com.watabou.utils.Callback;
import com.watabou.utils.Random; 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 @Override
public int icon() { public int icon() {
@@ -48,12 +48,7 @@ public class GuidingLight extends ClericSpell {
} }
@Override @Override
public String targetingPrompt() { protected void onTargetSelected(HolyTome tome, Hero hero, Integer target) {
return Messages.get(this, "prompt");
}
@Override
protected void activate(HolyTome tome, Hero hero, Integer target) {
if (target == null){ if (target == null){
return; return;
} }

View File

@@ -33,7 +33,7 @@ import com.watabou.noosa.audio.Sample;
public class HolyWard extends ClericSpell { public class HolyWard extends ClericSpell {
public static HolyWard INSTANCE = new HolyWard(); public static final HolyWard INSTANCE = new HolyWard();
@Override @Override
public int icon() { public int icon() {
@@ -41,7 +41,7 @@ public class HolyWard extends ClericSpell {
} }
@Override @Override
protected void activate(HolyTome tome, Hero hero, Integer target) { public void onCast(HolyTome tome, Hero hero) {
Buff.affect(hero, HolyArmBuff.class, 50f); Buff.affect(hero, HolyArmBuff.class, 50f);
Item.updateQuickslot(); Item.updateQuickslot();

View File

@@ -33,7 +33,7 @@ import com.watabou.noosa.audio.Sample;
public class HolyWeapon extends ClericSpell { public class HolyWeapon extends ClericSpell {
public static HolyWeapon INSTANCE = new HolyWeapon(); public static final HolyWeapon INSTANCE = new HolyWeapon();
@Override @Override
public int icon() { public int icon() {
@@ -46,7 +46,7 @@ public class HolyWeapon extends ClericSpell {
} }
@Override @Override
protected void activate(HolyTome tome, Hero hero, Integer target) { public void onCast(HolyTome tome, Hero hero) {
Buff.affect(hero, HolyWepBuff.class, 50f); Buff.affect(hero, HolyWepBuff.class, 50f);
Item.updateQuickslot(); Item.updateQuickslot();

View File

@@ -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 );
}

View File

@@ -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);
}

View File

@@ -25,9 +25,7 @@ import com.shatteredpixel.shatteredpixeldungeon.Chrome;
import com.shatteredpixel.shatteredpixeldungeon.Dungeon; import com.shatteredpixel.shatteredpixeldungeon.Dungeon;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero; import com.shatteredpixel.shatteredpixeldungeon.actors.hero.Hero;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.spells.ClericSpell; import com.shatteredpixel.shatteredpixeldungeon.actors.hero.spells.ClericSpell;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.spells.GuidingLight; import com.shatteredpixel.shatteredpixeldungeon.actors.hero.spells.TargetedClericSpell;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.spells.HolyWard;
import com.shatteredpixel.shatteredpixeldungeon.actors.hero.spells.HolyWeapon;
import com.shatteredpixel.shatteredpixeldungeon.items.artifacts.HolyTome; import com.shatteredpixel.shatteredpixeldungeon.items.artifacts.HolyTome;
import com.shatteredpixel.shatteredpixeldungeon.messages.Messages; import com.shatteredpixel.shatteredpixeldungeon.messages.Messages;
import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene; import com.shatteredpixel.shatteredpixeldungeon.scenes.GameScene;
@@ -72,11 +70,7 @@ public class WndClericSpells extends Window {
msg.setPos(0, title.bottom()+4); msg.setPos(0, title.bottom()+4);
add(msg); add(msg);
//TODO build spell list ArrayList<ClericSpell> spells = ClericSpell.getSpellList(cleric);
ArrayList<ClericSpell> spells = new ArrayList<>();
spells.add(GuidingLight.INSTANCE);
spells.add(HolyWeapon.INSTANCE);
spells.add(HolyWard.INSTANCE);
ArrayList<IconButton> spellBtns = new ArrayList<>(); 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())); GameScene.show(new WndTitledMessage(new HeroIcon(spell), Messages.titleCase(spell.name()), spell.desc()));
} else { } else {
hide(); hide();
spell.use(tome, Dungeon.hero); spell.onCast(tome, Dungeon.hero);
//TODO, probably need targeting logic here //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)); QuickSlotButton.useTargeting(Dungeon.quickslot.getSlot(tome));
} }
} }