Search in sources :

Example 16 with ISoliniaSpell

use of com.solinia.solinia.Interfaces.ISoliniaSpell in project solinia3-core by mixxit.

the class CommandEditSpell method onCommand.

@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    if (!(sender instanceof Player) && !(sender instanceof CommandSender))
        return false;
    if (sender instanceof Player) {
        Player player = (Player) sender;
        if (!player.isOp()) {
            player.sendMessage("This is an operator only command");
            return false;
        }
    }
    if (args.length == 0) {
        return false;
    }
    int spellid = Integer.parseInt(args[0]);
    if (args.length == 1) {
        try {
            ISoliniaSpell spell = StateManager.getInstance().getConfigurationManager().getSpell(spellid);
            if (spell != null) {
                spell.sendSpellSettingsToSender(sender);
            } else {
                sender.sendMessage("SPELL ID doesnt exist");
            }
            return true;
        } catch (CoreStateInitException e) {
            sender.sendMessage(e.getMessage());
        }
    }
    if (args.length < 3) {
        sender.sendMessage("Insufficient arguments: spellid setting value");
        return false;
    }
    String setting = args[1];
    String value = args[2];
    if (spellid < 1) {
        sender.sendMessage("Invalid spellid id");
        return false;
    }
    String[] additional = new String[0];
    if (args.length > 3) {
        additional = new String[args.length - 3];
        for (int i = 0; i < args.length; i++) {
            if (i < 3)
                continue;
            additional[i - 3] = args[i];
        }
    }
    try {
        if (StateManager.getInstance().getConfigurationManager().getSpell(spellid) == null) {
            sender.sendMessage("Cannot locate spell id: " + spellid);
            return false;
        }
        StateManager.getInstance().getConfigurationManager().editSpell(spellid, setting, value, additional);
        sender.sendMessage("Updating setting on spell");
    } catch (InvalidSpellSettingException ne) {
        sender.sendMessage("Invalid Spell setting: " + ne.getMessage());
    } catch (CoreStateInitException e) {
        // TODO Auto-generated catch block
        sender.sendMessage(e.getMessage());
    }
    return true;
}
Also used : Player(org.bukkit.entity.Player) ISoliniaSpell(com.solinia.solinia.Interfaces.ISoliniaSpell) InvalidSpellSettingException(com.solinia.solinia.Exceptions.InvalidSpellSettingException) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) CommandSender(org.bukkit.command.CommandSender) ConsoleCommandSender(org.bukkit.command.ConsoleCommandSender)

Example 17 with ISoliniaSpell

use of com.solinia.solinia.Interfaces.ISoliniaSpell in project solinia3-core by mixxit.

the class JsonSpellRepository method reload.

