Search in sources :

Example 6 with ISoliniaAAAbility

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

the class JsonAAAbilityRepository method reload.

@Override
public void reload() {
    List<ISoliniaAAAbility> file = new ArrayList<ISoliniaAAAbility>();
    try {
        GsonBuilder gsonbuilder = new GsonBuilder();
        gsonbuilder.registerTypeAdapterFactory(new ISoliniaAARankTypeAdapterFactory(SoliniaAARank.class));
        gsonbuilder.registerTypeAdapterFactory(new ISoliniaAAEffectTypeAdapterFactory(SoliniaAAEffect.class));
        Gson gson = gsonbuilder.create();
        BufferedReader br = new BufferedReader(new FileReader(filePath));
        file = gson.fromJson(br, new TypeToken<List<SoliniaAAAbility>>() {
        }.getType());
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
    aaabilities.clear();
    for (ISoliniaAAAbility i : file) {
        aaabilities.put(i.getId(), i);
    }
    System.out.println("Reloaded " + aaabilities.size() + " AA abilities");
}
Also used : GsonBuilder(com.google.gson.GsonBuilder) ArrayList(java.util.ArrayList) FileNotFoundException(java.io.FileNotFoundException) Gson(com.google.gson.Gson) ISoliniaAARankTypeAdapterFactory(com.solinia.solinia.Factories.ISoliniaAARankTypeAdapterFactory) SoliniaAAEffect(com.solinia.solinia.Models.SoliniaAAEffect) ISoliniaAAEffectTypeAdapterFactory(com.solinia.solinia.Factories.ISoliniaAAEffectTypeAdapterFactory) SoliniaAARank(com.solinia.solinia.Models.SoliniaAARank) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) ArrayList(java.util.ArrayList) List(java.util.List) ISoliniaAAAbility(com.solinia.solinia.Interfaces.ISoliniaAAAbility)

Example 7 with ISoliniaAAAbility

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

the class CommandEditAA 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 aaid = Integer.parseInt(args[0]);
    if (args.length == 1) {
        try {
            ISoliniaAAAbility aaability = StateManager.getInstance().getConfigurationManager().getAAAbility(aaid);
            if (aaability != null) {
                aaability.sendAASettingsToSender(sender);
            } else {
                sender.sendMessage("aaid doesnt exist");
            }
            return true;
        } catch (CoreStateInitException e) {
            sender.sendMessage(e.getMessage());
        }
    }
    if (args.length < 3) {
        sender.sendMessage("Insufficient arguments: aaid setting value");
        return false;
    }
    String setting = args[1];
    String value = args[2];
    if (aaid < 1) {
        sender.sendMessage("Invalid aaid");
        return false;
    }
    try {
        if (StateManager.getInstance().getConfigurationManager().getAAAbility(aaid) == null) {
            sender.sendMessage("Cannot locate aaid: " + aaid);
            return false;
        }
        StateManager.getInstance().getConfigurationManager().editAAAbility(aaid, setting, value);
        sender.sendMessage("Updating setting on aaability");
    } catch (InvalidAASettingException ne) {
        sender.sendMessage("Invalid aaability setting: " + ne.getMessage());
    } catch (CoreStateInitException e) {
        // TODO Auto-generated catch block
        sender.sendMessage(e.getMessage());
    }
    return true;
}
Also used : InvalidAASettingException(com.solinia.solinia.Exceptions.InvalidAASettingException) Player(org.bukkit.entity.Player) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) CommandSender(org.bukkit.command.CommandSender) ISoliniaAAAbility(com.solinia.solinia.Interfaces.ISoliniaAAAbility)

Example 8 with ISoliniaAAAbility

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

the class SoliniaPlayer method checkDoesntFizzle.

