Search in sources :

Example 51 with TextComponent

use of net.md_5.bungee.api.chat.TextComponent in project solinia3-core by mixxit.

the class SoliniaPlayer method setInteraction.

@Override
public void setInteraction(UUID interaction, ISoliniaNPC npc) {
    if (interaction == null) {
        this.interaction = interaction;
        this.getBukkitPlayer().sendMessage(ChatColor.GRAY + "* You are no longer interacting");
        return;
    }
    Entity e = Bukkit.getEntity(interaction);
    if (e == null)
        return;
    if (!(e instanceof LivingEntity))
        return;
    if (((Creature) e).getTarget() != null) {
        if (interaction != null) {
            this.getBukkitPlayer().sendMessage(ChatColor.GRAY + "* You are no longer interacting");
            interaction = null;
        }
        return;
    }
    if (Bukkit.getEntity(interaction) instanceof Wolf) {
        Wolf w = (Wolf) Bukkit.getEntity(interaction);
        if (w.getOwner() != null)
            return;
    }
    this.interaction = interaction;
    if (npc != null) {
        this.getBukkitPlayer().sendMessage(ChatColor.GRAY + "* You are now interacting with " + Bukkit.getEntity(interaction).getName() + " [" + npc.getId() + "] - Anything you type will be heared by the NPC and possibly responded to. Words in pink are trigger words you can type");
        if (npc.getMerchantid() > 0) {
            try {
                StateManager.getInstance().getEntityManager().getLivingEntity((LivingEntity) e).say("i have a [" + ChatColor.LIGHT_PURPLE + "SHOP" + ChatColor.AQUA + "] available if you are interested in buying or selling something", getBukkitPlayer());
            } catch (CoreStateInitException cse) {
            // 
            }
        }
        for (ISoliniaNPCEventHandler eventHandler : npc.getEventHandlers()) {
            if (!eventHandler.getInteractiontype().equals(InteractionType.ITEM))
                continue;
            // See if player has any items that are wanted
            int itemId = Integer.parseInt(eventHandler.getTriggerdata());
            if (itemId == 0)
                continue;
            if (Utils.getPlayerTotalCountOfItemId(getBukkitPlayer(), itemId) < 1)
                continue;
            try {
                ISoliniaItem item = StateManager.getInstance().getConfigurationManager().getItem(itemId);
                TextComponent tc = new TextComponent();
                tc.setText(ChatColor.YELLOW + "[QUEST] ");
                TextComponent tc2 = new TextComponent();
                tc2.setText(ChatColor.GRAY + "- Click here to give " + item.getDisplayname() + ChatColor.RESET);
                tc2.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/npcgive " + itemId));
                tc.addExtra(tc2);
                getBukkitPlayer().spigot().sendMessage(tc);
            } catch (CoreStateInitException eNotInitialised) {
                continue;
            }
        }
    }
}
Also used : ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) LivingEntity(org.bukkit.entity.LivingEntity) TextComponent(net.md_5.bungee.api.chat.TextComponent) ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) ISoliniaItem(com.solinia.solinia.Interfaces.ISoliniaItem) ISoliniaNPCEventHandler(com.solinia.solinia.Interfaces.ISoliniaNPCEventHandler) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ClickEvent(net.md_5.bungee.api.chat.ClickEvent) Wolf(org.bukkit.entity.Wolf)

Example 52 with TextComponent

use of net.md_5.bungee.api.chat.TextComponent in project solinia3-core by mixxit.

the class CommandAA method onCommand.