@Override
public void reload() {
    List<ISoliniaSpell> file = new ArrayList<ISoliniaSpell>();
    try {
        Gson gson = new Gson();
        BufferedReader br = new BufferedReader(new FileReader(filePath));
        file = gson.fromJson(br, new TypeToken<List<SoliniaSpell>>() {
        }.getType());
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
    spells.clear();
    for (ISoliniaSpell i : file) {
        spells.put(i.getId(), i);
    }
    System.out.println("Reloaded " + spells.size() + " spells");
}
Also used : ISoliniaSpell(com.solinia.solinia.Interfaces.ISoliniaSpell) ArrayList(java.util.ArrayList) BufferedReader(java.io.BufferedReader) FileNotFoundException(java.io.FileNotFoundException) Gson(com.google.gson.Gson) FileReader(java.io.FileReader) ArrayList(java.util.ArrayList) List(java.util.List)

Example 18 with ISoliniaSpell

use of com.solinia.solinia.Interfaces.ISoliniaSpell in project solinia3-core by mixxit.

the class SoliniaLivingEntity method Attack.

@Override
public boolean Attack(ISoliniaLivingEntity defender, EntityDamageEvent event, boolean arrowHit, Solinia3CorePlugin plugin) {
    int baseDamage = (int) event.getDamage(DamageModifier.BASE);
    try {
        if (defender.isPlayer() && isPlayer()) {
            ISoliniaPlayer defenderPlayer = SoliniaPlayerAdapter.Adapt((Player) defender.getBukkitLivingEntity());
            ISoliniaPlayer attackerPlayer = SoliniaPlayerAdapter.Adapt((Player) this.getBukkitLivingEntity());
            if (defenderPlayer.getGroup() != null && attackerPlayer.getGroup() != null) {
                if (defenderPlayer.getGroup().getId().equals(attackerPlayer.getGroup().getId())) {
                    Utils.CancelEvent(event);
                    ;
                    return false;
                }
            }
        }
    } catch (CoreStateInitException e) {
    // ignore
    }
    if (isPlayer()) {
        Player player = (Player) this.getBukkitLivingEntity();
        if (player.isSneaking()) {
            try {
                ISoliniaPlayer solplayer = SoliniaPlayerAdapter.Adapt(player);
                if (solplayer.getClassObj() != null) {
                    if (solplayer.getClassObj().isSneakFromCrouch()) {
                        player.sendMessage("You cannot concentrate on combat while meditating or sneaking");
                        Utils.CancelEvent(event);
                        ;
                        return false;
                    }
                }
            } catch (CoreStateInitException e) {
            // do nothing
            }
        }
    }
    if (usingValidWeapon() == false) {
        Utils.CancelEvent(event);
        ;
        return false;
    } else {
        if (Utils.IsSoliniaItem(getBukkitLivingEntity().getEquipment().getItemInMainHand())) {
            try {
                ISoliniaItem soliniaitem = StateManager.getInstance().getConfigurationManager().getItem(getBukkitLivingEntity().getEquipment().getItemInMainHand());
                // TODO move this
                if (soliniaitem.getBaneUndead() > 0 && defender.isUndead())
                    baseDamage += soliniaitem.getBaneUndead();
            } catch (CoreStateInitException e) {
                Utils.CancelEvent(event);
                ;
                return false;
            }
        }
    }
    if (baseDamage < 1)
        baseDamage = 1;
    if (defender == null) {
        Utils.CancelEvent(event);
        ;
        return false;
    }
    if (defender.getBukkitLivingEntity().isDead() || this.getBukkitLivingEntity().isDead() || this.getBukkitLivingEntity().getHealth() < 0) {
        Utils.CancelEvent(event);
        ;
        return false;
    }
    if (isInulvnerable()) {
        Utils.CancelEvent(event);
        ;
        return false;
    }
    if (isFeigned()) {
        Utils.CancelEvent(event);
        ;
        return false;
    }
    ItemStack weapon = this.getBukkitLivingEntity().getEquipment().getItemInHand();
    DamageHitInfo my_hit = new DamageHitInfo();
    my_hit.skill = Utils.getSkillForMaterial(weapon.getType().toString()).getSkillname();
    if (arrowHit) {
        my_hit.skill = "ARCHERY";
    }
    // Now figure out damage
    my_hit.damage_done = 1;
    my_hit.min_damage = 0;
    int mylevel = getLevel();
    int hate = 0;
    my_hit.base_damage = baseDamage;
    // amount of hate is based on the damage done
    if (hate == 0 && my_hit.base_damage > 1)
        hate = my_hit.base_damage;
    if (my_hit.base_damage > 0) {
        my_hit.base_damage = getDamageCaps(my_hit.base_damage);
        tryIncreaseSkill(my_hit.skill, 1);
        tryIncreaseSkill("OFFENSE", 1);
        int ucDamageBonus = 0;
        if (getClassObj() != null && getClassObj().isWarriorClass() && getLevel() >= 28) {
            ucDamageBonus = getWeaponDamageBonus(weapon);
            my_hit.min_damage = ucDamageBonus;
            hate += ucDamageBonus;
        }
        // TODO Sinister Strikes
        int hit_chance_bonus = 0;
        // we need this a few times
        my_hit.offense = getOffense(my_hit.skill);
        my_hit.tohit = getTotalToHit(my_hit.skill, hit_chance_bonus);
        doAttack(plugin, defender, my_hit);
    }
    defender.addToHateList(getBukkitLivingEntity().getUniqueId(), hate);
    if (getBukkitLivingEntity().isDead()) {
        Utils.CancelEvent(event);
        ;
        return false;
    }
    if (my_hit.damage_done > 0) {
        triggerDefensiveProcs(defender, my_hit.damage_done, arrowHit);
        try {
            event.setDamage(DamageModifier.ABSORPTION, 0);
        } catch (UnsupportedOperationException e) {
        }
        try {
            event.setDamage(DamageModifier.ARMOR, 0);
        } catch (UnsupportedOperationException e) {
        }
        try {
            event.setDamage(DamageModifier.BASE, my_hit.damage_done);
        } catch (UnsupportedOperationException e) {
        }
        try {
            event.setDamage(DamageModifier.BLOCKING, 0);
        } catch (UnsupportedOperationException e) {
        }
        try {
            event.setDamage(DamageModifier.HARD_HAT, 0);
        } catch (UnsupportedOperationException e) {
        }
        try {
            event.setDamage(DamageModifier.MAGIC, 0);
        } catch (UnsupportedOperationException e) {
        }
        try {
            event.setDamage(DamageModifier.RESISTANCE, 0);
        } catch (UnsupportedOperationException e) {
        }
        DecimalFormat df = new DecimalFormat();
        df.setMaximumFractionDigits(2);
        if (getBukkitLivingEntity() instanceof Player) {
            String name = defender.getBukkitLivingEntity().getName();
            if (defender.getBukkitLivingEntity().getCustomName() != null)
                name = defender.getBukkitLivingEntity().getCustomName();
            if (defender.isPlayer())
                System.out.println("Detected player " + getBukkitLivingEntity().getName() + " vs player " + defender.getName());
            ((Player) getBukkitLivingEntity()).spigot().sendMessage(ChatMessageType.ACTION_BAR, new TextComponent("You hit " + name + " for " + df.format(event.getDamage()) + " " + df.format(defender.getBukkitLivingEntity().getHealth() - event.getDamage()) + "/" + df.format(defender.getBukkitLivingEntity().getMaxHealth()) + " " + my_hit.skill + " damage"));
            if (defender.isNPC()) {
                ISoliniaNPC npc;
                try {
                    npc = StateManager.getInstance().getConfigurationManager().getNPC(defender.getNpcid());
                } catch (CoreStateInitException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
            // Only players get this
            if (getDoubleAttackCheck()) {
                if (getBukkitLivingEntity() instanceof Player) {
                    ((Player) getBukkitLivingEntity()).sendMessage(ChatColor.GRAY + "* You double attack!");
                    tryIncreaseSkill("DOUBLEATTACK", 1);
                }
                defender.damage(plugin, my_hit.damage_done, this.getBukkitLivingEntity());
            }
            try {
                if (Utils.IsSoliniaItem(getBukkitLivingEntity().getEquipment().getItemInMainHand())) {
                    try {
                        ISoliniaItem soliniaitem = SoliniaItemAdapter.Adapt(getBukkitLivingEntity().getEquipment().getItemInMainHand());
                        if (soliniaitem != null) {
                            // Check if item has any proc effects
                            if (soliniaitem.getWeaponabilityid() > 0 && event.getCause().equals(DamageCause.ENTITY_ATTACK)) {
                                ISoliniaSpell procSpell = StateManager.getInstance().getConfigurationManager().getSpell(soliniaitem.getWeaponabilityid());
                                if (procSpell != null) {
                                    // Chance to proc
                                    int procChance = getProcChancePct();
                                    int roll = Utils.RandomBetween(0, 100);
                                    if (roll < procChance) {
                                        // TODO - For now apply self and group to attacker, else attach to target
                                        switch(Utils.getSpellTargetType(procSpell.getTargettype())) {
                                            case Self:
                                                procSpell.tryApplyOnEntity(plugin, this.getBukkitLivingEntity(), this.getBukkitLivingEntity());
                                                break;
                                            case Group:
                                                procSpell.tryApplyOnEntity(plugin, this.getBukkitLivingEntity(), this.getBukkitLivingEntity());
                                                break;
                                            default:
                                                procSpell.tryApplyOnEntity(plugin, this.getBukkitLivingEntity(), defender.getBukkitLivingEntity());
                                        }
                                    }
                                }
                            }
                        }
                    } catch (SoliniaItemException e) {
                    // skip
                    }
                }
                // Check if attacker has any WeaponProc effects
                SoliniaEntitySpells effects = StateManager.getInstance().getEntityManager().getActiveEntitySpells(this.getBukkitLivingEntity());
                if (effects != null) {
                    for (SoliniaActiveSpell activeSpell : effects.getActiveSpells()) {
                        ISoliniaSpell spell = StateManager.getInstance().getConfigurationManager().getSpell(activeSpell.getSpellId());
                        if (spell == null)
                            continue;
                        if (!spell.isWeaponProc())
                            continue;
                        for (ActiveSpellEffect spelleffect : activeSpell.getActiveSpellEffects()) {
                            if (spelleffect.getSpellEffectType().equals(SpellEffectType.WeaponProc)) {
                                if (spelleffect.getBase() < 0)
                                    continue;
                                ISoliniaSpell procSpell = StateManager.getInstance().getConfigurationManager().getSpell(spelleffect.getBase());
                                if (spell == null)
                                    continue;
                                // Chance to proc
                                int procChance = getProcChancePct();
                                int roll = Utils.RandomBetween(0, 100);
                                if (roll < procChance) {
                                    boolean itemUseSuccess = procSpell.tryApplyOnEntity(plugin, this.getBukkitLivingEntity(), defender.getBukkitLivingEntity());
                                    if (procSpell.getActSpellCost(this) > 0)
                                        if (itemUseSuccess) {
                                            if (getBukkitLivingEntity() instanceof Player) {
                                                SoliniaPlayerAdapter.Adapt((Player) getBukkitLivingEntity()).reducePlayerMana(procSpell.getActSpellCost(this));
                                            }
                                        }
                                }
                            }
                        }
                    }
                }
            } catch (CoreStateInitException e) {
            }
        }
        if (defender.getBukkitLivingEntity() instanceof Player) {
            ((Player) defender.getBukkitLivingEntity()).spigot().sendMessage(ChatMessageType.ACTION_BAR, new TextComponent("You were hit by " + getBukkitLivingEntity().getCustomName() + " for " + df.format(event.getDamage()) + " " + my_hit.skill + " damage"));
        }
        if (event.getDamage() > getBukkitLivingEntity().getHealth() && hasDeathSave() > 0) {
            Utils.CancelEvent(event);
            removeDeathSaves(plugin);
            getBukkitLivingEntity().sendMessage("* Your death save boon has saved you from death!");
            return false;
        }
        defender.damageHook(event.getDamage(), getBukkitLivingEntity());
        return true;
    } else {
        Utils.CancelEvent(event);
        return false;
    }
}
Also used : TextComponent(net.md_5.bungee.api.chat.TextComponent) Player(org.bukkit.entity.Player) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) ISoliniaItem(com.solinia.solinia.Interfaces.ISoliniaItem) ISoliniaSpell(com.solinia.solinia.Interfaces.ISoliniaSpell) DecimalFormat(java.text.DecimalFormat) SoliniaItemException(com.solinia.solinia.Exceptions.SoliniaItemException) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ISoliniaNPC(com.solinia.solinia.Interfaces.ISoliniaNPC) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) ItemStack(org.bukkit.inventory.ItemStack)

Example 19 with ISoliniaSpell

use of com.solinia.solinia.Interfaces.ISoliniaSpell in project solinia3-core by mixxit.

the class SoliniaItem method useItemOnBlock.

@Override
public boolean useItemOnBlock(Player player, ISoliniaItem item, Block clickedBlock, boolean isConsumable) throws CoreStateInitException {
    ISoliniaSpell spell = StateManager.getInstance().getConfigurationManager().getSpell(item.getAbilityid());
    if (spell == null) {
        return false;
    }
    ISoliniaLivingEntity solentity = SoliniaLivingEntityAdapter.Adapt((LivingEntity) player);
    if (solentity == null)
        return false;
    if (!isConsumable)
        if (spell.getActSpellCost(solentity) > SoliniaPlayerAdapter.Adapt(player).getMana()) {
            player.sendMessage(ChatColor.GRAY + "Insufficient Mana [E]  (Hold crouch or use /trance to meditate)");
            return false;
        }
    boolean itemUseSuccess = false;
    itemUseSuccess = spell.tryApplyOnBlock(player, clickedBlock);
    if (itemUseSuccess) {
        SoliniaPlayerAdapter.Adapt(player).reducePlayerMana(spell.getActSpellCost(solentity));
    }
    return itemUseSuccess;
}
Also used : ISoliniaSpell(com.solinia.solinia.Interfaces.ISoliniaSpell) ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity)

