From 4dd3f77c888ae9dfb700530d541834c4ff80a111 Mon Sep 17 00:00:00 2001 From: Chris Kearney <chris.kearney@vevo.com> Date: Tue, 16 Aug 2016 17:13:17 -0700 Subject: [PATCH] migrating cast to use new spell code --- .../com/comandante/creeper/ConfigureNpc.java | 2 - .../use/LightningSpellBookUseAction.java | 8 +- .../creeper/command/CastCommand.java | 6 +- .../creeper/spells/BlackHoleSpell.java | 59 ----- .../creeper/spells/ClumsinessSpell.java | 62 ----- .../creeper/spells/EffectSerializer.java | 2 +- .../creeper/spells/EffectsManager.java | 38 +++ .../creeper/spells/FreezeSpell.java | 59 ----- .../creeper/spells/HealingSpell.java | 50 ---- .../creeper/spells/LightningSpell.java | 59 ----- .../spells/LightningSpellRunnable.java | 41 +-- .../creeper/spells/LizardlySpell.java | 60 ----- .../creeper/spells/RestoreSpell.java | 51 ---- .../com/comandante/creeper/spells/Spell.java | 247 ------------------ ...eSpellRunnable.java => SpellRunnable.java} | 2 +- .../creeper/spells/SpellTriggerRegistry.java | 24 -- .../com/comandante/creeper/spells/Spells.java | 59 +---- 17 files changed, 73 insertions(+), 756 deletions(-) delete mode 100644 src/main/java/com/comandante/creeper/spells/BlackHoleSpell.java delete mode 100644 src/main/java/com/comandante/creeper/spells/ClumsinessSpell.java delete mode 100644 src/main/java/com/comandante/creeper/spells/FreezeSpell.java delete mode 100644 src/main/java/com/comandante/creeper/spells/HealingSpell.java delete mode 100644 src/main/java/com/comandante/creeper/spells/LightningSpell.java delete mode 100644 src/main/java/com/comandante/creeper/spells/LizardlySpell.java delete mode 100644 src/main/java/com/comandante/creeper/spells/RestoreSpell.java delete mode 100644 src/main/java/com/comandante/creeper/spells/Spell.java rename src/main/java/com/comandante/creeper/spells/{ExecuteSpellRunnable.java => SpellRunnable.java} (89%) delete mode 100644 src/main/java/com/comandante/creeper/spells/SpellTriggerRegistry.java diff --git a/src/main/java/com/comandante/creeper/ConfigureNpc.java b/src/main/java/com/comandante/creeper/ConfigureNpc.java index 2907a39f..16a5f7f0 100644 --- a/src/main/java/com/comandante/creeper/ConfigureNpc.java +++ b/src/main/java/com/comandante/creeper/ConfigureNpc.java @@ -101,7 +101,5 @@ public class ConfigureNpc { gameManager.getForageManager().addForageToArea(Area.NORTH3_ZONE, marijuanaForageBuilder); gameManager.getForageManager().addForageToArea(Area.BLOODRIDGE2_ZONE, marijuanaForageBuilder); gameManager.getForageManager().addForageToArea(Area.BLOODRIDGE1_ZONE, marijuanaForageBuilder); - - SpellTriggerRegistry.addSpell(new LightningSpell(gameManager)); } } diff --git a/src/main/java/com/comandante/creeper/Items/use/LightningSpellBookUseAction.java b/src/main/java/com/comandante/creeper/Items/use/LightningSpellBookUseAction.java index bf40f416..3a79ea93 100644 --- a/src/main/java/com/comandante/creeper/Items/use/LightningSpellBookUseAction.java +++ b/src/main/java/com/comandante/creeper/Items/use/LightningSpellBookUseAction.java @@ -6,7 +6,7 @@ import com.comandante.creeper.Items.ItemUseAction; import com.comandante.creeper.managers.GameManager; import com.comandante.creeper.player.Player; import com.comandante.creeper.spells.Effect; -import com.comandante.creeper.spells.LightningSpell; +import com.comandante.creeper.spells.LightningSpellRunnable; import java.util.Set; @@ -27,13 +27,13 @@ public class LightningSpellBookUseAction implements ItemUseAction { @Override public void executeAction(GameManager gameManager, Player player, Item item) { - if (player.getLearnedSpells().contains(LightningSpell.NAME)) { - gameManager.getChannelUtils().write(player.getPlayerId(), "You already know how to use " + LightningSpell.NAME); + if (player.getLearnedSpells().contains(LightningSpellRunnable.name)) { + gameManager.getChannelUtils().write(player.getPlayerId(), "You already know how to use " + LightningSpellRunnable.name); dontDelete = true; return; } gameManager.writeToPlayerCurrentRoom(player.getPlayerId(), player.getPlayerName() + " reads a leatherbound aging spell book and gains knowledge about lightning spells."); - player.addLearnedSpellByName(LightningSpell.NAME); + player.addLearnedSpellByName(LightningSpellRunnable.name); } @Override diff --git a/src/main/java/com/comandante/creeper/command/CastCommand.java b/src/main/java/com/comandante/creeper/command/CastCommand.java index 43ac86f4..f3379b60 100644 --- a/src/main/java/com/comandante/creeper/command/CastCommand.java +++ b/src/main/java/com/comandante/creeper/command/CastCommand.java @@ -5,12 +5,10 @@ import com.comandante.creeper.managers.GameManager; import com.comandante.creeper.npc.Npc; import com.comandante.creeper.player.CoolDownType; import com.comandante.creeper.player.Player; -import com.comandante.creeper.spells.ExecuteSpellRunnable; +import com.comandante.creeper.spells.SpellRunnable; import com.comandante.creeper.spells.Spell; import com.comandante.creeper.spells.SpellTriggerRegistry; -import com.comandante.creeper.spells.Spells; import com.google.common.base.Joiner; -import com.google.common.collect.Sets; import org.jboss.netty.channel.ChannelHandlerContext; import org.jboss.netty.channel.MessageEvent; @@ -44,7 +42,7 @@ public class CastCommand extends Command { return; } String desiredSpellName = originalMessageParts.get(1); - Optional<ExecuteSpellRunnable> spellRunnable = gameManager.getSpells().getSpellRunnable(desiredSpellName); + Optional<SpellRunnable> spellRunnable = gameManager.getSpells().getSpellRunnable(desiredSpellName); if (!spellRunnable.isPresent() || !player.doesHaveSpellLearned(spellRunnable.get().getName())) { write("No spell found with the name: " + desiredSpellName + "\r\n"); return; diff --git a/src/main/java/com/comandante/creeper/spells/BlackHoleSpell.java b/src/main/java/com/comandante/creeper/spells/BlackHoleSpell.java deleted file mode 100644 index 24ba6bda..00000000 --- a/src/main/java/com/comandante/creeper/spells/BlackHoleSpell.java +++ /dev/null @@ -1,59 +0,0 @@ -package com.comandante.creeper.spells; - - -import com.comandante.creeper.managers.GameManager; -import com.comandante.creeper.player.Player; -import com.comandante.creeper.server.Color; -import com.comandante.creeper.stat.Stats; -import com.comandante.creeper.stat.StatsBuilder; -import com.google.common.collect.Lists; -import com.google.common.collect.Sets; - -import java.util.Arrays; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import static com.comandante.creeper.server.Color.BOLD_ON; - -public class BlackHoleSpell extends Spell { - - private final static String NAME = BOLD_ON + Color.BLACK + "black" + Color.RESET + " hole"; - private final static String DESCRIPTION = "A black hole."; - private final static Set<String> validTriggers = new HashSet<String>(Arrays.asList(new String[] - {"black", "black hole", "bh", "b", NAME} - )); - private final static Stats attackStats = new StatsBuilder() - .setStrength(180) - .setWeaponRatingMax(60) - .setWeaponRatingMin(50) - .setNumberOfWeaponRolls(4) - .createStats(); - private final static boolean isAreaSpell = true; - - private final static List<String> attackMessages = Lists.newArrayList("a massive " + BOLD_ON + Color.BLACK + "black hole" + Color.RESET + " begins to form in front of you "); - private static int manaCost = 20000000; - private final static int coolDownTicks = 4; - - private static EffectBuilder holeEffect = new EffectBuilder() - .setEffectApplyMessages(Lists.newArrayList("You are being " + Color.BOLD_ON + Color.BLUE + "nullified" + Color.RESET + " by a black hole!")) - .setEffectDescription("a dark vortex of nothingness.") - .setEffectName(Color.BOLD_ON + Color.BLACK + "Black vortex of" + Color.RESET + Color.BOLD_ON + Color.BLUE + " NOTHING" + Color.RESET) - .setDurationStats(new StatsBuilder().createStats()) - .setApplyStatsOnTick(new StatsBuilder().setCurrentHealth(-15000000000L).createStats()) - .setFrozenMovement(false) - .setLifeSpanTicks(2); - - public BlackHoleSpell(GameManager gameManager) { - super(gameManager, validTriggers, manaCost, attackStats, attackMessages, DESCRIPTION, NAME, Sets.newHashSet(holeEffect.createEffect()), isAreaSpell, null, coolDownTicks); - } - - @Override - public void attackSpell(Set<String> npcIds, Player player) { - Stats playerStats = player.getPlayerStatsWithEquipmentAndLevel(); - long willpower = playerStats.getWillpower(); - long i = 66666666666L + (willpower * 3); - this.setEffects(Sets.newHashSet(holeEffect.setApplyStatsOnTick(new StatsBuilder().setCurrentHealth(-i).createStats()).createEffect())); - super.attackSpell(npcIds, player); - } -} diff --git a/src/main/java/com/comandante/creeper/spells/ClumsinessSpell.java b/src/main/java/com/comandante/creeper/spells/ClumsinessSpell.java deleted file mode 100644 index 2fed54cb..00000000 --- a/src/main/java/com/comandante/creeper/spells/ClumsinessSpell.java +++ /dev/null @@ -1,62 +0,0 @@ -package com.comandante.creeper.spells; - -import com.comandante.creeper.Items.Item; -import com.comandante.creeper.Items.ItemType; -import com.comandante.creeper.Items.Loot; -import com.comandante.creeper.managers.GameManager; -import com.comandante.creeper.npc.Npc; -import com.comandante.creeper.player.Player; -import com.comandante.creeper.server.Color; -import com.comandante.creeper.stat.Stats; -import com.comandante.creeper.stat.StatsBuilder; -import com.comandante.creeper.world.Room; -import com.google.common.collect.Interner; -import com.google.common.collect.Interners; -import com.google.common.collect.Lists; -import com.google.common.collect.Sets; - -import java.util.Arrays; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import static com.comandante.creeper.server.Color.BOLD_ON; - -public class ClumsinessSpell extends Spell { - - private final static String NAME = BOLD_ON + Color.MAGENTA + "clumsiness" + Color.RESET; - private final static String DESCRIPTION = "A noticeable lapse in judgement occurs in your target."; - private final static Set<String> validTriggers = new HashSet<String>(Arrays.asList(new String[] - {"clumsiness", "clumsy", NAME} - )); - private final static Stats attackStats = new StatsBuilder().createStats(); - private final static boolean isAreaSpell = false; - - private final static List<String> attackMessages = Lists.newArrayList("awkwardness permeates and as a result " + BOLD_ON + Color.MAGENTA + "clumsiness" + Color.RESET + " is had by all."); - private final static int manaCost = 300; - private final static int coolDownTicks = 30; - - private final static SpellExecute spellExecute = new SpellExecute() { - @Override - public void executeNpc(GameManager gameManager, Npc npc, Player player) { - Interner<String> interner = Interners.newWeakInterner(); - synchronized (interner.intern(npc.getEntityId())) { - Loot loot = npc.getLoot(); - Room playerCurrentRoom = gameManager.getRoomManager().getPlayerCurrentRoom(player).get(); - Set<Item> items = gameManager.getLootManager().lootItemsReturn(loot); - if (items.size() > 0) { - for (Item item : items) { - gameManager.placeItemInRoom(playerCurrentRoom.getRoomId(), item.getItemId()); - gameManager.roomSay(playerCurrentRoom.getRoomId(), npc.getColorName() + Color.MAGENTA + " fumbles " + Color.RESET + item.getItemName(), player.getPlayerId()); - gameManager.getItemDecayManager().addItem(item); - } - npc.setLoot(new Loot(loot.getLootGoldMin(), loot.getLootGoldMax(), Sets.<ItemType>newHashSet())); - } - } - } - }; - - public ClumsinessSpell(GameManager gameManager) { - super(gameManager, validTriggers, manaCost, attackStats, attackMessages, DESCRIPTION, NAME, Sets.<Effect>newHashSet(), isAreaSpell, spellExecute, coolDownTicks); - } -} diff --git a/src/main/java/com/comandante/creeper/spells/EffectSerializer.java b/src/main/java/com/comandante/creeper/spells/EffectSerializer.java index ae991543..76f35028 100644 --- a/src/main/java/com/comandante/creeper/spells/EffectSerializer.java +++ b/src/main/java/com/comandante/creeper/spells/EffectSerializer.java @@ -1,4 +1,4 @@ -package com.comandante.creeper.Items; +package com.comandante.creeper.spells; import com.comandante.creeper.spells.Effect; import com.google.gson.GsonBuilder; diff --git a/src/main/java/com/comandante/creeper/spells/EffectsManager.java b/src/main/java/com/comandante/creeper/spells/EffectsManager.java index 2cfd600c..a082ed6e 100644 --- a/src/main/java/com/comandante/creeper/spells/EffectsManager.java +++ b/src/main/java/com/comandante/creeper/spells/EffectsManager.java @@ -10,19 +10,57 @@ import com.comandante.creeper.server.Color; import com.comandante.creeper.stat.Stats; import com.comandante.creeper.stat.StatsBuilder; import com.comandante.creeper.stat.StatsHelper; +import org.apache.log4j.Logger; import java.text.NumberFormat; import java.util.Arrays; import java.util.Locale; +import java.util.Set; public class EffectsManager { private final GameManager gameManager; + private static final Logger log = Logger.getLogger(EffectsManager.class); + public EffectsManager(GameManager gameManager) { this.gameManager = gameManager; } + public void applyEffectsToNpcs(Player player, Set<Npc> npcs, Set<Effect> effects) { + effects.forEach(effect -> + npcs.forEach(npc -> { + Effect nEffect = new Effect(effect); + nEffect.setPlayerId(player.getPlayerId()); + if (effect.getDurationStats().getCurrentHealth() < 0) { + log.error("ERROR! Someone added an effect with a health modifier which won't work for various reasons."); + return; + } + StatsHelper.combineStats(npc.getStats(), effect.getDurationStats()); + npc.addEffect(nEffect); + })); + } + + public void applyEffectsToPlayer(Player destinationPlayer, Player player, Set<Effect> effects) { + for (Effect effect : effects) { + Effect nEffect = new Effect(effect); + nEffect.setPlayerId(player.getPlayerId()); + gameManager.getEntityManager().saveEffect(nEffect); + if (effect.getDurationStats().getCurrentHealth() < 0) { + log.error("ERROR! Someone added an effect with a health modifier which won't work for various reasons."); + continue; + } + String effectApplyMessage; + if (destinationPlayer.addEffect(effect.getEntityId())) { + effectApplyMessage = Color.BOLD_ON + Color.GREEN + "[effect] " + Color.RESET + nEffect.getEffectName() + " applied!" + "\r\n"; + gameManager.getChannelUtils().write(destinationPlayer.getPlayerId(), effectApplyMessage); + } else { + effectApplyMessage = Color.BOLD_ON + Color.GREEN + "[effect] " + Color.RESET + Color.RED + "Unable to apply " + nEffect.getEffectName() + "!" + "\r\n"; + gameManager.getChannelUtils().write(player.getPlayerId(), effectApplyMessage); + } + } + } + public void application(Effect effect, Player player) { // if there are effecst that modify player health, deal with it here, you can't rely on combine stats. Stats applyStatsOnTick = effect.getApplyStatsOnTick(); diff --git a/src/main/java/com/comandante/creeper/spells/FreezeSpell.java b/src/main/java/com/comandante/creeper/spells/FreezeSpell.java deleted file mode 100644 index 8399b417..00000000 --- a/src/main/java/com/comandante/creeper/spells/FreezeSpell.java +++ /dev/null @@ -1,59 +0,0 @@ -package com.comandante.creeper.spells; - - -import com.comandante.creeper.managers.GameManager; -import com.comandante.creeper.player.Player; -import com.comandante.creeper.server.Color; -import com.comandante.creeper.stat.Stats; -import com.comandante.creeper.stat.StatsBuilder; -import com.google.common.collect.Lists; -import com.google.common.collect.Sets; - -import java.util.Arrays; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import static com.comandante.creeper.server.Color.BOLD_ON; - -public class FreezeSpell extends Spell { - - private final static String NAME = BOLD_ON + Color.CYAN + "freeze" + Color.RESET; - private final static String DESCRIPTION = "A vortex of ice."; - private final static Set<String> validTriggers = new HashSet<String>(Arrays.asList(new String[] - {"freeze", "f", NAME} - )); - private final static Stats attackStats = new StatsBuilder() - .setStrength(180) - .setWeaponRatingMax(60) - .setWeaponRatingMin(50) - .setNumberOfWeaponRolls(4) - .createStats(); - private final static boolean isAreaSpell = true; - - private final static List<String> attackMessages = Lists.newArrayList("a blizzard of " + BOLD_ON + Color.CYAN + "ice" + Color.RESET + " blasts through the area"); - private static int manaCost = 3000000; - private final static int coolDownTicks = 6; - - private static EffectBuilder freezeEffect = new EffectBuilder() - .setEffectApplyMessages(Lists.newArrayList("You are " + Color.BOLD_ON + Color.BLUE + "frozen" + Color.RESET + " by a violent blizzard!")) - .setEffectDescription("a torrent of ice crystals.") - .setEffectName(Color.BOLD_ON + Color.CYAN + "FROZEN" + Color.RESET) - .setDurationStats(new StatsBuilder().createStats()) - .setApplyStatsOnTick(new StatsBuilder().setCurrentHealth(-666666).createStats()) - .setFrozenMovement(true) - .setLifeSpanTicks(5); - - public FreezeSpell(GameManager gameManager) { - super(gameManager, validTriggers, manaCost, attackStats, attackMessages, DESCRIPTION, NAME, Sets.newHashSet(freezeEffect.createEffect()), isAreaSpell, null, coolDownTicks); - } - - @Override - public void attackSpell(Set<String> npcIds, Player player) { - Stats playerStats = player.getPlayerStatsWithEquipmentAndLevel(); - long willpower = playerStats.getWillpower(); - long i = 5000000 + (willpower * 3); - this.setEffects(Sets.newHashSet(freezeEffect.setApplyStatsOnTick(new StatsBuilder().setCurrentHealth(-i).createStats()).createEffect())); - super.attackSpell(npcIds, player); - } -} diff --git a/src/main/java/com/comandante/creeper/spells/HealingSpell.java b/src/main/java/com/comandante/creeper/spells/HealingSpell.java deleted file mode 100644 index 826ed597..00000000 --- a/src/main/java/com/comandante/creeper/spells/HealingSpell.java +++ /dev/null @@ -1,50 +0,0 @@ -package com.comandante.creeper.spells; - -import com.comandante.creeper.managers.GameManager; -import com.comandante.creeper.player.Player; -import com.comandante.creeper.server.Color; -import com.comandante.creeper.stat.Stats; -import com.comandante.creeper.stat.StatsBuilder; -import com.google.common.collect.Lists; -import com.google.common.collect.Sets; - -import java.util.Arrays; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import static com.comandante.creeper.server.Color.BOLD_ON; - -public class HealingSpell extends Spell { - - private final static String NAME = BOLD_ON + Color.MAGENTA + "healing" + Color.RESET; - private final static String DESCRIPTION = "A pure aura of healing."; - private final static Set<String> validTriggers = new HashSet<String>(Arrays.asList(new String[] - {"healing", "h", NAME} - )); - private final static Stats attackStats = new StatsBuilder().createStats(); - private final static boolean isAreaSpell = false; - - private final static List<String> attackMessages = Lists.newArrayList("an aura of " + BOLD_ON + Color.MAGENTA + "healing" + Color.RESET + " surrounds the area"); - private static int manaCost = 80000000; - private final static int coolDownTicks = 20; - - private static EffectBuilder fullHealEffect = new EffectBuilder() - .setEffectApplyMessages(Lists.newArrayList("An aura of " + Color.BOLD_ON + Color.MAGENTA + "healing" + Color.RESET + " surrounds you")) - .setEffectDescription("Heals a target to full health.") - .setEffectName(Color.BOLD_ON + Color.MAGENTA + "healing" + Color.RESET + Color.BOLD_ON + Color.YELLOW + " AURA" + Color.RESET) - .setDurationStats(new StatsBuilder().createStats()) - .setFrozenMovement(false) - .setLifeSpanTicks(1); - - public HealingSpell(GameManager gameManager) { - super(gameManager, validTriggers, manaCost, attackStats, attackMessages, DESCRIPTION, NAME, Sets.newHashSet(fullHealEffect.createEffect()), isAreaSpell, null, coolDownTicks); - } - - @Override - public void attackSpell(Player destinationPlayer, Player sourcePlayer) { - Stats stats = destinationPlayer.getPlayerStatsWithEquipmentAndLevel(); - this.setEffects(Sets.newHashSet(fullHealEffect.setApplyStatsOnTick(new StatsBuilder().setCurrentHealth((stats.getMaxHealth())).createStats()).createEffect())); - super.attackSpell(destinationPlayer, sourcePlayer); - } -} diff --git a/src/main/java/com/comandante/creeper/spells/LightningSpell.java b/src/main/java/com/comandante/creeper/spells/LightningSpell.java deleted file mode 100644 index b986b516..00000000 --- a/src/main/java/com/comandante/creeper/spells/LightningSpell.java +++ /dev/null @@ -1,59 +0,0 @@ -package com.comandante.creeper.spells; - - -import com.comandante.creeper.managers.GameManager; -import com.comandante.creeper.player.Player; -import com.comandante.creeper.server.Color; -import com.comandante.creeper.stat.Stats; -import com.comandante.creeper.stat.StatsBuilder; -import com.google.common.collect.Lists; -import com.google.common.collect.Sets; - -import java.util.Arrays; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import static com.comandante.creeper.server.Color.BOLD_ON; - -public class LightningSpell extends Spell { - - public final static String NAME = BOLD_ON + Color.YELLOW + "lightning" + Color.RESET + " bolt"; - private final static String DESCRIPTION = "A powerful bolt of lightning."; - private final static Set<String> validTriggers = new HashSet<String>(Arrays.asList(new String[] - {"lightning", "lightning bolt", "l", NAME} - )); - private final static Stats attackStats = new StatsBuilder() - .setStrength(180) - .setWeaponRatingMax(60) - .setWeaponRatingMin(50) - .setNumberOfWeaponRolls(4) - .createStats(); - private final static boolean isAreaSpell = true; - - private final static List<String> attackMessages = Lists.newArrayList("a broad stroke of " + BOLD_ON + Color.YELLOW + "lightning" + Color.RESET + " bolts across the sky"); - private static int manaCost = 60; - private final static int coolDownTicks = 4; - - private static EffectBuilder burnEffect = new EffectBuilder() - .setEffectApplyMessages(Lists.newArrayList("You are " + Color.BOLD_ON + Color.RED + "burning" + Color.RESET + " from the lightning strike!")) - .setEffectDescription("Fire left over from the lightning strike.") - .setEffectName(Color.BOLD_ON + Color.YELLOW + "lightning" + Color.RESET + Color.BOLD_ON + Color.RED + " BURN" + Color.RESET) - .setDurationStats(new StatsBuilder().createStats()) - .setApplyStatsOnTick(new StatsBuilder().setCurrentHealth(-150).createStats()) - .setFrozenMovement(false) - .setLifeSpanTicks(2); - - public LightningSpell(GameManager gameManager) { - super(gameManager, validTriggers, manaCost, attackStats, attackMessages, DESCRIPTION, NAME, Sets.newHashSet(burnEffect.createEffect()), isAreaSpell, null, coolDownTicks); - } - - @Override - public void attackSpell(Set<String> npcIds, Player player) { - Stats playerStats = player.getPlayerStatsWithEquipmentAndLevel(); - long willpower = playerStats.getWillpower(); - long i = 20 + (willpower * 3); - this.setEffects(Sets.newHashSet(burnEffect.setApplyStatsOnTick(new StatsBuilder().setCurrentHealth(-i).createStats()).createEffect())); - super.attackSpell(npcIds, player); - } -} diff --git a/src/main/java/com/comandante/creeper/spells/LightningSpellRunnable.java b/src/main/java/com/comandante/creeper/spells/LightningSpellRunnable.java index 8429fc16..7bced2a7 100644 --- a/src/main/java/com/comandante/creeper/spells/LightningSpellRunnable.java +++ b/src/main/java/com/comandante/creeper/spells/LightningSpellRunnable.java @@ -1,32 +1,26 @@ package com.comandante.creeper.spells; -import com.comandante.creeper.CreeperUtils; import com.comandante.creeper.managers.GameManager; import com.comandante.creeper.npc.Npc; import com.comandante.creeper.player.CoolDown; import com.comandante.creeper.player.CoolDownType; import com.comandante.creeper.player.Player; import com.comandante.creeper.server.Color; -import com.comandante.creeper.stat.Stats; -import com.comandante.creeper.stat.StatsBuilder; -import com.google.common.collect.Lists; -import com.google.common.collect.Sets; +import com.comandante.creeper.spells.SpellRunnable; import java.util.Arrays; -import java.util.HashSet; import java.util.Optional; -import java.util.Set; import static com.comandante.creeper.server.Color.BOLD_ON; -import static com.comandante.creeper.spells.Spells.getSpellAttack; -public class LightningSpellRunnable implements ExecuteSpellRunnable { +public class LightningSpellRunnable implements SpellRunnable { - private final GameManager gameManager; - private final int manaCost = 60; public final static String name = BOLD_ON + Color.YELLOW + "lightning" + Color.RESET + " bolt"; - private final static String description = "A powerful bolt of lightning."; - private final static String attackMessage = "a broad stroke of " + BOLD_ON + Color.YELLOW + "lightning" + Color.RESET + " bolts across the sky"; + public final static String description = "A powerful bolt of lightning."; + + private final static int manaCost = 60; + + private final GameManager gameManager; public LightningSpellRunnable(GameManager gameManager) { this.gameManager = gameManager; @@ -41,9 +35,9 @@ public class LightningSpellRunnable implements ExecuteSpellRunnable { } if (destinationNpc.isPresent()) { executeSpellAgainstNpc(sourcePlayer, destinationNpc.get()); + sourcePlayer.updatePlayerMana(-manaCost); + sourcePlayer.addCoolDown(new CoolDown(getName(), 5, CoolDownType.SPELL)); } - sourcePlayer.updatePlayerMana(-manaCost); - sourcePlayer.addCoolDown(new CoolDown(getName(), 5, CoolDownType.SPELL)); } @Override @@ -52,15 +46,26 @@ public class LightningSpellRunnable implements ExecuteSpellRunnable { } private void executeSpellAgainstNpc(Player player, Npc npc) { - gameManager.writeToPlayerCurrentRoom(player.getPlayerId(), player.getPlayerName() + Color.CYAN + " casts " + Color.RESET + "a " + Color.BOLD_ON + Color.WHITE + "[" + Color.RESET + getName() + Color.BOLD_ON + Color.WHITE + "]" + Color.RESET + " on " + npc.getColorName() + "! \r\n"); + announceSpellCastToCurrentRoom(player, npc.getColorName()); long intelligence = player.getPlayerStatsWithEquipmentAndLevel().getIntelligence(); long power = (player.getLevel() * 1) + (3 * intelligence); player.addActiveFight(npc); - String damageMessage = Color.BOLD_ON + Color.YELLOW + "[spell] " + Color.RESET + Color.YELLOW + "+" + power + Color.RESET + Color.BOLD_ON + Color.RED + " DAMAGE " + Color.RESET + attackMessage + Color.BOLD_ON + Color.RED + " >>>> " + Color.RESET + npc.getColorName(); - npc.doHealthDamage(player, Arrays.asList(damageMessage), -power); + npc.doHealthDamage(player, Arrays.asList(getDamageMessage(power, npc.getColorName())), -power); } private void executeSpellAgainstPlayer(Player player, Player destinationPlayer) { } + + private String getAttackMessage() { + return "a broad stroke of " + BOLD_ON + Color.YELLOW + "lightning" + Color.RESET + " bolts across the sky"; + } + + private String getDamageMessage(long amt, String name) { + return Color.BOLD_ON + Color.YELLOW + "[spell] " + Color.RESET + Color.YELLOW + "+" + amt + Color.RESET + Color.BOLD_ON + Color.RED + " DAMAGE " + Color.RESET + getAttackMessage() + Color.BOLD_ON + Color.RED + " >>>> " + Color.RESET + name; + } + + private void announceSpellCastToCurrentRoom(Player player, String name) { + gameManager.writeToPlayerCurrentRoom(player.getPlayerId(), player.getPlayerName() + Color.CYAN + " casts " + Color.RESET + "a " + Color.BOLD_ON + Color.WHITE + "[" + Color.RESET + getName() + Color.BOLD_ON + Color.WHITE + "]" + Color.RESET + " on " + name + "! \r\n"); + } } diff --git a/src/main/java/com/comandante/creeper/spells/LizardlySpell.java b/src/main/java/com/comandante/creeper/spells/LizardlySpell.java deleted file mode 100644 index 805d9952..00000000 --- a/src/main/java/com/comandante/creeper/spells/LizardlySpell.java +++ /dev/null @@ -1,60 +0,0 @@ -package com.comandante.creeper.spells; - -import com.comandante.creeper.Items.Item; -import com.comandante.creeper.Items.ItemType; -import com.comandante.creeper.Items.Loot; -import com.comandante.creeper.managers.GameManager; -import com.comandante.creeper.npc.Npc; -import com.comandante.creeper.player.Player; -import com.comandante.creeper.server.Color; -import com.comandante.creeper.spells.Effect; -import com.comandante.creeper.spells.Spell; -import com.comandante.creeper.stat.Stats; -import com.comandante.creeper.stat.StatsBuilder; -import com.comandante.creeper.world.Room; -import com.google.common.collect.Interner; -import com.google.common.collect.Interners; -import com.google.common.collect.Lists; -import com.google.common.collect.Sets; - -import java.util.Arrays; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import static com.comandante.creeper.server.Color.BOLD_ON; - -public class LizardlySpell extends Spell { - - private final static String NAME = BOLD_ON + Color.YELLOW + "lizzards" + Color.RESET; - private final static String DESCRIPTION = "Your target is LIZARDLY!!!!"; - private final static Set<String> validTriggers = new HashSet<String>(Arrays.asList(new String[] - {"lizardly", "liz", NAME} - )); - private final static Stats attackStats = new StatsBuilder().createStats(); - private final static boolean isAreaSpell = false; - - private final static List<String> attackMessages = Lists.newArrayList("tainted lizzard blood is flung through the air... " + BOLD_ON + Color.YELLOW + "lizardly" + Color.RESET + "!!!!"); - private final static int manaCost = 300; - private final static int coolDownTicks = 30; - - private static EffectBuilder aids = new EffectBuilder() - .setEffectApplyMessages(Lists.newArrayList("You feel closer to death as " + Color.BOLD_ON + Color.YELLOW + "lizzardly" + Color.RESET + " destroys your will to live!")) - .setEffectDescription("Target has aids.") - .setEffectName(Color.BOLD_ON + Color.RED + "aids" + Color.RESET + Color.BOLD_ON + Color.BLUE + " FOR LIFE" + Color.RESET) - .setDurationStats(new StatsBuilder().createStats()) - .setApplyStatsOnTick(new StatsBuilder().setCurrentHealth(-1000).createStats()) - .setFrozenMovement(false) - .setLifeSpanTicks(5); - - public LizardlySpell(GameManager gameManager) { - super(gameManager, validTriggers, manaCost, attackStats, attackMessages, DESCRIPTION, NAME, Sets.<Effect>newHashSet(), isAreaSpell, null, coolDownTicks); - } - - @Override - public void attackSpell(Player destinationPlayer, Player sourcePlayer) { - Stats stats = sourcePlayer.getPlayerStatsWithEquipmentAndLevel(); - this.setEffects(Sets.newHashSet(aids.setApplyStatsOnTick(new StatsBuilder().setCurrentHealth(-1000).createStats()).createEffect())); - super.attackSpell(destinationPlayer, sourcePlayer); - } -} diff --git a/src/main/java/com/comandante/creeper/spells/RestoreSpell.java b/src/main/java/com/comandante/creeper/spells/RestoreSpell.java deleted file mode 100644 index 0482aa83..00000000 --- a/src/main/java/com/comandante/creeper/spells/RestoreSpell.java +++ /dev/null @@ -1,51 +0,0 @@ -package com.comandante.creeper.spells; - -import com.comandante.creeper.managers.GameManager; -import com.comandante.creeper.player.Player; -import com.comandante.creeper.server.Color; -import com.comandante.creeper.stat.Stats; -import com.comandante.creeper.stat.StatsBuilder; -import com.google.common.collect.Lists; -import com.google.common.collect.Sets; - -import java.util.Arrays; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import static com.comandante.creeper.server.Color.BOLD_ON; - -public class RestoreSpell extends Spell { - - private final static String NAME = BOLD_ON + Color.MAGENTA + "restore" + Color.RESET; - private final static String DESCRIPTION = "A potent wave of healing."; - private final static Set<String> validTriggers = new HashSet<String>(Arrays.asList(new String[] - {"restore", "r", NAME} - )); - private final static Stats attackStats = new StatsBuilder().createStats(); - private final static boolean isAreaSpell = false; - - private final static List<String> attackMessages = Lists.newArrayList("a wave of " + BOLD_ON + Color.MAGENTA + "healing" + Color.RESET + " flows to those in need"); - private static int manaCost = 80; - private final static int coolDownTicks = 2; - - private static EffectBuilder burnEffect = new EffectBuilder() - .setEffectApplyMessages(Lists.newArrayList("You feel a rush of dopamine as a " + Color.BOLD_ON + Color.MAGENTA + "healing" + Color.RESET + " sensation flows through your body!")) - .setEffectDescription("Heals a target over time.") - .setEffectName(Color.BOLD_ON + Color.MAGENTA + "healing" + Color.RESET + Color.BOLD_ON + Color.BLUE + " WAVE" + Color.RESET) - .setDurationStats(new StatsBuilder().createStats()) - .setApplyStatsOnTick(new StatsBuilder().setCurrentHealth(400).createStats()) - .setFrozenMovement(false) - .setLifeSpanTicks(6); - - public RestoreSpell(GameManager gameManager) { - super(gameManager, validTriggers, manaCost, attackStats, attackMessages, DESCRIPTION, NAME, Sets.newHashSet(burnEffect.createEffect()), isAreaSpell, null, coolDownTicks); - } - - @Override - public void attackSpell(Player destinationPlayer, Player sourcePlayer) { - Stats stats = sourcePlayer.getPlayerStatsWithEquipmentAndLevel(); - this.setEffects(Sets.newHashSet(burnEffect.setApplyStatsOnTick(new StatsBuilder().setCurrentHealth(400 + (stats.getWillpower() * 6)).createStats()).createEffect())); - super.attackSpell(destinationPlayer, sourcePlayer); - } -} \ No newline at end of file diff --git a/src/main/java/com/comandante/creeper/spells/Spell.java b/src/main/java/com/comandante/creeper/spells/Spell.java deleted file mode 100644 index e6b3636e..00000000 --- a/src/main/java/com/comandante/creeper/spells/Spell.java +++ /dev/null @@ -1,247 +0,0 @@ -package com.comandante.creeper.spells; - - -import com.comandante.creeper.managers.GameManager; -import com.comandante.creeper.npc.Npc; -import com.comandante.creeper.player.CoolDown; -import com.comandante.creeper.player.CoolDownType; -import com.comandante.creeper.player.Player; -import com.comandante.creeper.server.Color; -import com.comandante.creeper.stat.Stats; -import com.comandante.creeper.stat.StatsHelper; -import com.google.common.collect.Interner; -import com.google.common.collect.Interners; -import org.apache.log4j.Logger; - -import java.util.*; - - -public abstract class Spell { - - private final String spellName; - private final String spellDescription; - private final List<String> attackMessages; - private final Stats attackStats; - private final int manaCost; - private final Set<String> validTriggers; - private final static Random random = new Random(); - private final GameManager gameManager; - private Set<Effect> effects; - private final boolean isAreaSpell; - private final SpellExecute spellExecute; - private final int coolDownTicks; - - private static final Logger log = Logger.getLogger(Spell.class); - - - public Spell(GameManager gameManager, - Set<String> validTriggers, - int manaCost, - Stats attackStats, - List<String> attackMessages, - String spellDescription, - String spellName, - Set<Effect> effects, - boolean isAreaSpell, - SpellExecute spellExecute, - int coolDownTicks) { - this.gameManager = gameManager; - this.validTriggers = validTriggers; - this.manaCost = manaCost; - this.attackStats = attackStats; - this.attackMessages = attackMessages; - this.spellDescription = spellDescription; - this.spellName = spellName; - this.effects = effects; - this.isAreaSpell = isAreaSpell; - this.spellExecute = spellExecute; - this.coolDownTicks = coolDownTicks; - } - - private long getSpellAttack(Stats victim) { - int rolls = 0; - int totDamage = 0; - while (rolls <= attackStats.getNumberOfWeaponRolls()) { - rolls++; - totDamage = totDamage + randInt((int)attackStats.getWeaponRatingMin(), (int)attackStats.getWeaponRatingMax()); - } - long i = attackStats.getStrength() + totDamage - victim.getArmorRating(); - if (i < 0) { - return 0; - } else { - return i; - } - } - - public String getAttackMessage(long amt, Npc npc) { - int i = random.nextInt(attackMessages.size()); - String s = attackMessages.get(i); - if (amt == 0) { - return s; - } else { - return Color.BOLD_ON + Color.YELLOW + "[spell] " + Color.RESET + Color.YELLOW + "+" + amt + Color.RESET + Color.BOLD_ON + Color.RED + " DAMAGE " + Color.RESET + s + Color.BOLD_ON + Color.RED + " >>>> " + Color.RESET + npc.getColorName(); - } - } - - private void applySpell(Set<String> npcIds, Player player) { - if (spellExecute != null) { - for (String npcId : npcIds) { - Npc npc = gameManager.getEntityManager().getNpcEntity(npcId); - spellExecute.executeNpc(gameManager, npc, player); - } - } - } - - public void attackSpell(Set<String> npcIds, Player player) { - Interner<String> interner = Interners.newWeakInterner(); - synchronized (interner.intern(player.getPlayerId())) { - long availableMana = gameManager.getPlayerManager().getPlayerMetadata(player.getPlayerId()).getStats().getCurrentMana(); - if (availableMana < manaCost) { - gameManager.getChannelUtils().write(player.getPlayerId(), "Not enough mana!" + "\r\n"); - } else { - applySpell(npcIds, player); - for (String npcId : npcIds) { - Npc npc = gameManager.getEntityManager().getNpcEntity(npcId); - gameManager.writeToPlayerCurrentRoom(player.getPlayerId(), player.getPlayerName() + Color.CYAN + " casts " + Color.RESET + "a " + Color.BOLD_ON + Color.WHITE + "[" + Color.RESET + spellName + Color.BOLD_ON + Color.WHITE + "]" + Color.RESET + " on " + npc.getColorName() + "! \r\n"); - long spellAttack = getSpellAttack(npc.getStats()); - final String spellAttackStr = getAttackMessage(spellAttack, npc); - player.addActiveFight(npc); - npc.doHealthDamage(player, Arrays.asList(spellAttackStr), -spellAttack); - } - if (npcIds.size() > 0) { - applyEffectsToNpcs(npcIds, player); - player.updatePlayerMana(-manaCost); - player.addCoolDown(new CoolDown(spellName, coolDownTicks, CoolDownType.SPELL)); - } - } - } - } - - public void attackSpell(Player destinationPlayer, Player sourcePlayer) { - Interner<String> interner = Interners.newWeakInterner(); - synchronized (interner.intern(sourcePlayer.getPlayerId())) { - long availableMana = gameManager.getPlayerManager().getPlayerMetadata(sourcePlayer.getPlayerId()).getStats().getCurrentMana(); - if (availableMana < manaCost) { - gameManager.getChannelUtils().write(sourcePlayer.getPlayerId(), "Not enough mana!" + "\r\n"); - } else { - gameManager.writeToPlayerCurrentRoom(sourcePlayer.getPlayerId(), sourcePlayer.getPlayerName() + Color.CYAN + " casts " + Color.RESET + "a " + Color.BOLD_ON + Color.WHITE + "[" + Color.RESET + spellName + Color.BOLD_ON + Color.WHITE + "]" + Color.RESET + " on " + destinationPlayer.getPlayerName() + "! \r\n"); - applyEffectsToPlayer(destinationPlayer, sourcePlayer); - sourcePlayer.updatePlayerMana(-manaCost); - sourcePlayer.addCoolDown(new CoolDown(spellName, coolDownTicks, CoolDownType.SPELL)); - } - } - } - - public void applyEffectsToPlayer(Player destinationPlayer, Player player) { - Interner<String> interner = Interners.newWeakInterner(); - synchronized (interner.intern(player.getPlayerId())) { - long availableMana = gameManager.getPlayerManager().getPlayerMetadata(player.getPlayerId()).getStats().getCurrentMana(); - if (availableMana < manaCost) { - gameManager.getChannelUtils().write(player.getPlayerId(), "Not enough mana!" + "\r\n"); - } else { - for (Effect effect : effects) { - Effect nEffect = new Effect(effect); - nEffect.setPlayerId(player.getPlayerId()); - gameManager.getEntityManager().saveEffect(nEffect); - if (effect.getDurationStats().getCurrentHealth() < 0) { - log.error("ERROR! Someone added an effect with a health modifier which won't work for various reasons."); - continue; - } - String effectApplyMessage; - if (destinationPlayer.addEffect(effect.getEntityId())) { - effectApplyMessage = Color.BOLD_ON + Color.GREEN + "[effect] " + Color.RESET + nEffect.getEffectName() + " applied!" + "\r\n"; - gameManager.getChannelUtils().write(destinationPlayer.getPlayerId(), effectApplyMessage); - } else { - effectApplyMessage = Color.BOLD_ON + Color.GREEN + "[effect] "+ Color.RESET + Color.RED + "Unable to apply " + nEffect.getEffectName() + "!" + "\r\n"; - gameManager.getChannelUtils().write(player.getPlayerId(), effectApplyMessage); - } - } - } - } - } - - public void applyEffectsToNpcs(Set<String> npcIds, Player player) { - Interner<String> interner = Interners.newWeakInterner(); - synchronized (interner.intern(player.getPlayerId())) { - long availableMana = gameManager.getPlayerManager().getPlayerMetadata(player.getPlayerId()).getStats().getCurrentMana(); - if (availableMana < manaCost) { - gameManager.getChannelUtils().write(player.getPlayerId(), "Not enough mana!" + "\r\n"); - } else { - for (Effect effect : effects) { - for (String npcId : npcIds) { - Npc npc = gameManager.getEntityManager().getNpcEntity(npcId); - if (npc == null) { - // assume this npc died - continue; - } - Effect nEffect = new Effect(effect); - nEffect.setPlayerId(player.getPlayerId()); - if (effect.getDurationStats().getCurrentHealth() < 0) { - log.error("ERROR! Someone added an effect with a health modifier which won't work for various reasons."); - continue; - } - StatsHelper.combineStats(npc.getStats(), effect.getDurationStats()); - // gameManager.getEffectsManager().application(nEffect, npc); - npc.addEffect(nEffect); - } - } - } - } - } - - private static int randInt(int min, int max) { - return random.nextInt((max - min) + 1) + min; - } - - public String getSpellName() { - return spellName; - } - - public String getSpellDescription() { - return spellDescription; - } - - public List<String> getAttackMessages() { - return attackMessages; - } - - public Stats getAttackStats() { - return attackStats; - } - - public int getManaCost() { - return manaCost; - } - - public Set<String> getValidTriggers() { - return validTriggers; - } - - public static Random getRandom() { - return random; - } - - public GameManager getGameManager() { - return gameManager; - } - - public Set<Effect> getEffects() { - return effects; - } - - public void setEffects(Set<Effect> effects) { - this.effects = effects; - } - - public boolean isAreaSpell() { - return isAreaSpell; - } - - public SpellExecute getSpellExecute() { - return spellExecute; - } - - interface SpellExecute { - public void executeNpc(GameManager gameManager, Npc npc, Player player); - } -} diff --git a/src/main/java/com/comandante/creeper/spells/ExecuteSpellRunnable.java b/src/main/java/com/comandante/creeper/spells/SpellRunnable.java similarity index 89% rename from src/main/java/com/comandante/creeper/spells/ExecuteSpellRunnable.java rename to src/main/java/com/comandante/creeper/spells/SpellRunnable.java index 7b67fb3e..4a6ac27d 100644 --- a/src/main/java/com/comandante/creeper/spells/ExecuteSpellRunnable.java +++ b/src/main/java/com/comandante/creeper/spells/SpellRunnable.java @@ -7,7 +7,7 @@ import com.comandante.creeper.player.Player; import java.util.Optional; -public interface ExecuteSpellRunnable { +public interface SpellRunnable { void run(Player sourcePlayer, Optional<Npc> destinationNpc, Optional<Player> destinationPlayer, GameManager gameManager); String getName(); } diff --git a/src/main/java/com/comandante/creeper/spells/SpellTriggerRegistry.java b/src/main/java/com/comandante/creeper/spells/SpellTriggerRegistry.java deleted file mode 100644 index e393bc68..00000000 --- a/src/main/java/com/comandante/creeper/spells/SpellTriggerRegistry.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.comandante.creeper.spells; - - -import com.google.common.collect.Maps; - -import java.util.Map; - -public class SpellTriggerRegistry { - - public static final Map<String, Spell> spellMap = Maps.newHashMap(); - public static final Map<String, Spell> spellNameMap = Maps.newHashMap(); - - - public static void addSpell(Spell spell) { - for (String trigger : spell.getValidTriggers()) { - spellMap.put(trigger, spell); - } - } - - public static Spell getSpell(String trigger) { - return spellMap.get(trigger); - } - -} diff --git a/src/main/java/com/comandante/creeper/spells/Spells.java b/src/main/java/com/comandante/creeper/spells/Spells.java index 5874a7d6..8c0e007a 100644 --- a/src/main/java/com/comandante/creeper/spells/Spells.java +++ b/src/main/java/com/comandante/creeper/spells/Spells.java @@ -7,8 +7,6 @@ import com.comandante.creeper.player.Player; import com.comandante.creeper.server.Color; import com.comandante.creeper.stat.Stats; import com.comandante.creeper.stat.StatsHelper; -import com.google.common.collect.Interner; -import com.google.common.collect.Interners; import com.google.common.collect.Sets; import org.apache.log4j.Logger; @@ -19,75 +17,26 @@ public class Spells { private GameManager gameManager; - private static final Logger log = Logger.getLogger(Spell.class); + private static final Logger log = Logger.getLogger(Spells.class); public Spells(GameManager gameManager) { this.gameManager = gameManager; } - public void executeSpell(Player sourcePlayer, Optional<Npc> destinationNpc, Optional<Player> destinationPlayer, ExecuteSpellRunnable executeSpellRunnable) { + public void executeSpell(Player sourcePlayer, Optional<Npc> destinationNpc, Optional<Player> destinationPlayer, SpellRunnable spellRunnable) { try { - executeSpellRunnable.run(sourcePlayer, destinationNpc, destinationPlayer, gameManager); + spellRunnable.run(sourcePlayer, destinationNpc, destinationPlayer, gameManager); } catch (Exception e) { log.error("Problem executing spell.", e); } } - public Optional<ExecuteSpellRunnable> getSpellRunnable(String triggerName) { + public Optional<SpellRunnable> getSpellRunnable(String triggerName) { if (Sets.newHashSet("lightning", "l").contains(triggerName)) { return Optional.of(new LightningSpellRunnable(gameManager)); } return Optional.empty(); } - - public void applyEffectsToNpcs(Player player, Set<Npc> npcs, Set<Effect> effects) { - effects.forEach(effect -> - npcs.forEach(npc -> { - Effect nEffect = new Effect(effect); - nEffect.setPlayerId(player.getPlayerId()); - if (effect.getDurationStats().getCurrentHealth() < 0) { - log.error("ERROR! Someone added an effect with a health modifier which won't work for various reasons."); - return; - } - StatsHelper.combineStats(npc.getStats(), effect.getDurationStats()); - npc.addEffect(nEffect); - })); - } - - public void applyEffectsToPlayer(Player destinationPlayer, Player player, Set<Effect> effects) { - for (Effect effect : effects) { - Effect nEffect = new Effect(effect); - nEffect.setPlayerId(player.getPlayerId()); - gameManager.getEntityManager().saveEffect(nEffect); - if (effect.getDurationStats().getCurrentHealth() < 0) { - log.error("ERROR! Someone added an effect with a health modifier which won't work for various reasons."); - continue; - } - String effectApplyMessage; - if (destinationPlayer.addEffect(effect.getEntityId())) { - effectApplyMessage = Color.BOLD_ON + Color.GREEN + "[effect] " + Color.RESET + nEffect.getEffectName() + " applied!" + "\r\n"; - gameManager.getChannelUtils().write(destinationPlayer.getPlayerId(), effectApplyMessage); - } else { - effectApplyMessage = Color.BOLD_ON + Color.GREEN + "[effect] " + Color.RESET + Color.RED + "Unable to apply " + nEffect.getEffectName() + "!" + "\r\n"; - gameManager.getChannelUtils().write(player.getPlayerId(), effectApplyMessage); - } - } - } - - public static long getSpellAttack(Stats player, Stats victim) { - int rolls = 0; - int totDamage = 0; - while (rolls <= player.getNumberOfWeaponRolls()) { - rolls++; - totDamage = totDamage + CreeperUtils.randInt((int) player.getWeaponRatingMin(), (int) player.getWeaponRatingMax()); - } - long i = player.getStrength() + totDamage - victim.getArmorRating(); - if (i < 0) { - return 0; - } else { - return i; - } - } } -- GitLab