@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    if (!(sender instanceof Player))
        return false;
    Player player = (Player) sender;
    try {
        ISoliniaPlayer solplayer = SoliniaPlayerAdapter.Adapt(player);
        player.sendMessage("Current AA Points: " + solplayer.getAAPoints());
        if (args.length < 1) {
            player.sendMessage(ChatColor.GRAY + "Insufficient arguments (list,buy)");
            return true;
        }
        switch(args[0]) {
            case "list":
                int pageno = 1;
                if (args.length > 1)
                    pageno = Integer.parseInt(args[1]);
                pageno = pageno - 1;
                int sizePerPage = 8;
                List<ISoliniaAARank> fullaaranks = solplayer.getBuyableAARanks();
                List<ISoliniaAARank> aaranks = fullaaranks.stream().skip(pageno * sizePerPage).limit(sizePerPage).collect(Collectors.toCollection(ArrayList::new));
                for (ISoliniaAARank aarank : aaranks) {
                    ISoliniaAAAbility aaAbility = StateManager.getInstance().getConfigurationManager().getAAAbility(aarank.getAbilityid());
                    if (aaAbility != null)
                        if (!aaAbility.isEnabled())
                            continue;
                    if (aarank.getCost() <= solplayer.getAAPoints()) {
                        if (solplayer.canPurchaseAlternateAdvancementRank(aaAbility, aarank)) {
                            TextComponent tc = new TextComponent();
                            tc.setText(ChatColor.LIGHT_PURPLE + aaAbility.getName() + " Rank " + aarank.getPosition() + ChatColor.RESET + " Cost: " + ChatColor.YELLOW + aarank.getCost() + ChatColor.RESET + " AA points /aa buy " + aarank.getId());
                            String details = ChatColor.GOLD + aaAbility.getName() + " Rank: " + aarank.getPosition() + ChatColor.RESET + "\n" + aarank.getDescription() + ChatColor.RESET;
                            tc.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(details).create()));
                            sender.spigot().sendMessage(tc);
                        } else {
                            TextComponent tc = new TextComponent();
                            tc.setText(ChatColor.GRAY + "[NB] " + aaAbility.getName() + " Rank " + aarank.getPosition() + ChatColor.GRAY + " Cost: " + ChatColor.GRAY + aarank.getCost() + ChatColor.GRAY + " Cannot purchase yet");
                            String details = ChatColor.GOLD + aaAbility.getName() + " Rank: " + aarank.getPosition() + ChatColor.RESET + "\n" + aarank.getDescription() + ChatColor.RESET;
                            tc.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(details).create()));
                            sender.spigot().sendMessage(tc);
                        }
                    } else {
                        TextComponent tc = new TextComponent();
                        tc.setText(ChatColor.GRAY + "[NA] " + aaAbility.getName() + " Rank " + aarank.getPosition() + ChatColor.GRAY + " Cost: " + ChatColor.RED + aarank.getCost() + ChatColor.GRAY + " Insufficient AA points");
                        String details = ChatColor.GOLD + aaAbility.getName() + " Rank: " + aarank.getPosition() + ChatColor.RESET + "\n" + aarank.getDescription() + ChatColor.RESET;
                        tc.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new ComponentBuilder(details).create()));
                        sender.spigot().sendMessage(tc);
                    }
                }
                player.sendMessage("Displayed Page " + ChatColor.GOLD + (pageno + 1) + ChatColor.RESET + "/" + ChatColor.GOLD + Math.ceil((float) fullaaranks.size() / (float) sizePerPage) + ChatColor.RESET + " (See /aa list <pageno>");
                player.sendMessage("More items may appear when you have more AA points available to spend");
                break;
            case "give":
                if (args.length < 3) {
                    player.sendMessage("That is not a valid player name and amount /aa give playername amount");
                    return true;
                }
                if (!player.isOp()) {
                    player.sendMessage("Op only command");
                    return true;
                }
                Player targetplayer = Bukkit.getPlayer(args[1]);
                if (targetplayer == null) {
                    player.sendMessage("Cannot find player");
                    return true;
                }
                int newpoints = Integer.parseInt(args[2]);
                if (newpoints < 1) {
                    player.sendMessage("Too few points never give them less than 1");
                    return true;
                }
                if (newpoints > 5) {
                    player.sendMessage("Too many points man.... never give them more than 5, its supposed to be hard to achieve");
                    return true;
                }
                ISoliniaPlayer targetsolplayer = SoliniaPlayerAdapter.Adapt(targetplayer);
                targetsolplayer.setAAPoints(targetsolplayer.getAAPoints() + newpoints);
                player.sendMessage("* Granted player " + newpoints + " aa points");
                targetplayer.sendMessage("* You have been granted " + newpoints + " AA points by Operator " + player.getName());
                break;
            case "buy":
                if (args.length < 2) {
                    player.sendMessage("That is not a valid AA rank id - /aa buy aaabilityrankid (see /aa list)");
                    return true;
                }
                int seekRankId = Integer.parseInt(args[1].toUpperCase());
                ISoliniaAARank aarank = StateManager.getInstance().getConfigurationManager().getAARank(seekRankId);
                if (aarank == null) {
                    player.sendMessage("That is not a valid AA rank id - /aa buy aaabilityrankid (see /aa list)");
                    return true;
                }
                ISoliniaAAAbility aa = StateManager.getInstance().getConfigurationManager().getAAAbility(aarank.getAbilityid());
                if (aa == null) {
                    player.sendMessage("That is not a valid AA rank id - /aa buy aaabilityrankid (see /aa list)");
                    return true;
                }
                if (!solplayer.canPurchaseAlternateAdvancementRank(aa, aarank)) {
                    player.sendMessage("You cannot buy that AA");
                    return true;
                }
                solplayer.purchaseAlternateAdvancementRank(aa, aarank);
                try {
                    ISoliniaLivingEntity solentity = SoliniaLivingEntityAdapter.Adapt(player);
                    if (player.getMaxHealth() < solentity.getMaxHP()) {
                        solplayer.updateMaxHp();
                    }
                } catch (CoreStateInitException e) {
                }
                return true;
            default:
                player.sendMessage(ChatColor.GRAY + "Invalid arguments (list,buy)");
                return true;
        }
    } catch (CoreStateInitException e) {
    }
    return true;
}
Also used : ISoliniaAARank(com.solinia.solinia.Interfaces.ISoliniaAARank) TextComponent(net.md_5.bungee.api.chat.TextComponent) HoverEvent(net.md_5.bungee.api.chat.HoverEvent) Player(org.bukkit.entity.Player) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) ISoliniaAAAbility(com.solinia.solinia.Interfaces.ISoliniaAAAbility) ComponentBuilder(net.md_5.bungee.api.chat.ComponentBuilder)