Example 20 with ISoliniaSpell

use of com.solinia.solinia.Interfaces.ISoliniaSpell in project solinia3-core by mixxit.

the class SoliniaItem method useItemOnEntity.

@Override
public boolean useItemOnEntity(Plugin plugin, Player player, LivingEntity targetentity, boolean isConsumable) throws CoreStateInitException {
    if (isPetControlRod()) {
        LivingEntity pet = StateManager.getInstance().getEntityManager().getPet(player);
        if (pet != null) {
            if (pet instanceof Wolf) {
                // Mez cancel target
                Timestamp mezExpiry = StateManager.getInstance().getEntityManager().getMezzed(targetentity);
                if (mezExpiry != null) {
                    ((Creature) pet).setTarget(null);
                    Wolf wolf = (Wolf) pet;
                    wolf.setTarget(null);
                    player.sendMessage("You cannot send your pet to attack a mezzed player");
                    return false;
                }
                if (!pet.getUniqueId().equals(targetentity.getUniqueId())) {
                    Wolf wolf = (Wolf) pet;
                    wolf.setTarget(targetentity);
                    player.sendMessage("You send your pet to attack!");
                    return true;
                } else {
                    Wolf wolf = (Wolf) pet;
                    wolf.setTarget(null);
                    player.sendMessage("You cannot send your pet to attack itself");
                    return false;
                }
            }
        }
    }
    if (isConsumable == true && isExperienceBonus()) {
        SoliniaPlayerAdapter.Adapt(player).grantExperienceBonusFromItem();
        System.out.println("Granted " + player.getName() + " experience bonus from item [" + SoliniaPlayerAdapter.Adapt(player).getExperienceBonusExpires().toString() + "]");
        return true;
    }
    ISoliniaSpell spell = StateManager.getInstance().getConfigurationManager().getSpell(getAbilityid());
    if (spell == null) {
        return false;
    }
    ISoliniaLivingEntity solentity = SoliniaLivingEntityAdapter.Adapt((LivingEntity) player);
    if (solentity == null)
        return false;
    if (!isConsumable)
        if (spell.getActSpellCost(solentity) > SoliniaPlayerAdapter.Adapt(player).getMana()) {
            player.sendMessage(ChatColor.GRAY + "Insufficient Mana  [E] (Hold crouch or use /trance to meditate)");
            return false;
        }
    try {
        if (StateManager.getInstance().getEntityManager().getEntitySpellCooldown(player, spell.getId()) != null) {
            LocalDateTime datetime = LocalDateTime.now();
            Timestamp nowtimestamp = Timestamp.valueOf(datetime);
            Timestamp expiretimestamp = StateManager.getInstance().getEntityManager().getEntitySpellCooldown(player, spell.getId());
            if (expiretimestamp != null)
                if (!nowtimestamp.after(expiretimestamp)) {
                    player.sendMessage("You do not have enough willpower to cast " + spell.getName() + " (Wait: " + ((expiretimestamp.getTime() - nowtimestamp.getTime()) / 1000) + "s");
                    return false;
                }
        }
    } catch (CoreStateInitException e) {
        // skip
        return false;
    }
    boolean itemUseSuccess = spell.tryApplyOnEntity(plugin, player, targetentity);
    if (itemUseSuccess) {
        if (spell.getRecastTime() > 0) {
            LocalDateTime datetime = LocalDateTime.now();
            Timestamp expiretimestamp = Timestamp.valueOf(datetime.plus(spell.getRecastTime(), ChronoUnit.MILLIS));
            StateManager.getInstance().getEntityManager().addEntitySpellCooldown(player, spell.getId(), expiretimestamp);
        }
        if (!isConsumable)
            SoliniaPlayerAdapter.Adapt(player).reducePlayerMana(spell.getActSpellCost(solentity));
    }
    return itemUseSuccess;
}
Also used : ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) LivingEntity(org.bukkit.entity.LivingEntity) LocalDateTime(java.time.LocalDateTime) Creature(org.bukkit.entity.Creature) ISoliniaSpell(com.solinia.solinia.Interfaces.ISoliniaSpell) ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) Wolf(org.bukkit.entity.Wolf) Timestamp(java.sql.Timestamp)