@Override
public boolean checkDoesntFizzle(ISoliniaSpell spell) {
    if (getBukkitPlayer().isOp())
        return true;
    // todo fizzle free features
    int no_fizzle_level = 0;
    ISoliniaAAAbility aa = null;
    int rank = 0;
    try {
        aa = StateManager.getInstance().getConfigurationManager().getFirstAAAbilityBySysname("SPELLCASTINGEXPERTISE");
    } catch (CoreStateInitException e) {
    }
    if (aa != null) {
        rank = Utils.getRankOfAAAbility(getBukkitPlayer(), aa);
        switch(rank) {
            case 1:
                no_fizzle_level = 20;
                break;
            case 2:
                no_fizzle_level += 35;
                break;
            case 3:
                no_fizzle_level += 52;
                break;
        }
    }
    if (spell.getMinLevelClass(getClassObj().getName()) < no_fizzle_level) {
        return true;
    }
    try {
        ISoliniaLivingEntity entity = SoliniaLivingEntityAdapter.Adapt(getBukkitPlayer());
        if (entity == null)
            return false;
        if (getClassObj() == null)
            return false;
        // TODO item/aa/spells fizzle bonus
        int par_skill = 0;
        int act_skill = 0;
        int minLevel = 0;
        for (SoliniaSpellClass spellClass : spell.getAllowedClasses()) {
            if (!spellClass.getClassname().toUpperCase().equals(getClassObj().getName().toUpperCase()))
                continue;
            minLevel = spellClass.getMinlevel();
            break;
        }
        par_skill = minLevel * 5 - 10;
        if (par_skill > 235)
            par_skill = 235;
        par_skill += minLevel;
        SoliniaPlayerSkill playerSkill = getSkill(Utils.getSkillType(spell.getSkill()).name().toUpperCase());
        if (playerSkill != null)
            act_skill = playerSkill.getValue();
        act_skill += getLevel();
        // todo: spell specialisation
        int specialisation = 0;
        float diff = par_skill + (float) (spell.getBasediff()) - act_skill;
        if (getClassObj().getName().equals("BARD")) {
            diff -= (entity.getCharisma() - 110) / 20.0;
        } else if (Utils.getCasterClass(getClassObj().getName().toUpperCase()).equals("W")) {
            diff -= (entity.getWisdom() - 125) / 20.0;
        } else if (Utils.getCasterClass(getClassObj().getName().toUpperCase()).equals("I")) {
            diff -= (entity.getIntelligence() - 125) / 20.0;
        }
        float basefizzle = 10;
        float fizzlechance = (float) (basefizzle - specialisation + diff / 5.0);
        // always at least 1% chance to fail or 5% to succeed
        fizzlechance = fizzlechance < 1 ? 1 : (fizzlechance > 95 ? 95 : fizzlechance);
        float fizzle_roll = Utils.RandomBetween(0, 100);
        // fizzlechance);
        if (fizzle_roll > fizzlechance)
            return true;
    } catch (CoreStateInitException e) {
        return false;
    }
    return false;
}
Also used : ISoliniaLivingEntity(com.solinia.solinia.Interfaces.ISoliniaLivingEntity) CoreStateInitException(com.solinia.solinia.Exceptions.CoreStateInitException) ISoliniaAAAbility(com.solinia.solinia.Interfaces.ISoliniaAAAbility)

Example 9 with ISoliniaAAAbility

use of com.solinia.solinia.Interfaces.ISoliniaAAAbility 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)

Aggregations

ISoliniaAAAbility (com.solinia.solinia.Interfaces.ISoliniaAAAbility)9 CoreStateInitException (com.solinia.solinia.Exceptions.CoreStateInitException)6 ISoliniaPlayer (com.solinia.solinia.Interfaces.ISoliniaPlayer)3 ISoliniaAARank (com.solinia.solinia.Interfaces.ISoliniaAARank)2 ISoliniaLivingEntity (com.solinia.solinia.Interfaces.ISoliniaLivingEntity)2 ArrayList (java.util.ArrayList)2 Player (org.bukkit.entity.Player)2 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 InvalidAASettingException (com.solinia.solinia.Exceptions.InvalidAASettingException)1 ISoliniaAAEffectTypeAdapterFactory (com.solinia.solinia.Factories.ISoliniaAAEffectTypeAdapterFactory)1 ISoliniaAARankTypeAdapterFactory (com.solinia.solinia.Factories.ISoliniaAARankTypeAdapterFactory)1 SoliniaAAEffect (com.solinia.solinia.Models.SoliniaAAEffect)1 SoliniaAARank (com.solinia.solinia.Models.SoliniaAARank)1 BufferedReader (java.io.BufferedReader)1 FileNotFoundException (java.io.FileNotFoundException)1 FileReader (java.io.FileReader)1 List (java.util.List)1 ComponentBuilder (net.md_5.bungee.api.chat.ComponentBuilder)1 HoverEvent (net.md_5.bungee.api.chat.HoverEvent)1