Example 53 with TextComponent

use of net.md_5.bungee.api.chat.TextComponent in project solinia3-core by mixxit.

the class CommandClaim method onCommand.

@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    try {
        if (args.length < 1) {
            sender.sendMessage(ChatColor.GRAY + "Insufficient arguments (list,claim)");
            return true;
        }
        switch(args[0]) {
            case "list":
                if (!(sender instanceof Player))
                    return false;
                Player player = (Player) sender;
                ISoliniaPlayer solplayer = SoliniaPlayerAdapter.Adapt(player);
                sender.sendMessage("Current Claims: " + solplayer.getAccountClaims().size());
                for (SoliniaAccountClaim claim : solplayer.getAccountClaims()) {
                    ISoliniaItem item = StateManager.getInstance().getConfigurationManager().getItem(claim.getItemid());
                    if (item == null)
                        continue;
                    TextComponent tc = new TextComponent();
                    tc.setText(ChatColor.LIGHT_PURPLE + item.getDisplayname() + " /claim claim " + claim.getId());
                    tc.setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_ITEM, new ComponentBuilder(item.asJsonString()).create()));
                    sender.spigot().sendMessage(tc);
                }
                return true;
            case "give":
                if (!sender.isOp())
                    return false;
                if (args.length < 3) {
                    sender.sendMessage("That is not a claim id - /claim give mcaccountname itemid");
                    return true;
                }
                String mcaccountname = args[1];
                int itemId = Integer.parseInt(args[2].toUpperCase());
                SoliniaAccountClaim newclaim = new SoliniaAccountClaim();
                newclaim.setId(StateManager.getInstance().getConfigurationManager().getNextAccountClaimId());
                newclaim.setMcname(mcaccountname);
                newclaim.setItemid(itemId);
                newclaim.setClaimed(false);
                StateManager.getInstance().getConfigurationManager().addAccountClaim(newclaim);
                sender.sendMessage("Account claim added!");
                return true;
            case "claim":
                if (!(sender instanceof Player))
                    return false;
                Player claimPlayer = (Player) sender;
                ISoliniaPlayer solClaimPlayer = SoliniaPlayerAdapter.Adapt(claimPlayer);
                sender.sendMessage("Current Claims: " + solClaimPlayer.getAccountClaims().size());
                if (args.length < 2) {
                    sender.sendMessage("That is not a claim id - /claim claim claimid (see /claim list)");
                    return true;
                }
                int seekClaimId = Integer.parseInt(args[1].toUpperCase());
                System.out.println("Looking up claims for player name: " + claimPlayer.getName() + " for claim ID: " + seekClaimId);
                SoliniaAccountClaim claim = StateManager.getInstance().getConfigurationManager().getAccountClaim(claimPlayer.getName().toUpperCase(), seekClaimId);
                if (claim == null) {
                    sender.sendMessage("That is not a valid claim - /claim claim claimid (see /claim list)");
                    return true;
                }
                ISoliniaItem item = StateManager.getInstance().getConfigurationManager().getItem(claim.getItemid());
                if (item == null) {
                    sender.sendMessage("That is not a valid claim item - /claim claim claimid (see /claim list)");
                    return true;
                }
                claimPlayer.getWorld().dropItemNaturally(claimPlayer.getLocation(), item.asItemStack());
                sender.sendMessage("Claim item dropped at your feet - ID: " + claim.getId());
                StateManager.getInstance().getConfigurationManager().removeClaim(claim.getId());
                return true;
            default:
                sender.sendMessage(ChatColor.GRAY + "Invalid arguments (list,claim)");
                return true;
        }
    } catch (CoreStateInitException e) {
    }
    return true;
}
Also used : SoliniaAccountClaim(com.solinia.solinia.Models.SoliniaAccountClaim) TextComponent(net.md_5.bungee.api.chat.TextComponent) HoverEvent(net.md_5.bungee.api.chat.HoverEvent) Player(org.bukkit.entity.Player) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) ISoliniaItem(com.solinia.solinia.Interfaces.ISoliniaItem) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) ComponentBuilder(net.md_5.bungee.api.chat.ComponentBuilder)