Aggregations

ISoliniaSpell (com.solinia.solinia.Interfaces.ISoliniaSpell)20 CoreStateInitException (com.solinia.solinia.Exceptions.CoreStateInitException)16 Player (org.bukkit.entity.Player)8 ArrayList (java.util.ArrayList)7 ISoliniaLivingEntity (com.solinia.solinia.Interfaces.ISoliniaLivingEntity)6 ISoliniaPlayer (com.solinia.solinia.Interfaces.ISoliniaPlayer)4 SoliniaSpellClass (com.solinia.solinia.Models.SoliniaSpellClass)4 TextComponent (net.md_5.bungee.api.chat.TextComponent)4 LivingEntity (org.bukkit.entity.LivingEntity)4 ISoliniaItem (com.solinia.solinia.Interfaces.ISoliniaItem)3 Timestamp (java.sql.Timestamp)3 LocalDateTime (java.time.LocalDateTime)3 NBTTagString (net.minecraft.server.v1_12_R1.NBTTagString)3 CommandSender (org.bukkit.command.CommandSender)3 ConsoleCommandSender (org.bukkit.command.ConsoleCommandSender)3 ItemStack (org.bukkit.inventory.ItemStack)3 ISoliniaClass (com.solinia.solinia.Interfaces.ISoliniaClass)2 SoliniaActiveSpell (com.solinia.solinia.Models.SoliniaActiveSpell)2 SoliniaEntitySpells (com.solinia.solinia.Models.SoliniaEntitySpells)2 DecimalFormat (java.text.DecimalFormat)2