From 324ee878627b983b515deb493f54a890265e055b Mon Sep 17 00:00:00 2001 From: NeumimTo Date: Mon, 3 Jul 2017 23:34:41 +0200 Subject: [PATCH 1/9] some bugfixes, improvements, skill library --- Plugin/pom.xml | 2 +- .../neumimto/rpg/commands/CommandAdmin.java | 45 ++++++++++++--- .../rpg/configuration/PluginConfig.java | 4 +- .../neumimto/rpg/effects/EffectService.java | 10 ++-- .../neumimto/rpg/entities/EntityService.java | 3 +- .../rpg/entities/PropertyContainer.java | 1 + .../rpg/inventory/InventoryService.java | 13 ++--- .../rpg/listeners/InventoryListener.java | 2 - .../rpg/players/CharacterService.java | 17 ++++-- .../java/cz/neumimto/rpg/utils/Utils.java | 2 +- Plugin/src/main/resources/config/Runes.conf | 56 +++++++++++++------ Skills/pom.xml | 2 +- .../effects/negative/DOTFireDamageEffect.java | 4 +- .../negative/LesserFireResistanceEffect.java | 2 - .../effects/positive/AllSkillsBonus.java | 6 +- .../effects/positive/DamageToMana.java | 8 ++- .../positive/ElementalResistanceEffect.java | 2 +- .../IncreasedMovementSpeedEffect.java | 48 ++++++++++++++++ .../effects/positive/LifeAfterKillEffect.java | 3 +- .../effects/positive/MaxLifeBonus.java | 5 +- 20 files changed, 172 insertions(+), 63 deletions(-) create mode 100644 Skills/src/main/java/cz/neumimto/effects/positive/IncreasedMovementSpeedEffect.java diff --git a/Plugin/pom.xml b/Plugin/pom.xml index 3dc6f62e3..7fa0affc7 100644 --- a/Plugin/pom.xml +++ b/Plugin/pom.xml @@ -14,7 +14,7 @@ NT-RPG cz.neumimto.rpg - 1.0.6 + 1.0.7 ${maven.build.timestamp} diff --git a/Plugin/src/main/java/cz/neumimto/rpg/commands/CommandAdmin.java b/Plugin/src/main/java/cz/neumimto/rpg/commands/CommandAdmin.java index 208f575d0..de7cb3849 100644 --- a/Plugin/src/main/java/cz/neumimto/rpg/commands/CommandAdmin.java +++ b/Plugin/src/main/java/cz/neumimto/rpg/commands/CommandAdmin.java @@ -51,11 +51,9 @@ import javax.annotation.Nullable; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; -import java.util.Set; +import java.util.*; import java.util.concurrent.TimeUnit; +import java.util.stream.Collectors; @ResourceLoader.Command @@ -98,7 +96,7 @@ public CommandResult process(CommandSource commandSource, String s) throws Comma } - if (commandSource.hasPermission("ntrpg.superadmin")) { + if (!commandSource.hasPermission("ntrpg.superadmin")) { return CommandResult.empty(); } @@ -136,7 +134,7 @@ public CommandResult process(CommandSource commandSource, String s) throws Comma } else if (a[0].equalsIgnoreCase("delete")) { - } else if (a[0].equalsIgnoreCase("enchantment")) { + } else if (a[0].equalsIgnoreCase("enchantment") || a[0].equalsIgnoreCase("e")) { if (a[1].equalsIgnoreCase("add")) { String name = a[2]; name = name.replaceAll("_", " "); @@ -148,7 +146,11 @@ public CommandResult process(CommandSource commandSource, String s) throws Comma if (player.getItemInHand(HandTypes.MAIN_HAND).isPresent()) { ItemStack itemStack = player.getItemInHand(HandTypes.MAIN_HAND).get(); CustomItemData itemData = inventoryService.getItemData(itemStack); - itemData.enchantements().put(globalEffect.getName(), a[3]); + Map map = new HashMap<>(); + map.putAll(itemData.getEnchantements()); + map.put(globalEffect.getName(), a.length == 2 ? "" : a[3].replaceAll("_", " ")); + itemStack = inventoryService.setEnchantments(map, itemStack); + player.setItemInHand(HandTypes.MAIN_HAND, itemStack); player.sendMessage(Text.of("Enchantment " + globalEffect.getName() + " added")); } else { player.sendMessage(Text.of(Localization.NO_ITEM_IN_HAND)); @@ -256,4 +258,33 @@ public CommandResult process(CommandSource commandSource, String s) throws Comma } return CommandResult.success(); } + + @Override + public List getSuggestions(CommandSource source, String arguments, @Nullable Location targetPosition) throws CommandException { + String[] a = arguments.split(" "); + List ar = new ArrayList<>(); + if (a[0].equalsIgnoreCase("enchantment") || a[0].equalsIgnoreCase("e") ) { + if (a.length == 1) { + ar.add("add"); + ar.add("remove"); + return ar; + } else if (a[1].equalsIgnoreCase("add")) { + if (a.length == 2) { + ar.addAll(effectService.getGlobalEffects().keySet()); + } else { + String q = a[2].replaceAll("_", " "); + int lim = 20; + for (String e : effectService.getGlobalEffects().keySet()) { + if (e.toLowerCase().startsWith(q.toLowerCase())) { + ar.add(e); + lim --; + if (lim == 0) + return ar; + } + } + } + } + } + return ar.stream().map(w -> w.replaceAll(" ", "_")).collect(Collectors.toList()); + } } diff --git a/Plugin/src/main/java/cz/neumimto/rpg/configuration/PluginConfig.java b/Plugin/src/main/java/cz/neumimto/rpg/configuration/PluginConfig.java index ab27ad206..bc0523602 100644 --- a/Plugin/src/main/java/cz/neumimto/rpg/configuration/PluginConfig.java +++ b/Plugin/src/main/java/cz/neumimto/rpg/configuration/PluginConfig.java @@ -113,14 +113,12 @@ public class PluginConfig { public static double MAX_PARTY_SIZE = -68458; - //todo see ActiveCharacter mergeWeapons - /* @ConfigValue @Comment(content = {"If a player chooses a race and a class, where both those groups define damage value for one specific weapon, or projectile" + " this option specifies how the weapon damage will be calculated.", "1 = sum", "2 = take higher value"}) public static int WEAPON_MERGE_STRTATEGY = 2; -*/ + } diff --git a/Plugin/src/main/java/cz/neumimto/rpg/effects/EffectService.java b/Plugin/src/main/java/cz/neumimto/rpg/effects/EffectService.java index f25b8e26d..0345dafa2 100644 --- a/Plugin/src/main/java/cz/neumimto/rpg/effects/EffectService.java +++ b/Plugin/src/main/java/cz/neumimto/rpg/effects/EffectService.java @@ -188,7 +188,6 @@ protected void removeEffect(IEffectContainer container, IEffect iEffect, IEffect } else if (container.getEffects().contains(iEffect)){ container.removeStack(iEffect); if (container.getEffects().isEmpty()) { - iEffect.onRemove(); consumer.removeEffect(container); } } @@ -210,14 +209,11 @@ public void removeEffect(String iEffect, IEffectConsumer consumer, IEffectSource while (iterator.hasNext()) { e = iterator.next(); if (e.getEffectSourceProvider() == effectSource) { - iterator.remove(); if (effectSet.contains(e)) effectSet.remove(e); + removeEffect(effect, e, consumer); } } - if (effect.getEffects().isEmpty()) { - consumer.removeEffect(effect); - } } } @@ -251,6 +247,10 @@ public IGlobalEffect getGlobalEffect(String name) { return globalEffects.get(name.toLowerCase()); } + public Map getGlobalEffects() { + return globalEffects; + } + /** * Applies global effect with unlimited duration * diff --git a/Plugin/src/main/java/cz/neumimto/rpg/entities/EntityService.java b/Plugin/src/main/java/cz/neumimto/rpg/entities/EntityService.java index a3d790303..16f01453f 100644 --- a/Plugin/src/main/java/cz/neumimto/rpg/entities/EntityService.java +++ b/Plugin/src/main/java/cz/neumimto/rpg/entities/EntityService.java @@ -6,6 +6,7 @@ import cz.neumimto.rpg.IEntity; import cz.neumimto.rpg.configuration.PluginConfig; import cz.neumimto.rpg.effects.EffectService; +import cz.neumimto.rpg.effects.IEffectConsumer; import cz.neumimto.rpg.events.skills.SkillHealEvent; import cz.neumimto.rpg.players.CharacterService; import cz.neumimto.rpg.players.IActiveCharacter; @@ -107,7 +108,7 @@ public double getExperiences(EntityType type) { return d; } - public float getEntityProperty(IEntity entity, int id) { + public float getEntityProperty(IEffectConsumer entity, int id) { return Math.min(entity.getProperty(id), propertyService.getMaxPropertyValue(id)); } diff --git a/Plugin/src/main/java/cz/neumimto/rpg/entities/PropertyContainer.java b/Plugin/src/main/java/cz/neumimto/rpg/entities/PropertyContainer.java index 97cc57be4..9088edfe5 100644 --- a/Plugin/src/main/java/cz/neumimto/rpg/entities/PropertyContainer.java +++ b/Plugin/src/main/java/cz/neumimto/rpg/entities/PropertyContainer.java @@ -1,5 +1,6 @@ package cz.neumimto.rpg.entities; + /** * Created by NeumimTo on 29.3.17. */ diff --git a/Plugin/src/main/java/cz/neumimto/rpg/inventory/InventoryService.java b/Plugin/src/main/java/cz/neumimto/rpg/inventory/InventoryService.java index 10718a71c..11f8eccba 100644 --- a/Plugin/src/main/java/cz/neumimto/rpg/inventory/InventoryService.java +++ b/Plugin/src/main/java/cz/neumimto/rpg/inventory/InventoryService.java @@ -28,6 +28,7 @@ import cz.neumimto.rpg.effects.*; import cz.neumimto.rpg.gui.Gui; import cz.neumimto.rpg.inventory.data.CustomItemData; +import cz.neumimto.rpg.inventory.data.NKeys; import cz.neumimto.rpg.inventory.runewords.RWService; import cz.neumimto.rpg.inventory.runewords.Rune; import cz.neumimto.rpg.inventory.runewords.RuneWord; @@ -662,14 +663,12 @@ public void setRestrictions(ItemStack itemStack, List restrictions, int } } - public ItemStack setEnchantments(ItemStack itemStack, Map effects) { + public ItemStack setEnchantments(Map effects,ItemStack itemStack) { CustomItemData itemData = getItemData(itemStack); - for (Map.Entry iGlobalEffectStringEntry : effects.entrySet()) { - IGlobalEffect a = iGlobalEffectStringEntry.getKey(); - if (a != null) { - itemData.getEnchantements().put(a.getName(), iGlobalEffectStringEntry.getValue()); - } - } + Map map = new HashMap<>(); + map.putAll(itemData.getEnchantements()); + map.putAll(effects); + itemData.setEnchantements(map); itemStack.offer(itemData); return updateLore(itemStack); } diff --git a/Plugin/src/main/java/cz/neumimto/rpg/listeners/InventoryListener.java b/Plugin/src/main/java/cz/neumimto/rpg/listeners/InventoryListener.java index 94e0a72e3..ffe495597 100644 --- a/Plugin/src/main/java/cz/neumimto/rpg/listeners/InventoryListener.java +++ b/Plugin/src/main/java/cz/neumimto/rpg/listeners/InventoryListener.java @@ -136,8 +136,6 @@ public void onItemDrop(DropItemEvent event, @First(typeFilter = {EntitySpawnCaus if (hotbarObject == HotbarObject.EMPTYHAND_OR_CONSUMABLE) { return; } - hotbarObject.onUnEquip(character); - character.setHotbarSlot(hotbar.getSelectedSlotIndex(), HotbarObject.EMPTYHAND_OR_CONSUMABLE); inventoryService.initializeHotbar(character, hotbar.getSelectedSlotIndex()); } diff --git a/Plugin/src/main/java/cz/neumimto/rpg/players/CharacterService.java b/Plugin/src/main/java/cz/neumimto/rpg/players/CharacterService.java index b9b9210e3..105707cb2 100644 --- a/Plugin/src/main/java/cz/neumimto/rpg/players/CharacterService.java +++ b/Plugin/src/main/java/cz/neumimto/rpg/players/CharacterService.java @@ -29,6 +29,8 @@ import cz.neumimto.rpg.effects.*; import cz.neumimto.rpg.effects.common.def.BossBarExpNotifier; import cz.neumimto.rpg.effects.common.def.CombatEffect; +import cz.neumimto.rpg.entities.EntityService; +import cz.neumimto.rpg.entities.PropertyContainer; import cz.neumimto.rpg.events.*; import cz.neumimto.rpg.events.character.CharacterWeaponUpdateEvent; import cz.neumimto.rpg.events.character.EventCharacterArmorPostUpdate; @@ -95,11 +97,14 @@ public class CharacterService { private GroupService groupService; @Inject - private PropertyService propertyService; + private EntityService entityService; @Inject private DamageService damageService; + @Inject + private PropertyService propertyService; + @Inject private Logger logger; @@ -867,11 +872,13 @@ public void characterSetMaxHealth(IActiveCharacter character, float newHealht) { /** * Updates character walkspeed to match DefaultProperties.walk_speed property * - * @param character + * @param entity */ - public void updateWalkSpeed(IActiveCharacter character) { - double speed = getCharacterProperty(character, DefaultProperties.walk_speed); - character.getPlayer().offer(Keys.WALKING_SPEED, speed); + public void updateWalkSpeed(IEffectConsumer entity) { + double speed = entityService.getEntityProperty(entity, DefaultProperties.walk_speed); + entity.getEntity().offer(Keys.WALKING_SPEED, speed); + if (PluginConfig.DEBUG) + logger.info(entity + " setting walk speed to " + speed); } /** diff --git a/Plugin/src/main/java/cz/neumimto/rpg/utils/Utils.java b/Plugin/src/main/java/cz/neumimto/rpg/utils/Utils.java index db8528f0e..507896145 100644 --- a/Plugin/src/main/java/cz/neumimto/rpg/utils/Utils.java +++ b/Plugin/src/main/java/cz/neumimto/rpg/utils/Utils.java @@ -243,7 +243,7 @@ public static String capitalizeFirst(String str) { public static String extractNumber(String string) { Matcher matcher = REGEXP_NUMBER.matcher(string); - if (matcher.matches()) { + if (matcher.find()) { return matcher.group(); } return null; diff --git a/Plugin/src/main/resources/config/Runes.conf b/Plugin/src/main/resources/config/Runes.conf index 9fae98fa4..dfbecc646 100644 --- a/Plugin/src/main/resources/config/Runes.conf +++ b/Plugin/src/main/resources/config/Runes.conf @@ -1,16 +1,40 @@ -Runes:{ - Ohm: {} - Vex: {} - Jah: {} - Ist: {} - }, -RuneWords:[ - { - Name: "Particles!" - MinLevel: 10 - Effects: [ - "Fire particles" - ] - Runes: [Vex, Ohm, Ist] - } -] + public class DamageBonus extends EffectBase { + public static final String name = "BonusDamage"; + float bonusDamage; + + public DamageBonus(IEffectConsumer consumer, long duration, float bonusDamage) { + super(name, consumer); + setDuration(duration); + setBonusDamage(bonusDamage); + } + + public float getBonusDamage() { + return bonusDamage; + } + + public void setBonusDamage(float bonusDamage) { + this.bonusDamage = bonusDamage; + } + + @Override + public void onApply() { + super.onApply(); + IActiveCharacter character = (IActiveCharacter) getConsumer(); + character.setCharacterProperty(DefaultProperties.weapon_damage_bonus, character.getCharacterProperty(DefaultProperties.weapon_damage_bonus) + getBonusDamage()); + getGlobalScope().damageService.recalculateCharacterWeaponDamage(character); + } + + @Override + public void onRemove() { + super.onRemove(); + IActiveCharacter character = (IActiveCharacter) getConsumer(); + character.setCharacterProperty(DefaultProperties.weapon_damage_bonus, character.getCharacterProperty(DefaultProperties.weapon_damage_bonus) - getBonusDamage()); + getGlobalScope().damageService.recalculateCharacterWeaponDamage(character); + } + } + + + + IActiveCharacter entity = ... + DamageBonus damagebonu = new DamageBonus(entity,10L,10f); + effectService.addEffect(damagebonu,entity) \ No newline at end of file diff --git a/Skills/pom.xml b/Skills/pom.xml index 6d59ec879..8d189401e 100644 --- a/Skills/pom.xml +++ b/Skills/pom.xml @@ -52,7 +52,7 @@ cz.neumimto.rpg NT-RPG - 1.0.6 + 1.0.7 provided diff --git a/Skills/src/main/java/cz/neumimto/effects/negative/DOTFireDamageEffect.java b/Skills/src/main/java/cz/neumimto/effects/negative/DOTFireDamageEffect.java index 21a3a8793..d9bbfeeea 100644 --- a/Skills/src/main/java/cz/neumimto/effects/negative/DOTFireDamageEffect.java +++ b/Skills/src/main/java/cz/neumimto/effects/negative/DOTFireDamageEffect.java @@ -14,13 +14,13 @@ public class DOTFireDamageEffect extends EffectBase { private double damage; - public DOTFireDamageEffect(String name, IEffectConsumer consumer, double damage, long period, long duration) { + public DOTFireDamageEffect(IEffectConsumer consumer, double damage, long period, long duration) { super(name, consumer); setDuration(duration); setPeriod(period); } - public DOTFireDamageEffect(IActiveCharacter character, long duration, String damage) { + public DOTFireDamageEffect(IEffectConsumer character, long duration, String damage) { super(name, character); setDuration(duration); setPeriod(1000L); diff --git a/Skills/src/main/java/cz/neumimto/effects/negative/LesserFireResistanceEffect.java b/Skills/src/main/java/cz/neumimto/effects/negative/LesserFireResistanceEffect.java index 5bfc5d3a0..a1fd55a45 100644 --- a/Skills/src/main/java/cz/neumimto/effects/negative/LesserFireResistanceEffect.java +++ b/Skills/src/main/java/cz/neumimto/effects/negative/LesserFireResistanceEffect.java @@ -39,7 +39,5 @@ public void onRemove() { float characterProperty = getConsumer().getProperty(DefaultProperties.fire_damage_protection_mult); getConsumer().setProperty(DefaultProperties.fire_damage_protection_mult, characterProperty + getValue()); } - - } diff --git a/Skills/src/main/java/cz/neumimto/effects/positive/AllSkillsBonus.java b/Skills/src/main/java/cz/neumimto/effects/positive/AllSkillsBonus.java index f4059dee0..6579ac7ba 100644 --- a/Skills/src/main/java/cz/neumimto/effects/positive/AllSkillsBonus.java +++ b/Skills/src/main/java/cz/neumimto/effects/positive/AllSkillsBonus.java @@ -14,15 +14,15 @@ public class AllSkillsBonus extends EffectBase { public static final String name = "All skills"; - public AllSkillsBonus(IActiveCharacter character, long duration, int value) { + public AllSkillsBonus(IEffectConsumer character, long duration, int value) { super(name, character); setDuration(duration); setStackable(true, new IntegerEffectStackingStrategy()); setValue(value); } - public AllSkillsBonus(IActiveCharacter character, long duration, String value) { - this(character, duration, Integer.parseInt(InventoryService.REGEXP_NUMBER.matcher(value).group())); + public AllSkillsBonus(IEffectConsumer character, long duration, String value) { + this(character, duration, Integer.parseInt(Utils.extractNumber(value))); } @Override diff --git a/Skills/src/main/java/cz/neumimto/effects/positive/DamageToMana.java b/Skills/src/main/java/cz/neumimto/effects/positive/DamageToMana.java index 94124acba..1d86c23b5 100644 --- a/Skills/src/main/java/cz/neumimto/effects/positive/DamageToMana.java +++ b/Skills/src/main/java/cz/neumimto/effects/positive/DamageToMana.java @@ -3,22 +3,24 @@ import cz.neumimto.rpg.ClassGenerator; import cz.neumimto.rpg.effects.EffectBase; +import cz.neumimto.rpg.effects.IEffectConsumer; import cz.neumimto.rpg.effects.common.stacking.DoubleEffectStackingStrategy; import cz.neumimto.rpg.players.IActiveCharacter; +import cz.neumimto.rpg.utils.Utils; @ClassGenerator.Generate(id = "name") public class DamageToMana extends EffectBase { public static final String name = "Damage to mana"; - public DamageToMana(IActiveCharacter character, long duration, double percentage) { + public DamageToMana(IEffectConsumer character, long duration, double percentage) { super(name, character); setDuration(duration); setValue(percentage); setStackable(true, new DoubleEffectStackingStrategy()); } - public DamageToMana(IActiveCharacter character, long duration, String value) { - this(character, duration, Double.parseDouble(value)); + public DamageToMana(IEffectConsumer character, long duration, String value) { + this(character, duration, Double.parseDouble(Utils.extractNumber(value))); } } diff --git a/Skills/src/main/java/cz/neumimto/effects/positive/ElementalResistanceEffect.java b/Skills/src/main/java/cz/neumimto/effects/positive/ElementalResistanceEffect.java index 1c6e9a55d..8e8837c02 100644 --- a/Skills/src/main/java/cz/neumimto/effects/positive/ElementalResistanceEffect.java +++ b/Skills/src/main/java/cz/neumimto/effects/positive/ElementalResistanceEffect.java @@ -23,7 +23,7 @@ public ElementalResistanceEffect(IEffectConsumer consumer, float percentage, lon setDuration(duration); } - public ElementalResistanceEffect(IActiveCharacter character, long duration, String level) { + public ElementalResistanceEffect(IEffectConsumer character, long duration, String level) { this(character, Float.parseFloat(level), duration); } diff --git a/Skills/src/main/java/cz/neumimto/effects/positive/IncreasedMovementSpeedEffect.java b/Skills/src/main/java/cz/neumimto/effects/positive/IncreasedMovementSpeedEffect.java new file mode 100644 index 000000000..e562c6335 --- /dev/null +++ b/Skills/src/main/java/cz/neumimto/effects/positive/IncreasedMovementSpeedEffect.java @@ -0,0 +1,48 @@ +package cz.neumimto.effects.positive; + +import cz.neumimto.rpg.ClassGenerator; +import cz.neumimto.rpg.effects.EffectBase; +import cz.neumimto.rpg.effects.IEffectConsumer; +import cz.neumimto.rpg.effects.common.stacking.FloatEffectStackingStrategy; +import cz.neumimto.rpg.players.IActiveCharacter; +import cz.neumimto.rpg.players.properties.DefaultProperties; +import cz.neumimto.rpg.utils.Utils; + +/** + * Created by NeumimTo on 3.7.2017. + */ +@ClassGenerator.Generate(id = "name") +public class IncreasedMovementSpeedEffect extends EffectBase { + + public static final String name = "Movement Speed"; + + public IncreasedMovementSpeedEffect(IEffectConsumer consumer, long duration, float value) { + super(name,consumer); + setValue(value); + setDuration(duration); + setStackable(true, new FloatEffectStackingStrategy()); + } + + public IncreasedMovementSpeedEffect(IEffectConsumer character, long duration, String level) { + this(character, duration, Float.parseFloat(Utils.extractNumber(level)) / 100); + } + + @Override + public void onApply() { + getConsumer().setProperty(DefaultProperties.walk_speed, getConsumer().getProperty(DefaultProperties.walk_speed) + getValue()); + getGlobalScope().characterService.updateWalkSpeed(getConsumer()); + } + + @Override + public void onRemove() { + getConsumer().setProperty(DefaultProperties.walk_speed, getConsumer().getProperty(DefaultProperties.walk_speed) - getValue()); + getGlobalScope().characterService.updateWalkSpeed(getConsumer()); + } + + @Override + public void setValue(Float o) { + if (getValue() != null) + throw new IllegalStateException("Operation permited"); + super.setValue(o); + } +} diff --git a/Skills/src/main/java/cz/neumimto/effects/positive/LifeAfterKillEffect.java b/Skills/src/main/java/cz/neumimto/effects/positive/LifeAfterKillEffect.java index 6e5e2c412..d60b0480e 100644 --- a/Skills/src/main/java/cz/neumimto/effects/positive/LifeAfterKillEffect.java +++ b/Skills/src/main/java/cz/neumimto/effects/positive/LifeAfterKillEffect.java @@ -2,6 +2,7 @@ import cz.neumimto.rpg.ClassGenerator; import cz.neumimto.rpg.effects.EffectBase; +import cz.neumimto.rpg.effects.IEffectConsumer; import cz.neumimto.rpg.effects.common.stacking.FloatEffectStackingStrategy; import cz.neumimto.rpg.players.IActiveCharacter; import cz.neumimto.rpg.utils.Utils; @@ -10,7 +11,7 @@ public class LifeAfterKillEffect extends EffectBase { public static final String name = "Life after each kill"; - public LifeAfterKillEffect(IActiveCharacter character, long duration, String healedAmount) { + public LifeAfterKillEffect(IEffectConsumer character, long duration, String healedAmount) { super(name, character); setDuration(duration); setValue(Float.parseFloat(Utils.extractNumber(healedAmount))); diff --git a/Skills/src/main/java/cz/neumimto/effects/positive/MaxLifeBonus.java b/Skills/src/main/java/cz/neumimto/effects/positive/MaxLifeBonus.java index 960422b82..4ef8b417e 100644 --- a/Skills/src/main/java/cz/neumimto/effects/positive/MaxLifeBonus.java +++ b/Skills/src/main/java/cz/neumimto/effects/positive/MaxLifeBonus.java @@ -2,15 +2,16 @@ import cz.neumimto.rpg.ClassGenerator; import cz.neumimto.rpg.effects.EffectBase; +import cz.neumimto.rpg.effects.IEffectConsumer; import cz.neumimto.rpg.players.IActiveCharacter; @ClassGenerator.Generate(id = "name") public class MaxLifeBonus extends EffectBase { - public static final String name = "Max. life bonus"; + public static final String name = "Max life"; - public MaxLifeBonus(IActiveCharacter character, long duration, String level) { + public MaxLifeBonus(IEffectConsumer character, long duration, String level) { //todo } From 1f11c43f9376604c44f4c27e47a895ed0e006fc1 Mon Sep 17 00:00:00 2001 From: NeumimTo Date: Wed, 5 Jul 2017 21:29:51 +0200 Subject: [PATCH 2/9] added stuff into skill library + bugfixes --- NT-RPG-WEBGUI/pom.xml | 2 +- .../java/cz/neumimto/rpg/NtRpgPlugin.java | 2 +- .../cz/neumimto/rpg/effects/EffectBase.java | 11 +++ .../neumimto/rpg/effects/EffectContainer.java | 39 +++++++++++ .../neumimto/rpg/effects/EffectService.java | 12 +++- .../rpg/effects/EffectSourceType.java | 3 +- .../java/cz/neumimto/rpg/effects/IEffect.java | 4 ++ .../rpg/effects/IEffectContainer.java | 15 ++-- .../stacking/UnstackableEffectData.java | 11 +++ .../neumimto/rpg/entities/EntityService.java | 1 + .../listeners/EntityLifecycleListener.java | 5 -- .../rpg/players/CharacterService.java | 1 - .../java/cz/neumimto/rpg/skills/ISkill.java | 8 +++ .../cz/neumimto/rpg/skills/SkillNodes.java | 4 +- .../cz/neumimto/rpg/skills/SkillSettings.java | 2 + .../java/cz/neumimto/rpg/utils/Utils.java | 13 +++- .../cz/neumimto/AdditionalProperties.java | 14 ++++ .../main/java/cz/neumimto/SkillListener.java | 51 ++++++++++++++ .../java/cz/neumimto/SkillLocalization.java | 12 ++++ .../neumimto/effects/negative/StunEffect.java | 11 +-- .../effects/positive/ArrowstormEffect.java | 69 +++++++++++++++++++ .../cz/neumimto/effects/positive/Bash.java | 52 ++++++++++++++ .../positive/BurningPrescenseEffect.java | 47 +++++++++++++ .../cz/neumimto/events/StunApplyEvent.java | 34 +++++++++ .../java/cz/neumimto/model/BashModel.java | 22 ++++++ .../neumimto/model/BurningpresenseModel.java | 22 ++++++ .../java/cz/neumimto/skills/Arrowblast.java | 7 ++ .../java/cz/neumimto/skills/Arrowstorm.java | 45 ++++++++++++ .../main/java/cz/neumimto/skills/Basher.java | 63 +++++++++++++++++ .../cz/neumimto/skills/BurningPrescense.java | 51 ++++++++++++++ .../cz/neumimto/skills/SkillMegabolt.java | 1 - 31 files changed, 610 insertions(+), 24 deletions(-) create mode 100644 Plugin/src/main/java/cz/neumimto/rpg/effects/common/stacking/UnstackableEffectData.java create mode 100644 Skills/src/main/java/cz/neumimto/AdditionalProperties.java create mode 100644 Skills/src/main/java/cz/neumimto/effects/positive/ArrowstormEffect.java create mode 100644 Skills/src/main/java/cz/neumimto/effects/positive/Bash.java create mode 100644 Skills/src/main/java/cz/neumimto/effects/positive/BurningPrescenseEffect.java create mode 100644 Skills/src/main/java/cz/neumimto/events/StunApplyEvent.java create mode 100644 Skills/src/main/java/cz/neumimto/model/BashModel.java create mode 100644 Skills/src/main/java/cz/neumimto/model/BurningpresenseModel.java create mode 100644 Skills/src/main/java/cz/neumimto/skills/Arrowblast.java create mode 100644 Skills/src/main/java/cz/neumimto/skills/Arrowstorm.java create mode 100644 Skills/src/main/java/cz/neumimto/skills/Basher.java create mode 100644 Skills/src/main/java/cz/neumimto/skills/BurningPrescense.java diff --git a/NT-RPG-WEBGUI/pom.xml b/NT-RPG-WEBGUI/pom.xml index 992e755cc..f56d13c7c 100644 --- a/NT-RPG-WEBGUI/pom.xml +++ b/NT-RPG-WEBGUI/pom.xml @@ -69,7 +69,7 @@ cz.neumimto.rpg NT-RPG - 1.0.6 + 1.0.7 provided diff --git a/Plugin/src/main/java/cz/neumimto/rpg/NtRpgPlugin.java b/Plugin/src/main/java/cz/neumimto/rpg/NtRpgPlugin.java index 90de58ebf..0b551c9a1 100644 --- a/Plugin/src/main/java/cz/neumimto/rpg/NtRpgPlugin.java +++ b/Plugin/src/main/java/cz/neumimto/rpg/NtRpgPlugin.java @@ -58,7 +58,7 @@ /** * Created by NeumimTo on 29.4.2015. */ -@Plugin(id = "nt-rpg", version = "1.0.6", name = "NT-Rpg", dependencies = { +@Plugin(id = "nt-rpg", version = "1.0.7", name = "NT-Rpg", dependencies = { @Dependency(id = "nt-core", version = "1.7",optional = false) }) public class NtRpgPlugin { diff --git a/Plugin/src/main/java/cz/neumimto/rpg/effects/EffectBase.java b/Plugin/src/main/java/cz/neumimto/rpg/effects/EffectBase.java index 083ccf0f6..b4fd2fe11 100644 --- a/Plugin/src/main/java/cz/neumimto/rpg/effects/EffectBase.java +++ b/Plugin/src/main/java/cz/neumimto/rpg/effects/EffectBase.java @@ -50,6 +50,7 @@ public class EffectBase implements IEffect { private Value value; private EffectStackingStrategy effectStackingStrategy; private IEffectContainer> container; + private boolean tickingDisabled = false; public EffectBase(String name, IEffectConsumer consumer) { this(); @@ -278,4 +279,14 @@ protected void addEffectType(EffectType e) { effectTypes = new HashSet<>(); effectTypes.add(e); } + + @Override + public boolean isTickingDisabled() { + return tickingDisabled; + } + + @Override + public void setTickingDisabled(boolean tickingDisabled) { + this.tickingDisabled = tickingDisabled; + } } diff --git a/Plugin/src/main/java/cz/neumimto/rpg/effects/EffectContainer.java b/Plugin/src/main/java/cz/neumimto/rpg/effects/EffectContainer.java index 0d5cec002..22af0792a 100644 --- a/Plugin/src/main/java/cz/neumimto/rpg/effects/EffectContainer.java +++ b/Plugin/src/main/java/cz/neumimto/rpg/effects/EffectContainer.java @@ -1,5 +1,7 @@ package cz.neumimto.rpg.effects; +import cz.neumimto.rpg.effects.common.stacking.UnstackableEffectData; + import java.util.HashSet; import java.util.Set; @@ -59,4 +61,41 @@ public K getStackedValue() { public void setStackedValue(K k) { this.value = k; } + + + public static class UnstackableSingleInstance extends EffectContainer, IEffect>> { + + public UnstackableSingleInstance(IEffect iEffect) { + super(iEffect); + } + + @Override + public void stackEffect(IEffect> unstackableEffectDataIEffect, IEffectSourceProvider effectSourceProvider) { + super.stackEffect(unstackableEffectDataIEffect, effectSourceProvider); + } + + @Override + public void removeStack(IEffect> iEffect) { + super.removeStack(iEffect); + updateStackedValue(); + } + + + @Override + public void updateStackedValue() { + UnstackableEffectData stackedValue = getStackedValue(); + IEffect> next = null; + for (IEffect> effect : getEffects()) { + if (stackedValue.isInferiorTo(effect.getValue())) { + if (next != null) { + next.setTickingDisabled(true); + } + next = effect; + setStackedValue(effect.getValue()); + } else { + effect.setTickingDisabled(true); + } + } + } + } } diff --git a/Plugin/src/main/java/cz/neumimto/rpg/effects/EffectService.java b/Plugin/src/main/java/cz/neumimto/rpg/effects/EffectService.java index 0345dafa2..917acfa44 100644 --- a/Plugin/src/main/java/cz/neumimto/rpg/effects/EffectService.java +++ b/Plugin/src/main/java/cz/neumimto/rpg/effects/EffectService.java @@ -37,7 +37,7 @@ public class EffectService { - public static final long TICK_PERIOD = 250L; + public static final long TICK_PERIOD = 5L; private static final long unlimited_duration = -1; @@ -136,8 +136,10 @@ public void run() { * @param effect */ public void tickEffect(IEffect effect, long time) { - effect.onTick(); - effect.tickCountIncrement(); + if (!effect.isTickingDisabled()) { + effect.onTick(); + effect.tickCountIncrement(); + } effect.setLastTickTime(time); } @@ -180,6 +182,9 @@ public void removeEffect(IEffect iEffect, IEffectConsumer consumer) { } } + public void removeEffect(IEffectContainer> container, IEffectConsumer consumer) { + container.forEach(a->removeEffect(a, consumer)); + } protected void removeEffect(IEffectContainer container, IEffect iEffect, IEffectConsumer consumer) { if (iEffect == container) { @@ -285,6 +290,7 @@ public void removeGlobalEffectsAsEnchantments(Map itemEff }); } + public boolean isGlobalEffect(String s) { return globalEffects.containsKey(s.toLowerCase()); } diff --git a/Plugin/src/main/java/cz/neumimto/rpg/effects/EffectSourceType.java b/Plugin/src/main/java/cz/neumimto/rpg/effects/EffectSourceType.java index a921cf25f..be4a5bbd2 100644 --- a/Plugin/src/main/java/cz/neumimto/rpg/effects/EffectSourceType.java +++ b/Plugin/src/main/java/cz/neumimto/rpg/effects/EffectSourceType.java @@ -18,7 +18,8 @@ public enum EffectSourceType implements IEffectSource { CLASS(false), CHARM(true), INTERNAL(true), - COMMAND(true); + COMMAND(true), + EFFECT(false); private boolean m; diff --git a/Plugin/src/main/java/cz/neumimto/rpg/effects/IEffect.java b/Plugin/src/main/java/cz/neumimto/rpg/effects/IEffect.java index b9d11be01..cf3810871 100644 --- a/Plugin/src/main/java/cz/neumimto/rpg/effects/IEffect.java +++ b/Plugin/src/main/java/cz/neumimto/rpg/effects/IEffect.java @@ -113,4 +113,8 @@ default > IEffectContainer constructEffectContainer() IEffectContainer> getEffectContainer(); void setEffectContainer(IEffectContainer> iEffectContainer); + + boolean isTickingDisabled(); + + void setTickingDisabled(boolean tickingDisabled); } diff --git a/Plugin/src/main/java/cz/neumimto/rpg/effects/IEffectContainer.java b/Plugin/src/main/java/cz/neumimto/rpg/effects/IEffectContainer.java index 40174c960..40d9662e7 100644 --- a/Plugin/src/main/java/cz/neumimto/rpg/effects/IEffectContainer.java +++ b/Plugin/src/main/java/cz/neumimto/rpg/effects/IEffectContainer.java @@ -6,7 +6,7 @@ /** * Created by NeumimTo on 1.4.2017. */ -public interface IEffectContainer> { +public interface IEffectContainer> extends IEffectSourceProvider { Set getEffects(); @@ -33,9 +33,11 @@ default void forEach(Consumer consumer) { } default void updateStackedValue(){ - setStackedValue(getEffectStackingStrategy().getDefaultValue()); - for (T t : getEffects()) { - setStackedValue(t.getEffectStackingStrategy().mergeValues(getStackedValue(), t.getValue())); + if (getEffectStackingStrategy() != null) { + setStackedValue(getEffectStackingStrategy().getDefaultValue()); + for (T t : getEffects()) { + setStackedValue(t.getEffectStackingStrategy().mergeValues(getStackedValue(), t.getValue())); + } } } @@ -49,4 +51,9 @@ default void removeStack(T iEffect) { getEffects().remove(iEffect); iEffect.onRemove(); } + + @Override + default IEffectSource getType() { + return EffectSourceType.EFFECT; + } } diff --git a/Plugin/src/main/java/cz/neumimto/rpg/effects/common/stacking/UnstackableEffectData.java b/Plugin/src/main/java/cz/neumimto/rpg/effects/common/stacking/UnstackableEffectData.java new file mode 100644 index 000000000..ce4548e7b --- /dev/null +++ b/Plugin/src/main/java/cz/neumimto/rpg/effects/common/stacking/UnstackableEffectData.java @@ -0,0 +1,11 @@ +package cz.neumimto.rpg.effects.common.stacking; + +/** + * Created by NeumimTo on 5.7.2017. + */ +public interface UnstackableEffectData extends Comparable { + + default boolean isInferiorTo(T replacement) { + return this != replacement && compareTo(replacement) > 0; + } +} diff --git a/Plugin/src/main/java/cz/neumimto/rpg/entities/EntityService.java b/Plugin/src/main/java/cz/neumimto/rpg/entities/EntityService.java index 16f01453f..0f1aee1ad 100644 --- a/Plugin/src/main/java/cz/neumimto/rpg/entities/EntityService.java +++ b/Plugin/src/main/java/cz/neumimto/rpg/entities/EntityService.java @@ -71,6 +71,7 @@ public void remove(UUID e) { IMob iMob = entityHashMap.get(e); effectService.removeAllEffects(iMob); entityHashMap.remove(e); + iMob.detach(); } } diff --git a/Plugin/src/main/java/cz/neumimto/rpg/listeners/EntityLifecycleListener.java b/Plugin/src/main/java/cz/neumimto/rpg/listeners/EntityLifecycleListener.java index fe8ecd45e..42ce4c07d 100644 --- a/Plugin/src/main/java/cz/neumimto/rpg/listeners/EntityLifecycleListener.java +++ b/Plugin/src/main/java/cz/neumimto/rpg/listeners/EntityLifecycleListener.java @@ -146,11 +146,6 @@ public void onEntityDespawn(DestructEntityEvent event) { } } IMob mob = (IMob) entityService.get(event.getTargetEntity()); - Collection values = mob.getEffectMap().values(); - for (IEffect value : values) { - effectService.stopEffect(value); - } - mob.detach(); entityService.remove(event.getTargetEntity().getUniqueId()); } } diff --git a/Plugin/src/main/java/cz/neumimto/rpg/players/CharacterService.java b/Plugin/src/main/java/cz/neumimto/rpg/players/CharacterService.java index 105707cb2..643911579 100644 --- a/Plugin/src/main/java/cz/neumimto/rpg/players/CharacterService.java +++ b/Plugin/src/main/java/cz/neumimto/rpg/players/CharacterService.java @@ -676,7 +676,6 @@ public Pair upgradeSkill(IAct cc.setUsedSkillPoints(s + 1); CharacterSkill characterSkill = character.getCharacterBase().getCharacterSkill(skill); characterSkill.setLevel(extendedSkillInfo.getLevel()); - putInSaveQueue(character.getCharacterBase()); skill.skillUpgrade(character, event.getLevel()); p.key = SkillTreeActionResult.UPGRADED; p.value = new SkillTreeActionResult.Data(skill.getName(), event.getLevel() + ""); diff --git a/Plugin/src/main/java/cz/neumimto/rpg/skills/ISkill.java b/Plugin/src/main/java/cz/neumimto/rpg/skills/ISkill.java index 1636b6032..6690b41b2 100644 --- a/Plugin/src/main/java/cz/neumimto/rpg/skills/ISkill.java +++ b/Plugin/src/main/java/cz/neumimto/rpg/skills/ISkill.java @@ -77,6 +77,14 @@ default float getFloatNodeValue(ExtendedSkillInfo extendedSkillInfo, ISkillNode return extendedSkillInfo.getSkillData().getSkillSettings().getLevelNodeValue(node,extendedSkillInfo.getTotalLevel()); } + default int getIntNodeValue(ExtendedSkillInfo extendedSkillInfo, ISkillNode node) { + return getIntNodeValue(extendedSkillInfo, node.value()); + } + + default int getIntNodeValue(ExtendedSkillInfo extendedSkillInfo, String node) { + return (int) extendedSkillInfo.getSkillData().getSkillSettings().getLevelNodeValue(node,extendedSkillInfo.getTotalLevel()); + } + default long getLongNodeValue(ExtendedSkillInfo extendedSkillInfo, ISkillNode node) { return (long) extendedSkillInfo.getSkillData().getSkillSettings().getLevelNodeValue(node,extendedSkillInfo.getTotalLevel()); } diff --git a/Plugin/src/main/java/cz/neumimto/rpg/skills/SkillNodes.java b/Plugin/src/main/java/cz/neumimto/rpg/skills/SkillNodes.java index 298e4dc08..cf7576f7a 100644 --- a/Plugin/src/main/java/cz/neumimto/rpg/skills/SkillNodes.java +++ b/Plugin/src/main/java/cz/neumimto/rpg/skills/SkillNodes.java @@ -14,7 +14,9 @@ public enum SkillNodes implements ISkillNode { PROJECTILE_TYPE("projectile-type", null), RANGE("range", SkillModifierProcessor.D_STACK), DURATION("duration", SkillModifierProcessor.L_STACK), - AMOUNT("amount", SkillModifierProcessor.D_STACK); + AMOUNT("amount", SkillModifierProcessor.D_STACK), + PERIOD("period", SkillModifierProcessor.L_STACK), + CHANCE("chance", SkillModifierProcessor.D_STACK ); private final String str; diff --git a/Plugin/src/main/java/cz/neumimto/rpg/skills/SkillSettings.java b/Plugin/src/main/java/cz/neumimto/rpg/skills/SkillSettings.java index ab53c86c2..e13d072ef 100644 --- a/Plugin/src/main/java/cz/neumimto/rpg/skills/SkillSettings.java +++ b/Plugin/src/main/java/cz/neumimto/rpg/skills/SkillSettings.java @@ -18,6 +18,8 @@ package cz.neumimto.rpg.skills; +import cz.neumimto.rpg.players.properties.DefaultProperties; + import java.util.HashMap; import java.util.Map; diff --git a/Plugin/src/main/java/cz/neumimto/rpg/utils/Utils.java b/Plugin/src/main/java/cz/neumimto/rpg/utils/Utils.java index 507896145..0d5b8e67f 100644 --- a/Plugin/src/main/java/cz/neumimto/rpg/utils/Utils.java +++ b/Plugin/src/main/java/cz/neumimto/rpg/utils/Utils.java @@ -25,6 +25,7 @@ import cz.neumimto.rpg.NtRpgPlugin; import cz.neumimto.rpg.players.IActiveCharacter; import cz.neumimto.rpg.players.properties.PropertyService; +import cz.neumimto.rpg.skills.NDamageType; import org.spongepowered.api.Sponge; import org.spongepowered.api.block.BlockType; import org.spongepowered.api.block.BlockTypes; @@ -36,12 +37,17 @@ import org.spongepowered.api.entity.living.Living; import org.spongepowered.api.entity.living.player.Player; import org.spongepowered.api.entity.projectile.Projectile; +import org.spongepowered.api.event.cause.Cause; +import org.spongepowered.api.event.cause.NamedCause; +import org.spongepowered.api.event.cause.entity.damage.source.DamageSource; +import org.spongepowered.api.event.entity.DamageEntityEvent; import org.spongepowered.api.text.Text; import org.spongepowered.api.util.blockray.BlockRay; import org.spongepowered.api.util.blockray.BlockRayHit; import org.spongepowered.api.world.Location; import org.spongepowered.api.world.World; import org.spongepowered.api.world.extent.EntityUniverse; +import org.spongepowered.common.event.damage.SpongeDamageSourceBuilder; import java.util.*; import java.util.function.Consumer; @@ -205,7 +211,12 @@ public static boolean canDamage(IActiveCharacter character, Living l) { } } } - return true; + DamageSource build = new SpongeDamageSourceBuilder() + .type(NDamageType.DAMAGE_CHECK) + .absolute() + .build(); + + return l.damage(0, build); } public static boolean isLivingEntity(Entity entity) { diff --git a/Skills/src/main/java/cz/neumimto/AdditionalProperties.java b/Skills/src/main/java/cz/neumimto/AdditionalProperties.java new file mode 100644 index 000000000..2a4200ab4 --- /dev/null +++ b/Skills/src/main/java/cz/neumimto/AdditionalProperties.java @@ -0,0 +1,14 @@ +package cz.neumimto; + +import cz.neumimto.rpg.players.properties.Property; +import cz.neumimto.rpg.players.properties.PropertyContainer; + +/** + * Created by NeumimTo on 5.7.2017. + */ +@PropertyContainer +public class AdditionalProperties { + + @Property(name = "stun_duration_mult", default_ = 1) + public static int stun_duration_mult; +} diff --git a/Skills/src/main/java/cz/neumimto/SkillListener.java b/Skills/src/main/java/cz/neumimto/SkillListener.java index 4a9c8ab57..473a8fdac 100644 --- a/Skills/src/main/java/cz/neumimto/SkillListener.java +++ b/Skills/src/main/java/cz/neumimto/SkillListener.java @@ -1,19 +1,30 @@ package cz.neumimto; import cz.neumimto.core.ioc.Inject; +import cz.neumimto.effects.negative.StunEffect; +import cz.neumimto.effects.positive.Bash; import cz.neumimto.effects.positive.DamageToMana; import cz.neumimto.effects.positive.LifeAfterKillEffect; +import cz.neumimto.events.StunApplyEvent; +import cz.neumimto.model.BashModel; import cz.neumimto.rpg.ResourceLoader; +import cz.neumimto.rpg.effects.EffectService; import cz.neumimto.rpg.effects.IEffectContainer; import cz.neumimto.rpg.entities.EntityService; +import cz.neumimto.rpg.events.INEntityWeaponDamageEvent; import cz.neumimto.rpg.events.character.CharacterDamageEntityEvent; import cz.neumimto.rpg.players.CharacterService; import cz.neumimto.rpg.players.IActiveCharacter; +import cz.neumimto.rpg.players.properties.DefaultProperties; +import cz.neumimto.rpg.players.properties.PropertyService; +import cz.neumimto.skills.Basher; +import org.spongepowered.api.Game; import org.spongepowered.api.entity.living.player.Player; import org.spongepowered.api.event.Listener; import org.spongepowered.api.event.entity.DestructEntityEvent; import java.util.Optional; +import java.util.concurrent.ThreadLocalRandom; /** * Created by ja on 21.5.2016. @@ -27,6 +38,15 @@ public class SkillListener { @Inject private EntityService entityService; + @Inject + private EffectService effectService; + + @Inject + private PropertyService propertyService; + + @Inject + private Game game; + @Listener public void onKill(DestructEntityEvent.Death event) { Optional first = event.getCause().first(Player.class); @@ -54,4 +74,35 @@ public void onDamage(CharacterDamageEntityEvent event) { } } } + + @Listener + public void onDamage(INEntityWeaponDamageEvent event) { + if (event.getSource().hasEffect(Bash.name)) { + IEffectContainer effect = event.getSource().getEffect(Bash.name); + BashModel stackedValue = effect.getStackedValue(); + long time = System.currentTimeMillis(); + float reduced = entityService.getEntityProperty(event.getTarget(), DefaultProperties.cooldown_reduce); + long cooldown = (long) (reduced * (float) stackedValue.cooldown); + if (stackedValue.lasttime + cooldown <= time) { + int rnd = ThreadLocalRandom.current().nextInt(100); + if (rnd <= stackedValue.chance) { + StunEffect stunEffect = new StunEffect(event.getTarget(),stackedValue.stunDuration); + if (stackedValue.damage > 0) { + event.setDamage(event.getDamage() + stackedValue.damage); + } + if (!game.getEventManager().post(new StunApplyEvent(event.getSource(), event.getTarget(), stunEffect))) { + effectService.addEffect(stunEffect, event.getTarget(), effect); + stackedValue.lasttime = time; + } + } + } + } + } + + @Listener + public void onStunApply(StunApplyEvent event) { + StunEffect effect = event.getEffect(); + float f = entityService.getEntityProperty(event.getSource(), AdditionalProperties.stun_duration_mult); + effect.setDuration((long) (f * event.getEffect().getDuration())); + } } diff --git a/Skills/src/main/java/cz/neumimto/SkillLocalization.java b/Skills/src/main/java/cz/neumimto/SkillLocalization.java index 8a777fb94..69adc8fd1 100644 --- a/Skills/src/main/java/cz/neumimto/SkillLocalization.java +++ b/Skills/src/main/java/cz/neumimto/SkillLocalization.java @@ -60,4 +60,16 @@ public class SkillLocalization { @ConfigValue public static String AGI = "Agility"; + + @ConfigValue + public static String Arrowstorm = "Shoots a random number of arrows"; + + @ConfigValue + public static String basher; + + @ConfigValue + public static String burningPrescense = ""; + + @ConfigValue + public static String burningPrescense_desc = ""; } diff --git a/Skills/src/main/java/cz/neumimto/effects/negative/StunEffect.java b/Skills/src/main/java/cz/neumimto/effects/negative/StunEffect.java index 7e3d5bdb1..5bf695415 100644 --- a/Skills/src/main/java/cz/neumimto/effects/negative/StunEffect.java +++ b/Skills/src/main/java/cz/neumimto/effects/negative/StunEffect.java @@ -1,6 +1,7 @@ package cz.neumimto.effects.negative; import cz.neumimto.rpg.ClassGenerator; +import cz.neumimto.rpg.IEntity; import cz.neumimto.rpg.effects.*; import org.spongepowered.api.world.Location; import org.spongepowered.api.world.World; @@ -13,10 +14,14 @@ public class StunEffect extends EffectBase> { public static final String name = "Stun"; + public StunEffect(IEffectConsumer consumer, long duration, String value) { + this(consumer, duration); + } + public StunEffect(IEffectConsumer consumer, long duration) { super(name, consumer); setValue(consumer.getEntity().getLocation()); - setPeriod(5L); + setPeriod(50L); setDuration(duration); addEffectType(CommonEffectTypes.SILENCE); addEffectType(CommonEffectTypes.STUN); @@ -27,8 +32,4 @@ public void onTick() { getConsumer().getEntity().setLocation(getValue()); } - @Override - public SingleEffectInstanceContainer constructEffectContainer() { - return new SingleEffectInstanceContainer(this); - } } diff --git a/Skills/src/main/java/cz/neumimto/effects/positive/ArrowstormEffect.java b/Skills/src/main/java/cz/neumimto/effects/positive/ArrowstormEffect.java new file mode 100644 index 000000000..5f6aedbb5 --- /dev/null +++ b/Skills/src/main/java/cz/neumimto/effects/positive/ArrowstormEffect.java @@ -0,0 +1,69 @@ +package cz.neumimto.effects.positive; + +import cz.neumimto.rpg.ClassGenerator; +import cz.neumimto.rpg.ResourceLoader; +import cz.neumimto.rpg.damage.SkillDamageSourceBuilder; +import cz.neumimto.rpg.effects.EffectBase; +import cz.neumimto.rpg.effects.EffectContainer; +import cz.neumimto.rpg.effects.IEffectConsumer; +import cz.neumimto.rpg.effects.IEffectContainer; +import cz.neumimto.rpg.skills.ProjectileProperties; +import cz.neumimto.rpg.skills.SkillNodes; +import cz.neumimto.rpg.utils.Utils; +import org.spongepowered.api.entity.Entity; +import org.spongepowered.api.entity.EntityTypes; +import org.spongepowered.api.entity.living.Living; +import org.spongepowered.api.world.World; + +import java.util.HashSet; +import java.util.Set; + +import static java.lang.Math.cos; +import static java.lang.Math.sin; + +/** + * Created by NeumimTo on 4.7.2017. + */ +@ClassGenerator.Generate(id = "name") +public class ArrowstormEffect extends EffectBase implements IEffectContainer { + + public static final String name = "Arrowstorm"; + private int arrows; + + public ArrowstormEffect(IEffectConsumer consumer, long period, int arrows) { + super(name, consumer); + this.arrows = arrows; + setDuration(-1L); + setPeriod(period); + } + + @Override + public void onTick() { + if (arrows != 0) { + Living entity = getConsumer().getEntity(); + World world = entity.getWorld(); + world.createEntity(EntityTypes.TIPPED_ARROW, + entity.getLocation().getPosition() + .add(cos((entity.getRotation().getX() - 90) % 360 + ) * 0.2, 1.8, sin((entity.getRotation().getX() - 90) % 360) * 0.2)); + arrows--; + } else { + setDuration(0); //remove the effect next effect scheduler phase + } + } + + @Override + public Set getEffects() { + return new HashSet<>(); + } + + @Override + public Object getStackedValue() { + return null; + } + + @Override + public void setStackedValue(Object o) { + + } +} diff --git a/Skills/src/main/java/cz/neumimto/effects/positive/Bash.java b/Skills/src/main/java/cz/neumimto/effects/positive/Bash.java new file mode 100644 index 000000000..221e81d68 --- /dev/null +++ b/Skills/src/main/java/cz/neumimto/effects/positive/Bash.java @@ -0,0 +1,52 @@ +package cz.neumimto.effects.positive; + +import cz.neumimto.model.BashModel; +import cz.neumimto.rpg.ClassGenerator; +import cz.neumimto.rpg.effects.*; +import cz.neumimto.rpg.utils.Utils; + +/** + * Created by NeumimTo on 4.7.2017. + */ +@ClassGenerator.Generate(id = "name") +public class Bash extends EffectBase { + + public static final String name = "Bash"; + + public Bash(IEffectConsumer consumer, long duration, String value) { + super(name, consumer); + BashModel model = new BashModel(); + + String[] split = value.split(", "); + if (split.length > 0) { + model.chance = Integer.parseInt(Utils.extractNumber(split[0])); + model.damage = 0; + model.cooldown = 2000; + model.stunDuration = 500; + if (split.length > 1) { + model.damage = Double.parseDouble(Utils.extractNumber(split[1])); + if (split.length > 2) { + model.stunDuration = Long.parseLong(Utils.extractNumber(split[2])) * 1000; + if (split.length > 3) { + model.cooldown = Long.parseLong(Utils.extractNumber(split[3])) * 100; + } + } + } + } + setValue(model); + setDuration(duration); + setStackable(true, null); + } + + public Bash(IEffectConsumer consumer, long duration, BashModel value) { + super(name, consumer); + setValue(value); + setDuration(duration); + } + + + @Override + public IEffectContainer constructEffectContainer() { + return new EffectContainer.UnstackableSingleInstance(this); + } +} diff --git a/Skills/src/main/java/cz/neumimto/effects/positive/BurningPrescenseEffect.java b/Skills/src/main/java/cz/neumimto/effects/positive/BurningPrescenseEffect.java new file mode 100644 index 000000000..a9ce19344 --- /dev/null +++ b/Skills/src/main/java/cz/neumimto/effects/positive/BurningPrescenseEffect.java @@ -0,0 +1,47 @@ +package cz.neumimto.effects.positive; + +import cz.neumimto.model.BurningpresenseModel; +import cz.neumimto.rpg.ClassGenerator; +import cz.neumimto.rpg.effects.*; +import cz.neumimto.rpg.effects.common.stacking.FloatEffectStackingStrategy; +import cz.neumimto.rpg.utils.Utils; +import cz.neumimto.skills.BurningPrescense; + +/** + * Created by ja on 5.7.2017. + */ +@ClassGenerator.Generate(id = "name") +public class BurningPrescenseEffect extends EffectBase{ + public static final String name = "Burning Prescense"; + + public BurningPrescenseEffect(IEffectConsumer consumer, long duration, String value) { + super(name, consumer); + setDuration(duration); + BurningpresenseModel model = new BurningpresenseModel(); + String[] split = value.split(", "); + if (value.length() > 0) { + model.damage = Float.parseFloat(Utils.extractNumber(split[0])); + model.radius = 3; + model.period = 3000; + if (value.length() > 1) { + model.radius = Float.parseFloat(Utils.extractNumber(split[1])); + if (value.length() >= 2) { + model.period = Long.parseLong(Utils.extractNumber(split[1])) * 100; + } + } + } + } + + + public BurningPrescenseEffect(IEffectConsumer consumer, long duration, BurningpresenseModel model) { + super(name, consumer); + setDuration(duration); + setValue(model); + } + + + @Override + public IEffectContainer constructEffectContainer() { + return new EffectContainer.UnstackableSingleInstance(this); + } +} diff --git a/Skills/src/main/java/cz/neumimto/events/StunApplyEvent.java b/Skills/src/main/java/cz/neumimto/events/StunApplyEvent.java new file mode 100644 index 000000000..83b2652df --- /dev/null +++ b/Skills/src/main/java/cz/neumimto/events/StunApplyEvent.java @@ -0,0 +1,34 @@ +package cz.neumimto.events; + +import cz.neumimto.effects.negative.StunEffect; +import cz.neumimto.effects.positive.Bash; +import cz.neumimto.rpg.effects.IEffectConsumer; +import cz.neumimto.rpg.events.CancellableEvent; + +/** + * Created by NeumimTo on 5.7.2017. + */ +public class StunApplyEvent extends CancellableEvent { + + private final IEffectConsumer source; + private final IEffectConsumer target; + private final StunEffect effect; + + public StunApplyEvent(IEffectConsumer source, IEffectConsumer target, StunEffect effect) { + this.source = source; + this.target = target; + this.effect = effect; + } + + public IEffectConsumer getSource() { + return source; + } + + public IEffectConsumer getTarget() { + return target; + } + + public StunEffect getEffect() { + return effect; + } +} diff --git a/Skills/src/main/java/cz/neumimto/model/BashModel.java b/Skills/src/main/java/cz/neumimto/model/BashModel.java new file mode 100644 index 000000000..5ee2f05c3 --- /dev/null +++ b/Skills/src/main/java/cz/neumimto/model/BashModel.java @@ -0,0 +1,22 @@ +package cz.neumimto.model; + +import cz.neumimto.rpg.effects.common.stacking.UnstackableEffectData; + +/** + * Created by NeumimTo on 4.7.2017. + */ +public class BashModel implements UnstackableEffectData { + public long stunDuration; + public int chance; + public long cooldown; + public double damage; + public long lasttime; + + @Override + public int compareTo(BashModel o) { + if (o == null) { + return -1; + } + return (int) (((o.damage + o.stunDuration) * o.chance) - ((damage + stunDuration) * chance)); + } +} diff --git a/Skills/src/main/java/cz/neumimto/model/BurningpresenseModel.java b/Skills/src/main/java/cz/neumimto/model/BurningpresenseModel.java new file mode 100644 index 000000000..8054d3b9c --- /dev/null +++ b/Skills/src/main/java/cz/neumimto/model/BurningpresenseModel.java @@ -0,0 +1,22 @@ +package cz.neumimto.model; + +import cz.neumimto.rpg.effects.common.stacking.UnstackableEffectData; + +/** + * Created by NeumimTo on 5.7.2017. + */ +public class BurningpresenseModel implements UnstackableEffectData { + + public long period; + public float damage; + public float radius; + public int duration; + + @Override + public int compareTo(BurningpresenseModel o) { + if (o == null) + return -1; + + return (int) ((int) (o.period + o.damage + o.radius) - (period + damage + radius)); + } +} diff --git a/Skills/src/main/java/cz/neumimto/skills/Arrowblast.java b/Skills/src/main/java/cz/neumimto/skills/Arrowblast.java new file mode 100644 index 000000000..895c4819e --- /dev/null +++ b/Skills/src/main/java/cz/neumimto/skills/Arrowblast.java @@ -0,0 +1,7 @@ +package cz.neumimto.skills; + +/** + * Created by ja on 4.7.2017. + */ +public class Arrowblast { +} diff --git a/Skills/src/main/java/cz/neumimto/skills/Arrowstorm.java b/Skills/src/main/java/cz/neumimto/skills/Arrowstorm.java new file mode 100644 index 000000000..9af84ea47 --- /dev/null +++ b/Skills/src/main/java/cz/neumimto/skills/Arrowstorm.java @@ -0,0 +1,45 @@ +package cz.neumimto.skills; + +import cz.neumimto.SkillLocalization; +import cz.neumimto.core.ioc.Inject; +import cz.neumimto.effects.positive.ArrowstormEffect; +import cz.neumimto.rpg.ResourceLoader; +import cz.neumimto.rpg.effects.EffectService; +import cz.neumimto.rpg.players.IActiveCharacter; +import cz.neumimto.rpg.skills.*; +import org.spongepowered.api.event.cause.entity.damage.DamageTypes; + +import java.util.concurrent.ThreadLocalRandom; + +/** + * Created by NeumimTo on 4.7.2017. + */ +@ResourceLoader.Skill +public class Arrowstorm extends ActiveSkill { + + @Inject + private EffectService effectService; + + public Arrowstorm() { + setDamageType(DamageTypes.PROJECTILE); + setName("Arrowstorm"); + setDescription(SkillLocalization.Arrowstorm); + SkillSettings settings = new SkillSettings(); + settings.addNode(SkillNodes.DAMAGE, 10, 10); + settings.addNode("min-arrows", 5, 1); + settings.addNode("max-arrows", 10, 1); + settings.addNode(SkillNodes.PERIOD, 2500, -100); + super.settings = settings; + setDamageType(NDamageType.LIGHTNING); + } + + @Override + public SkillResult cast(IActiveCharacter character, ExtendedSkillInfo info, SkillModifier modifier) { + int min = getIntNodeValue(info, "min-arrows"); + int max = getIntNodeValue(info, "max-arrows"); + int arrows = ThreadLocalRandom.current().nextInt(max - min) + min; + min = getIntNodeValue(info, SkillNodes.PERIOD); + effectService.addEffect(new ArrowstormEffect(character, min, arrows), character, this); + return SkillResult.OK; + } +} diff --git a/Skills/src/main/java/cz/neumimto/skills/Basher.java b/Skills/src/main/java/cz/neumimto/skills/Basher.java new file mode 100644 index 000000000..c681b2751 --- /dev/null +++ b/Skills/src/main/java/cz/neumimto/skills/Basher.java @@ -0,0 +1,63 @@ +package cz.neumimto.skills; + +import antlr.ASdebug.IASDebugStream; +import cz.neumimto.AdditionalProperties; +import cz.neumimto.SkillLocalization; +import cz.neumimto.core.ioc.Inject; +import cz.neumimto.effects.positive.Bash; +import cz.neumimto.model.BashModel; +import cz.neumimto.rpg.ResourceLoader; +import cz.neumimto.rpg.effects.EffectService; +import cz.neumimto.rpg.entities.EntityService; +import cz.neumimto.rpg.players.IActiveCharacter; +import cz.neumimto.rpg.players.properties.DefaultProperties; +import cz.neumimto.rpg.skills.*; +import org.spongepowered.api.event.cause.entity.damage.DamageTypes; + +/** + * Created by NeumimTo on 4.7.2017. + */ +@ResourceLoader.Skill +public class Basher extends PassiveSkill { + + @Inject + private EffectService effectService; + + @Inject + private EntityService entityService; + + public Basher() { + setName("Arrowstorm"); + setDescription(SkillLocalization.basher); + SkillSettings settings = new SkillSettings(); + settings.addNode(SkillNodes.DAMAGE, 10, 10); + settings.addNode(SkillNodes.CHANCE, 0.1f, 0.005f); + settings.addNode(SkillNodes.PERIOD, 2500, -100); + super.settings = settings; + setDamageType(DamageTypes.ATTACK); + } + + @Override + public void applyEffect(ExtendedSkillInfo info, IActiveCharacter character) { + BashModel model = getBashModel(info, character); + effectService.addEffect(new Bash(character,-1, model), character, this); + } + + @Override + public void skillUpgrade(IActiveCharacter IActiveCharacter, int level) { + super.skillUpgrade(IActiveCharacter, level); + ExtendedSkillInfo info = IActiveCharacter.getSkills().get(getName()); + BashModel model = getBashModel(info, IActiveCharacter); + effectService.removeEffect(Bash.name, IActiveCharacter, this); + effectService.addEffect(new Bash(IActiveCharacter,-1, model), IActiveCharacter, this); + } + + private BashModel getBashModel(ExtendedSkillInfo info, IActiveCharacter character) { + BashModel model = new BashModel(); + model.chance = getIntNodeValue(info, SkillNodes.CHANCE); + model.cooldown = getLongNodeValue(info, SkillNodes.COOLDOWN); + model.damage = getIntNodeValue(info, SkillNodes.DAMAGE); + model.stunDuration = getLongNodeValue(info, SkillNodes.DURATION); + return model; + } +} diff --git a/Skills/src/main/java/cz/neumimto/skills/BurningPrescense.java b/Skills/src/main/java/cz/neumimto/skills/BurningPrescense.java new file mode 100644 index 000000000..e89ce1e0a --- /dev/null +++ b/Skills/src/main/java/cz/neumimto/skills/BurningPrescense.java @@ -0,0 +1,51 @@ +package cz.neumimto.skills; + +import cz.neumimto.SkillLocalization; +import cz.neumimto.core.ioc.Inject; +import cz.neumimto.effects.positive.BurningPrescenseEffect; +import cz.neumimto.model.BurningpresenseModel; +import cz.neumimto.rpg.ResourceLoader; +import cz.neumimto.rpg.effects.EffectService; +import cz.neumimto.rpg.players.IActiveCharacter; +import cz.neumimto.rpg.skills.*; +import org.spongepowered.api.event.cause.entity.damage.DamageTypes; + +/** + * Created by NeumimTo on 4.7.2017. + */ +@ResourceLoader.Skill +public class BurningPrescense extends ActiveSkill { + + @Inject + private EffectService effectService; + + public BurningPrescense() { + setName(SkillLocalization.burningPrescense); + setDescription(SkillLocalization.burningPrescense_desc); + SkillSettings settings = new SkillSettings(); + settings.addNode(SkillNodes.CHANCE, 0.1f, 0.005f); + settings.addNode(SkillNodes.PERIOD, 2500, -100); + settings.addNode(SkillNodes.RADIUS, 2500, -100); + super.settings = settings; + setDamageType(DamageTypes.FIRE); + } + + @Override + public SkillResult cast(IActiveCharacter character, ExtendedSkillInfo info, SkillModifier modifier) { + if (character.hasEffect(BurningPrescenseEffect.name)) { + effectService.removeEffect(character.getEffect(BurningPrescenseEffect.name), character); + } else { + BurningpresenseModel model = getBPModel(info, character); + model.duration = -1; + } + return SkillResult.OK; + } + + private BurningpresenseModel getBPModel(ExtendedSkillInfo info, IActiveCharacter character) { + BurningpresenseModel model = new BurningpresenseModel(); + model.period = getIntNodeValue(info, SkillNodes.PERIOD); + model.radius = getLongNodeValue(info, SkillNodes.RADIUS); + model.damage = getIntNodeValue(info, SkillNodes.DAMAGE); + return model; + } +} diff --git a/Skills/src/main/java/cz/neumimto/skills/SkillMegabolt.java b/Skills/src/main/java/cz/neumimto/skills/SkillMegabolt.java index 8169811a3..3e4c37961 100644 --- a/Skills/src/main/java/cz/neumimto/skills/SkillMegabolt.java +++ b/Skills/src/main/java/cz/neumimto/skills/SkillMegabolt.java @@ -36,7 +36,6 @@ public SkillResult cast(IActiveCharacter iActiveCharacter, ExtendedSkillInfo ext SkillDamageSourceBuilder builder = new SkillDamageSourceBuilder(); builder.fromSkill(this); builder.setCaster(iActiveCharacter); - builder.type(getDamageType()); SkillDamageSource src = builder.build(); for (Entity e : nearbyEntities) { if (Utils.isLivingEntity(e)) { From c23f2b78fda81cc9b6f49695c58e19832352472a Mon Sep 17 00:00:00 2001 From: NeumimTo Date: Thu, 6 Jul 2017 16:56:16 +0200 Subject: [PATCH 3/9] more bugfixes --- .../neumimto/rpg/effects/EffectService.java | 21 ++++++---- .../neumimto/rpg/effects/IEffectConsumer.java | 2 + .../rpg/effects/IEffectContainer.java | 4 +- .../java/cz/neumimto/rpg/entities/IMob.java | 3 -- .../cz/neumimto/rpg/entities/NEntity.java | 5 +++ .../rpg/events/SkillDamageEventLate.java | 2 + .../neumimto/rpg/listeners/BasicListener.java | 1 - .../listeners/EntityLifecycleListener.java | 2 - .../neumimto/rpg/players/ActiveCharacter.java | 5 +++ .../rpg/players/PreloadCharacter.java | 5 +++ .../cz/neumimto/rpg/skills/SkillSettings.java | 4 +- .../effects/positive/ArrowstormEffect.java | 41 +++++++++++++------ .../java/cz/neumimto/skills/Arrowstorm.java | 1 - .../main/java/cz/neumimto/skills/Basher.java | 2 +- .../cz/neumimto/skills/SkillFireball.java | 6 +-- 15 files changed, 68 insertions(+), 36 deletions(-) diff --git a/Plugin/src/main/java/cz/neumimto/rpg/effects/EffectService.java b/Plugin/src/main/java/cz/neumimto/rpg/effects/EffectService.java index 917acfa44..13acc3424 100644 --- a/Plugin/src/main/java/cz/neumimto/rpg/effects/EffectService.java +++ b/Plugin/src/main/java/cz/neumimto/rpg/effects/EffectService.java @@ -137,6 +137,10 @@ public void run() { */ public void tickEffect(IEffect effect, long time) { if (!effect.isTickingDisabled()) { + if (effect.getConsumer().isDetached()) { + removeEffect(effect.getName(), effect.getConsumer(), effect.getEffectSourceProvider()); + return; + } effect.onTick(); effect.tickCountIncrement(); } @@ -154,16 +158,14 @@ public void tickEffect(IEffect effect, long time) { public void addEffect(IEffect iEffect, IEffectConsumer consumer, IEffectSourceProvider effectSourceProvider) { IEffectContainer eff = consumer.getEffect(iEffect.getName()); if (eff == null) { - IEffectContainer iEffectContainer = iEffect.constructEffectContainer(); - iEffect.setEffectContainer(iEffectContainer); - consumer.addEffect(iEffectContainer); - iEffect.setEffectSourceProvider(effectSourceProvider); + eff = iEffect.constructEffectContainer(); + consumer.addEffect(eff); iEffect.onApply(); } else if (eff.isStackable()) { - iEffect.setEffectContainer(eff); - iEffect.setEffectSourceProvider(effectSourceProvider); eff.stackEffect(iEffect, effectSourceProvider); } + iEffect.setEffectContainer(eff); + iEffect.setEffectSourceProvider(effectSourceProvider); if (iEffect.requiresRegister()) runEffect(iEffect); } @@ -188,7 +190,9 @@ public void removeEffect(IEffectContainer> container, IEffectConsu protected void removeEffect(IEffectContainer container, IEffect iEffect, IEffectConsumer consumer) { if (iEffect == container) { - iEffect.onRemove(); + if (!iEffect.getConsumer().isDetached()) { + iEffect.onRemove(); + } consumer.removeEffect(iEffect); } else if (container.getEffects().contains(iEffect)){ container.removeStack(iEffect); @@ -197,6 +201,7 @@ protected void removeEffect(IEffectContainer container, IEffect iEffect, IEffect } } iEffect.setConsumer(null); + pendingRemovals.add(iEffect); } /** @@ -214,8 +219,6 @@ public void removeEffect(String iEffect, IEffectConsumer consumer, IEffectSource while (iterator.hasNext()) { e = iterator.next(); if (e.getEffectSourceProvider() == effectSource) { - if (effectSet.contains(e)) - effectSet.remove(e); removeEffect(effect, e, consumer); } } diff --git a/Plugin/src/main/java/cz/neumimto/rpg/effects/IEffectConsumer.java b/Plugin/src/main/java/cz/neumimto/rpg/effects/IEffectConsumer.java index 5d5fbe132..84e314450 100644 --- a/Plugin/src/main/java/cz/neumimto/rpg/effects/IEffectConsumer.java +++ b/Plugin/src/main/java/cz/neumimto/rpg/effects/IEffectConsumer.java @@ -117,4 +117,6 @@ default void addPotionEffect(PotionEffect e) { } void sendMessage(String message); + + boolean isDetached(); } diff --git a/Plugin/src/main/java/cz/neumimto/rpg/effects/IEffectContainer.java b/Plugin/src/main/java/cz/neumimto/rpg/effects/IEffectContainer.java index 40d9662e7..1a5de85ec 100644 --- a/Plugin/src/main/java/cz/neumimto/rpg/effects/IEffectContainer.java +++ b/Plugin/src/main/java/cz/neumimto/rpg/effects/IEffectContainer.java @@ -49,7 +49,9 @@ default void updateStackedValue(){ default void removeStack(T iEffect) { getEffects().remove(iEffect); - iEffect.onRemove(); + if (!iEffect.getConsumer().isDetached()) { + iEffect.onRemove(); + } } @Override diff --git a/Plugin/src/main/java/cz/neumimto/rpg/entities/IMob.java b/Plugin/src/main/java/cz/neumimto/rpg/entities/IMob.java index dc7344915..ef15b186d 100644 --- a/Plugin/src/main/java/cz/neumimto/rpg/entities/IMob.java +++ b/Plugin/src/main/java/cz/neumimto/rpg/entities/IMob.java @@ -20,7 +20,4 @@ default IEntityType getType() { void detach(); - default boolean isDetached() { - return getEntity() == null; - }; } diff --git a/Plugin/src/main/java/cz/neumimto/rpg/entities/NEntity.java b/Plugin/src/main/java/cz/neumimto/rpg/entities/NEntity.java index af800fdc4..6ebe50b72 100644 --- a/Plugin/src/main/java/cz/neumimto/rpg/entities/NEntity.java +++ b/Plugin/src/main/java/cz/neumimto/rpg/entities/NEntity.java @@ -75,6 +75,11 @@ public Living getEntity() { return entity.get(); } + @Override + public boolean isDetached() { + return entity == null || entity.get() == null; + } + @Override public Map getEffectMap() { return effectSet; diff --git a/Plugin/src/main/java/cz/neumimto/rpg/events/SkillDamageEventLate.java b/Plugin/src/main/java/cz/neumimto/rpg/events/SkillDamageEventLate.java index 884b91e20..eeb2c8915 100644 --- a/Plugin/src/main/java/cz/neumimto/rpg/events/SkillDamageEventLate.java +++ b/Plugin/src/main/java/cz/neumimto/rpg/events/SkillDamageEventLate.java @@ -20,6 +20,8 @@ public SkillDamageEventLate(IEntity caster, IEntity target, ISkill skill, double this.target = target; this.skill = skill; this.damage = damage; + this.damageType = type; + this.targetResistance = resistance; } public IEntity getCaster() { diff --git a/Plugin/src/main/java/cz/neumimto/rpg/listeners/BasicListener.java b/Plugin/src/main/java/cz/neumimto/rpg/listeners/BasicListener.java index 0377b48b0..363a90edb 100644 --- a/Plugin/src/main/java/cz/neumimto/rpg/listeners/BasicListener.java +++ b/Plugin/src/main/java/cz/neumimto/rpg/listeners/BasicListener.java @@ -268,7 +268,6 @@ public void onIndirectEntityDamage(DamageEntityEvent event, IEntity target = entityService.get(event.getTargetEntity()); ProjectileProperties projectileProperties = ProjectileProperties.cache.get(projectile); if (projectileProperties != null) { - event.setCancelled(true); ProjectileProperties.cache.remove(projectile); projectileProperties.consumer.accept(shooter, target); return; diff --git a/Plugin/src/main/java/cz/neumimto/rpg/listeners/EntityLifecycleListener.java b/Plugin/src/main/java/cz/neumimto/rpg/listeners/EntityLifecycleListener.java index 42ce4c07d..3b77f081b 100644 --- a/Plugin/src/main/java/cz/neumimto/rpg/listeners/EntityLifecycleListener.java +++ b/Plugin/src/main/java/cz/neumimto/rpg/listeners/EntityLifecycleListener.java @@ -137,7 +137,6 @@ public void onEntityDespawn(DestructEntityEvent event) { } Optional sds = event.getCause().first(SkillDamageSource.class); if (sds.isPresent()) { - SkillDamageSource source = sds.get(); IEntity caster = source.getCaster(); if (caster.getType() == IEntityType.CHARACTER) { @@ -145,7 +144,6 @@ public void onEntityDespawn(DestructEntityEvent event) { characterService.addExperiences((IActiveCharacter) caster, exp, ExperienceSource.PVE); } } - IMob mob = (IMob) entityService.get(event.getTargetEntity()); entityService.remove(event.getTargetEntity().getUniqueId()); } } diff --git a/Plugin/src/main/java/cz/neumimto/rpg/players/ActiveCharacter.java b/Plugin/src/main/java/cz/neumimto/rpg/players/ActiveCharacter.java index 5b93ab8cb..0b7825c60 100644 --- a/Plugin/src/main/java/cz/neumimto/rpg/players/ActiveCharacter.java +++ b/Plugin/src/main/java/cz/neumimto/rpg/players/ActiveCharacter.java @@ -717,6 +717,11 @@ public void updateSelectedHotbarSlot() { selected = hotbar.getSelectedSlotIndex(); } + @Override + public boolean isDetached() { + return getPlayer() == null; + } + @Override public int hashCode() { return getPlayer().getUniqueId().hashCode() * 37; diff --git a/Plugin/src/main/java/cz/neumimto/rpg/players/PreloadCharacter.java b/Plugin/src/main/java/cz/neumimto/rpg/players/PreloadCharacter.java index 00f38a120..d2c644fa7 100644 --- a/Plugin/src/main/java/cz/neumimto/rpg/players/PreloadCharacter.java +++ b/Plugin/src/main/java/cz/neumimto/rpg/players/PreloadCharacter.java @@ -620,4 +620,9 @@ public void setSlotsToReinitialize(List slotsToReinitialize) { public void updateSelectedHotbarSlot() { } + + @Override + public boolean isDetached() { + return true; + } } diff --git a/Plugin/src/main/java/cz/neumimto/rpg/skills/SkillSettings.java b/Plugin/src/main/java/cz/neumimto/rpg/skills/SkillSettings.java index e13d072ef..50de326c1 100644 --- a/Plugin/src/main/java/cz/neumimto/rpg/skills/SkillSettings.java +++ b/Plugin/src/main/java/cz/neumimto/rpg/skills/SkillSettings.java @@ -57,7 +57,7 @@ public boolean hasNode(ISkillNode node) { } public void addNode(String s, float val) { - settingsMap.put(s, val); + settingsMap.put(s.toLowerCase(), val); } public void addObjectNode(String k, String v) { @@ -78,7 +78,7 @@ public float getNodeValue(ISkillNode n) { } public float getNodeValue(String s) { - return settingsMap.get(s); + return settingsMap.get(s.toLowerCase()); } public float getLevelNodeValue(ISkillNode n, int level) { diff --git a/Skills/src/main/java/cz/neumimto/effects/positive/ArrowstormEffect.java b/Skills/src/main/java/cz/neumimto/effects/positive/ArrowstormEffect.java index 5f6aedbb5..16a955692 100644 --- a/Skills/src/main/java/cz/neumimto/effects/positive/ArrowstormEffect.java +++ b/Skills/src/main/java/cz/neumimto/effects/positive/ArrowstormEffect.java @@ -1,25 +1,27 @@ package cz.neumimto.effects.positive; +import com.flowpowered.math.imaginary.Quaterniond; +import com.flowpowered.math.vector.Vector3d; import cz.neumimto.rpg.ClassGenerator; -import cz.neumimto.rpg.ResourceLoader; -import cz.neumimto.rpg.damage.SkillDamageSourceBuilder; import cz.neumimto.rpg.effects.EffectBase; -import cz.neumimto.rpg.effects.EffectContainer; +import cz.neumimto.rpg.effects.IEffect; import cz.neumimto.rpg.effects.IEffectConsumer; import cz.neumimto.rpg.effects.IEffectContainer; -import cz.neumimto.rpg.skills.ProjectileProperties; -import cz.neumimto.rpg.skills.SkillNodes; -import cz.neumimto.rpg.utils.Utils; +import org.spongepowered.api.data.key.Keys; import org.spongepowered.api.entity.Entity; import org.spongepowered.api.entity.EntityTypes; import org.spongepowered.api.entity.living.Living; +import org.spongepowered.api.entity.projectile.arrow.Arrow; +import org.spongepowered.api.event.cause.Cause; +import org.spongepowered.api.event.cause.entity.spawn.SpawnCause; +import org.spongepowered.api.event.cause.entity.spawn.SpawnTypes; import org.spongepowered.api.world.World; -import java.util.HashSet; +import java.util.Collections; import java.util.Set; -import static java.lang.Math.cos; -import static java.lang.Math.sin; +import static com.flowpowered.math.TrigMath.cos; +import static com.flowpowered.math.TrigMath.sin; /** * Created by NeumimTo on 4.7.2017. @@ -42,10 +44,18 @@ public void onTick() { if (arrows != 0) { Living entity = getConsumer().getEntity(); World world = entity.getWorld(); - world.createEntity(EntityTypes.TIPPED_ARROW, + Vector3d rotation = entity.getRotation(); + Vector3d direction = Quaterniond.fromAxesAnglesDeg(rotation.getX(), -rotation.getY(), rotation.getZ()).getDirection(); + + Entity arrow = world.createEntity(EntityTypes.TIPPED_ARROW, entity.getLocation().getPosition() - .add(cos((entity.getRotation().getX() - 90) % 360 - ) * 0.2, 1.8, sin((entity.getRotation().getX() - 90) % 360) * 0.2)); + .add(cos((entity.getRotation().getX() - 90) % 360) * 0.2, + 1.8, + sin((entity.getRotation().getX() - 90) % 360) * 0.2)); + Arrow sb = (Arrow) arrow; + sb.setShooter(entity); + world.spawnEntity(sb, Cause.source(SpawnCause.builder().type(SpawnTypes.PLUGIN).build()).build()); + sb.offer(Keys.VELOCITY, direction.mul(3f)); arrows--; } else { setDuration(0); //remove the effect next effect scheduler phase @@ -54,7 +64,7 @@ public void onTick() { @Override public Set getEffects() { - return new HashSet<>(); + return Collections.singleton(this); } @Override @@ -62,6 +72,11 @@ public Object getStackedValue() { return null; } + @Override + public void removeStack(IEffect iEffect) { + + } + @Override public void setStackedValue(Object o) { diff --git a/Skills/src/main/java/cz/neumimto/skills/Arrowstorm.java b/Skills/src/main/java/cz/neumimto/skills/Arrowstorm.java index 9af84ea47..7121fedc0 100644 --- a/Skills/src/main/java/cz/neumimto/skills/Arrowstorm.java +++ b/Skills/src/main/java/cz/neumimto/skills/Arrowstorm.java @@ -30,7 +30,6 @@ public Arrowstorm() { settings.addNode("max-arrows", 10, 1); settings.addNode(SkillNodes.PERIOD, 2500, -100); super.settings = settings; - setDamageType(NDamageType.LIGHTNING); } @Override diff --git a/Skills/src/main/java/cz/neumimto/skills/Basher.java b/Skills/src/main/java/cz/neumimto/skills/Basher.java index c681b2751..012c28296 100644 --- a/Skills/src/main/java/cz/neumimto/skills/Basher.java +++ b/Skills/src/main/java/cz/neumimto/skills/Basher.java @@ -27,7 +27,7 @@ public class Basher extends PassiveSkill { private EntityService entityService; public Basher() { - setName("Arrowstorm"); + setName("Basher"); setDescription(SkillLocalization.basher); SkillSettings settings = new SkillSettings(); settings.addNode(SkillNodes.DAMAGE, 10, 10); diff --git a/Skills/src/main/java/cz/neumimto/skills/SkillFireball.java b/Skills/src/main/java/cz/neumimto/skills/SkillFireball.java index 54dfd0b41..eb812920f 100644 --- a/Skills/src/main/java/cz/neumimto/skills/SkillFireball.java +++ b/Skills/src/main/java/cz/neumimto/skills/SkillFireball.java @@ -1,5 +1,6 @@ package cz.neumimto.skills; +import com.flowpowered.math.TrigMath; import com.flowpowered.math.imaginary.Quaterniond; import com.flowpowered.math.vector.Vector3d; import cz.neumimto.rpg.ResourceLoader; @@ -17,8 +18,8 @@ import org.spongepowered.api.event.cause.entity.damage.DamageTypes; import org.spongepowered.api.world.World; -import static java.lang.Math.cos; -import static java.lang.Math.sin; +import static com.flowpowered.math.TrigMath.cos; +import static com.flowpowered.math.TrigMath.sin; /** * Created by NeumimTo on 23.12.2015. @@ -60,6 +61,5 @@ public SkillResult cast(IActiveCharacter character, ExtendedSkillInfo info, Skil target.getEntity().damage(projectileProperties.getDamage(), build.build()); }); return SkillResult.OK; - } } From 8f233712bfbbaba526a316840a11822b5f210145 Mon Sep 17 00:00:00 2001 From: NeumimTo Date: Thu, 6 Jul 2017 18:20:59 +0200 Subject: [PATCH 4/9] spawn lightning --- Skills/src/main/java/cz/neumimto/skills/Arrowstorm.java | 3 ++- Skills/src/main/java/cz/neumimto/skills/SkillMegabolt.java | 6 +++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Skills/src/main/java/cz/neumimto/skills/Arrowstorm.java b/Skills/src/main/java/cz/neumimto/skills/Arrowstorm.java index 7121fedc0..3b485b869 100644 --- a/Skills/src/main/java/cz/neumimto/skills/Arrowstorm.java +++ b/Skills/src/main/java/cz/neumimto/skills/Arrowstorm.java @@ -28,7 +28,7 @@ public Arrowstorm() { settings.addNode(SkillNodes.DAMAGE, 10, 10); settings.addNode("min-arrows", 5, 1); settings.addNode("max-arrows", 10, 1); - settings.addNode(SkillNodes.PERIOD, 2500, -100); + settings.addNode(SkillNodes.PERIOD, 500, -10); super.settings = settings; } @@ -38,6 +38,7 @@ public SkillResult cast(IActiveCharacter character, ExtendedSkillInfo info, Skil int max = getIntNodeValue(info, "max-arrows"); int arrows = ThreadLocalRandom.current().nextInt(max - min) + min; min = getIntNodeValue(info, SkillNodes.PERIOD); + min = min <= 0 ? 1 : min; effectService.addEffect(new ArrowstormEffect(character, min, arrows), character, this); return SkillResult.OK; } diff --git a/Skills/src/main/java/cz/neumimto/skills/SkillMegabolt.java b/Skills/src/main/java/cz/neumimto/skills/SkillMegabolt.java index 3e4c37961..de0ac3bd2 100644 --- a/Skills/src/main/java/cz/neumimto/skills/SkillMegabolt.java +++ b/Skills/src/main/java/cz/neumimto/skills/SkillMegabolt.java @@ -9,6 +9,9 @@ import org.spongepowered.api.entity.Entity; import org.spongepowered.api.entity.EntityTypes; import org.spongepowered.api.entity.living.Living; +import org.spongepowered.api.event.cause.Cause; +import org.spongepowered.api.event.cause.entity.spawn.SpawnCause; +import org.spongepowered.api.event.cause.entity.spawn.SpawnTypes; import java.util.Set; @@ -42,7 +45,8 @@ public SkillResult cast(IActiveCharacter iActiveCharacter, ExtendedSkillInfo ext Living l = (Living) e; if (Utils.canDamage(iActiveCharacter, l)) { l.damage(damage,src); - l.getLocation().getExtent().createEntity(EntityTypes.LIGHTNING, l.getLocation().getPosition()); + Entity li = l.getLocation().getExtent().createEntity(EntityTypes.LIGHTNING, l.getLocation().getPosition()); + l.getLocation().getExtent().spawnEntity(li, Cause.source(SpawnCause.builder().type(SpawnTypes.PLUGIN).build()).build()); } } } From 3c8b9514e9b4fef7d08608faf1675dd4f3e0c28c Mon Sep 17 00:00:00 2001 From: NeumimTo Date: Thu, 6 Jul 2017 23:03:50 +0200 Subject: [PATCH 5/9] added bunch of skills for testing --- .../rpg/damage/SkillDamageSourceBuilder.java | 11 +-- .../cz/neumimto/rpg/skills/NDamageType.java | 11 +++ .../cz/neumimto/rpg/skills/SkillNodes.java | 3 +- .../cz/neumimto/rpg/skills/Targetted.java | 11 ++- .../cz/neumimto/rpg/utils/XORShiftRnd.java | 13 +++- .../main/java/cz/neumimto/SkillListener.java | 65 ++++++++++++++-- .../java/cz/neumimto/SkillLocalization.java | 18 +++++ .../effects/ResoluteTechniqueEffect.java | 20 +++++ .../effects/negative/MultiboltEffect.java | 59 ++++++++++++++ .../effects/positive/ArrowstormEffect.java | 8 ++ .../effects/positive/CriticalEffect.java | 42 ++++++++++ .../effects/positive/DodgeEffect.java | 21 +++++ .../neumimto/events/CriticalStrikeEvent.java | 31 ++++++++ .../cz/neumimto/events/DamageDodgedEvent.java | 34 +++++++++ .../neumimto/model/CriticalEffectModel.java | 27 +++++++ .../cz/neumimto/model/MultiboltModel.java | 14 ++++ .../java/cz/neumimto/skills/Arrowstorm.java | 6 +- .../java/cz/neumimto/skills/Critical.java | 58 ++++++++++++++ .../main/java/cz/neumimto/skills/Dodge.java | 50 ++++++++++++ .../java/cz/neumimto/skills/Multibolt.java | 57 ++++++++++++++ .../cz/neumimto/skills/ResoluteTechnique.java | 33 ++++++++ .../cz/neumimto/skills/SkillLightning.java | 76 +++++++++---------- 22 files changed, 608 insertions(+), 60 deletions(-) create mode 100644 Skills/src/main/java/cz/neumimto/effects/ResoluteTechniqueEffect.java create mode 100644 Skills/src/main/java/cz/neumimto/effects/negative/MultiboltEffect.java create mode 100644 Skills/src/main/java/cz/neumimto/effects/positive/CriticalEffect.java create mode 100644 Skills/src/main/java/cz/neumimto/effects/positive/DodgeEffect.java create mode 100644 Skills/src/main/java/cz/neumimto/events/CriticalStrikeEvent.java create mode 100644 Skills/src/main/java/cz/neumimto/events/DamageDodgedEvent.java create mode 100644 Skills/src/main/java/cz/neumimto/model/CriticalEffectModel.java create mode 100644 Skills/src/main/java/cz/neumimto/model/MultiboltModel.java create mode 100644 Skills/src/main/java/cz/neumimto/skills/Critical.java create mode 100644 Skills/src/main/java/cz/neumimto/skills/Dodge.java create mode 100644 Skills/src/main/java/cz/neumimto/skills/Multibolt.java create mode 100644 Skills/src/main/java/cz/neumimto/skills/ResoluteTechnique.java diff --git a/Plugin/src/main/java/cz/neumimto/rpg/damage/SkillDamageSourceBuilder.java b/Plugin/src/main/java/cz/neumimto/rpg/damage/SkillDamageSourceBuilder.java index 77671f6fa..26f8e6ec4 100644 --- a/Plugin/src/main/java/cz/neumimto/rpg/damage/SkillDamageSourceBuilder.java +++ b/Plugin/src/main/java/cz/neumimto/rpg/damage/SkillDamageSourceBuilder.java @@ -19,6 +19,7 @@ import cz.neumimto.rpg.IEntity; import cz.neumimto.rpg.effects.IEffect; +import cz.neumimto.rpg.effects.IEffectConsumer; import cz.neumimto.rpg.players.IActiveCharacter; import cz.neumimto.rpg.skills.ISkill; import org.spongepowered.api.entity.living.player.Player; @@ -31,8 +32,8 @@ public class SkillDamageSourceBuilder extends AbstractDamageSourceBuilder { protected ISkill skill; - protected IEntity caster; - protected IEntity target; + protected IEffectConsumer caster; + protected IEffectConsumer target; protected IEffect effect; public ISkill getSkill() { @@ -50,7 +51,7 @@ public SkillDamageSourceBuilder fromSkill(ISkill skill) { return this; } - public IEntity getCaster() { + public IEffectConsumer getCaster() { return caster; } @@ -64,7 +65,7 @@ public SkillDamageSource build() throws IllegalStateException { return new SkillDamageSource(this); } - public IEntity getTarget() { + public IEffectConsumer getTarget() { return target; } @@ -73,7 +74,7 @@ public SkillDamageSourceBuilder setTarget(IEntity target) { return this; } - public void setCaster(IEntity caster) { + public void setCaster(IEffectConsumer caster) { this.caster = caster; } diff --git a/Plugin/src/main/java/cz/neumimto/rpg/skills/NDamageType.java b/Plugin/src/main/java/cz/neumimto/rpg/skills/NDamageType.java index 9d5eaf2c0..7d4dc259b 100644 --- a/Plugin/src/main/java/cz/neumimto/rpg/skills/NDamageType.java +++ b/Plugin/src/main/java/cz/neumimto/rpg/skills/NDamageType.java @@ -20,6 +20,17 @@ import org.spongepowered.api.event.cause.entity.damage.DamageTypes; public class NDamageType { + public static final DamageType MEELE_CRITICAL = new DamageType() { + @Override + public String getId() { + return "ntrpg:meele_critical"; + } + + @Override + public String getName() { + return "meelecritical"; + } + }; public static DamageType LIGHTNING = new DamageType() { @Override public String getId() { diff --git a/Plugin/src/main/java/cz/neumimto/rpg/skills/SkillNodes.java b/Plugin/src/main/java/cz/neumimto/rpg/skills/SkillNodes.java index cf7576f7a..1898701f5 100644 --- a/Plugin/src/main/java/cz/neumimto/rpg/skills/SkillNodes.java +++ b/Plugin/src/main/java/cz/neumimto/rpg/skills/SkillNodes.java @@ -16,7 +16,8 @@ public enum SkillNodes implements ISkillNode { DURATION("duration", SkillModifierProcessor.L_STACK), AMOUNT("amount", SkillModifierProcessor.D_STACK), PERIOD("period", SkillModifierProcessor.L_STACK), - CHANCE("chance", SkillModifierProcessor.D_STACK ); + CHANCE("chance", SkillModifierProcessor.D_STACK ), + MULTIPLIER("multiplier",SkillModifierProcessor.F_MAX); private final String str; diff --git a/Plugin/src/main/java/cz/neumimto/rpg/skills/Targetted.java b/Plugin/src/main/java/cz/neumimto/rpg/skills/Targetted.java index 4d7584376..f18c5cd85 100644 --- a/Plugin/src/main/java/cz/neumimto/rpg/skills/Targetted.java +++ b/Plugin/src/main/java/cz/neumimto/rpg/skills/Targetted.java @@ -25,14 +25,21 @@ public abstract class Targetted extends ActiveSkill implements ITargetted { - @Inject - private Game game; + + @Override + public void init() { + super.init(); + settings.addNode(SkillNodes.RANGE, 10, 10); + } @Override public SkillResult cast(IActiveCharacter character, ExtendedSkillInfo info,SkillModifier modifier) { int range = (int) info.getSkillData().getSkillSettings().getLevelNodeValue(SkillNodes.RANGE, info.getTotalLevel()); Living l = Utils.getTargettedEntity(character, range); if (l != null) { + if (getDamageType() != null && !Utils.canDamage(character, l)) { + return SkillResult.CANCELLED; + } SkillFindTargetEvent event = new SkillFindTargetEvent(character, l, this); game.getEventManager().post(event); if (event.isCancelled()) { diff --git a/Plugin/src/main/java/cz/neumimto/rpg/utils/XORShiftRnd.java b/Plugin/src/main/java/cz/neumimto/rpg/utils/XORShiftRnd.java index 3638c06c4..d8b37eed3 100644 --- a/Plugin/src/main/java/cz/neumimto/rpg/utils/XORShiftRnd.java +++ b/Plugin/src/main/java/cz/neumimto/rpg/utils/XORShiftRnd.java @@ -20,6 +20,17 @@ public int nextInt(int max) { return (out < 0) ? -out : out; } + public double nextDouble(long max) { + long out = nextLong() % max; + return (out < 0) ? -out * 0.01d : out * 0.01d; //.00 precision is enough + } + + //just so we dont have to typecast after + public float nextFloat(int max) { + int out = nextInt() % max; + return (out < 0) ? -out * 0.01f : out * 0.01f; //.00 precision is enough + } + public int nextInt() { l ^= (l << 21); l ^= (l >>> 35); @@ -27,7 +38,7 @@ public int nextInt() { return (int) l; } - public long nextLong(int max) { + public long nextLong(long max) { long out = nextLong() % max; return (out < 0) ? -out : out; } diff --git a/Skills/src/main/java/cz/neumimto/SkillListener.java b/Skills/src/main/java/cz/neumimto/SkillListener.java index 473a8fdac..bf4b780fd 100644 --- a/Skills/src/main/java/cz/neumimto/SkillListener.java +++ b/Skills/src/main/java/cz/neumimto/SkillListener.java @@ -1,12 +1,14 @@ package cz.neumimto; import cz.neumimto.core.ioc.Inject; +import cz.neumimto.effects.ResoluteTechniqueEffect; import cz.neumimto.effects.negative.StunEffect; -import cz.neumimto.effects.positive.Bash; -import cz.neumimto.effects.positive.DamageToMana; -import cz.neumimto.effects.positive.LifeAfterKillEffect; +import cz.neumimto.effects.positive.*; +import cz.neumimto.events.CriticalStrikeEvent; +import cz.neumimto.events.DamageDodgedEvent; import cz.neumimto.events.StunApplyEvent; import cz.neumimto.model.BashModel; +import cz.neumimto.model.CriticalEffectModel; import cz.neumimto.rpg.ResourceLoader; import cz.neumimto.rpg.effects.EffectService; import cz.neumimto.rpg.effects.IEffectContainer; @@ -17,14 +19,17 @@ import cz.neumimto.rpg.players.IActiveCharacter; import cz.neumimto.rpg.players.properties.DefaultProperties; import cz.neumimto.rpg.players.properties.PropertyService; -import cz.neumimto.skills.Basher; +import cz.neumimto.rpg.utils.XORShiftRnd; +import cz.neumimto.skills.ResoluteTechnique; import org.spongepowered.api.Game; import org.spongepowered.api.entity.living.player.Player; import org.spongepowered.api.event.Listener; +import org.spongepowered.api.event.Order; import org.spongepowered.api.event.entity.DestructEntityEvent; +import org.spongepowered.api.event.filter.IsCancelled; +import org.spongepowered.api.util.Tristate; import java.util.Optional; -import java.util.concurrent.ThreadLocalRandom; /** * Created by ja on 21.5.2016. @@ -76,7 +81,25 @@ public void onDamage(CharacterDamageEntityEvent event) { } @Listener + @SuppressWarnings("unchecked") public void onDamage(INEntityWeaponDamageEvent event) { + XORShiftRnd random = new XORShiftRnd(); + //dodge + if (event.getTarget().hasEffect(DodgeEffect.name)) { + IEffectContainer effect = event.getSource().getEffect(DodgeEffect.name); + Float stackedValue = effect.getStackedValue(); + float next = random.nextFloat(100); + if (stackedValue <= next) { + DamageDodgedEvent event0 = new DamageDodgedEvent(event.getSource(), event.getTarget(), effect); + boolean t = game.getEventManager().post(event0); + if (t) { + event.setCancelled(t); + event.setDamage(0); + return; + } + } + } + //bash if (event.getSource().hasEffect(Bash.name)) { IEffectContainer effect = event.getSource().getEffect(Bash.name); BashModel stackedValue = effect.getStackedValue(); @@ -84,7 +107,7 @@ public void onDamage(INEntityWeaponDamageEvent event) { float reduced = entityService.getEntityProperty(event.getTarget(), DefaultProperties.cooldown_reduce); long cooldown = (long) (reduced * (float) stackedValue.cooldown); if (stackedValue.lasttime + cooldown <= time) { - int rnd = ThreadLocalRandom.current().nextInt(100); + int rnd = random.nextInt(100); if (rnd <= stackedValue.chance) { StunEffect stunEffect = new StunEffect(event.getTarget(),stackedValue.stunDuration); if (stackedValue.damage > 0) { @@ -97,6 +120,16 @@ public void onDamage(INEntityWeaponDamageEvent event) { } } } + if (event.getSource().hasEffect(CriticalEffect.name)) { + IEffectContainer effect = event.getSource().getEffect(CriticalEffect.name); + CriticalEffectModel stackedValue = effect.getStackedValue(); + if (stackedValue.chance <= random.nextInt(100)) { + CriticalStrikeEvent criticalStrikeEvent = new CriticalStrikeEvent(event.getSource(), event.getTarget(), stackedValue.mult * event.getDamage()); + if (!game.getEventManager().post(criticalStrikeEvent)) { + event.setDamage(event.getDamage() + criticalStrikeEvent.getDamage()); + } + } + } } @Listener @@ -105,4 +138,24 @@ public void onStunApply(StunApplyEvent event) { float f = entityService.getEntityProperty(event.getSource(), AdditionalProperties.stun_duration_mult); effect.setDuration((long) (f * event.getEffect().getDuration())); } + + @Listener(order = Order.LAST) + @IsCancelled(Tristate.UNDEFINED) + public void onCriticalStrike(CriticalStrikeEvent event) { + if (event.isCancelled()) { + if (event.getSource().hasEffect(ResoluteTechniqueEffect.name)) { + event.setCancelled(false); + } + } + } + + @Listener(order = Order.LAST) + @IsCancelled(Tristate.UNDEFINED) + public void onDodge(DamageDodgedEvent event) { + if (event.isCancelled()) { + if (event.getSource().hasEffect(ResoluteTechniqueEffect.name)) { + event.setCancelled(false); + } + } + } } diff --git a/Skills/src/main/java/cz/neumimto/SkillLocalization.java b/Skills/src/main/java/cz/neumimto/SkillLocalization.java index 69adc8fd1..b046a36a0 100644 --- a/Skills/src/main/java/cz/neumimto/SkillLocalization.java +++ b/Skills/src/main/java/cz/neumimto/SkillLocalization.java @@ -72,4 +72,22 @@ public class SkillLocalization { @ConfigValue public static String burningPrescense_desc = ""; + + @ConfigValue + public static String SKILL_MULTIBOLT_DESC = ""; + + @ConfigValue + public static String SKILL_MULTIBOLT_LORE = ""; + + @ConfigValue + public static String SKILL_DODGE_LORE = "";; + + @ConfigValue + public static String SKILL_DODGE_DESC = "";; + + @ConfigValue + public static String SKILL_RESOLUTE_TECHNIQUE_DESC = ""; + + @ConfigValue + public static String SKILL_RESOLUTE_TECHNIQUE_LORE = ""; } diff --git a/Skills/src/main/java/cz/neumimto/effects/ResoluteTechniqueEffect.java b/Skills/src/main/java/cz/neumimto/effects/ResoluteTechniqueEffect.java new file mode 100644 index 000000000..73ec92a3a --- /dev/null +++ b/Skills/src/main/java/cz/neumimto/effects/ResoluteTechniqueEffect.java @@ -0,0 +1,20 @@ +package cz.neumimto.effects; + +import cz.neumimto.rpg.ClassGenerator; +import cz.neumimto.rpg.effects.EffectBase; +import cz.neumimto.rpg.effects.IEffectConsumer; + +/** + * Created by NeumimTo on 6.7.2017. + */ +@ClassGenerator.Generate(id = "name") +public class ResoluteTechniqueEffect extends EffectBase { + + public static final String name = "Resolute Technique"; + + public ResoluteTechniqueEffect(IEffectConsumer consumer, long duration, String value) { + super(name, consumer); + setDuration(duration); + setStackable(true, null); + } +} diff --git a/Skills/src/main/java/cz/neumimto/effects/negative/MultiboltEffect.java b/Skills/src/main/java/cz/neumimto/effects/negative/MultiboltEffect.java new file mode 100644 index 000000000..af8f5514b --- /dev/null +++ b/Skills/src/main/java/cz/neumimto/effects/negative/MultiboltEffect.java @@ -0,0 +1,59 @@ +package cz.neumimto.effects.negative; + +import cz.neumimto.model.MultiboltModel; +import cz.neumimto.rpg.ClassGenerator; +import cz.neumimto.rpg.damage.SkillDamageSourceBuilder; +import cz.neumimto.rpg.effects.EffectBase; +import cz.neumimto.rpg.effects.IEffectConsumer; +import cz.neumimto.rpg.skills.NDamageType; +import org.spongepowered.api.entity.Entity; +import org.spongepowered.api.entity.EntityTypes; +import org.spongepowered.api.entity.living.Living; +import org.spongepowered.api.event.cause.Cause; +import org.spongepowered.api.event.cause.entity.spawn.SpawnCause; +import org.spongepowered.api.event.cause.entity.spawn.SpawnTypes; + +/** + * Created by NeumimTo on 6.7.2017. + */ +public class MultiboltEffect extends EffectBase { + + private final IEffectConsumer source; + private final MultiboltModel model; + + public MultiboltEffect(IEffectConsumer consumer, IEffectConsumer source, MultiboltModel model) { + super("Multibolt", consumer); + this.source = source; + this.model = model; + setPeriod(1000); + setDuration(getPeriod() * model.timesToHit); + } + + @Override + public void onApply() { + super.onApply(); + damage(); + } + + @Override + public void onTick() { + super.onTick(); + if (model.timesToHit <= 0) { + setDuration(0); + } else { + damage(); + } + } + + public void damage() { + Living entity = getConsumer().getEntity(); + SkillDamageSourceBuilder build = new SkillDamageSourceBuilder(); + build.setEffect(this); + build.setCaster(source); + build.type(NDamageType.LIGHTNING); + entity.damage(model.damage, build.build()); + Entity q = entity.getLocation().getExtent().createEntity(EntityTypes.LIGHTNING, entity.getLocation().getPosition()); + entity.getLocation().getExtent().spawnEntity(q, Cause.source(SpawnCause.builder().type(SpawnTypes.PLUGIN).build()).build()); + model.timesToHit--; + } +} diff --git a/Skills/src/main/java/cz/neumimto/effects/positive/ArrowstormEffect.java b/Skills/src/main/java/cz/neumimto/effects/positive/ArrowstormEffect.java index 16a955692..5de77768b 100644 --- a/Skills/src/main/java/cz/neumimto/effects/positive/ArrowstormEffect.java +++ b/Skills/src/main/java/cz/neumimto/effects/positive/ArrowstormEffect.java @@ -7,6 +7,7 @@ import cz.neumimto.rpg.effects.IEffect; import cz.neumimto.rpg.effects.IEffectConsumer; import cz.neumimto.rpg.effects.IEffectContainer; +import cz.neumimto.rpg.utils.Utils; import org.spongepowered.api.data.key.Keys; import org.spongepowered.api.entity.Entity; import org.spongepowered.api.entity.EntityTypes; @@ -39,6 +40,13 @@ public ArrowstormEffect(IEffectConsumer consumer, long period, int arrows) { setPeriod(period); } + public ArrowstormEffect(IEffectConsumer consumer, long duration, String data) { + super(name, consumer); + setDuration(duration); + setDuration(-1L); + setPeriod(Integer.parseInt(Utils.extractNumber(data))); + } + @Override public void onTick() { if (arrows != 0) { diff --git a/Skills/src/main/java/cz/neumimto/effects/positive/CriticalEffect.java b/Skills/src/main/java/cz/neumimto/effects/positive/CriticalEffect.java new file mode 100644 index 000000000..dfde3e4c9 --- /dev/null +++ b/Skills/src/main/java/cz/neumimto/effects/positive/CriticalEffect.java @@ -0,0 +1,42 @@ +package cz.neumimto.effects.positive; + +import cz.neumimto.model.BashModel; +import cz.neumimto.model.CriticalEffectModel; +import cz.neumimto.rpg.ClassGenerator; +import cz.neumimto.rpg.effects.EffectBase; +import cz.neumimto.rpg.effects.IEffectConsumer; +import cz.neumimto.rpg.players.IActiveCharacter; +import cz.neumimto.rpg.utils.Utils; + +/** + * Created by NeumimTo on 6.7.2017. + */ +@ClassGenerator.Generate(id = "name") +public class CriticalEffect extends EffectBase { + + public static final String name = "Critical"; + + public CriticalEffect(IActiveCharacter consumer,long duration, CriticalEffectModel model) { + super(name, consumer); + setValue(model); + setStackable(true, null); + setDuration(duration); + } + + public CriticalEffect(IEffectConsumer consumer, long duration, String value) { + super(name, consumer); + CriticalEffectModel model = new CriticalEffectModel(); + + String[] split = value.split(", "); + if (split.length > 0) { + model.chance = Integer.parseInt(Utils.extractNumber(split[0])); + model.mult = 2; + if (split.length > 1) { + model.mult = Float.parseFloat(Utils.extractNumber(split[1])); + } + } + setValue(model); + setDuration(duration); + setStackable(true, null); + } +} diff --git a/Skills/src/main/java/cz/neumimto/effects/positive/DodgeEffect.java b/Skills/src/main/java/cz/neumimto/effects/positive/DodgeEffect.java new file mode 100644 index 000000000..8b98ba1a5 --- /dev/null +++ b/Skills/src/main/java/cz/neumimto/effects/positive/DodgeEffect.java @@ -0,0 +1,21 @@ +package cz.neumimto.effects.positive; + +import cz.neumimto.rpg.ClassGenerator; +import cz.neumimto.rpg.effects.EffectBase; +import cz.neumimto.rpg.effects.common.stacking.FloatEffectStackingStrategy; +import cz.neumimto.rpg.players.IActiveCharacter; + +/** + * Created by ja on 6.7.2017. + */ +@ClassGenerator.Generate(id = "name") +public class DodgeEffect extends EffectBase { + + public static final String name = "Dodge"; + + public DodgeEffect(IActiveCharacter character, float chance) { + super(name, character); + setValue(chance); + setStackable(true, new FloatEffectStackingStrategy()); + } +} diff --git a/Skills/src/main/java/cz/neumimto/events/CriticalStrikeEvent.java b/Skills/src/main/java/cz/neumimto/events/CriticalStrikeEvent.java new file mode 100644 index 000000000..560a7a50d --- /dev/null +++ b/Skills/src/main/java/cz/neumimto/events/CriticalStrikeEvent.java @@ -0,0 +1,31 @@ +package cz.neumimto.events; + +import cz.neumimto.rpg.IEntity; +import cz.neumimto.rpg.events.CancellableEvent; + +/** + * Created by NeumimTo on 6.7.2017. + */ +public class CriticalStrikeEvent extends CancellableEvent { + private final IEntity source; + private final IEntity target; + private final double damage; + + public CriticalStrikeEvent(IEntity source, IEntity target, double effect) { + this.source = source; + this.target = target; + this.damage = effect; + } + + public IEntity getSource() { + return source; + } + + public IEntity getTarget() { + return target; + } + + public double getDamage() { + return damage; + } +} diff --git a/Skills/src/main/java/cz/neumimto/events/DamageDodgedEvent.java b/Skills/src/main/java/cz/neumimto/events/DamageDodgedEvent.java new file mode 100644 index 000000000..ce8c4c58f --- /dev/null +++ b/Skills/src/main/java/cz/neumimto/events/DamageDodgedEvent.java @@ -0,0 +1,34 @@ +package cz.neumimto.events; + +import cz.neumimto.effects.positive.DodgeEffect; +import cz.neumimto.rpg.IEntity; +import cz.neumimto.rpg.effects.IEffectContainer; +import cz.neumimto.rpg.events.CancellableEvent; + +/** + * Created by NeumimTo on 6.7.2017. + */ +public class DamageDodgedEvent extends CancellableEvent { + private final IEntity source; + private final IEntity target; + private final IEffectContainer effect; + + public DamageDodgedEvent(IEntity source, IEntity target, IEffectContainer effect) { + + this.source = source; + this.target = target; + this.effect = effect; + } + + public IEntity getSource() { + return source; + } + + public IEntity getTarget() { + return target; + } + + public IEffectContainer getEffect() { + return effect; + } +} diff --git a/Skills/src/main/java/cz/neumimto/model/CriticalEffectModel.java b/Skills/src/main/java/cz/neumimto/model/CriticalEffectModel.java new file mode 100644 index 000000000..8a20f6112 --- /dev/null +++ b/Skills/src/main/java/cz/neumimto/model/CriticalEffectModel.java @@ -0,0 +1,27 @@ +package cz.neumimto.model; + +import cz.neumimto.rpg.effects.common.stacking.UnstackableEffectData; + +/** + * Created by NeumimTo on 6.7.2017. + */ +public class CriticalEffectModel implements UnstackableEffectData { + public int chance; + public float mult; + + public CriticalEffectModel() { + } + + public CriticalEffectModel(int chance, float mult) { + this.chance = chance; + this.mult = mult; + } + + @Override + public int compareTo(CriticalEffectModel o) { + if (o == null) { + return -1; + } + return (int) ((o.chance + o.mult) - (chance + mult)); + } +} diff --git a/Skills/src/main/java/cz/neumimto/model/MultiboltModel.java b/Skills/src/main/java/cz/neumimto/model/MultiboltModel.java new file mode 100644 index 000000000..cbff56fa5 --- /dev/null +++ b/Skills/src/main/java/cz/neumimto/model/MultiboltModel.java @@ -0,0 +1,14 @@ +package cz.neumimto.model; + +/** + * Created by NeumimTo on 6.7.2017. + */ +public class MultiboltModel { + public int timesToHit; + public double damage; + + public MultiboltModel(int timesToHit, double damage) { + this.timesToHit = timesToHit; + this.damage = damage; + } +} diff --git a/Skills/src/main/java/cz/neumimto/skills/Arrowstorm.java b/Skills/src/main/java/cz/neumimto/skills/Arrowstorm.java index 3b485b869..3b715c1a0 100644 --- a/Skills/src/main/java/cz/neumimto/skills/Arrowstorm.java +++ b/Skills/src/main/java/cz/neumimto/skills/Arrowstorm.java @@ -26,9 +26,9 @@ public Arrowstorm() { setDescription(SkillLocalization.Arrowstorm); SkillSettings settings = new SkillSettings(); settings.addNode(SkillNodes.DAMAGE, 10, 10); - settings.addNode("min-arrows", 5, 1); - settings.addNode("max-arrows", 10, 1); - settings.addNode(SkillNodes.PERIOD, 500, -10); + settings.addNode("min-arrows", 35, 1); + settings.addNode("max-arrows", 45, 1); + settings.addNode(SkillNodes.PERIOD, 100, -10); super.settings = settings; } diff --git a/Skills/src/main/java/cz/neumimto/skills/Critical.java b/Skills/src/main/java/cz/neumimto/skills/Critical.java new file mode 100644 index 000000000..553cf59c1 --- /dev/null +++ b/Skills/src/main/java/cz/neumimto/skills/Critical.java @@ -0,0 +1,58 @@ +package cz.neumimto.skills; + +import cz.neumimto.SkillLocalization; +import cz.neumimto.core.ioc.Inject; +import cz.neumimto.effects.positive.CriticalEffect; +import cz.neumimto.effects.positive.DodgeEffect; +import cz.neumimto.model.CriticalEffectModel; +import cz.neumimto.rpg.ResourceLoader; +import cz.neumimto.rpg.effects.EffectService; +import cz.neumimto.rpg.effects.IEffectContainer; +import cz.neumimto.rpg.players.IActiveCharacter; +import cz.neumimto.rpg.skills.*; +import org.spongepowered.api.event.cause.entity.damage.DamageType; +import org.spongepowered.api.event.cause.entity.damage.DamageTypes; + +/** + * Created by ja on 6.7.2017. + */ +@ResourceLoader.Skill +public class Critical extends PassiveSkill { + + @Inject + private EffectService effectService; + + public Critical() { + setName("Dodge"); + setLore(SkillLocalization.SKILL_DODGE_LORE); + setDescription(SkillLocalization.SKILL_DODGE_DESC); + SkillSettings skillSettings = new SkillSettings(); + skillSettings.addNode(SkillNodes.CHANCE, 10, 20); + skillSettings.addNode(SkillNodes.MULTIPLIER, 10, 20); + super.settings = skillSettings; + setDamageType(NDamageType.MEELE_CRITICAL); + } + + @Override + public void applyEffect(ExtendedSkillInfo info, IActiveCharacter character) { + int chance = getIntNodeValue(info, SkillNodes.CHANCE); + float mult = getFloatNodeValue(info, SkillNodes.MULTIPLIER); + CriticalEffectModel model = new CriticalEffectModel(chance, mult); + CriticalEffect dodgeEffect = new CriticalEffect(character, -1, model); + effectService.addEffect(dodgeEffect, character, this); + } + + @Override + public void skillUpgrade(IActiveCharacter character, int level) { + ExtendedSkillInfo info = character.getSkill(getName()); + float chance = getFloatNodeValue(info, SkillNodes.CHANCE); + IEffectContainer effect = character.getEffect(DodgeEffect.name); + for (DodgeEffect dodgeEffect : effect.getEffects()) { + if (dodgeEffect.getEffectSourceProvider() == this) { + dodgeEffect.setValue(chance); + break; + } + } + effect.updateStackedValue(); + } +} diff --git a/Skills/src/main/java/cz/neumimto/skills/Dodge.java b/Skills/src/main/java/cz/neumimto/skills/Dodge.java new file mode 100644 index 000000000..ffe34569d --- /dev/null +++ b/Skills/src/main/java/cz/neumimto/skills/Dodge.java @@ -0,0 +1,50 @@ +package cz.neumimto.skills; + +import cz.neumimto.SkillLocalization; +import cz.neumimto.core.ioc.Inject; +import cz.neumimto.effects.positive.DodgeEffect; +import cz.neumimto.rpg.ResourceLoader; +import cz.neumimto.rpg.effects.EffectService; +import cz.neumimto.rpg.effects.IEffectContainer; +import cz.neumimto.rpg.players.IActiveCharacter; +import cz.neumimto.rpg.skills.*; + +/** + * Created by NeumimTo on 6.7.2017. + */ +@ResourceLoader.Skill +public class Dodge extends PassiveSkill { + + @Inject + private EffectService effectService; + + public Dodge() { + setName("Dodge"); + setLore(SkillLocalization.SKILL_DODGE_LORE); + setDescription(SkillLocalization.SKILL_DODGE_DESC); + SkillSettings skillSettings = new SkillSettings(); + skillSettings.addNode(SkillNodes.CHANCE, 10, 20); + super.settings = skillSettings; + } + + @Override + public void applyEffect(ExtendedSkillInfo info, IActiveCharacter character) { + float chance = getFloatNodeValue(info, SkillNodes.CHANCE); + DodgeEffect dodgeEffect = new DodgeEffect(character, chance); + effectService.addEffect(dodgeEffect, character, this); + } + + @Override + public void skillUpgrade(IActiveCharacter character, int level) { + ExtendedSkillInfo info = character.getSkill(getName()); + float chance = getFloatNodeValue(info, SkillNodes.CHANCE); + IEffectContainer effect = character.getEffect(DodgeEffect.name); + for (DodgeEffect dodgeEffect : effect.getEffects()) { + if (dodgeEffect.getEffectSourceProvider() == this) { + dodgeEffect.setValue(chance); + break; + } + } + effect.updateStackedValue(); + } +} diff --git a/Skills/src/main/java/cz/neumimto/skills/Multibolt.java b/Skills/src/main/java/cz/neumimto/skills/Multibolt.java new file mode 100644 index 000000000..738e695f6 --- /dev/null +++ b/Skills/src/main/java/cz/neumimto/skills/Multibolt.java @@ -0,0 +1,57 @@ +package cz.neumimto.skills; + +import cz.neumimto.SkillLocalization; +import cz.neumimto.core.ioc.Inject; +import cz.neumimto.effects.negative.MultiboltEffect; +import cz.neumimto.model.MultiboltModel; +import cz.neumimto.rpg.IEntity; +import cz.neumimto.rpg.ResourceLoader; +import cz.neumimto.rpg.damage.SkillDamageSourceBuilder; +import cz.neumimto.rpg.effects.EffectService; +import cz.neumimto.rpg.effects.IEffect; +import cz.neumimto.rpg.entities.EntityService; +import cz.neumimto.rpg.players.IActiveCharacter; +import cz.neumimto.rpg.skills.*; +import org.spongepowered.api.entity.Entity; +import org.spongepowered.api.entity.EntityTypes; +import org.spongepowered.api.entity.living.Living; +import org.spongepowered.api.event.cause.Cause; +import org.spongepowered.api.event.cause.entity.spawn.SpawnCause; +import org.spongepowered.api.event.cause.entity.spawn.SpawnTypes; + +/** + * Created by NeumimTo on 6.7.2017. + */ +@ResourceLoader.Skill +public class Multibolt extends Targetted { + + @Inject + private EntityService entityService; + + @Inject + private EffectService effectService; + + public Multibolt() { + super(); + setName("Multibolt"); + setLore(SkillLocalization.SKILL_MULTIBOLT_LORE); + setDescription(SkillLocalization.SKILL_MULTIBOLT_DESC); + setDamageType(NDamageType.LIGHTNING); + SkillSettings skillSettings = new SkillSettings(); + skillSettings.addNode(SkillNodes.DAMAGE, 10, 20); + skillSettings.addNode("times-hit", 10, 20); + super.settings = skillSettings; + setDamageType(NDamageType.LIGHTNING); + } + + @Override + public SkillResult castOn(Living target, IActiveCharacter source, ExtendedSkillInfo info) { + float damage = getFloatNodeValue(info, SkillNodes.DAMAGE); + int timesToHit = getIntNodeValue(info, "times-hit"); + MultiboltModel model = new MultiboltModel(timesToHit, damage); + IEntity iEntity = entityService.get(target); + IEffect effect = new MultiboltEffect(iEntity,source, model); + effectService.addEffect(effect, iEntity, this); + return SkillResult.OK; + } +} diff --git a/Skills/src/main/java/cz/neumimto/skills/ResoluteTechnique.java b/Skills/src/main/java/cz/neumimto/skills/ResoluteTechnique.java new file mode 100644 index 000000000..6f7039d26 --- /dev/null +++ b/Skills/src/main/java/cz/neumimto/skills/ResoluteTechnique.java @@ -0,0 +1,33 @@ +package cz.neumimto.skills; + +import cz.neumimto.SkillLocalization; +import cz.neumimto.core.ioc.Inject; +import cz.neumimto.effects.ResoluteTechniqueEffect; +import cz.neumimto.rpg.ResourceLoader; +import cz.neumimto.rpg.effects.EffectService; +import cz.neumimto.rpg.players.IActiveCharacter; +import cz.neumimto.rpg.skills.*; + +/** + * Created by NeumimTo on 6.7.2017. + */ +@ResourceLoader.Skill +public class ResoluteTechnique extends PassiveSkill { + + @Inject + private EffectService effectService; + + public ResoluteTechnique() { + setName("Resolute Technique"); + setName("Multibolt"); + setLore(SkillLocalization.SKILL_RESOLUTE_TECHNIQUE_LORE); + setDescription(SkillLocalization.SKILL_RESOLUTE_TECHNIQUE_DESC); + super.settings = new SkillSettings(); + } + + @Override + public void applyEffect(ExtendedSkillInfo info, IActiveCharacter character) { + ResoluteTechniqueEffect effect = new ResoluteTechniqueEffect(character, -1, null); + effectService.addEffect(effect, character, this); + } +} diff --git a/Skills/src/main/java/cz/neumimto/skills/SkillLightning.java b/Skills/src/main/java/cz/neumimto/skills/SkillLightning.java index 91caee17e..8c8770237 100644 --- a/Skills/src/main/java/cz/neumimto/skills/SkillLightning.java +++ b/Skills/src/main/java/cz/neumimto/skills/SkillLightning.java @@ -1,58 +1,50 @@ package cz.neumimto.skills; -import cz.neumimto.rpg.IEntity; -import cz.neumimto.rpg.ResourceLoader; import cz.neumimto.SkillLocalization; import cz.neumimto.core.ioc.Inject; +import cz.neumimto.rpg.IEntity; +import cz.neumimto.rpg.ResourceLoader; import cz.neumimto.rpg.damage.SkillDamageSourceBuilder; import cz.neumimto.rpg.entities.EntityService; import cz.neumimto.rpg.players.IActiveCharacter; import cz.neumimto.rpg.skills.*; -import cz.neumimto.rpg.utils.Utils; +import org.spongepowered.api.entity.Entity; import org.spongepowered.api.entity.EntityTypes; import org.spongepowered.api.entity.living.Living; -import org.spongepowered.api.event.cause.entity.damage.DamageType; +import org.spongepowered.api.event.cause.Cause; +import org.spongepowered.api.event.cause.entity.spawn.SpawnCause; +import org.spongepowered.api.event.cause.entity.spawn.SpawnTypes; /** * Created by NeumimTo on 29.12.2015. */ @ResourceLoader.Skill -public class SkillLightning extends ActiveSkill { - - @Inject - EntityService entityService; - - public SkillLightning() { - setName("Lightning"); - setLore(SkillLocalization.SKILL_LIGHTNING_LORE); - setDescription(SkillLocalization.SKILL_LIGHTNING_DESC); - setDamageType(NDamageType.LIGHTNING); - SkillSettings skillSettings = new SkillSettings(); - skillSettings.addNode(SkillNodes.DAMAGE, 10, 20); - skillSettings.addNode(SkillNodes.RANGE,10 ,10); - super.settings = skillSettings; - setDamageType(NDamageType.LIGHTNING); - } - - @Override - public SkillResult cast(IActiveCharacter iActiveCharacter, ExtendedSkillInfo extendedSkillInfo,SkillModifier skillModifier) { - int range = (int) settings.getLevelNodeValue(SkillNodes.RANGE,extendedSkillInfo.getTotalLevel()); - Living l = Utils.getTargettedEntity(iActiveCharacter,range); - if (l == null) - return SkillResult.NO_TARGET; - IEntity e = entityService.get(l); - if (e != null) { - float damage = settings.getLevelNodeValue(SkillNodes.DAMAGE,extendedSkillInfo.getTotalLevel()); - SkillDamageSourceBuilder build = new SkillDamageSourceBuilder(); - build.fromSkill(this); - build.setCaster(iActiveCharacter); - build.type(getDamageType()); - l.damage(damage,build.build()); - l.getLocation().getExtent().createEntity(EntityTypes.LIGHTNING, l.getLocation().getPosition()); - - } - return SkillResult.OK; - } - - +public class SkillLightning extends Targetted { + + @Inject + EntityService entityService; + + public SkillLightning() { + setName("Lightning"); + setLore(SkillLocalization.SKILL_LIGHTNING_LORE); + setDescription(SkillLocalization.SKILL_LIGHTNING_DESC); + setDamageType(NDamageType.LIGHTNING); + SkillSettings skillSettings = new SkillSettings(); + skillSettings.addNode(SkillNodes.DAMAGE, 10, 20); + skillSettings.addNode(SkillNodes.RANGE, 10, 10); + super.settings = skillSettings; + setDamageType(NDamageType.LIGHTNING); + } + + @Override + public SkillResult castOn(Living target, IActiveCharacter source, ExtendedSkillInfo info) { + float damage = settings.getLevelNodeValue(SkillNodes.DAMAGE, info.getTotalLevel()); + SkillDamageSourceBuilder build = new SkillDamageSourceBuilder(); + build.fromSkill(this); + build.setCaster(source); + target.damage(damage, build.build()); + Entity q = target.getLocation().getExtent().createEntity(EntityTypes.LIGHTNING, target.getLocation().getPosition()); + target.getLocation().getExtent().spawnEntity(q, Cause.source(SpawnCause.builder().type(SpawnTypes.PLUGIN).build()).build()); + return SkillResult.OK; + } } From 691297de4d9ea0d85a0bc69b5e713f15e5bdf37d Mon Sep 17 00:00:00 2001 From: NeumimTo Date: Sat, 8 Jul 2017 15:32:11 +0200 Subject: [PATCH 6/9] added bunch of skills, some refactoring for api improvements --- .../rpg/configuration/Localization.java | 1 + .../rpg/damage/SkillDamageSourceBuilder.java | 10 +- .../rpg/effects/IEffectContainer.java | 10 ++ .../common/stacking/ValueProcessor.java | 101 ++++++++++++++++++ .../events/CharacterWeaponDamageEvent.java | 8 +- .../rpg/events/INEntityDamageEvent.java | 54 ++++++++++ .../rpg/events/INEntityWeaponDamageEvent.java | 40 +------ .../neumimto/rpg/events/SkillDamageEvent.java | 34 +----- .../java/cz/neumimto/rpg/skills/ISkill.java | 10 +- .../main/java/cz/neumimto/SkillListener.java | 47 +++++++- .../java/cz/neumimto/SkillLocalization.java | 30 ++++++ .../cz/neumimto/effects/ManaDrainEffect.java | 25 +++++ .../effects/negative/MultiboltEffect.java | 5 +- .../positive/BurningPrescenseEffect.java | 2 - .../effects/positive/DampenEffect.java | 33 ++++++ .../cz/neumimto/events/ManaDrainEvent.java | 37 +++++++ .../java/cz/neumimto/skills/Arrowblast.java | 7 -- .../skills/{ => active}/Arrowstorm.java | 2 +- .../skills/{ => active}/BrainSap.java | 4 +- .../skills/{ => active}/BurningPrescense.java | 2 +- .../cz/neumimto/skills/active/Empathy.java | 53 +++++++++ .../skills/{ => active}/Multibolt.java | 2 +- .../skills/{ => active}/SkillFireball.java | 2 +- .../{ => active}/SkillInvisibility.java | 2 +- .../skills/{ => active}/SkillJump.java | 2 +- .../skills/{ => active}/SkillLightning.java | 2 +- .../skills/{ => active}/SkillMegabolt.java | 2 +- .../skills/{ => active}/SkillSoulbind.java | 2 +- .../skills/{ => active}/SkillSpeed.java | 2 +- .../skills/{ => active}/SkillTeleport.java | 2 +- .../cz/neumimto/skills/active/Wrestle.java | 66 ++++++++++++ .../neumimto/skills/{ => passive}/Basher.java | 2 +- .../skills/{ => passive}/Critical.java | 31 +++--- .../cz/neumimto/skills/passive/Dampen.java | 45 ++++++++ .../neumimto/skills/{ => passive}/Dodge.java | 10 +- .../cz/neumimto/skills/passive/Drain.java | 49 +++++++++ .../{ => passive}/ResoluteTechnique.java | 2 +- 37 files changed, 601 insertions(+), 137 deletions(-) create mode 100644 Plugin/src/main/java/cz/neumimto/rpg/effects/common/stacking/ValueProcessor.java create mode 100644 Plugin/src/main/java/cz/neumimto/rpg/events/INEntityDamageEvent.java create mode 100644 Skills/src/main/java/cz/neumimto/effects/ManaDrainEffect.java create mode 100644 Skills/src/main/java/cz/neumimto/effects/positive/DampenEffect.java create mode 100644 Skills/src/main/java/cz/neumimto/events/ManaDrainEvent.java delete mode 100644 Skills/src/main/java/cz/neumimto/skills/Arrowblast.java rename Skills/src/main/java/cz/neumimto/skills/{ => active}/Arrowstorm.java (97%) rename Skills/src/main/java/cz/neumimto/skills/{ => active}/BrainSap.java (94%) rename Skills/src/main/java/cz/neumimto/skills/{ => active}/BurningPrescense.java (98%) create mode 100644 Skills/src/main/java/cz/neumimto/skills/active/Empathy.java rename Skills/src/main/java/cz/neumimto/skills/{ => active}/Multibolt.java (98%) rename Skills/src/main/java/cz/neumimto/skills/{ => active}/SkillFireball.java (98%) rename Skills/src/main/java/cz/neumimto/skills/{ => active}/SkillInvisibility.java (97%) rename Skills/src/main/java/cz/neumimto/skills/{ => active}/SkillJump.java (97%) rename Skills/src/main/java/cz/neumimto/skills/{ => active}/SkillLightning.java (98%) rename Skills/src/main/java/cz/neumimto/skills/{ => active}/SkillMegabolt.java (98%) rename Skills/src/main/java/cz/neumimto/skills/{ => active}/SkillSoulbind.java (99%) rename Skills/src/main/java/cz/neumimto/skills/{ => active}/SkillSpeed.java (97%) rename Skills/src/main/java/cz/neumimto/skills/{ => active}/SkillTeleport.java (98%) create mode 100644 Skills/src/main/java/cz/neumimto/skills/active/Wrestle.java rename Skills/src/main/java/cz/neumimto/skills/{ => passive}/Basher.java (98%) rename Skills/src/main/java/cz/neumimto/skills/{ => passive}/Critical.java (64%) create mode 100644 Skills/src/main/java/cz/neumimto/skills/passive/Dampen.java rename Skills/src/main/java/cz/neumimto/skills/{ => passive}/Dodge.java (85%) create mode 100644 Skills/src/main/java/cz/neumimto/skills/passive/Drain.java rename Skills/src/main/java/cz/neumimto/skills/{ => passive}/ResoluteTechnique.java (96%) diff --git a/Plugin/src/main/java/cz/neumimto/rpg/configuration/Localization.java b/Plugin/src/main/java/cz/neumimto/rpg/configuration/Localization.java index 61c158b4c..4164a7f3a 100644 --- a/Plugin/src/main/java/cz/neumimto/rpg/configuration/Localization.java +++ b/Plugin/src/main/java/cz/neumimto/rpg/configuration/Localization.java @@ -350,4 +350,5 @@ public class Localization { @ConfigValue public static String ITEM_DAMAGE = "Item damage"; + public static String SKILL_DRAIN_DESC; } diff --git a/Plugin/src/main/java/cz/neumimto/rpg/damage/SkillDamageSourceBuilder.java b/Plugin/src/main/java/cz/neumimto/rpg/damage/SkillDamageSourceBuilder.java index 26f8e6ec4..c598d4419 100644 --- a/Plugin/src/main/java/cz/neumimto/rpg/damage/SkillDamageSourceBuilder.java +++ b/Plugin/src/main/java/cz/neumimto/rpg/damage/SkillDamageSourceBuilder.java @@ -32,8 +32,8 @@ public class SkillDamageSourceBuilder extends AbstractDamageSourceBuilder { protected ISkill skill; - protected IEffectConsumer caster; - protected IEffectConsumer target; + protected IEntity caster; + protected IEntity target; protected IEffect effect; public ISkill getSkill() { @@ -51,7 +51,7 @@ public SkillDamageSourceBuilder fromSkill(ISkill skill) { return this; } - public IEffectConsumer getCaster() { + public IEntity getCaster() { return caster; } @@ -65,7 +65,7 @@ public SkillDamageSource build() throws IllegalStateException { return new SkillDamageSource(this); } - public IEffectConsumer getTarget() { + public IEntity getTarget() { return target; } @@ -74,7 +74,7 @@ public SkillDamageSourceBuilder setTarget(IEntity target) { return this; } - public void setCaster(IEffectConsumer caster) { + public void setCaster(IEntity caster) { this.caster = caster; } diff --git a/Plugin/src/main/java/cz/neumimto/rpg/effects/IEffectContainer.java b/Plugin/src/main/java/cz/neumimto/rpg/effects/IEffectContainer.java index 1a5de85ec..b88fe7d1c 100644 --- a/Plugin/src/main/java/cz/neumimto/rpg/effects/IEffectContainer.java +++ b/Plugin/src/main/java/cz/neumimto/rpg/effects/IEffectContainer.java @@ -54,6 +54,16 @@ default void removeStack(T iEffect) { } } + default void updateValue(K value, IEffectSourceProvider provider) { + for (T t : getEffects()) { + if (t.getEffectSourceProvider() == provider) { + t.setValue(value); + break; + } + } + updateStackedValue(); + } + @Override default IEffectSource getType() { return EffectSourceType.EFFECT; diff --git a/Plugin/src/main/java/cz/neumimto/rpg/effects/common/stacking/ValueProcessor.java b/Plugin/src/main/java/cz/neumimto/rpg/effects/common/stacking/ValueProcessor.java new file mode 100644 index 000000000..d3f986d5c --- /dev/null +++ b/Plugin/src/main/java/cz/neumimto/rpg/effects/common/stacking/ValueProcessor.java @@ -0,0 +1,101 @@ +package cz.neumimto.rpg.effects.common.stacking; + +import cz.neumimto.rpg.effects.EffectContainer; +import cz.neumimto.rpg.effects.IEffect; + +/** + * Created by NeumimTo on 7.7.2017. + */ +public abstract class ValueProcessor> extends EffectContainer { + + + public ValueProcessor(I numberIEffect) { + super(numberIEffect); + } + + @Override + public void updateStackedValue() { + setStackedValue(findValue()); + } + + public abstract T findValue(); + + public static class D_MAX extends ValueProcessor> { + + public D_MAX(IEffect floatIEffect) { + super(floatIEffect); + } + + @Override + public Double findValue() { + return getEffects().stream().mapToDouble(IEffect::getValue).max().orElse(0D); + } + + } + + public static class L_MAX extends ValueProcessor> { + + public L_MAX(IEffect floatIEffect) { + super(floatIEffect); + } + + @Override + public Long findValue() { + return getEffects().stream().mapToLong(IEffect::getValue).max().orElse(0L); + } + + } + + public static class D_MIN extends ValueProcessor> { + + public D_MIN(IEffect floatIEffect) { + super(floatIEffect); + } + + @Override + public Double findValue() { + return getEffects().stream().mapToDouble(IEffect::getValue).min().orElse(0D); + } + + } + + public static class L_MIN extends ValueProcessor> { + + public L_MIN(IEffect floatIEffect) { + super(floatIEffect); + } + + @Override + public Long findValue() { + return getEffects().stream().mapToLong(IEffect::getValue).min().orElse(0L); + } + + } + + + public static class D_AVG extends ValueProcessor> { + + public D_AVG(IEffect floatIEffect) { + super(floatIEffect); + } + + @Override + public Double findValue() { + return getEffects().stream().mapToDouble(IEffect::getValue).average().orElse(0D); + } + + } + + public static class L_AVG extends ValueProcessor> { + + public L_AVG(IEffect floatIEffect) { + super(floatIEffect); + } + + @Override + public Long findValue() { + return (long) getEffects().stream().mapToLong(IEffect::getValue).average().orElse(0D); + } + + } +} diff --git a/Plugin/src/main/java/cz/neumimto/rpg/events/CharacterWeaponDamageEvent.java b/Plugin/src/main/java/cz/neumimto/rpg/events/CharacterWeaponDamageEvent.java index 3e049af9a..6ff6240d1 100644 --- a/Plugin/src/main/java/cz/neumimto/rpg/events/CharacterWeaponDamageEvent.java +++ b/Plugin/src/main/java/cz/neumimto/rpg/events/CharacterWeaponDamageEvent.java @@ -4,17 +4,13 @@ import cz.neumimto.rpg.players.IActiveCharacter; /** - * Created by ja on 17.6.2017. + * Created by NeumimTo on 17.6.2017. */ public class CharacterWeaponDamageEvent extends INEntityWeaponDamageEvent { - private IActiveCharacter character; + public CharacterWeaponDamageEvent(IActiveCharacter source, IEntity target, double damage) { super(source, target, damage); } - - public CharacterWeaponDamageEvent(IActiveCharacter character, IEntity iEntity) { - super(character, iEntity); - } } diff --git a/Plugin/src/main/java/cz/neumimto/rpg/events/INEntityDamageEvent.java b/Plugin/src/main/java/cz/neumimto/rpg/events/INEntityDamageEvent.java new file mode 100644 index 000000000..a0fc1e59f --- /dev/null +++ b/Plugin/src/main/java/cz/neumimto/rpg/events/INEntityDamageEvent.java @@ -0,0 +1,54 @@ +package cz.neumimto.rpg.events; + +import cz.neumimto.rpg.IEntity; +import org.spongepowered.api.event.cause.entity.damage.DamageType; + +/** + * Created by NeumimTo on 8.7.2017. + */ +public class INEntityDamageEvent extends CancellableEvent { + private IEntity source; + private IEntity target; + private double damage; + private DamageType type; + + public INEntityDamageEvent(IEntity source, IEntity target, double damage, DamageType type) { + + this.source = source; + this.target = target; + this.damage = damage; + this.type = type; + } + + public IEntity getSource() { + return source; + } + + public void setSource(IEntity source) { + this.source = source; + } + + public IEntity getTarget() { + return target; + } + + public void setTarget(IEntity target) { + this.target = target; + } + + public double getDamage() { + return damage; + } + + public void setDamage(double damage) { + this.damage = damage; + } + + public DamageType getType() { + return type; + } + + public void setType(DamageType type) { + this.type = type; + } +} diff --git a/Plugin/src/main/java/cz/neumimto/rpg/events/INEntityWeaponDamageEvent.java b/Plugin/src/main/java/cz/neumimto/rpg/events/INEntityWeaponDamageEvent.java index 7f793ebac..3d4943c63 100644 --- a/Plugin/src/main/java/cz/neumimto/rpg/events/INEntityWeaponDamageEvent.java +++ b/Plugin/src/main/java/cz/neumimto/rpg/events/INEntityWeaponDamageEvent.java @@ -2,47 +2,15 @@ import cz.neumimto.rpg.IEntity; import cz.neumimto.rpg.players.IActiveCharacter; +import org.spongepowered.api.event.cause.entity.damage.DamageTypes; /** - * Created by ja on 17.6.2017. + * Created by NeumimTo on 17.6.2017. */ -public class INEntityWeaponDamageEvent extends CancellableEvent { - private IEntity source; - private IEntity target; - private double damage; +public class INEntityWeaponDamageEvent extends INEntityDamageEvent { public INEntityWeaponDamageEvent(IEntity source, IEntity target, double damage) { - this.source = source; - this.target = target; - this.damage = damage; + super(source, target, damage, DamageTypes.ATTACK); } - public INEntityWeaponDamageEvent(IEntity source, IEntity target) { - this.source = source; - this.target = target; - } - - public IEntity getSource() { - return source; - } - - public void setSource(IEntity source) { - this.source = source; - } - - public IEntity getTarget() { - return target; - } - - public void setTarget(IEntity target) { - this.target = target; - } - - public double getDamage() { - return damage; - } - - public void setDamage(double damage) { - this.damage = damage; - } } diff --git a/Plugin/src/main/java/cz/neumimto/rpg/events/SkillDamageEvent.java b/Plugin/src/main/java/cz/neumimto/rpg/events/SkillDamageEvent.java index 42db26773..04577fe87 100644 --- a/Plugin/src/main/java/cz/neumimto/rpg/events/SkillDamageEvent.java +++ b/Plugin/src/main/java/cz/neumimto/rpg/events/SkillDamageEvent.java @@ -7,34 +7,12 @@ /** * Created by NeumimTo on 18.6.2017. */ -public class SkillDamageEvent extends CancellableEvent { - IEntity caster; - IEntity target; +public class SkillDamageEvent extends INEntityDamageEvent { ISkill skill; - double damage; - DamageType damageType; public SkillDamageEvent(IEntity caster, IEntity target, ISkill skill, double damage, DamageType damageType) { - this.caster = caster; - this.target = target; + super(caster, target, damage, damageType); this.skill = skill; - this.damage = damage; - } - - public IEntity getCaster() { - return caster; - } - - public void setCaster(IEntity caster) { - this.caster = caster; - } - - public IEntity getTarget() { - return target; - } - - public void setTarget(IEntity target) { - this.target = target; } public ISkill getSkill() { @@ -44,12 +22,4 @@ public ISkill getSkill() { public void setSkill(ISkill skill) { this.skill = skill; } - - public double getDamage() { - return damage; - } - - public void setDamage(double damage) { - this.damage = damage; - } } diff --git a/Plugin/src/main/java/cz/neumimto/rpg/skills/ISkill.java b/Plugin/src/main/java/cz/neumimto/rpg/skills/ISkill.java index 6690b41b2..fca8f7186 100644 --- a/Plugin/src/main/java/cz/neumimto/rpg/skills/ISkill.java +++ b/Plugin/src/main/java/cz/neumimto/rpg/skills/ISkill.java @@ -74,7 +74,11 @@ public interface ISkill extends IEffectSourceProvider { void setDamageType(DamageType type); default float getFloatNodeValue(ExtendedSkillInfo extendedSkillInfo, ISkillNode node) { - return extendedSkillInfo.getSkillData().getSkillSettings().getLevelNodeValue(node,extendedSkillInfo.getTotalLevel()); + return getFloatNodeValue(extendedSkillInfo, node.value()); + } + + default float getFloatNodeValue(ExtendedSkillInfo extendedSkillInfo, String node) { + return extendedSkillInfo.getSkillData().getSkillSettings().getLevelNodeValue(node,extendedSkillInfo.getTotalLevel()); } default int getIntNodeValue(ExtendedSkillInfo extendedSkillInfo, ISkillNode node) { @@ -89,6 +93,10 @@ default long getLongNodeValue(ExtendedSkillInfo extendedSkillInfo, ISkillNode no return (long) extendedSkillInfo.getSkillData().getSkillSettings().getLevelNodeValue(node,extendedSkillInfo.getTotalLevel()); } + default double getDoubleNodeValue(ExtendedSkillInfo extendedSkillInfo, String node) { + return extendedSkillInfo.getSkillData().getSkillSettings().getLevelNodeValue(node,extendedSkillInfo.getTotalLevel()); + } + @Override default IEffectSource getType() { return EffectSourceType.SKILL; diff --git a/Skills/src/main/java/cz/neumimto/SkillListener.java b/Skills/src/main/java/cz/neumimto/SkillListener.java index bf4b780fd..0fe93bc7c 100644 --- a/Skills/src/main/java/cz/neumimto/SkillListener.java +++ b/Skills/src/main/java/cz/neumimto/SkillListener.java @@ -1,26 +1,31 @@ package cz.neumimto; import cz.neumimto.core.ioc.Inject; +import cz.neumimto.effects.ManaDrainEffect; import cz.neumimto.effects.ResoluteTechniqueEffect; import cz.neumimto.effects.negative.StunEffect; import cz.neumimto.effects.positive.*; import cz.neumimto.events.CriticalStrikeEvent; import cz.neumimto.events.DamageDodgedEvent; +import cz.neumimto.events.ManaDrainEvent; import cz.neumimto.events.StunApplyEvent; import cz.neumimto.model.BashModel; import cz.neumimto.model.CriticalEffectModel; +import cz.neumimto.rpg.IEntityType; import cz.neumimto.rpg.ResourceLoader; import cz.neumimto.rpg.effects.EffectService; import cz.neumimto.rpg.effects.IEffectContainer; import cz.neumimto.rpg.entities.EntityService; +import cz.neumimto.rpg.events.INEntityDamageEvent; import cz.neumimto.rpg.events.INEntityWeaponDamageEvent; import cz.neumimto.rpg.events.character.CharacterDamageEntityEvent; import cz.neumimto.rpg.players.CharacterService; import cz.neumimto.rpg.players.IActiveCharacter; +import cz.neumimto.rpg.players.IReservable; +import cz.neumimto.rpg.players.Mana; import cz.neumimto.rpg.players.properties.DefaultProperties; import cz.neumimto.rpg.players.properties.PropertyService; import cz.neumimto.rpg.utils.XORShiftRnd; -import cz.neumimto.skills.ResoluteTechnique; import org.spongepowered.api.Game; import org.spongepowered.api.entity.living.player.Player; import org.spongepowered.api.event.Listener; @@ -80,9 +85,24 @@ public void onDamage(CharacterDamageEntityEvent event) { } } + @Listener + public void onEntityDamage(INEntityDamageEvent event) { + + } + @Listener @SuppressWarnings("unchecked") - public void onDamage(INEntityWeaponDamageEvent event) { + public void onWeaponDamage(INEntityWeaponDamageEvent event) { + if (event.getTarget().hasEffect(DampenEffect.name)) { + if (event.getSource().getType() == IEntityType.CHARACTER) { + IActiveCharacter character = (IActiveCharacter) event.getSource(); + IEffectContainer effect = event.getTarget().getEffect(DampenEffect.name); + if (character.getMana().getValue() <= effect.getStackedValue()) { + event.setCancelled(true); + return; + } + } + } XORShiftRnd random = new XORShiftRnd(); //dodge if (event.getTarget().hasEffect(DodgeEffect.name)) { @@ -120,6 +140,7 @@ public void onDamage(INEntityWeaponDamageEvent event) { } } } + //critical if (event.getSource().hasEffect(CriticalEffect.name)) { IEffectContainer effect = event.getSource().getEffect(CriticalEffect.name); CriticalEffectModel stackedValue = effect.getStackedValue(); @@ -130,6 +151,16 @@ public void onDamage(INEntityWeaponDamageEvent event) { } } } + //manadrain + if (event.getTarget().getType() == IEntityType.CHARACTER) { + IActiveCharacter character = (IActiveCharacter) event.getTarget(); + if (character.hasEffect(ManaDrainEffect.name)) { + IEffectContainer container = character.getEffect(ManaDrainEffect.name); + IReservable mana = character.getMana(); + double k = character.getMana().getValue() - container.getStackedValue(); + ManaDrainEvent mde = new ManaDrainEvent(event.getSource(), character, k); + } + } } @Listener @@ -139,7 +170,7 @@ public void onStunApply(StunApplyEvent event) { effect.setDuration((long) (f * event.getEffect().getDuration())); } - @Listener(order = Order.LAST) + @Listener(order = Order.LATE) @IsCancelled(Tristate.UNDEFINED) public void onCriticalStrike(CriticalStrikeEvent event) { if (event.isCancelled()) { @@ -149,7 +180,7 @@ public void onCriticalStrike(CriticalStrikeEvent event) { } } - @Listener(order = Order.LAST) + @Listener(order = Order.LATE) @IsCancelled(Tristate.UNDEFINED) public void onDodge(DamageDodgedEvent event) { if (event.isCancelled()) { @@ -158,4 +189,12 @@ public void onDodge(DamageDodgedEvent event) { } } } + + @Listener(order = Order.LAST) + @IsCancelled(Tristate.FALSE) + public void onManaDrain(ManaDrainEvent mde) { + IReservable mana = mde.getTarget().getMana(); + double k = mana.getValue() - mde.getAmountDrained() <= 0 ? 0 : mana.getValue() - mde.getAmountDrained(); + mana.setValue(k); + } } diff --git a/Skills/src/main/java/cz/neumimto/SkillLocalization.java b/Skills/src/main/java/cz/neumimto/SkillLocalization.java index b046a36a0..275f0b269 100644 --- a/Skills/src/main/java/cz/neumimto/SkillLocalization.java +++ b/Skills/src/main/java/cz/neumimto/SkillLocalization.java @@ -90,4 +90,34 @@ public class SkillLocalization { @ConfigValue public static String SKILL_RESOLUTE_TECHNIQUE_LORE = ""; + + @ConfigValue + public static String SKILL_WRESTLE_LORE = ""; + + @ConfigValue + public static String SKILL_WRESTLE_DESC = ""; + + @ConfigValue + public static String SKILL_DRAIN_DESC = ""; + + @ConfigValue + public static String SKILL_DRAIN_LORE = ""; + + @ConfigValue + public static String SKILL_CRITICAL_DESC = ""; + + @ConfigValue + public static String SKILL_CRITICAL_LORE = ""; + + @ConfigValue + public static String SKILL_EMPHATY_DESC = ""; + + @ConfigValue + public static String SKILL_EMPHATY_LORE = ""; + + @ConfigValue + public static String SKILL_DAMPEN_DESC = ""; + + @ConfigValue + public static String SKILL_DAMPEN_LORE = ""; } diff --git a/Skills/src/main/java/cz/neumimto/effects/ManaDrainEffect.java b/Skills/src/main/java/cz/neumimto/effects/ManaDrainEffect.java new file mode 100644 index 000000000..0e042c527 --- /dev/null +++ b/Skills/src/main/java/cz/neumimto/effects/ManaDrainEffect.java @@ -0,0 +1,25 @@ +package cz.neumimto.effects; + +import cz.neumimto.rpg.ClassGenerator; +import cz.neumimto.rpg.effects.EffectBase; +import cz.neumimto.rpg.players.IActiveCharacter; +import cz.neumimto.rpg.utils.Utils; + +/** + * Created by NeumimTo on 7.7.2017. + */ +@ClassGenerator.Generate(id = "name") +public class ManaDrainEffect extends EffectBase { + + public static final String name = "Mana Drain"; + + public ManaDrainEffect(IActiveCharacter character, long duration, float value) { + super(name, character); + setDuration(duration); + setValue(value); + } + + public ManaDrainEffect(IActiveCharacter character, long duration, String value) { + this(character, duration, Float.parseFloat(Utils.extractNumber(value))); + } +} diff --git a/Skills/src/main/java/cz/neumimto/effects/negative/MultiboltEffect.java b/Skills/src/main/java/cz/neumimto/effects/negative/MultiboltEffect.java index af8f5514b..180e1f0d8 100644 --- a/Skills/src/main/java/cz/neumimto/effects/negative/MultiboltEffect.java +++ b/Skills/src/main/java/cz/neumimto/effects/negative/MultiboltEffect.java @@ -2,6 +2,7 @@ import cz.neumimto.model.MultiboltModel; import cz.neumimto.rpg.ClassGenerator; +import cz.neumimto.rpg.IEntity; import cz.neumimto.rpg.damage.SkillDamageSourceBuilder; import cz.neumimto.rpg.effects.EffectBase; import cz.neumimto.rpg.effects.IEffectConsumer; @@ -18,10 +19,10 @@ */ public class MultiboltEffect extends EffectBase { - private final IEffectConsumer source; + private final IEntity source; private final MultiboltModel model; - public MultiboltEffect(IEffectConsumer consumer, IEffectConsumer source, MultiboltModel model) { + public MultiboltEffect(IEffectConsumer consumer, IEntity source, MultiboltModel model) { super("Multibolt", consumer); this.source = source; this.model = model; diff --git a/Skills/src/main/java/cz/neumimto/effects/positive/BurningPrescenseEffect.java b/Skills/src/main/java/cz/neumimto/effects/positive/BurningPrescenseEffect.java index a9ce19344..5bb38892e 100644 --- a/Skills/src/main/java/cz/neumimto/effects/positive/BurningPrescenseEffect.java +++ b/Skills/src/main/java/cz/neumimto/effects/positive/BurningPrescenseEffect.java @@ -3,9 +3,7 @@ import cz.neumimto.model.BurningpresenseModel; import cz.neumimto.rpg.ClassGenerator; import cz.neumimto.rpg.effects.*; -import cz.neumimto.rpg.effects.common.stacking.FloatEffectStackingStrategy; import cz.neumimto.rpg.utils.Utils; -import cz.neumimto.skills.BurningPrescense; /** * Created by ja on 5.7.2017. diff --git a/Skills/src/main/java/cz/neumimto/effects/positive/DampenEffect.java b/Skills/src/main/java/cz/neumimto/effects/positive/DampenEffect.java new file mode 100644 index 000000000..3d6ff3380 --- /dev/null +++ b/Skills/src/main/java/cz/neumimto/effects/positive/DampenEffect.java @@ -0,0 +1,33 @@ +package cz.neumimto.effects.positive; + +import cz.neumimto.rpg.ClassGenerator; +import cz.neumimto.rpg.effects.*; +import cz.neumimto.rpg.effects.common.stacking.ValueProcessor; +import cz.neumimto.rpg.utils.Utils; + +/** + * Created by NeumimTo on 7.7.2017. + */ +@ClassGenerator.Generate(id = "name") +public class DampenEffect extends EffectBase { + + public static final String name = "Dampen"; + + public DampenEffect(IEffectConsumer consumer, long duration, String value) { + this(consumer, duration,Double.parseDouble(Utils.extractNumber(value))); + } + + public DampenEffect(IEffectConsumer consumer, long duration, double value) { + super(name, consumer); + setDuration(duration); + setValue(value); + setStackable(true, null); + } + + + @Override + @SuppressWarnings("unchecked") + public IEffectContainer constructEffectContainer() { + return new ValueProcessor.D_MIN(this); + } +} diff --git a/Skills/src/main/java/cz/neumimto/events/ManaDrainEvent.java b/Skills/src/main/java/cz/neumimto/events/ManaDrainEvent.java new file mode 100644 index 000000000..38ecdea72 --- /dev/null +++ b/Skills/src/main/java/cz/neumimto/events/ManaDrainEvent.java @@ -0,0 +1,37 @@ +package cz.neumimto.events; + +import cz.neumimto.rpg.IEntity; +import cz.neumimto.rpg.events.CancellableEvent; +import cz.neumimto.rpg.players.IActiveCharacter; + +/** + * Created by NeumimTo on 7.7.2017. + */ +public class ManaDrainEvent extends CancellableEvent { + private final IEntity source; + private final IActiveCharacter target; + private double amountDrained; + + public ManaDrainEvent(IEntity source, IActiveCharacter target, double k) { + + this.source = source; + this.target = target; + this.amountDrained = k; + } + + public IEntity getSource() { + return source; + } + + public IActiveCharacter getTarget() { + return target; + } + + public double getAmountDrained() { + return amountDrained; + } + + public void setAmountDrained(double amountDrained) { + this.amountDrained = amountDrained; + } +} diff --git a/Skills/src/main/java/cz/neumimto/skills/Arrowblast.java b/Skills/src/main/java/cz/neumimto/skills/Arrowblast.java deleted file mode 100644 index 895c4819e..000000000 --- a/Skills/src/main/java/cz/neumimto/skills/Arrowblast.java +++ /dev/null @@ -1,7 +0,0 @@ -package cz.neumimto.skills; - -/** - * Created by ja on 4.7.2017. - */ -public class Arrowblast { -} diff --git a/Skills/src/main/java/cz/neumimto/skills/Arrowstorm.java b/Skills/src/main/java/cz/neumimto/skills/active/Arrowstorm.java similarity index 97% rename from Skills/src/main/java/cz/neumimto/skills/Arrowstorm.java rename to Skills/src/main/java/cz/neumimto/skills/active/Arrowstorm.java index 3b715c1a0..0a1b25d88 100644 --- a/Skills/src/main/java/cz/neumimto/skills/Arrowstorm.java +++ b/Skills/src/main/java/cz/neumimto/skills/active/Arrowstorm.java @@ -1,4 +1,4 @@ -package cz.neumimto.skills; +package cz.neumimto.skills.active; import cz.neumimto.SkillLocalization; import cz.neumimto.core.ioc.Inject; diff --git a/Skills/src/main/java/cz/neumimto/skills/BrainSap.java b/Skills/src/main/java/cz/neumimto/skills/active/BrainSap.java similarity index 94% rename from Skills/src/main/java/cz/neumimto/skills/BrainSap.java rename to Skills/src/main/java/cz/neumimto/skills/active/BrainSap.java index 2619d2556..da0896878 100644 --- a/Skills/src/main/java/cz/neumimto/skills/BrainSap.java +++ b/Skills/src/main/java/cz/neumimto/skills/active/BrainSap.java @@ -1,4 +1,4 @@ -package cz.neumimto.skills; +package cz.neumimto.skills.active; import cz.neumimto.rpg.IEntity; import cz.neumimto.rpg.ResourceLoader; @@ -7,7 +7,6 @@ import cz.neumimto.rpg.damage.SkillDamageSource; import cz.neumimto.rpg.damage.SkillDamageSourceBuilder; import cz.neumimto.rpg.entities.EntityService; -import cz.neumimto.rpg.events.SkillDamageEvent; import cz.neumimto.rpg.events.SkillDamageEventLate; import cz.neumimto.rpg.players.IActiveCharacter; import cz.neumimto.rpg.skills.*; @@ -15,7 +14,6 @@ import org.spongepowered.api.entity.living.Living; import org.spongepowered.api.event.Listener; import org.spongepowered.api.event.Order; -import org.spongepowered.api.event.entity.DamageEntityEvent; import org.spongepowered.api.event.filter.cause.First; /** diff --git a/Skills/src/main/java/cz/neumimto/skills/BurningPrescense.java b/Skills/src/main/java/cz/neumimto/skills/active/BurningPrescense.java similarity index 98% rename from Skills/src/main/java/cz/neumimto/skills/BurningPrescense.java rename to Skills/src/main/java/cz/neumimto/skills/active/BurningPrescense.java index e89ce1e0a..40eb20c7d 100644 --- a/Skills/src/main/java/cz/neumimto/skills/BurningPrescense.java +++ b/Skills/src/main/java/cz/neumimto/skills/active/BurningPrescense.java @@ -1,4 +1,4 @@ -package cz.neumimto.skills; +package cz.neumimto.skills.active; import cz.neumimto.SkillLocalization; import cz.neumimto.core.ioc.Inject; diff --git a/Skills/src/main/java/cz/neumimto/skills/active/Empathy.java b/Skills/src/main/java/cz/neumimto/skills/active/Empathy.java new file mode 100644 index 000000000..4b7764e12 --- /dev/null +++ b/Skills/src/main/java/cz/neumimto/skills/active/Empathy.java @@ -0,0 +1,53 @@ +package cz.neumimto.skills.active; + +import cz.neumimto.SkillLocalization; +import cz.neumimto.core.ioc.Inject; +import cz.neumimto.rpg.ResourceLoader; +import cz.neumimto.rpg.damage.SkillDamageSource; +import cz.neumimto.rpg.damage.SkillDamageSourceBuilder; +import cz.neumimto.rpg.entities.EntityService; +import cz.neumimto.rpg.players.IActiveCharacter; +import cz.neumimto.rpg.skills.*; +import org.spongepowered.api.data.key.Keys; +import org.spongepowered.api.entity.EntityTypes; +import org.spongepowered.api.entity.living.Living; +import org.spongepowered.api.entity.living.player.Player; +import org.spongepowered.api.event.cause.entity.damage.DamageTypes; + +/** + * Created by NeumimTo on 7.7.2017. + */ +@ResourceLoader.Skill +public class Empathy extends Targetted { + + @Inject + private EntityService entityService; + + public Empathy() { + setName("Empathy"); + setDescription(SkillLocalization.SKILL_EMPHATY_DESC); + super.settings = new SkillSettings(); + settings.addNode(SkillNodes.MULTIPLIER, 10, 10); + settings.addNode("max-damage", -1, 0); + setDamageType(DamageTypes.MAGIC); + } + + @Override + public SkillResult castOn(Living target, IActiveCharacter source, ExtendedSkillInfo info) { + Player entity = source.getEntity(); + Double max = entity.get(Keys.MAX_HEALTH).get(); + Double a = entity.get(Keys.HEALTH).get(); + a = max - a; + a *= getFloatNodeValue(info, SkillNodes.MULTIPLIER); + max = getDoubleNodeValue(info, "max-damage"); + if (max > 0) { + a = a < max ? max : a; + } + SkillDamageSource build = new SkillDamageSourceBuilder() + .fromSkill(this) + .setTarget(entityService.get(target)) + .setCaster(source).build(); + target.damage(a, build); + return SkillResult.CANCELLED; + } +} diff --git a/Skills/src/main/java/cz/neumimto/skills/Multibolt.java b/Skills/src/main/java/cz/neumimto/skills/active/Multibolt.java similarity index 98% rename from Skills/src/main/java/cz/neumimto/skills/Multibolt.java rename to Skills/src/main/java/cz/neumimto/skills/active/Multibolt.java index 738e695f6..309923355 100644 --- a/Skills/src/main/java/cz/neumimto/skills/Multibolt.java +++ b/Skills/src/main/java/cz/neumimto/skills/active/Multibolt.java @@ -1,4 +1,4 @@ -package cz.neumimto.skills; +package cz.neumimto.skills.active; import cz.neumimto.SkillLocalization; import cz.neumimto.core.ioc.Inject; diff --git a/Skills/src/main/java/cz/neumimto/skills/SkillFireball.java b/Skills/src/main/java/cz/neumimto/skills/active/SkillFireball.java similarity index 98% rename from Skills/src/main/java/cz/neumimto/skills/SkillFireball.java rename to Skills/src/main/java/cz/neumimto/skills/active/SkillFireball.java index eb812920f..2a1498474 100644 --- a/Skills/src/main/java/cz/neumimto/skills/SkillFireball.java +++ b/Skills/src/main/java/cz/neumimto/skills/active/SkillFireball.java @@ -1,4 +1,4 @@ -package cz.neumimto.skills; +package cz.neumimto.skills.active; import com.flowpowered.math.TrigMath; import com.flowpowered.math.imaginary.Quaterniond; diff --git a/Skills/src/main/java/cz/neumimto/skills/SkillInvisibility.java b/Skills/src/main/java/cz/neumimto/skills/active/SkillInvisibility.java similarity index 97% rename from Skills/src/main/java/cz/neumimto/skills/SkillInvisibility.java rename to Skills/src/main/java/cz/neumimto/skills/active/SkillInvisibility.java index e4b4917f4..152255824 100644 --- a/Skills/src/main/java/cz/neumimto/skills/SkillInvisibility.java +++ b/Skills/src/main/java/cz/neumimto/skills/active/SkillInvisibility.java @@ -1,4 +1,4 @@ -package cz.neumimto.skills; +package cz.neumimto.skills.active; import cz.neumimto.core.ioc.Inject; import cz.neumimto.rpg.ResourceLoader; diff --git a/Skills/src/main/java/cz/neumimto/skills/SkillJump.java b/Skills/src/main/java/cz/neumimto/skills/active/SkillJump.java similarity index 97% rename from Skills/src/main/java/cz/neumimto/skills/SkillJump.java rename to Skills/src/main/java/cz/neumimto/skills/active/SkillJump.java index 9d6fb77e3..7e6db5f2f 100644 --- a/Skills/src/main/java/cz/neumimto/skills/SkillJump.java +++ b/Skills/src/main/java/cz/neumimto/skills/active/SkillJump.java @@ -1,4 +1,4 @@ -package cz.neumimto.skills; +package cz.neumimto.skills.active; import com.flowpowered.math.imaginary.Quaterniond; import com.flowpowered.math.vector.Vector3d; diff --git a/Skills/src/main/java/cz/neumimto/skills/SkillLightning.java b/Skills/src/main/java/cz/neumimto/skills/active/SkillLightning.java similarity index 98% rename from Skills/src/main/java/cz/neumimto/skills/SkillLightning.java rename to Skills/src/main/java/cz/neumimto/skills/active/SkillLightning.java index 8c8770237..2ee6b39a6 100644 --- a/Skills/src/main/java/cz/neumimto/skills/SkillLightning.java +++ b/Skills/src/main/java/cz/neumimto/skills/active/SkillLightning.java @@ -1,4 +1,4 @@ -package cz.neumimto.skills; +package cz.neumimto.skills.active; import cz.neumimto.SkillLocalization; import cz.neumimto.core.ioc.Inject; diff --git a/Skills/src/main/java/cz/neumimto/skills/SkillMegabolt.java b/Skills/src/main/java/cz/neumimto/skills/active/SkillMegabolt.java similarity index 98% rename from Skills/src/main/java/cz/neumimto/skills/SkillMegabolt.java rename to Skills/src/main/java/cz/neumimto/skills/active/SkillMegabolt.java index de0ac3bd2..0611cdc04 100644 --- a/Skills/src/main/java/cz/neumimto/skills/SkillMegabolt.java +++ b/Skills/src/main/java/cz/neumimto/skills/active/SkillMegabolt.java @@ -1,4 +1,4 @@ -package cz.neumimto.skills; +package cz.neumimto.skills.active; import cz.neumimto.rpg.ResourceLoader; import cz.neumimto.rpg.damage.SkillDamageSource; diff --git a/Skills/src/main/java/cz/neumimto/skills/SkillSoulbind.java b/Skills/src/main/java/cz/neumimto/skills/active/SkillSoulbind.java similarity index 99% rename from Skills/src/main/java/cz/neumimto/skills/SkillSoulbind.java rename to Skills/src/main/java/cz/neumimto/skills/active/SkillSoulbind.java index 4afaaca12..4c3fa9df7 100644 --- a/Skills/src/main/java/cz/neumimto/skills/SkillSoulbind.java +++ b/Skills/src/main/java/cz/neumimto/skills/active/SkillSoulbind.java @@ -1,4 +1,4 @@ -package cz.neumimto.skills; +package cz.neumimto.skills.active; import cz.neumimto.rpg.ResourceLoader; import cz.neumimto.SkillLocalization; diff --git a/Skills/src/main/java/cz/neumimto/skills/SkillSpeed.java b/Skills/src/main/java/cz/neumimto/skills/active/SkillSpeed.java similarity index 97% rename from Skills/src/main/java/cz/neumimto/skills/SkillSpeed.java rename to Skills/src/main/java/cz/neumimto/skills/active/SkillSpeed.java index 97e70d0a1..6a33111cb 100644 --- a/Skills/src/main/java/cz/neumimto/skills/SkillSpeed.java +++ b/Skills/src/main/java/cz/neumimto/skills/active/SkillSpeed.java @@ -1,4 +1,4 @@ -package cz.neumimto.skills; +package cz.neumimto.skills.active; import cz.neumimto.rpg.ResourceLoader; import cz.neumimto.SkillLocalization; diff --git a/Skills/src/main/java/cz/neumimto/skills/SkillTeleport.java b/Skills/src/main/java/cz/neumimto/skills/active/SkillTeleport.java similarity index 98% rename from Skills/src/main/java/cz/neumimto/skills/SkillTeleport.java rename to Skills/src/main/java/cz/neumimto/skills/active/SkillTeleport.java index 101cf46b8..96adf7fcb 100644 --- a/Skills/src/main/java/cz/neumimto/skills/SkillTeleport.java +++ b/Skills/src/main/java/cz/neumimto/skills/active/SkillTeleport.java @@ -1,4 +1,4 @@ -package cz.neumimto.skills; +package cz.neumimto.skills.active; import com.flowpowered.math.vector.Vector3d; import cz.neumimto.rpg.ResourceLoader; diff --git a/Skills/src/main/java/cz/neumimto/skills/active/Wrestle.java b/Skills/src/main/java/cz/neumimto/skills/active/Wrestle.java new file mode 100644 index 000000000..b52313f8d --- /dev/null +++ b/Skills/src/main/java/cz/neumimto/skills/active/Wrestle.java @@ -0,0 +1,66 @@ +package cz.neumimto.skills.active; + +import cz.neumimto.SkillLocalization; +import cz.neumimto.core.ioc.Inject; +import cz.neumimto.effects.negative.StunEffect; +import cz.neumimto.rpg.ResourceLoader; +import cz.neumimto.rpg.damage.SkillDamageSourceBuilder; +import cz.neumimto.rpg.effects.EffectService; +import cz.neumimto.rpg.effects.IEffectConsumer; +import cz.neumimto.rpg.entities.EntityService; +import cz.neumimto.rpg.players.IActiveCharacter; +import cz.neumimto.rpg.skills.*; +import cz.neumimto.rpg.utils.Utils; +import org.spongepowered.api.entity.Entity; +import org.spongepowered.api.entity.living.Living; +import org.spongepowered.api.event.cause.entity.damage.DamageTypes; + +/** + * Created by NeumimTo on 7.7.2017. + */ +@ResourceLoader.Skill +public class Wrestle extends Targetted { + + @Inject + private EffectService effectService; + + @Inject + private EntityService entityService; + + public Wrestle() { + setName("Wrestle"); + setDescription(SkillLocalization.SKILL_WRESTLE_DESC); + setLore(SkillLocalization.SKILL_WRESTLE_LORE); + setDamageType(NDamageType.PHYSICAL); + SkillSettings settings = new SkillSettings(); + settings.addNode(SkillNodes.RADIUS, 3, 0.5f); + settings.addNode(SkillNodes.DURATION, 1, 0.1f); + settings.addNode(SkillNodes.DAMAGE, 1, 0.5f); + super.settings = settings; + } + + @Override + public SkillResult castOn(Living target, IActiveCharacter source, ExtendedSkillInfo info) { + int intNodeValue = getIntNodeValue(info, SkillNodes.RADIUS); + float floatNodeValue = getFloatNodeValue(info, SkillNodes.DAMAGE); + long duration = getLongNodeValue(info, SkillNodes.DURATION); + for (Entity entity : target.getNearbyEntities(intNodeValue)) { + if (Utils.isLivingEntity(entity)) { + Living l = (Living) entity; + if (Utils.canDamage(source, l)) { + IEffectConsumer t = entityService.get(target); + StunEffect stunEffect = new StunEffect(t, duration); + effectService.addEffect(stunEffect, t, this); + if (floatNodeValue > 0) { + SkillDamageSourceBuilder build = new SkillDamageSourceBuilder(); + build.fromSkill(this); + build.setCaster(source); + build.type(DamageTypes.ATTACK); + entity.damage(floatNodeValue, build.build()); + } + } + } + } + return SkillResult.OK; + } +} diff --git a/Skills/src/main/java/cz/neumimto/skills/Basher.java b/Skills/src/main/java/cz/neumimto/skills/passive/Basher.java similarity index 98% rename from Skills/src/main/java/cz/neumimto/skills/Basher.java rename to Skills/src/main/java/cz/neumimto/skills/passive/Basher.java index 012c28296..a805199d9 100644 --- a/Skills/src/main/java/cz/neumimto/skills/Basher.java +++ b/Skills/src/main/java/cz/neumimto/skills/passive/Basher.java @@ -1,4 +1,4 @@ -package cz.neumimto.skills; +package cz.neumimto.skills.passive; import antlr.ASdebug.IASDebugStream; import cz.neumimto.AdditionalProperties; diff --git a/Skills/src/main/java/cz/neumimto/skills/Critical.java b/Skills/src/main/java/cz/neumimto/skills/passive/Critical.java similarity index 64% rename from Skills/src/main/java/cz/neumimto/skills/Critical.java rename to Skills/src/main/java/cz/neumimto/skills/passive/Critical.java index 553cf59c1..15e7b4901 100644 --- a/Skills/src/main/java/cz/neumimto/skills/Critical.java +++ b/Skills/src/main/java/cz/neumimto/skills/passive/Critical.java @@ -1,17 +1,14 @@ -package cz.neumimto.skills; +package cz.neumimto.skills.passive; import cz.neumimto.SkillLocalization; import cz.neumimto.core.ioc.Inject; import cz.neumimto.effects.positive.CriticalEffect; -import cz.neumimto.effects.positive.DodgeEffect; import cz.neumimto.model.CriticalEffectModel; import cz.neumimto.rpg.ResourceLoader; import cz.neumimto.rpg.effects.EffectService; import cz.neumimto.rpg.effects.IEffectContainer; import cz.neumimto.rpg.players.IActiveCharacter; import cz.neumimto.rpg.skills.*; -import org.spongepowered.api.event.cause.entity.damage.DamageType; -import org.spongepowered.api.event.cause.entity.damage.DamageTypes; /** * Created by ja on 6.7.2017. @@ -23,9 +20,9 @@ public class Critical extends PassiveSkill { private EffectService effectService; public Critical() { - setName("Dodge"); - setLore(SkillLocalization.SKILL_DODGE_LORE); - setDescription(SkillLocalization.SKILL_DODGE_DESC); + setName("Critical"); + setLore(SkillLocalization.SKILL_CRITICAL_LORE); + setDescription(SkillLocalization.SKILL_CRITICAL_DESC); SkillSettings skillSettings = new SkillSettings(); skillSettings.addNode(SkillNodes.CHANCE, 10, 20); skillSettings.addNode(SkillNodes.MULTIPLIER, 10, 20); @@ -35,9 +32,7 @@ public Critical() { @Override public void applyEffect(ExtendedSkillInfo info, IActiveCharacter character) { - int chance = getIntNodeValue(info, SkillNodes.CHANCE); - float mult = getFloatNodeValue(info, SkillNodes.MULTIPLIER); - CriticalEffectModel model = new CriticalEffectModel(chance, mult); + CriticalEffectModel model = getModel(info); CriticalEffect dodgeEffect = new CriticalEffect(character, -1, model); effectService.addEffect(dodgeEffect, character, this); } @@ -45,14 +40,14 @@ public void applyEffect(ExtendedSkillInfo info, IActiveCharacter character) { @Override public void skillUpgrade(IActiveCharacter character, int level) { ExtendedSkillInfo info = character.getSkill(getName()); - float chance = getFloatNodeValue(info, SkillNodes.CHANCE); - IEffectContainer effect = character.getEffect(DodgeEffect.name); - for (DodgeEffect dodgeEffect : effect.getEffects()) { - if (dodgeEffect.getEffectSourceProvider() == this) { - dodgeEffect.setValue(chance); - break; - } - } + IEffectContainer effect = character.getEffect(CriticalEffect.name); + effect.updateValue(getModel(info), this); effect.updateStackedValue(); } + + private CriticalEffectModel getModel(ExtendedSkillInfo info) { + int chance = getIntNodeValue(info, SkillNodes.CHANCE); + float mult = getFloatNodeValue(info, SkillNodes.MULTIPLIER); + return new CriticalEffectModel(chance, mult); + } } diff --git a/Skills/src/main/java/cz/neumimto/skills/passive/Dampen.java b/Skills/src/main/java/cz/neumimto/skills/passive/Dampen.java new file mode 100644 index 000000000..bd613c613 --- /dev/null +++ b/Skills/src/main/java/cz/neumimto/skills/passive/Dampen.java @@ -0,0 +1,45 @@ +package cz.neumimto.skills.passive; + +import cz.neumimto.SkillLocalization; +import cz.neumimto.core.ioc.Inject; +import cz.neumimto.effects.positive.DampenEffect; +import cz.neumimto.rpg.ResourceLoader; +import cz.neumimto.rpg.effects.EffectService; +import cz.neumimto.rpg.effects.IEffectContainer; +import cz.neumimto.rpg.players.IActiveCharacter; +import cz.neumimto.rpg.skills.*; + +/** + * Created by NeumimTo on 7.7.2017. + */ +@ResourceLoader.Skill +public class Dampen extends PassiveSkill { + + @Inject + private EffectService effectService; + + public Dampen() { + setName("Dampen"); + setLore(SkillLocalization.SKILL_DAMPEN_LORE); + setDescription(SkillLocalization.SKILL_DAMPEN_DESC); + SkillSettings skillSettings = new SkillSettings(); + skillSettings.addNode("min-mana", 310, -5); + super.settings = skillSettings; + } + + @Override + public void applyEffect(ExtendedSkillInfo info, IActiveCharacter character) { + double val = getDoubleNodeValue(info, "min-mana"); + DampenEffect eff = new DampenEffect(character, -1, val); + effectService.addEffect(eff, character, this); + } + + @Override + public void skillUpgrade(IActiveCharacter IActiveCharacter, int level) { + super.skillUpgrade(IActiveCharacter, level); + + double val = getDoubleNodeValue(IActiveCharacter.getSkill(getName()), "min-mana"); + IEffectContainer effect = IActiveCharacter.getEffect(DampenEffect.name); + effect.updateValue(val, this); + } +} diff --git a/Skills/src/main/java/cz/neumimto/skills/Dodge.java b/Skills/src/main/java/cz/neumimto/skills/passive/Dodge.java similarity index 85% rename from Skills/src/main/java/cz/neumimto/skills/Dodge.java rename to Skills/src/main/java/cz/neumimto/skills/passive/Dodge.java index ffe34569d..098e65aed 100644 --- a/Skills/src/main/java/cz/neumimto/skills/Dodge.java +++ b/Skills/src/main/java/cz/neumimto/skills/passive/Dodge.java @@ -1,4 +1,4 @@ -package cz.neumimto.skills; +package cz.neumimto.skills.passive; import cz.neumimto.SkillLocalization; import cz.neumimto.core.ioc.Inject; @@ -39,12 +39,6 @@ public void skillUpgrade(IActiveCharacter character, int level) { ExtendedSkillInfo info = character.getSkill(getName()); float chance = getFloatNodeValue(info, SkillNodes.CHANCE); IEffectContainer effect = character.getEffect(DodgeEffect.name); - for (DodgeEffect dodgeEffect : effect.getEffects()) { - if (dodgeEffect.getEffectSourceProvider() == this) { - dodgeEffect.setValue(chance); - break; - } - } - effect.updateStackedValue(); + effect.updateValue(chance, this); } } diff --git a/Skills/src/main/java/cz/neumimto/skills/passive/Drain.java b/Skills/src/main/java/cz/neumimto/skills/passive/Drain.java new file mode 100644 index 000000000..a7657ca66 --- /dev/null +++ b/Skills/src/main/java/cz/neumimto/skills/passive/Drain.java @@ -0,0 +1,49 @@ +package cz.neumimto.skills.passive; + +import cz.neumimto.SkillLocalization; +import cz.neumimto.core.ioc.Inject; +import cz.neumimto.effects.ManaDrainEffect; +import cz.neumimto.rpg.ResourceLoader; +import cz.neumimto.rpg.configuration.Localization; +import cz.neumimto.rpg.effects.EffectService; +import cz.neumimto.rpg.effects.IEffectContainer; +import cz.neumimto.rpg.players.IActiveCharacter; +import cz.neumimto.rpg.skills.ExtendedSkillInfo; +import cz.neumimto.rpg.skills.PassiveSkill; +import cz.neumimto.rpg.skills.SkillNodes; +import cz.neumimto.rpg.skills.SkillSettings; + +/** + * Created by NeumimTo on 7.7.2017. + */ +@ResourceLoader.Skill +public class Drain extends PassiveSkill { + + @Inject + private EffectService effectService; + + public Drain() { + setName("Drain"); + setLore(SkillLocalization.SKILL_DRAIN_LORE); + setDescription(SkillLocalization.SKILL_DRAIN_DESC); + SkillSettings settings = new SkillSettings(); + settings.addNode(SkillNodes.AMOUNT, 1, 1); + super.settings = settings; + } + + @Override + public void applyEffect(ExtendedSkillInfo info, IActiveCharacter character) { + float floatNodeValue = getFloatNodeValue(info, SkillNodes.AMOUNT); + ManaDrainEffect effect = new ManaDrainEffect(character, -1L, floatNodeValue); + effectService.addEffect(effect, character, this); + } + + @Override + public void skillUpgrade(IActiveCharacter IActiveCharacter, int level) { + super.skillUpgrade(IActiveCharacter, level); + ExtendedSkillInfo skill = IActiveCharacter.getSkill(getName()); + float floatNodeValue = getFloatNodeValue(skill, SkillNodes.AMOUNT); + IEffectContainer container = IActiveCharacter.getEffect(ManaDrainEffect.name); + container.updateValue(floatNodeValue, this); + } +} diff --git a/Skills/src/main/java/cz/neumimto/skills/ResoluteTechnique.java b/Skills/src/main/java/cz/neumimto/skills/passive/ResoluteTechnique.java similarity index 96% rename from Skills/src/main/java/cz/neumimto/skills/ResoluteTechnique.java rename to Skills/src/main/java/cz/neumimto/skills/passive/ResoluteTechnique.java index 6f7039d26..9ba259105 100644 --- a/Skills/src/main/java/cz/neumimto/skills/ResoluteTechnique.java +++ b/Skills/src/main/java/cz/neumimto/skills/passive/ResoluteTechnique.java @@ -1,4 +1,4 @@ -package cz.neumimto.skills; +package cz.neumimto.skills.passive; import cz.neumimto.SkillLocalization; import cz.neumimto.core.ioc.Inject; From c0b7a7a951a304d5e007dd910c841cb4161f6ac7 Mon Sep 17 00:00:00 2001 From: NeumimTo Date: Sun, 9 Jul 2017 14:38:35 +0200 Subject: [PATCH 7/9] improved user guis, added some particles --- .../rpg/configuration/Localization.java | 3 +- .../effects/common/def/ManaBarNotifier.java | 105 ++++++++++++++++++ .../common/stacking/ValueProcessor.java | 1 - .../main/java/cz/neumimto/rpg/gui/Gui.java | 6 + .../cz/neumimto/rpg/gui/IActionDecorator.java | 21 ++++ .../cz/neumimto/rpg/gui/IPlayerMessage.java | 4 + .../cz/neumimto/rpg/gui/VanilaMessaging.java | 24 ++-- .../rpg/inventory/CannotUseItemReson.java | 8 ++ .../rpg/inventory/InventoryService.java | 59 ++++++---- .../rpg/listeners/InventoryListener.java | 3 +- .../src/main/test/cz/neumimto/rpg/Tests.java | 4 +- .../src/main/java/cz/neumimto/Decorator.java | 35 ++++++ .../main/java/cz/neumimto/SkillListener.java | 81 ++++++++++++++ Skills/src/main/java/cz/neumimto/Utils.java | 7 -- .../effects/decoration/ParticleDecorator.java | 64 +++++++++++ .../effects/negative/MultiboltEffect.java | 10 +- .../effects/positive/AlchemyEffect.java | 19 ++++ .../effects/positive/PotionEffect.java | 36 ++++++ .../cz/neumimto/model/PotionEffectModel.java | 22 ++++ .../cz/neumimto/skills/active/Multibolt.java | 1 - .../skills/active/SkillLightning.java | 4 +- .../neumimto/skills/active/SkillMegabolt.java | 4 +- 22 files changed, 465 insertions(+), 56 deletions(-) create mode 100644 Plugin/src/main/java/cz/neumimto/rpg/effects/common/def/ManaBarNotifier.java create mode 100644 Plugin/src/main/java/cz/neumimto/rpg/gui/IActionDecorator.java create mode 100644 Plugin/src/main/java/cz/neumimto/rpg/inventory/CannotUseItemReson.java create mode 100644 Skills/src/main/java/cz/neumimto/Decorator.java delete mode 100644 Skills/src/main/java/cz/neumimto/Utils.java create mode 100644 Skills/src/main/java/cz/neumimto/effects/decoration/ParticleDecorator.java create mode 100644 Skills/src/main/java/cz/neumimto/effects/positive/AlchemyEffect.java create mode 100644 Skills/src/main/java/cz/neumimto/effects/positive/PotionEffect.java create mode 100644 Skills/src/main/java/cz/neumimto/model/PotionEffectModel.java diff --git a/Plugin/src/main/java/cz/neumimto/rpg/configuration/Localization.java b/Plugin/src/main/java/cz/neumimto/rpg/configuration/Localization.java index 4164a7f3a..77fd9eaeb 100644 --- a/Plugin/src/main/java/cz/neumimto/rpg/configuration/Localization.java +++ b/Plugin/src/main/java/cz/neumimto/rpg/configuration/Localization.java @@ -49,7 +49,7 @@ public class Localization { public static String WEAPON_EQUIPED = "You have equiped weapon %1"; @ConfigValue - public static String WEAPON_CANT_BE_EQUIPED = "You can't use %1"; + public static String WEAPON_CANT_BE_EQUIPED = "You are not trained to use %1"; @ConfigValue public static String CHARACTER_CREATION = ""; @@ -350,5 +350,4 @@ public class Localization { @ConfigValue public static String ITEM_DAMAGE = "Item damage"; - public static String SKILL_DRAIN_DESC; } diff --git a/Plugin/src/main/java/cz/neumimto/rpg/effects/common/def/ManaBarNotifier.java b/Plugin/src/main/java/cz/neumimto/rpg/effects/common/def/ManaBarNotifier.java new file mode 100644 index 000000000..22d7fbebf --- /dev/null +++ b/Plugin/src/main/java/cz/neumimto/rpg/effects/common/def/ManaBarNotifier.java @@ -0,0 +1,105 @@ +package cz.neumimto.rpg.effects.common.def; + +import cz.neumimto.rpg.effects.CoreEffectTypes; +import cz.neumimto.rpg.effects.EffectBase; +import cz.neumimto.rpg.effects.IEffectContainer; +import cz.neumimto.rpg.effects.IEffectSourceProvider; +import cz.neumimto.rpg.players.ExtendedNClass; +import cz.neumimto.rpg.players.IActiveCharacter; +import cz.neumimto.rpg.utils.Utils; +import org.spongepowered.api.boss.BossBarColors; +import org.spongepowered.api.boss.BossBarOverlays; +import org.spongepowered.api.boss.ServerBossBar; +import org.spongepowered.api.entity.living.player.Player; +import org.spongepowered.api.text.Text; + +import java.util.*; + +/** + * Created by NeumimTo on 9.7.2017. + */ +public class ManaBarNotifier extends EffectBase implements IEffectContainer { + + + public static final String name = "ManaBar"; + private IActiveCharacter character; + private Player player; + private ServerBossBar bossBar; + + + public ManaBarNotifier(IActiveCharacter consumer) { + super(name, consumer); + this.character = consumer; + this.player = consumer.getPlayer(); + effectTypes.add(CoreEffectTypes.GUI); + setPeriod(5000); + setDuration(-1); + } + + public void notifyManaChange() { + if (bossBar == null) { + bossBar = ServerBossBar.builder() + .visible(false) + .playEndBossMusic(false) + .darkenSky(false) + .name(Text.of("manabar")) + .overlay(BossBarOverlays.PROGRESS) + .color(BossBarColors.BLUE) + .createFog(false) + .percent(0) + .build(); + bossBar.addPlayer(player); + } + bossBar.setName(Text.of("Mana: " + "(" + character.getMana().getValue() + "/" + character.getMana().getMaxValue()+ ")")); + bossBar.setPercent((float) (Utils.getPercentage(character.getMana().getValue(),character.getMana().getMaxValue()) * 0.01f)); + bossBar.setVisible(true); + setLastTickTime(System.currentTimeMillis()); + + } + + @Override + public void onTick() { + if (bossBar.isVisible()) { + bossBar.setVisible(false); + } + + } + + @Override + public void onRemove() { + bossBar.removePlayer(player); + + } + + @Override + public void setDuration(long l) { + if (l >= 0) + throw new IllegalArgumentException(); + super.setDuration(l); + } + + @Override + public Set getEffects() { + return new HashSet<>(Collections.singletonList(this)); + } + + @Override + public ManaBarNotifier getStackedValue() { + return this; + } + + @Override + public ManaBarNotifier constructEffectContainer() { + return this; + } + + @Override + public void setStackedValue(Object o) { + + } + + @Override + public void stackEffect(ManaBarNotifier v, IEffectSourceProvider effectSourceProvider) { + + } +} diff --git a/Plugin/src/main/java/cz/neumimto/rpg/effects/common/stacking/ValueProcessor.java b/Plugin/src/main/java/cz/neumimto/rpg/effects/common/stacking/ValueProcessor.java index d3f986d5c..13ecff89a 100644 --- a/Plugin/src/main/java/cz/neumimto/rpg/effects/common/stacking/ValueProcessor.java +++ b/Plugin/src/main/java/cz/neumimto/rpg/effects/common/stacking/ValueProcessor.java @@ -43,7 +43,6 @@ public L_MAX(IEffect floatIEffect) { public Long findValue() { return getEffects().stream().mapToLong(IEffect::getValue).max().orElse(0L); } - } public static class D_MIN extends ValueProcessor> { diff --git a/Plugin/src/main/java/cz/neumimto/rpg/gui/Gui.java b/Plugin/src/main/java/cz/neumimto/rpg/gui/Gui.java index 5306bf6c0..c16983fd8 100644 --- a/Plugin/src/main/java/cz/neumimto/rpg/gui/Gui.java +++ b/Plugin/src/main/java/cz/neumimto/rpg/gui/Gui.java @@ -21,6 +21,7 @@ import cz.neumimto.core.ioc.IoC; import cz.neumimto.rpg.effects.EffectStatusType; import cz.neumimto.rpg.effects.IEffect; +import cz.neumimto.rpg.inventory.CannotUseItemReson; import cz.neumimto.rpg.inventory.runewords.RuneWord; import cz.neumimto.rpg.players.CharacterBase; import cz.neumimto.rpg.players.ExtendedNClass; @@ -31,6 +32,7 @@ import cz.neumimto.rpg.skills.SkillData; import cz.neumimto.rpg.skills.SkillTree; import org.spongepowered.api.entity.living.player.Player; +import org.spongepowered.api.item.inventory.ItemStack; import java.util.List; import java.util.Map; @@ -173,4 +175,8 @@ public static void displayHealth(IActiveCharacter character) { public static void displayMana(IActiveCharacter character) { getMessageTypeOf(character).displayMana(character); } + + public static void sendCannotUseItemNotification(IActiveCharacter character, ItemStack is, CannotUseItemReson reason) { + getMessageTypeOf(character).sendCannotUseItemNotification(character, is, reason); + } } diff --git a/Plugin/src/main/java/cz/neumimto/rpg/gui/IActionDecorator.java b/Plugin/src/main/java/cz/neumimto/rpg/gui/IActionDecorator.java new file mode 100644 index 000000000..d65bfbd8b --- /dev/null +++ b/Plugin/src/main/java/cz/neumimto/rpg/gui/IActionDecorator.java @@ -0,0 +1,21 @@ +package cz.neumimto.rpg.gui; + +import org.spongepowered.api.entity.Entity; +import org.spongepowered.api.scheduler.Task; +import org.spongepowered.api.world.Location; +import org.spongepowered.api.world.World; + +import java.util.function.BiConsumer; + +/** + * Created by NeumimTo on 9.7.2017. + */ +public interface IActionDecorator { + + void strikeLightning(Location location); + + void createTrajectory(Entity entity, int interval, int maxticks, BiConsumer e); + + + +} diff --git a/Plugin/src/main/java/cz/neumimto/rpg/gui/IPlayerMessage.java b/Plugin/src/main/java/cz/neumimto/rpg/gui/IPlayerMessage.java index 672d16770..f4cfdbf63 100644 --- a/Plugin/src/main/java/cz/neumimto/rpg/gui/IPlayerMessage.java +++ b/Plugin/src/main/java/cz/neumimto/rpg/gui/IPlayerMessage.java @@ -20,6 +20,7 @@ import cz.neumimto.rpg.effects.EffectStatusType; import cz.neumimto.rpg.effects.IEffect; +import cz.neumimto.rpg.inventory.CannotUseItemReson; import cz.neumimto.rpg.inventory.runewords.RuneWord; import cz.neumimto.rpg.players.CharacterBase; import cz.neumimto.rpg.players.ExtendedNClass; @@ -30,6 +31,7 @@ import cz.neumimto.rpg.skills.SkillData; import cz.neumimto.rpg.skills.SkillTree; import org.spongepowered.api.entity.living.player.Player; +import org.spongepowered.api.item.inventory.ItemStack; import java.util.List; import java.util.Map; @@ -97,4 +99,6 @@ public interface IPlayerMessage { void displayHealth(IActiveCharacter character); void displayMana(IActiveCharacter character); + + void sendCannotUseItemNotification(IActiveCharacter character, ItemStack is, CannotUseItemReson reason); } diff --git a/Plugin/src/main/java/cz/neumimto/rpg/gui/VanilaMessaging.java b/Plugin/src/main/java/cz/neumimto/rpg/gui/VanilaMessaging.java index 0299afe62..4c48dd479 100644 --- a/Plugin/src/main/java/cz/neumimto/rpg/gui/VanilaMessaging.java +++ b/Plugin/src/main/java/cz/neumimto/rpg/gui/VanilaMessaging.java @@ -31,6 +31,8 @@ import cz.neumimto.rpg.configuration.PluginConfig; import cz.neumimto.rpg.effects.*; import cz.neumimto.rpg.effects.common.def.BossBarExpNotifier; +import cz.neumimto.rpg.effects.common.def.ManaBarNotifier; +import cz.neumimto.rpg.inventory.CannotUseItemReson; import cz.neumimto.rpg.inventory.data.InventoryCommandItemMenuData; import cz.neumimto.rpg.inventory.data.MenuInventoryData; import cz.neumimto.rpg.inventory.data.NKeys; @@ -703,17 +705,19 @@ public void displayHealth(IActiveCharacter character) { @Override public void displayMana(IActiveCharacter character) { - double value = character.getMana().getValue(); - double maxValue = character.getMana().getMaxValue(); - double reservedAmount = character.getMana().getReservedAmount(); - + IEffectContainer barExpNotifier = character.getEffect(ManaBarNotifier.name); + ManaBarNotifier effect = (ManaBarNotifier) barExpNotifier; + if (effect == null) { + effect = new ManaBarNotifier(character); + effectService.addEffect(effect, character, InternalEffectSourceProvider.INSTANCE); + } + effect.notifyManaChange(); + } - LiteralText a = Text.builder(Localization.MANA + " ").color(TextColors.GOLD) - .append(Text.builder(value + "").color(TextColors.BLUE).build()) - .append(Text.builder("/").color(TextColors.WHITE).build()) - .append(Text.builder(String.valueOf(maxValue - reservedAmount)).color(TextColors.DARK_BLUE).build()) - .append(Text.builder(" (" + maxValue + ") ").color(TextColors.GRAY).build()).build(); - character.getPlayer().sendMessage(a); + @Override + public void sendCannotUseItemNotification(IActiveCharacter character, ItemStack is, CannotUseItemReson reason) { + if (reason == CannotUseItemReson.CONFIG) + character.getPlayer().sendMessage(Text.of()); } } diff --git a/Plugin/src/main/java/cz/neumimto/rpg/inventory/CannotUseItemReson.java b/Plugin/src/main/java/cz/neumimto/rpg/inventory/CannotUseItemReson.java new file mode 100644 index 000000000..dbea6e141 --- /dev/null +++ b/Plugin/src/main/java/cz/neumimto/rpg/inventory/CannotUseItemReson.java @@ -0,0 +1,8 @@ +package cz.neumimto.rpg.inventory; + +/** + * Created by NeumimTo on 9.7.2017. + */ +public enum CannotUseItemReson { + LEVEL, CONFIG, OK, LORE +} diff --git a/Plugin/src/main/java/cz/neumimto/rpg/inventory/InventoryService.java b/Plugin/src/main/java/cz/neumimto/rpg/inventory/InventoryService.java index 11f8eccba..f9f155d29 100644 --- a/Plugin/src/main/java/cz/neumimto/rpg/inventory/InventoryService.java +++ b/Plugin/src/main/java/cz/neumimto/rpg/inventory/InventoryService.java @@ -195,9 +195,10 @@ public void initializeHotbar(IActiveCharacter character, int slot, ItemStack toP if (hotbarObject != HotbarObject.EMPTYHAND_OR_CONSUMABLE) { hotbarObject.setSlot(slot); character.getHotbar()[slot] = hotbarObject; - if (!canUse(i, character)) { + CannotUseItemReson reason = canWear(i, character); + if (reason != CannotUseItemReson.OK) { ItemStack itemStack = s.poll().get(); - ItemStackUtils.dropItem(character.getPlayer(), itemStack); + dropItem(character, itemStack, reason); character.getHotbar()[slot] = HotbarObject.EMPTYHAND_OR_CONSUMABLE; return; } @@ -276,9 +277,10 @@ public void initializeArmor(IActiveCharacter character) { ItemStack is = null; if (chestplate.isPresent()) { is = chestplate.get(); - if (!canWear(is, character)) { + CannotUseItemReson reason = canWear(is, character); + if (reason != CannotUseItemReson.OK) { character.getPlayer().setChestplate(null); - ItemStackUtils.dropItem(character.getPlayer(), is); + dropItem(character, is, reason); } else { Armor armor = getChestplate(character); @@ -296,9 +298,10 @@ public void initializeArmor(IActiveCharacter character) { Optional helmet = character.getPlayer().getHelmet(); if (helmet.isPresent()) { is = helmet.get(); - if (!canWear(is, character)) { + CannotUseItemReson reason = canWear(is, character); + if (reason != CannotUseItemReson.OK) { character.getPlayer().setHelmet(null); - ItemStackUtils.dropItem(character.getPlayer(), is); + dropItem(character, is, reason); } else { Armor armor = getHelmet(character); @@ -315,9 +318,10 @@ public void initializeArmor(IActiveCharacter character) { Optional boots = character.getPlayer().getBoots(); if (boots.isPresent()) { is = boots.get(); - if (!canWear(is, character)) { + CannotUseItemReson reason = canWear(is, character); + if (reason != CannotUseItemReson.OK) { character.getPlayer().setBoots(null); - ItemStackUtils.dropItem(character.getPlayer(), is); + dropItem(character, is, reason); } else { Armor armor = getBoots(character); Armor armor1 = character.getEquipedArmor().get(EquipmentTypes.BOOTS); @@ -331,9 +335,11 @@ public void initializeArmor(IActiveCharacter character) { Optional leggings = character.getPlayer().getLeggings(); if (leggings.isPresent()) { is = leggings.get(); - if (!canWear(is, character)) { + CannotUseItemReson reason = canWear(is, character); + if (reason != CannotUseItemReson.OK) { character.getPlayer().setLeggings(null); - ItemStackUtils.dropItem(character.getPlayer(), is); + + dropItem(character, is, reason); } else { Armor armor = getLeggings(character); @@ -347,6 +353,12 @@ public void initializeArmor(IActiveCharacter character) { } } + + private void dropItem(IActiveCharacter character, ItemStack is, CannotUseItemReson reason) { + ItemStackUtils.dropItem(character.getPlayer(), is); + Gui.sendCannotUseItemNotification(character, is, reason); + } + protected HotbarObject getHotbarObject(IActiveCharacter character, ItemStack is) { if (is == null) return HotbarObject.EMPTYHAND_OR_CONSUMABLE; @@ -567,10 +579,10 @@ public void reinitializePlayerInventory(IActiveCharacter character) { } - public boolean canWear(ItemStack itemStack, IActiveCharacter character) { + public CannotUseItemReson canWear(ItemStack itemStack, IActiveCharacter character) { if (ItemStackUtils.any_armor.contains(itemStack.getItem())) { if (!character.canWear(itemStack)) { - return false; + return CannotUseItemReson.CONFIG; } } CustomItemData itemData = getItemData(itemStack); @@ -578,25 +590,21 @@ public boolean canWear(ItemStack itemStack, IActiveCharacter character) { } - public boolean canUse(ItemStack itemStack, IActiveCharacter character) { + public CannotUseItemReson canUse(ItemStack itemStack, IActiveCharacter character) { if (ItemStackUtils.weapons.contains(itemStack.getItem())) { if (!character.canUse(itemStack.getItem())) { - return false; + return CannotUseItemReson.CONFIG; } } return checkRestrictions(character, getItemData(itemStack)); } - private boolean checkRestrictions(IActiveCharacter character, CustomItemData itemData) { + private CannotUseItemReson checkRestrictions(IActiveCharacter character, CustomItemData itemData) { ListValue strings = itemData.groupRestricitons(); if (strings.isEmpty()) - return true; + return CannotUseItemReson.OK; int k = 0; - if (character.getPrimaryClass().getLevel() < itemData.itemLevel().get()) { - return false; - } - for (String string : strings) { if (string.contains(character.getRace().getName())) { k++; @@ -609,7 +617,16 @@ private boolean checkRestrictions(IActiveCharacter character, CustomItemData ite } } } - return strings.size() == k; + + if (strings.size() == k) { + if (character.getPrimaryClass().getLevel() < itemData.itemLevel().get()) { + return CannotUseItemReson.OK; + } else { + return CannotUseItemReson.LEVEL; + } + } else { + return CannotUseItemReson.LORE; + } } diff --git a/Plugin/src/main/java/cz/neumimto/rpg/listeners/InventoryListener.java b/Plugin/src/main/java/cz/neumimto/rpg/listeners/InventoryListener.java index ffe495597..6034b0c88 100644 --- a/Plugin/src/main/java/cz/neumimto/rpg/listeners/InventoryListener.java +++ b/Plugin/src/main/java/cz/neumimto/rpg/listeners/InventoryListener.java @@ -21,6 +21,7 @@ import cz.neumimto.core.ioc.Inject; import cz.neumimto.rpg.ResourceLoader; import cz.neumimto.rpg.damage.DamageService; +import cz.neumimto.rpg.inventory.CannotUseItemReson; import cz.neumimto.rpg.inventory.HotbarObject; import cz.neumimto.rpg.inventory.InventoryService; import cz.neumimto.rpg.players.CharacterService; @@ -108,7 +109,7 @@ public void onItemPickup(ChangeInventoryEvent.Pickup event, @First(typeFilter = int index = ((SlotAdapter)i).getOrdinal(); if (Utils.isHotbar(index)) { ItemStack a = slotTransaction.getFinal().createStack(); - if (!inventoryService.canUse(a, character)) { + if (inventoryService.canUse(a, character) != CannotUseItemReson.OK) { event.setCancelled(true); return; } else { diff --git a/Plugin/src/main/test/cz/neumimto/rpg/Tests.java b/Plugin/src/main/test/cz/neumimto/rpg/Tests.java index fc0b40974..823245a1d 100644 --- a/Plugin/src/main/test/cz/neumimto/rpg/Tests.java +++ b/Plugin/src/main/test/cz/neumimto/rpg/Tests.java @@ -3,6 +3,7 @@ import cz.neumimto.rpg.effects.IGlobalEffect; import cz.neumimto.rpg.effects.common.positive.SpeedBoost; +import cz.neumimto.rpg.effects.common.stacking.ValueProcessor; import cz.neumimto.rpg.persistance.GroupDao; import cz.neumimto.rpg.skills.SkillService; import cz.neumimto.rpg.skills.SkillTree; @@ -55,7 +56,7 @@ public void testConfig() throws NoSuchFieldException, IllegalAccessException { } - @Test + // @Test public void testEffectClassGenerator() { ClassGenerator classGenerator = new ClassGenerator(); IGlobalEffect eff = null; @@ -86,4 +87,5 @@ public void testDynamicListener() throws Exception { e.printStackTrace(); } } + } diff --git a/Skills/src/main/java/cz/neumimto/Decorator.java b/Skills/src/main/java/cz/neumimto/Decorator.java new file mode 100644 index 000000000..60048a3b3 --- /dev/null +++ b/Skills/src/main/java/cz/neumimto/Decorator.java @@ -0,0 +1,35 @@ +package cz.neumimto; + +import cz.neumimto.core.ioc.IoC; +import cz.neumimto.effects.decoration.ParticleDecorator; +import org.spongepowered.api.entity.Entity; +import org.spongepowered.api.scheduler.Task; +import org.spongepowered.api.world.Location; +import org.spongepowered.api.world.World; + +import java.util.function.BiConsumer; + +/** + * Created by NeumimTo on 6.2.2016. + */ + +public class Decorator { + + public static ParticleDecorator decorator; + + static { + decorator = IoC.get().build(ParticleDecorator.class); + } + + public static void strikeLightning(Entity entity) { + strikeLightning(entity.getLocation()); + } + + public static void strikeLightning(Location location) { + decorator.strikeLightning(location); + } + + public static void createTrajectory(Entity entity, int interval, int maxticks, BiConsumer e) { + decorator.createTrajectory(entity, interval, maxticks, e); + } +} diff --git a/Skills/src/main/java/cz/neumimto/SkillListener.java b/Skills/src/main/java/cz/neumimto/SkillListener.java index 0fe93bc7c..10011460a 100644 --- a/Skills/src/main/java/cz/neumimto/SkillListener.java +++ b/Skills/src/main/java/cz/neumimto/SkillListener.java @@ -3,6 +3,7 @@ import cz.neumimto.core.ioc.Inject; import cz.neumimto.effects.ManaDrainEffect; import cz.neumimto.effects.ResoluteTechniqueEffect; +import cz.neumimto.effects.decoration.ParticleDecorator; import cz.neumimto.effects.negative.StunEffect; import cz.neumimto.effects.positive.*; import cz.neumimto.events.CriticalStrikeEvent; @@ -11,6 +12,7 @@ import cz.neumimto.events.StunApplyEvent; import cz.neumimto.model.BashModel; import cz.neumimto.model.CriticalEffectModel; +import cz.neumimto.model.PotionEffectModel; import cz.neumimto.rpg.IEntityType; import cz.neumimto.rpg.ResourceLoader; import cz.neumimto.rpg.effects.EffectService; @@ -27,14 +29,35 @@ import cz.neumimto.rpg.players.properties.PropertyService; import cz.neumimto.rpg.utils.XORShiftRnd; import org.spongepowered.api.Game; +import org.spongepowered.api.block.BlockTypes; +import org.spongepowered.api.data.key.Keys; +import org.spongepowered.api.data.type.HandTypes; +import org.spongepowered.api.effect.particle.ParticleEffect; +import org.spongepowered.api.effect.particle.ParticleTypes; +import org.spongepowered.api.effect.potion.PotionEffectType; +import org.spongepowered.api.entity.Entity; import org.spongepowered.api.entity.living.player.Player; import org.spongepowered.api.event.Listener; import org.spongepowered.api.event.Order; +import org.spongepowered.api.event.action.InteractEvent; +import org.spongepowered.api.event.block.InteractBlockEvent; import org.spongepowered.api.event.entity.DestructEntityEvent; +import org.spongepowered.api.event.entity.InteractEntityEvent; +import org.spongepowered.api.event.entity.projectile.LaunchProjectileEvent; import org.spongepowered.api.event.filter.IsCancelled; +import org.spongepowered.api.event.filter.cause.First; +import org.spongepowered.api.event.filter.cause.Root; +import org.spongepowered.api.event.filter.type.Include; +import org.spongepowered.api.event.item.inventory.InteractItemEvent; +import org.spongepowered.api.event.item.inventory.UseItemStackEvent; +import org.spongepowered.api.item.ItemTypes; +import org.spongepowered.api.item.inventory.ItemStack; +import org.spongepowered.api.scheduler.Task; import org.spongepowered.api.util.Tristate; import java.util.Optional; +import java.util.function.BiConsumer; +import java.util.function.Consumer; /** * Created by ja on 21.5.2016. @@ -197,4 +220,62 @@ public void onManaDrain(ManaDrainEvent mde) { double k = mana.getValue() - mde.getAmountDrained() <= 0 ? 0 : mana.getValue() - mde.getAmountDrained(); mana.setValue(k); } + + @Listener(order = Order.FIRST) + public void onItemConsume(UseItemStackEvent.Start event, @Root(typeFilter = Player.class) Player player) { + Optional itemInHand = player.getItemInHand(HandTypes.MAIN_HAND); + processConsumption(player, itemInHand, (e, l) -> { + if (l.cooldowns.containsKey(e)) { + if (l.cooldowns.get(e) <= System.currentTimeMillis()) + event.setCancelled(true); + } + }); + } + + private void processConsumption(Player player, Optional itemInHand, BiConsumer l) { + if (itemInHand.isPresent()) { + ItemStack itemStack = itemInHand.get(); + if (itemStack.getItem() == ItemTypes.POTION + || itemStack.getItem() == ItemTypes.SPLASH_POTION + || itemStack.getItem() == ItemTypes.LINGERING_POTION) { + IActiveCharacter character = characterService.getCharacter(player); + if (character.hasEffect(PotionEffect.name)) { + PotionEffect effect = (PotionEffect) character.getEffect(PotionEffect.name); + l.accept(null, effect.getValue()); + } + } + } + } + + @Listener(order = Order.LATE) + public void onItemConsumerFinish(UseItemStackEvent.Finish event, @Root(typeFilter = Player.class) Player player) { + Optional itemInHand = player.getItemInHand(HandTypes.MAIN_HAND); + processConsumption(player, itemInHand, (e, l) -> { + long k = System.currentTimeMillis(); + l.cooldowns.put(e, l.potions.get(e) + k); + }); + } + + @Listener + public void onBlockInteract(InteractBlockEvent event, @First(typeFilter = Player.class) Player player) { + if (event.getTargetBlock().getState().getType() == BlockTypes.BREWING_STAND) { + IActiveCharacter character = characterService.getCharacter(player); + if (!character.hasEffect(AlchemyEffect.name)) { + event.setCancelled(true); + } + } + } + + @Listener + public void onArrowFire(LaunchProjectileEvent event, @First(typeFilter = Entity.class) Entity e ){ + + Decorator.createTrajectory( + event.getTargetEntity(), + 1, + 1, + new ParticleDecorator.SIMPLE_TRAJECTORY( + ParticleEffect.builder() + .quantity(5).type(ParticleTypes.AMBIENT_MOB_SPELL).build())); + } + } diff --git a/Skills/src/main/java/cz/neumimto/Utils.java b/Skills/src/main/java/cz/neumimto/Utils.java deleted file mode 100644 index ce24c9ea8..000000000 --- a/Skills/src/main/java/cz/neumimto/Utils.java +++ /dev/null @@ -1,7 +0,0 @@ -package cz.neumimto; - -/** - * Created by NeumimTo on 6.2.2016. - */ -public class Utils { -} diff --git a/Skills/src/main/java/cz/neumimto/effects/decoration/ParticleDecorator.java b/Skills/src/main/java/cz/neumimto/effects/decoration/ParticleDecorator.java new file mode 100644 index 000000000..87db73643 --- /dev/null +++ b/Skills/src/main/java/cz/neumimto/effects/decoration/ParticleDecorator.java @@ -0,0 +1,64 @@ +package cz.neumimto.effects.decoration; + +import cz.neumimto.Decorator; +import cz.neumimto.core.ioc.Inject; +import cz.neumimto.core.ioc.Singleton; +import cz.neumimto.rpg.NtRpgPlugin; +import cz.neumimto.rpg.gui.IActionDecorator; +import org.spongepowered.api.Sponge; +import org.spongepowered.api.effect.particle.ParticleEffect; +import org.spongepowered.api.entity.Entity; +import org.spongepowered.api.entity.EntityTypes; +import org.spongepowered.api.event.cause.Cause; +import org.spongepowered.api.event.cause.entity.spawn.SpawnCause; +import org.spongepowered.api.event.cause.entity.spawn.SpawnTypes; +import org.spongepowered.api.scheduler.Task; +import org.spongepowered.api.world.Location; +import org.spongepowered.api.world.World; + +import java.util.concurrent.TimeUnit; +import java.util.function.BiConsumer; + +/** + * Created by NeumimTo on 9.7.2017. + */ +@Singleton +public class ParticleDecorator implements IActionDecorator { + + @Inject + private NtRpgPlugin plugin; + + @Override + public void strikeLightning(Location location) { + Entity q = location.getExtent().createEntity(EntityTypes.LIGHTNING, location.getPosition()); + location.getExtent().spawnEntity(q, Cause.source(SpawnCause.builder().type(SpawnTypes.PLUGIN).build()).build()); + } + + @Override + public void createTrajectory(Entity entity, int interval, int maxticks, BiConsumer e) { + Sponge.getScheduler() + .createTaskBuilder() + .delay(1L, TimeUnit.MILLISECONDS) + .interval(interval, TimeUnit.MILLISECONDS) + .execute((task -> { + if (!entity.isRemoved()) { + e.accept(task, entity); + } + })).submit(plugin); + } + + public static class SIMPLE_TRAJECTORY implements BiConsumer { + + private ParticleEffect eff; + + public SIMPLE_TRAJECTORY(ParticleEffect eff) { + this.eff = eff; + } + + @Override + public void accept(Task task, Entity entity) { + entity.getWorld().spawnParticles(eff, entity.getLocation().getPosition()); + } + } + +} diff --git a/Skills/src/main/java/cz/neumimto/effects/negative/MultiboltEffect.java b/Skills/src/main/java/cz/neumimto/effects/negative/MultiboltEffect.java index 180e1f0d8..28f11e61c 100644 --- a/Skills/src/main/java/cz/neumimto/effects/negative/MultiboltEffect.java +++ b/Skills/src/main/java/cz/neumimto/effects/negative/MultiboltEffect.java @@ -1,18 +1,13 @@ package cz.neumimto.effects.negative; +import cz.neumimto.Decorator; import cz.neumimto.model.MultiboltModel; -import cz.neumimto.rpg.ClassGenerator; import cz.neumimto.rpg.IEntity; import cz.neumimto.rpg.damage.SkillDamageSourceBuilder; import cz.neumimto.rpg.effects.EffectBase; import cz.neumimto.rpg.effects.IEffectConsumer; import cz.neumimto.rpg.skills.NDamageType; -import org.spongepowered.api.entity.Entity; -import org.spongepowered.api.entity.EntityTypes; import org.spongepowered.api.entity.living.Living; -import org.spongepowered.api.event.cause.Cause; -import org.spongepowered.api.event.cause.entity.spawn.SpawnCause; -import org.spongepowered.api.event.cause.entity.spawn.SpawnTypes; /** * Created by NeumimTo on 6.7.2017. @@ -53,8 +48,7 @@ public void damage() { build.setCaster(source); build.type(NDamageType.LIGHTNING); entity.damage(model.damage, build.build()); - Entity q = entity.getLocation().getExtent().createEntity(EntityTypes.LIGHTNING, entity.getLocation().getPosition()); - entity.getLocation().getExtent().spawnEntity(q, Cause.source(SpawnCause.builder().type(SpawnTypes.PLUGIN).build()).build()); + Decorator.strikeLightning(entity); model.timesToHit--; } } diff --git a/Skills/src/main/java/cz/neumimto/effects/positive/AlchemyEffect.java b/Skills/src/main/java/cz/neumimto/effects/positive/AlchemyEffect.java new file mode 100644 index 000000000..17bc3517a --- /dev/null +++ b/Skills/src/main/java/cz/neumimto/effects/positive/AlchemyEffect.java @@ -0,0 +1,19 @@ +package cz.neumimto.effects.positive; + +import cz.neumimto.rpg.ClassGenerator; +import cz.neumimto.rpg.effects.EffectBase; +import cz.neumimto.rpg.effects.IEffectConsumer; + +/** + * Created by NeumimTo on 9.7.2017. + */ +@ClassGenerator.Generate(id = "name") +public class AlchemyEffect extends EffectBase { + + public static final String name = "Alchemy"; + + public AlchemyEffect(IEffectConsumer consumer, long duration, String value) { + super(name, consumer); + setDuration(duration); + } +} diff --git a/Skills/src/main/java/cz/neumimto/effects/positive/PotionEffect.java b/Skills/src/main/java/cz/neumimto/effects/positive/PotionEffect.java new file mode 100644 index 000000000..d71854dda --- /dev/null +++ b/Skills/src/main/java/cz/neumimto/effects/positive/PotionEffect.java @@ -0,0 +1,36 @@ +package cz.neumimto.effects.positive; + +import cz.neumimto.model.PotionEffectModel; +import cz.neumimto.rpg.effects.*; + +/** + * Created by NeumimTo on 9.7.2017. + */ +public class PotionEffect extends EffectBase { + public static final String name = "Potion"; + + public PotionEffect(IEffectConsumer consumer, long duration, PotionEffectModel model) { + super(name, consumer); + setDuration(duration); + setValue(model); + setStackable(true, null); + } + + + @Override + public IEffectContainer constructEffectContainer() { + return new EffectContainer(this) { + @Override + public void updateStackedValue() { + setStackedValue(null); + for (PotionEffect potionEffect : getEffects()) { + if (getStackedValue() == null) { + setStackedValue(potionEffect.getValue()); + } else { + getStackedValue().mergeWith(potionEffect.getValue()); + } + } + } + }; + } +} diff --git a/Skills/src/main/java/cz/neumimto/model/PotionEffectModel.java b/Skills/src/main/java/cz/neumimto/model/PotionEffectModel.java new file mode 100644 index 000000000..31f9a7e9b --- /dev/null +++ b/Skills/src/main/java/cz/neumimto/model/PotionEffectModel.java @@ -0,0 +1,22 @@ +package cz.neumimto.model; + +import org.spongepowered.api.effect.potion.PotionEffectType; + +import java.util.HashMap; +import java.util.Map; + +/** + * Created by NeumimTo on 9.7.2017. + */ +public class PotionEffectModel { + public Map potions; + public Map cooldowns; + public PotionEffectModel() { + this.potions = new HashMap<>(); + cooldowns = new HashMap<>(); + } + + public void mergeWith(PotionEffectModel that) { + that.potions.forEach((k, v) -> potions.merge(k, v, Long::min)); + } +} diff --git a/Skills/src/main/java/cz/neumimto/skills/active/Multibolt.java b/Skills/src/main/java/cz/neumimto/skills/active/Multibolt.java index 309923355..b72bbd1bc 100644 --- a/Skills/src/main/java/cz/neumimto/skills/active/Multibolt.java +++ b/Skills/src/main/java/cz/neumimto/skills/active/Multibolt.java @@ -32,7 +32,6 @@ public class Multibolt extends Targetted { private EffectService effectService; public Multibolt() { - super(); setName("Multibolt"); setLore(SkillLocalization.SKILL_MULTIBOLT_LORE); setDescription(SkillLocalization.SKILL_MULTIBOLT_DESC); diff --git a/Skills/src/main/java/cz/neumimto/skills/active/SkillLightning.java b/Skills/src/main/java/cz/neumimto/skills/active/SkillLightning.java index 2ee6b39a6..65a3b54e9 100644 --- a/Skills/src/main/java/cz/neumimto/skills/active/SkillLightning.java +++ b/Skills/src/main/java/cz/neumimto/skills/active/SkillLightning.java @@ -1,5 +1,6 @@ package cz.neumimto.skills.active; +import cz.neumimto.Decorator; import cz.neumimto.SkillLocalization; import cz.neumimto.core.ioc.Inject; import cz.neumimto.rpg.IEntity; @@ -43,8 +44,7 @@ public SkillResult castOn(Living target, IActiveCharacter source, ExtendedSkillI build.fromSkill(this); build.setCaster(source); target.damage(damage, build.build()); - Entity q = target.getLocation().getExtent().createEntity(EntityTypes.LIGHTNING, target.getLocation().getPosition()); - target.getLocation().getExtent().spawnEntity(q, Cause.source(SpawnCause.builder().type(SpawnTypes.PLUGIN).build()).build()); + Decorator.strikeLightning(target); return SkillResult.OK; } } diff --git a/Skills/src/main/java/cz/neumimto/skills/active/SkillMegabolt.java b/Skills/src/main/java/cz/neumimto/skills/active/SkillMegabolt.java index 0611cdc04..8956f295a 100644 --- a/Skills/src/main/java/cz/neumimto/skills/active/SkillMegabolt.java +++ b/Skills/src/main/java/cz/neumimto/skills/active/SkillMegabolt.java @@ -1,5 +1,6 @@ package cz.neumimto.skills.active; +import cz.neumimto.Decorator; import cz.neumimto.rpg.ResourceLoader; import cz.neumimto.rpg.damage.SkillDamageSource; import cz.neumimto.rpg.damage.SkillDamageSourceBuilder; @@ -45,8 +46,7 @@ public SkillResult cast(IActiveCharacter iActiveCharacter, ExtendedSkillInfo ext Living l = (Living) e; if (Utils.canDamage(iActiveCharacter, l)) { l.damage(damage,src); - Entity li = l.getLocation().getExtent().createEntity(EntityTypes.LIGHTNING, l.getLocation().getPosition()); - l.getLocation().getExtent().spawnEntity(li, Cause.source(SpawnCause.builder().type(SpawnTypes.PLUGIN).build()).build()); + Decorator.strikeLightning(l); } } } From 1bbb0805038ac8b35a676245c09d86f6aae7b246 Mon Sep 17 00:00:00 2001 From: NeumimTo Date: Sun, 9 Jul 2017 16:03:53 +0200 Subject: [PATCH 8/9] cancel the task --- .../java/cz/neumimto/rpg/gui/VanilaMessaging.java | 2 ++ Skills/src/main/java/cz/neumimto/SkillListener.java | 12 ------------ .../effects/decoration/ParticleDecorator.java | 12 +++++++----- 3 files changed, 9 insertions(+), 17 deletions(-) diff --git a/Plugin/src/main/java/cz/neumimto/rpg/gui/VanilaMessaging.java b/Plugin/src/main/java/cz/neumimto/rpg/gui/VanilaMessaging.java index 4c48dd479..7364f3f2a 100644 --- a/Plugin/src/main/java/cz/neumimto/rpg/gui/VanilaMessaging.java +++ b/Plugin/src/main/java/cz/neumimto/rpg/gui/VanilaMessaging.java @@ -56,6 +56,8 @@ import org.spongepowered.api.Game; import org.spongepowered.api.Sponge; import org.spongepowered.api.data.key.Keys; +import org.spongepowered.api.entity.ArmorEquipable; +import org.spongepowered.api.entity.living.monster.ZombiePigman; import org.spongepowered.api.entity.living.player.Player; import org.spongepowered.api.event.Listener; import org.spongepowered.api.event.cause.Cause; diff --git a/Skills/src/main/java/cz/neumimto/SkillListener.java b/Skills/src/main/java/cz/neumimto/SkillListener.java index 10011460a..4e17762a0 100644 --- a/Skills/src/main/java/cz/neumimto/SkillListener.java +++ b/Skills/src/main/java/cz/neumimto/SkillListener.java @@ -266,16 +266,4 @@ public void onBlockInteract(InteractBlockEvent event, @First(typeFilter = Player } } - @Listener - public void onArrowFire(LaunchProjectileEvent event, @First(typeFilter = Entity.class) Entity e ){ - - Decorator.createTrajectory( - event.getTargetEntity(), - 1, - 1, - new ParticleDecorator.SIMPLE_TRAJECTORY( - ParticleEffect.builder() - .quantity(5).type(ParticleTypes.AMBIENT_MOB_SPELL).build())); - } - } diff --git a/Skills/src/main/java/cz/neumimto/effects/decoration/ParticleDecorator.java b/Skills/src/main/java/cz/neumimto/effects/decoration/ParticleDecorator.java index 87db73643..9920a1344 100644 --- a/Skills/src/main/java/cz/neumimto/effects/decoration/ParticleDecorator.java +++ b/Skills/src/main/java/cz/neumimto/effects/decoration/ParticleDecorator.java @@ -36,15 +36,17 @@ public void strikeLightning(Location location) { @Override public void createTrajectory(Entity entity, int interval, int maxticks, BiConsumer e) { - Sponge.getScheduler() + Task submit = Sponge.getScheduler() .createTaskBuilder() .delay(1L, TimeUnit.MILLISECONDS) .interval(interval, TimeUnit.MILLISECONDS) .execute((task -> { - if (!entity.isRemoved()) { - e.accept(task, entity); - } - })).submit(plugin); + if (!entity.isRemoved()) { + e.accept(task, entity); + } else { + task.cancel(); + } + })).submit(plugin); } public static class SIMPLE_TRAJECTORY implements BiConsumer { From d5869a694eb2726cb5a0f4811780dcf11210a287 Mon Sep 17 00:00:00 2001 From: NeumimTo Date: Sat, 15 Jul 2017 20:43:34 +0200 Subject: [PATCH 9/9] some improvements, and a new skill --- .../cz/neumimto/rpg/effects/EffectBase.java | 4 +- .../java/cz/neumimto/rpg/effects/IEffect.java | 2 +- .../cz/neumimto/rpg/gui/IActionDecorator.java | 5 +- .../cz/neumimto/rpg/skills/AbstractSkill.java | 3 +- .../java/cz/neumimto/rpg/skills/ISkill.java | 4 + .../java/cz/neumimto/rpg/utils/Utils.java | 34 +++++-- .../src/main/java/cz/neumimto/Decorator.java | 12 +++ .../effects/decoration/ParticleDecorator.java | 48 +++++----- .../neumimto/effects/negative/Blindness.java | 59 ++++++++++++ .../cz/neumimto/skills/active/Despair.java | 92 +++++++++++++++++++ 10 files changed, 227 insertions(+), 36 deletions(-) create mode 100644 Skills/src/main/java/cz/neumimto/effects/negative/Blindness.java create mode 100644 Skills/src/main/java/cz/neumimto/skills/active/Despair.java diff --git a/Plugin/src/main/java/cz/neumimto/rpg/effects/EffectBase.java b/Plugin/src/main/java/cz/neumimto/rpg/effects/EffectBase.java index b4fd2fe11..e4a518bda 100644 --- a/Plugin/src/main/java/cz/neumimto/rpg/effects/EffectBase.java +++ b/Plugin/src/main/java/cz/neumimto/rpg/effects/EffectBase.java @@ -35,7 +35,7 @@ public class EffectBase implements IEffect { private boolean stackable = false; private String name; private int level; - private Set potions = new HashSet<>(); + private Set potions; private IEffectConsumer consumer; private long duration = -1; private long period = -1; @@ -124,6 +124,8 @@ public void setConsumer(IEffectConsumer consumer) { @Override public Set getPotions() { + if (potions == null) + potions = new HashSet<>(); return potions; } diff --git a/Plugin/src/main/java/cz/neumimto/rpg/effects/IEffect.java b/Plugin/src/main/java/cz/neumimto/rpg/effects/IEffect.java index cf3810871..b5bb83820 100644 --- a/Plugin/src/main/java/cz/neumimto/rpg/effects/IEffect.java +++ b/Plugin/src/main/java/cz/neumimto/rpg/effects/IEffect.java @@ -40,7 +40,7 @@ static GlobalScope getGlobalScope() { default void reApplyPotions() { for (PotionEffect e : getPotions()) { - getConsumer().addPotionEffect(e.getType(), e.getAmplifier(), e.getDuration()); + getConsumer().addPotionEffect(e.getType(), e.getAmplifier(), e.getDuration()); } } diff --git a/Plugin/src/main/java/cz/neumimto/rpg/gui/IActionDecorator.java b/Plugin/src/main/java/cz/neumimto/rpg/gui/IActionDecorator.java index d65bfbd8b..373da4c1c 100644 --- a/Plugin/src/main/java/cz/neumimto/rpg/gui/IActionDecorator.java +++ b/Plugin/src/main/java/cz/neumimto/rpg/gui/IActionDecorator.java @@ -1,11 +1,13 @@ package cz.neumimto.rpg.gui; +import org.spongepowered.api.effect.particle.ParticleEffect; import org.spongepowered.api.entity.Entity; import org.spongepowered.api.scheduler.Task; import org.spongepowered.api.world.Location; import org.spongepowered.api.world.World; import java.util.function.BiConsumer; +import java.util.function.Consumer; /** * Created by NeumimTo on 9.7.2017. @@ -16,6 +18,5 @@ public interface IActionDecorator { void createTrajectory(Entity entity, int interval, int maxticks, BiConsumer e); - - + void circle(Location location, int count, double radius, Consumer callback); } diff --git a/Plugin/src/main/java/cz/neumimto/rpg/skills/AbstractSkill.java b/Plugin/src/main/java/cz/neumimto/rpg/skills/AbstractSkill.java index 800fd3d59..1e04235dd 100644 --- a/Plugin/src/main/java/cz/neumimto/rpg/skills/AbstractSkill.java +++ b/Plugin/src/main/java/cz/neumimto/rpg/skills/AbstractSkill.java @@ -170,8 +170,7 @@ public void setDamageType(DamageType type) { /* Skills are singletons */ @Override public boolean equals(Object o) { - if (this == o) return true; - return false; + return this == o; } @Override diff --git a/Plugin/src/main/java/cz/neumimto/rpg/skills/ISkill.java b/Plugin/src/main/java/cz/neumimto/rpg/skills/ISkill.java index fca8f7186..a7c44fe8b 100644 --- a/Plugin/src/main/java/cz/neumimto/rpg/skills/ISkill.java +++ b/Plugin/src/main/java/cz/neumimto/rpg/skills/ISkill.java @@ -97,6 +97,10 @@ default double getDoubleNodeValue(ExtendedSkillInfo extendedSkillInfo, String no return extendedSkillInfo.getSkillData().getSkillSettings().getLevelNodeValue(node,extendedSkillInfo.getTotalLevel()); } + default double getDoubleNodeValue(ExtendedSkillInfo extendedSkillInfo, ISkillNode node) { + return getDoubleNodeValue(extendedSkillInfo, node.value()); + } + @Override default IEffectSource getType() { return EffectSourceType.SKILL; diff --git a/Plugin/src/main/java/cz/neumimto/rpg/utils/Utils.java b/Plugin/src/main/java/cz/neumimto/rpg/utils/Utils.java index 0d5b8e67f..d95f32cce 100644 --- a/Plugin/src/main/java/cz/neumimto/rpg/utils/Utils.java +++ b/Plugin/src/main/java/cz/neumimto/rpg/utils/Utils.java @@ -113,15 +113,35 @@ public static boolean isNumeric(String str) { return str.matches("-?\\d+(\\.\\d+)?"); } - public static Set getNearbyEntities(Location l, int radius) { - double s = Math.pow(radius, 2); - HashSet ee = new HashSet<>(); - for (Entity e : l.getExtent().getEntities()) { - if (e.getLocation().getPosition().distanceSquared(l.getX(), l.getY(), l.getZ()) <= s) { - ee.add(e); + public static Set getNearbyEntities(Location l, int radius){ + int chunkRadius = radius < 16 ? 1 : (radius - (radius % 16))/16; + HashSet set = new HashSet<>(); + double pow = Math.pow(radius, 2); + for (int chX = 0 -chunkRadius; chX <= chunkRadius; chX ++){ + for (int chZ = 0 -chunkRadius; chZ <= chunkRadius; chZ++){ + Location chunkLoc = new Location(l.getExtent(),l.getBlockX()+(chX*16),l.getBlockY(),l.getBlockZ()+(chZ*16)); + for (Entity e : chunkLoc.getExtent().getEntities()){ + if (e.getLocation().getPosition().distanceSquared(l.getPosition()) <= pow) + set.add(e); + } + } + } + return set; + } + + public static Set getNearbyEntitiesPrecise(Location l, int radius){ + int chunkRadius = radius < 16 ? 1 : (radius - (radius % 16))/16; + HashSet set = new HashSet<>(); + for (int chX = 0 -chunkRadius; chX <= chunkRadius; chX ++){ + for (int chZ = 0 -chunkRadius; chZ <= chunkRadius; chZ++){ + Location chunkLoc = new Location(l.getExtent(),l.getBlockX()+(chX*16),l.getBlockY(),l.getBlockZ()+(chZ*16)); + for (Entity e : chunkLoc.getExtent().getEntities()){ + if (e.getLocation().getPosition().distance(l.getPosition()) <= radius) + set.add(e); + } } } - return ee; + return set; } diff --git a/Skills/src/main/java/cz/neumimto/Decorator.java b/Skills/src/main/java/cz/neumimto/Decorator.java index 60048a3b3..8e42c883a 100644 --- a/Skills/src/main/java/cz/neumimto/Decorator.java +++ b/Skills/src/main/java/cz/neumimto/Decorator.java @@ -2,12 +2,14 @@ import cz.neumimto.core.ioc.IoC; import cz.neumimto.effects.decoration.ParticleDecorator; +import org.spongepowered.api.effect.particle.ParticleEffect; import org.spongepowered.api.entity.Entity; import org.spongepowered.api.scheduler.Task; import org.spongepowered.api.world.Location; import org.spongepowered.api.world.World; import java.util.function.BiConsumer; +import java.util.function.Consumer; /** * Created by NeumimTo on 6.2.2016. @@ -32,4 +34,14 @@ public static void strikeLightning(Location location) { public static void createTrajectory(Entity entity, int interval, int maxticks, BiConsumer e) { decorator.createTrajectory(entity, interval, maxticks, e); } + + public static void circle(Location location, int count, double radius, Consumer callback) { + decorator.circle(location, count, radius, callback); + } + + public static void particleExplosion(Location location, int size) { + + } + + } diff --git a/Skills/src/main/java/cz/neumimto/effects/decoration/ParticleDecorator.java b/Skills/src/main/java/cz/neumimto/effects/decoration/ParticleDecorator.java index 9920a1344..6239c1885 100644 --- a/Skills/src/main/java/cz/neumimto/effects/decoration/ParticleDecorator.java +++ b/Skills/src/main/java/cz/neumimto/effects/decoration/ParticleDecorator.java @@ -1,5 +1,6 @@ package cz.neumimto.effects.decoration; +import com.flowpowered.math.TrigMath; import cz.neumimto.Decorator; import cz.neumimto.core.ioc.Inject; import cz.neumimto.core.ioc.Singleton; @@ -15,9 +16,13 @@ import org.spongepowered.api.scheduler.Task; import org.spongepowered.api.world.Location; import org.spongepowered.api.world.World; +import org.spongepowered.api.world.extent.Extent; +import java.util.HashSet; +import java.util.Set; import java.util.concurrent.TimeUnit; import java.util.function.BiConsumer; +import java.util.function.Consumer; /** * Created by NeumimTo on 9.7.2017. @@ -36,31 +41,28 @@ public void strikeLightning(Location location) { @Override public void createTrajectory(Entity entity, int interval, int maxticks, BiConsumer e) { - Task submit = Sponge.getScheduler() - .createTaskBuilder() - .delay(1L, TimeUnit.MILLISECONDS) - .interval(interval, TimeUnit.MILLISECONDS) - .execute((task -> { - if (!entity.isRemoved()) { - e.accept(task, entity); - } else { - task.cancel(); - } - })).submit(plugin); + Sponge.getScheduler() + .createTaskBuilder() + .delay(1L, TimeUnit.MILLISECONDS) + .interval(interval, TimeUnit.MILLISECONDS) + .execute((task -> { + if (!entity.isRemoved()) { + e.accept(task, entity); + } else { + task.cancel(); + } + })).submit(plugin); } - public static class SIMPLE_TRAJECTORY implements BiConsumer { - - private ParticleEffect eff; - - public SIMPLE_TRAJECTORY(ParticleEffect eff) { - this.eff = eff; - } - - @Override - public void accept(Task task, Entity entity) { - entity.getWorld().spawnParticles(eff, entity.getLocation().getPosition()); + @Override + public void circle(Location location, int count, double radius, Consumer callback) { + Extent e = location.getExtent(); + double increment = TrigMath.TWO_PI/count; + for (int i = 0; i < count; i++) { + double angle = i * increment; + double x = location.getX() + radius * TrigMath.cos(angle); + double z = location.getZ() + radius * TrigMath.sin(angle); + callback.accept(new Location(e, x, location.getY(), z)); } } - } diff --git a/Skills/src/main/java/cz/neumimto/effects/negative/Blindness.java b/Skills/src/main/java/cz/neumimto/effects/negative/Blindness.java new file mode 100644 index 000000000..f3afa1351 --- /dev/null +++ b/Skills/src/main/java/cz/neumimto/effects/negative/Blindness.java @@ -0,0 +1,59 @@ +package cz.neumimto.effects.negative; + +import cz.neumimto.rpg.ClassGenerator; +import cz.neumimto.rpg.effects.*; +import org.spongepowered.api.effect.potion.PotionEffect; +import org.spongepowered.api.effect.potion.PotionEffectTypes; + +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; + +/** + * Created by NeumimTo on 9.7.2017. + */ +@ClassGenerator.Generate(id = "name") +public class Blindness extends EffectBase implements IEffectContainer { + + public static final String name = "Blindness"; + + public Blindness(IEffectConsumer consumer, long duration, String value) { + this(consumer, duration); + setValue(duration); + setDuration(duration); + getPotions().add(getEffect()); + } + + public Blindness(IEffectConsumer consumer, long duration) { + super(name, consumer); + } + + + @Override + public Set getEffects() { + return new HashSet<>(Arrays.asList(this)); + } + + @Override + public Long getStackedValue() { + return getDuration(); + } + + @Override + public void setStackedValue(Long aLong) { + setDuration(aLong); + } + + @Override + public void stackEffect(Blindness blindness, IEffectSourceProvider effectSourceProvider) { + setStackedValue(getStackedValue() + blindness.getStackedValue()); + } + + private PotionEffect getEffect() { + return PotionEffect.builder() + .potionType(PotionEffectTypes.BLINDNESS) + .particles(false) + .duration((int) (20 * getStackedValue() / 1000)) + .build(); //miliseconds to minecraft ticks + } +} diff --git a/Skills/src/main/java/cz/neumimto/skills/active/Despair.java b/Skills/src/main/java/cz/neumimto/skills/active/Despair.java new file mode 100644 index 000000000..d5a8e5efb --- /dev/null +++ b/Skills/src/main/java/cz/neumimto/skills/active/Despair.java @@ -0,0 +1,92 @@ +package cz.neumimto.skills.active; + +import com.flowpowered.math.vector.Vector3d; +import cz.neumimto.Decorator; +import cz.neumimto.ParticleUtils; +import cz.neumimto.core.ioc.Inject; +import cz.neumimto.effects.negative.Blindness; +import cz.neumimto.rpg.IEntity; +import cz.neumimto.rpg.ResourceLoader; +import cz.neumimto.rpg.damage.SkillDamageSource; +import cz.neumimto.rpg.damage.SkillDamageSourceBuilder; +import cz.neumimto.rpg.effects.EffectService; +import cz.neumimto.rpg.entities.EntityService; +import cz.neumimto.rpg.players.IActiveCharacter; +import cz.neumimto.rpg.skills.*; +import cz.neumimto.rpg.utils.Utils; +import org.spongepowered.api.effect.particle.ParticleEffect; +import org.spongepowered.api.effect.particle.ParticleOptions; +import org.spongepowered.api.effect.particle.ParticleTypes; +import org.spongepowered.api.entity.Entity; +import org.spongepowered.api.entity.living.Living; +import org.spongepowered.api.event.cause.entity.damage.DamageTypes; +import org.spongepowered.api.util.Color; +import org.spongepowered.api.util.Direction; +import org.spongepowered.api.world.Location; +import org.spongepowered.api.world.World; + +import java.util.ArrayList; +import java.util.Set; + +/** + * Created by NeumimTo on 15.7.2017. + */ +@ResourceLoader.Skill +public class Despair extends ActiveSkill { + + @Inject + private EntityService entityService; + + @Inject + private EffectService effectService; + + public Despair() { + setName("Despair"); + setDamageType(DamageTypes.MAGIC); + SkillSettings settings = new SkillSettings(); + settings.addNode(SkillNodes.DURATION, 1000L, 500); + settings.addNode(SkillNodes.DAMAGE, 10L, 1.5f); + settings.addNode(SkillNodes.RADIUS, 7L, 2); + super.settings = settings; + } + + @Override + public SkillResult cast(IActiveCharacter character, ExtendedSkillInfo info, SkillModifier modifier) { + int k = getIntNodeValue(info, SkillNodes.RADIUS); + Set nearbyEntities = Utils.getNearbyEntities(character.getEntity().getLocation(), k); + double damage = getDoubleNodeValue(info, SkillNodes.DAMAGE); + long duration = getLongNodeValue(info, SkillNodes.DURATION); + + for (Entity nearbyEntity : nearbyEntities) { + if (Utils.isLivingEntity(nearbyEntity)) { + Living l = (Living) nearbyEntity; + if (Utils.canDamage(character, l)) { + IEntity iEntity = entityService.get(l); + SkillDamageSource build = new SkillDamageSourceBuilder() + .fromSkill(this) + .setTarget(iEntity) + .setCaster(character).build(); + l.damage(damage, build); + Blindness blindness = new Blindness(iEntity, duration); + effectService.addEffect(blindness, character, this); + } + } + } + + Vector3d vec = new Vector3d(0,1,0); + Decorator.circle(character.getEntity().getLocation(), 36, k, location -> { + ParticleEffect build = ParticleEffect.builder() + .type(ParticleTypes.SPELL) + .option(ParticleOptions.COLOR, Color.GRAY) + .build(); + character.getEntity().getLocation().getExtent().spawnParticles(build, location.getPosition().add(vec)); + build = ParticleEffect.builder() + .type(ParticleTypes.MOB_SPELL) + .option(ParticleOptions.COLOR, Color.GRAY) + .build(); + character.getEntity().getLocation().getExtent().spawnParticles(build, location.getPosition().add(vec)); + }); + + return SkillResult.OK; + } +}