Example 54 with TextComponent

use of net.md_5.bungee.api.chat.TextComponent 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 55 with TextComponent

use of net.md_5.bungee.api.chat.TextComponent in project solinia3-core by mixxit.

the class SoliniaLivingEntity method tryCriticalHit.

private DamageHitInfo tryCriticalHit(ISoliniaLivingEntity defender, DamageHitInfo hit) {
    if (defender == null)
        return hit;
    if (hit.damage_done < 1)
        return hit;
    String className = "UNKNOWN";
    if (getClassObj() != null) {
        className = getClassObj().getName();
    }
    // TODO Slay Undead AA
    // 2: Try Melee Critical
    boolean innateCritical = false;
    int critChance = Utils.getCriticalChanceBonus(this, hit.skill);
    if ((className.equals("WARRIOR") || className.equals("BERSERKER")) && getLevel() >= 12)
        innateCritical = true;
    else if (className.equals("RANGER") && getLevel() >= 12 && hit.skill.equals("ARCHERY"))
        innateCritical = true;
    else if (className.equals("ROGUE") && getLevel() >= 12 && hit.skill.equals("THROWING"))
        innateCritical = true;
    // we have a chance to crit!
    if (innateCritical || critChance > 0) {
        int difficulty = 0;
        if (hit.skill.equals("ARCHERY"))
            difficulty = 3400;
        else if (hit.skill.equals("THROWING"))
            difficulty = 1100;
        else
            difficulty = 8900;
        // attacker.sendMessage("You have a chance to cause a critical (Diffulty dice
        // roll: " + difficulty);
        int roll = Utils.RandomBetween(1, difficulty);
        // attacker.sendMessage("Critical chance roll ended up as: " + roll);
        int dex_bonus = getDexterity();
        if (dex_bonus > 255)
            dex_bonus = 255 + ((dex_bonus - 255) / 5);
        dex_bonus += 45;
        // so if we have an innate crit we have a better chance, except for ber throwing
        if (!innateCritical || (className.equals("BERSERKER") && hit.skill.equals("THROWING")))
            dex_bonus = dex_bonus * 3 / 5;
        if (critChance > 0)
            dex_bonus += dex_bonus * critChance / 100;
        // check if we crited
        if (roll < dex_bonus) {
            // TODO: Finishing Blow
            // step 2: calculate damage
            hit.damage_done = Math.max(hit.damage_done, hit.base_damage) + 5;
            // attacker.sendMessage("Taking the maximum out of damageDone: " + damageDone +
            // " vs baseDamage: " + baseDamage + " adding 5 to it");
            double og_damage = hit.damage_done;
            int crit_mod = 170 + Utils.getCritDmgMod(hit.skill);
            if (crit_mod < 100) {
                crit_mod = 100;
            }
            // attacker.sendMessage("Crit mod was: " + crit_mod);
            hit.damage_done = hit.damage_done * crit_mod / 100;
            // attacker.sendMessage("DamageDone was calculated at: " + damageDone);
            // TODO Spell bonuses && holyforge
            double totalCritBonus = (hit.damage_done - hit.base_damage);
            DecimalFormat df = new DecimalFormat();
            df.setMaximumFractionDigits(2);
            // Berserker
            if (isBerserk()) {
                hit.damage_done += og_damage * 119 / 100;
                // attacker.sendMessage("You are also berserker: damageDone now is: " +
                // damageDone);
                // attacker.sendMessage("* Your berserker status causes a critical blow!");
                totalCritBonus = (hit.damage_done - hit.base_damage);
                if (getBukkitLivingEntity() instanceof Player) {
                    ((Player) getBukkitLivingEntity()).spigot().sendMessage(ChatMessageType.ACTION_BAR, new TextComponent("* Your berserker status causes additional critical blow damage [" + df.format(totalCritBonus) + "]!"));
                }
                return hit;
            }
            if (getBukkitLivingEntity() instanceof Player) {
                ((Player) getBukkitLivingEntity()).spigot().sendMessage(ChatMessageType.ACTION_BAR, new TextComponent("You scored additional critical damage! [" + df.format(totalCritBonus) + "]"));
            }
            // attacker.sendMessage("* Your score a critical hit (" + damageDone + ")!");
            return hit;
        }
    }
    return hit;
}
Also used : TextComponent(net.md_5.bungee.api.chat.TextComponent) Player(org.bukkit.entity.Player) ISoliniaPlayer(com.solinia.solinia.Interfaces.ISoliniaPlayer) DecimalFormat(java.text.DecimalFormat)

