Well it's better then most I've seen out there but meh, if you don't wanna scrap it post it.
|
I made this base for lunar spells for somebody. Just more of an OOP approach I guess.
Didn't want to scrap it so posting this for whoever wants to use this design.
I don't need feedback, thanks
Code:public interface Spell { public abstract void execute(Player player); public abstract Item[] getItemRequirements(); //runes public abstract int getLevelRequirement(); }I chose to use a static factory for convenience I guess.Code:public abstract class LunarSpell extends Spell { }
Code:public class LunarFactory { //spell id, spell private static Map<Integer, LunarSpell> spells = new HashMap<>(); static { bind(30186, new StringJewlarySpell()); bind(30242, new PlankMakeSpell()); bind(30322, new SpellbookSwapSpell()); bind(30091, new CureMeSpell()); bind(30202, new MagicImbueSpell()); bind(30293, new NPCContactSpell()); bind(30154, new SuperGlassMakeSpell()); } public static void execute(Player player, int buttonId) { LunarSpell spell = spells.get(buttonId); if (spell != null) { if (player.getSkillManager().getCurrentLevel(Skill.MAGIC) < spell.getLevelRequirement()) { player.sendMessage("You do not have the required magic level to cast this spell."); return; } if (!player.getInventory().contains(spell.getItemRequirements())) { player.sendMessage("You do not have enough runes to cast this spell."); return; } spell.execute(player); } else { System.err.println(buttonId + " has not been binded."); } } private static void bind(int buttonId, LunarSpell spell) { spells.put(buttonId, spell); } }Code:public class CureMe extends LunarSpell { @Override public void execute(Player player) { if (player.isPoisoned()) { player.setPoison(false); player.sendMessage("You have been cured of poison."); } else { player.sendMessage("You are not poisoned."); } } @Override public Item[] getItemRequirements() { return new Item[] { ... }; } @Override public int getLevelRequirement() { return 71; } }
Well it's better then most I've seen out there but meh, if you don't wanna scrap it post it.
wrong if statementCode:if (player.getInventory().contains(spell.getItemRequirements())) { player.sendMessage("You do not have enough runes to cast this spell."); return; }
Yeah if this was complete, it'd definitely be far better than any I've seen so far (I've only seen like 3 different approaches to this). Should add a few other things to this though, such as the delay between the usage of spells (so the players can't just spamclick it).. and possibly some other things.
Looks good though. Most people are unfortunately dumber than a pair of socks and won't know what the hell to even do with this.
It's a base, fairly standard however at least your effort is nice. Good job
Pretty much
It's not, my contain method accepted an array.
Unfortunantly people can't or won't need to do.
Your delays etc would be done in the execute method however changing the code to use a scheduler is pretty trivial to do with the small factory.
Standard in what way? I could give you 10 other classes that would just require you to bind(id, spell); - I think that is pretty good. However I can already see improvements that can be made to the overall design (which you guys won't care about )
Because this does nothing for you? You just threw an extremely basic "factory pattern" together, a basic interface, and then released it and called it a base. Also I don't understand the inherit difference between a lunar spell book and any other spell book. Generalize it (especialyl if you insist on doing it this way).
At least provide base classes for common spells:
TeleportSpell(int anim, int gfx, int delay, Location loc),
LunarTeleport(Location loc) exnds Teleport
super(LUNAR_TELEPORT_ANIM, ..GFX, ..DELAY, loc);
DamageSpell(int anim, int gfx, int projectileGfx, int projectileSpeed, int minDamage, int maxDamage, Type type)
StrikeSpell(...) etends DamageSpell you get the point, you can also load a lot of data from JSON or XML instead of hard coding - at least provide a base for that.
Code:enum Type { FIRE, WATER, ... ICE { @Override void effect(final Entity victim) { //freeze logic } //default void effect(final Entity victim) { //nothing? idk how RS works exactly } boolean isWeak(final Npc victim) { return victim.getStats().getWeakness().equals(this); } }
Non-standard would be releasing an editor or at least using a scripting language to implement the spells (hard-coding up to n classes is idiotic).
I don't expect you to do anything of the sort - its your choice on what you want to release, but don't act like this is a gift from god himself if you're gonna slap some shit in our faces and call it a base.
« Previous Thread | Next Thread » |
Thread Information |
Users Browsing this ThreadThere are currently 1 users browsing this thread. (0 members and 1 guests) |