Aggregations

TextComponent (net.md_5.bungee.api.chat.TextComponent)78 ClickEvent (net.md_5.bungee.api.chat.ClickEvent)21 HoverEvent (net.md_5.bungee.api.chat.HoverEvent)15 Player (org.bukkit.entity.Player)14 CoreStateInitException (com.solinia.solinia.Exceptions.CoreStateInitException)12 ComponentBuilder (net.md_5.bungee.api.chat.ComponentBuilder)12 ProxiedPlayer (net.md_5.bungee.api.connection.ProxiedPlayer)12 ISoliniaPlayer (com.solinia.solinia.Interfaces.ISoliniaPlayer)11 ArrayList (java.util.ArrayList)11 IOException (java.io.IOException)6 BaseComponent (net.md_5.bungee.api.chat.BaseComponent)6 Configuration (net.md_5.bungee.config.Configuration)6 YamlConfiguration (net.md_5.bungee.config.YamlConfiguration)6 ISoliniaItem (com.solinia.solinia.Interfaces.ISoliniaItem)5 ChatColor (net.md_5.bungee.api.ChatColor)5 ItemStack (org.bukkit.inventory.ItemStack)5 ISoliniaLivingEntity (com.solinia.solinia.Interfaces.ISoliniaLivingEntity)4 ISoliniaSpell (com.solinia.solinia.Interfaces.ISoliniaSpell)4 DecimalFormat (java.text.DecimalFormat)4 HashMap (java.util.HashMap)4