Search in sources :

Example 1 with RewardType

use of au.com.mineauz.minigames.minigame.reward.RewardType in project Minigames by AddstarMC.

the class StandardRewardScheme method giveRewards.

private void giveRewards(List<RewardType> rewards, MinigamePlayer player) {
    for (RewardType reward : rewards) {
        if (reward != null) {
            MinigameUtils.debugMessage("Giving " + player.getName() + " " + reward.getName() + " reward type.");
            reward.giveReward(player);
        }
    }
}
Also used : RewardType(au.com.mineauz.minigames.minigame.reward.RewardType)

Example 2 with RewardType

use of au.com.mineauz.minigames.minigame.reward.RewardType in project Minigames by AddstarMC.

the class RewardSign method signUse.

@Override
public boolean signUse(Sign sign, MinigamePlayer player) {
    Location loc = sign.getLocation();
    if (!MinigameUtils.isMinigameTool(player.getPlayer().getInventory().getItemInMainHand())) {
        String label = sign.getLine(2).toLowerCase();
        if (player.isInMinigame()) {
            if (!player.hasTempClaimedReward(label)) {
                if (mdata.hasRewardSign(loc)) {
                    Rewards rew = mdata.getRewardSign(loc);
                    for (RewardType r : rew.getReward()) {
                        r.giveReward(player);
                    }
                }
                player.addTempClaimedReward(label);
            }
        } else {
            if (!player.hasClaimedReward(label)) {
                if (mdata.hasRewardSign(loc)) {
                    Rewards rew = mdata.getRewardSign(loc);
                    for (RewardType r : rew.getReward()) {
                        r.giveReward(player);
                    }
                    player.updateInventory();
                }
                player.addClaimedReward(label);
            }
        }
    } else if (player.getPlayer().hasPermission("minigame.tool")) {
        Rewards rew = null;
        if (!mdata.hasRewardSign(loc)) {
            mdata.addRewardSign(loc);
        }
        rew = mdata.getRewardSign(loc);
        Menu rewardMenu = new Menu(5, getName(), player);
        rewardMenu.addItem(new MenuItemRewardGroupAdd("Add Group", MenuUtility.getCreateMaterial(), rew), 42);
        rewardMenu.addItem(new MenuItemRewardAdd("Add Item", MenuUtility.getCreateMaterial(), rew), 43);
        final MenuItemCustom mic = new MenuItemCustom("Save Rewards", MenuUtility.getSaveMaterial());
        final Location floc = loc;
        mic.setClick(object -> {
            mdata.saveRewardSign(MinigameUtils.createLocationID(floc), true);
            mic.getContainer().getViewer().sendInfoMessage("Saved rewards for this sign.");
            mic.getContainer().getViewer().getPlayer().closeInventory();
            return null;
        });
        rewardMenu.addItem(mic, 44);
        // List<String> list = new ArrayList<String>();
        // for(RewardRarity r : RewardRarity.values()){
        // list.add(r.toString());
        // }
        List<MenuItem> mi = new ArrayList<>();
        for (RewardType item : rew.getRewards()) {
            mi.add(item.getMenuItem());
        }
        List<String> des = new ArrayList<>();
        des.add("Double Click to edit");
        for (RewardGroup group : rew.getGroups()) {
            MenuItemRewardGroup rwg = new MenuItemRewardGroup(group.getName() + " Group", des, Material.CHEST, group, rew);
            mi.add(rwg);
        }
        rewardMenu.addItems(mi);
        rewardMenu.displayMenu(player);
    }
    return true;
}
Also used : Sign(org.bukkit.block.Sign) RewardType(au.com.mineauz.minigames.minigame.reward.RewardType) RewardGroup(au.com.mineauz.minigames.minigame.reward.RewardGroup) MinigamePlayer(au.com.mineauz.minigames.objects.MinigamePlayer) MinigameManager(au.com.mineauz.minigames.managers.MinigameManager) au.com.mineauz.minigames(au.com.mineauz.minigames) SignChangeEvent(org.bukkit.event.block.SignChangeEvent) ArrayList(java.util.ArrayList) List(java.util.List) Rewards(au.com.mineauz.minigames.minigame.reward.Rewards) Location(org.bukkit.Location) au.com.mineauz.minigames.menu(au.com.mineauz.minigames.menu) ChatColor(org.bukkit.ChatColor) Material(org.bukkit.Material) RewardGroup(au.com.mineauz.minigames.minigame.reward.RewardGroup) RewardType(au.com.mineauz.minigames.minigame.reward.RewardType) Rewards(au.com.mineauz.minigames.minigame.reward.Rewards) ArrayList(java.util.ArrayList) List(java.util.List) Location(org.bukkit.Location)

Example 3 with RewardType

use of au.com.mineauz.minigames.minigame.reward.RewardType in project Minigames by AddstarMC.

the class HierarchyRewardScheme method awardPlayer.

@Override
public void awardPlayer(MinigamePlayer player, StoredGameStats data, Minigame minigame, boolean firstCompletion) {
    T value = getValue(player, data, minigame);
    Rewards reward;
    TreeMap<T, Rewards> rewards = (firstCompletion ? primaryRewards : secondaryRewards);
    // Calculate rewards
    switch(comparisonType.getFlag()) {
        case Equal:
            reward = rewards.get(value);
            break;
        case Lesser:
            reward = null;
            for (Entry<T, Rewards> entry : rewards.entrySet()) {
                if (value.compareTo(entry.getKey()) < 0) {
                    reward = entry.getValue();
                    break;
                }
            }
            break;
        case Greater:
            reward = null;
            for (Entry<T, Rewards> entry : rewards.descendingMap().entrySet()) {
                if (value.compareTo(entry.getKey()) > 0) {
                    reward = entry.getValue();
                    break;
                }
            }
            break;
        default:
            throw new AssertionError();
    }
    // Apply reward
    if (reward != null) {
        List<RewardType> rewardItems = reward.getReward();
        for (RewardType item : rewardItems) {
            item.giveReward(player);
        }
    }
}
Also used : RewardType(au.com.mineauz.minigames.minigame.reward.RewardType) Rewards(au.com.mineauz.minigames.minigame.reward.Rewards)

Example 4 with RewardType

use of au.com.mineauz.minigames.minigame.reward.RewardType in project Minigames by AddstarMC.

the class TreasureHuntMechanic method spawnTreasure.

public static void spawnTreasure(final Minigame mgm) {
    final TreasureHuntModule thm = TreasureHuntModule.getMinigameModule(mgm);
    if (thm.hasTreasureLocation())
        removeTreasure(mgm);
    if (!thm.getCurrentHints().isEmpty())
        thm.clearHints();
    thm.setTreasureFound(false);
    Location tcpos = mgm.getStartLocations().get(0).clone();
    final Location rpos = tcpos;
    double rx;
    double ry;
    double rz;
    final int maxradius;
    if (thm.getMaxRadius() == 0) {
        maxradius = 1000;
    } else {
        maxradius = thm.getMaxRadius();
    }
    final int maxheight = thm.getMaxHeight();
    Random rand = new Random();
    int rrad = rand.nextInt(maxradius);
    double randCir = 2 * Math.PI * rand.nextInt(360) / 360;
    rx = tcpos.getX() - 0.5 + Math.round(rrad * Math.cos(randCir));
    rz = tcpos.getZ() - 0.5 + Math.round(rrad * Math.sin(randCir));
    ry = tcpos.getY() + rand.nextInt(maxheight);
    rpos.setX(rx);
    rpos.setY(ry);
    rpos.setZ(rz);
    // TODO: Improve so no invalid spawns (Not over void, Strict containment)
    switch(rpos.getBlock().getType()) {
        case AIR:
        case CAVE_AIR:
        case VOID_AIR:
            while (rpos.getBlock().getType() == Material.AIR && rpos.getY() > 1) {
                rpos.setY(rpos.getY() - 1);
            }
            rpos.setY(rpos.getY() + 1);
            Bukkit.getScheduler().runTaskLater(plugin, () -> rpos.getBlock().setType(Material.CHEST), 1L);
            break;
        default:
            while (rpos.getBlock().getType() != Material.AIR && rpos.getY() < 255) {
                rpos.setY(rpos.getY() + 1);
            }
            Bukkit.getScheduler().runTaskLater(plugin, () -> rpos.getBlock().setType(Material.CHEST), 1L);
            break;
    }
    // Fill new chest
    Bukkit.getScheduler().runTaskLater(plugin, () -> {
        if (rpos.getBlock().getState() instanceof Chest) {
            final Chest chest = (Chest) rpos.getBlock().getState();
            // TODO: Treasure hunt needs own rewards specification
            RewardsModule rewards = RewardsModule.getModule(mgm);
            if (rewards.getScheme() instanceof StandardRewardScheme) {
                if (!((StandardRewardScheme) rewards.getScheme()).getPrimaryReward().getRewards().isEmpty()) {
                    int numitems = (int) Math.round(Math.random() * (thm.getMaxTreasure() - thm.getMinTreasure())) + thm.getMinTreasure();
                    final ItemStack[] items = new ItemStack[27];
                    for (int i = 0; i < numitems; i++) {
                        RewardType rew = ((StandardRewardScheme) rewards.getScheme()).getPrimaryReward().getReward().get(0);
                        if (rew instanceof ItemReward) {
                            ItemReward irew = (ItemReward) rew;
                            items[i] = irew.getRewardItem();
                        }
                    }
                    Collections.shuffle(Arrays.asList(items));
                    chest.getInventory().setContents(items);
                }
            }
        }
    }, 0L);
    thm.setTreasureLocation(rpos);
    plugin.getLogger().info(MinigameUtils.formStr("minigame.treasurehunt.consSpawn", mgm.getName(false), rpos.getBlockX() + ", " + rpos.getBlockY() + ", " + rpos.getBlockZ()));
    MinigameUtils.broadcast(MinigameUtils.formStr("minigame.treasurehunt.plySpawn", maxradius, thm.getLocation()), mgm, "minigame.treasure.announce");
    mgm.setMinigameTimer(new MinigameTimer(mgm, mgm.getTimer()));
}
Also used : Chest(org.bukkit.block.Chest) ItemReward(au.com.mineauz.minigames.minigame.reward.ItemReward) MinigameTimer(au.com.mineauz.minigames.MinigameTimer) RewardsModule(au.com.mineauz.minigames.minigame.reward.RewardsModule) TreasureHuntModule(au.com.mineauz.minigames.minigame.modules.TreasureHuntModule) RewardType(au.com.mineauz.minigames.minigame.reward.RewardType) ItemStack(org.bukkit.inventory.ItemStack) StandardRewardScheme(au.com.mineauz.minigames.minigame.reward.scheme.StandardRewardScheme)

Example 5 with RewardType

use of au.com.mineauz.minigames.minigame.reward.RewardType in project Minigames by AddstarMC.

the class MenuItemRewardGroup method onDoubleClick.

@Override
public ItemStack onDoubleClick() {
    Menu rewardMenu = new Menu(5, getName(), getContainer().getViewer());
    rewardMenu.setPreviousPage(getContainer());
    List<String> des = new ArrayList<>();
    des.add("Click this with an item");
    des.add("to add it to rewards.");
    des.add("Click without an item");
    des.add("to add a money reward.");
    rewardMenu.addItem(new MenuItemRewardAdd("Add Item", des, MenuUtility.getCreateMaterial(), group), 43);
    rewardMenu.addItem(new MenuItemPage("Save " + getName(), MenuUtility.getSaveMaterial(), rewardMenu.getPreviousPage()), 44);
    // List<String> list = new ArrayList<>();
    // for(RewardRarity r : RewardRarity.values()){
    // list.add(r.toString());
    // }
    List<MenuItem> mi = new ArrayList<>();
    for (RewardType item : group.getItems()) {
        mi.add(item.getMenuItem());
    }
    rewardMenu.addItems(mi);
    rewardMenu.displayMenu(getContainer().getViewer());
    return null;
}
Also used : RewardType(au.com.mineauz.minigames.minigame.reward.RewardType) ArrayList(java.util.ArrayList)

Aggregations

RewardType (au.com.mineauz.minigames.minigame.reward.RewardType)6 Rewards (au.com.mineauz.minigames.minigame.reward.Rewards)2 ArrayList (java.util.ArrayList)2 au.com.mineauz.minigames (au.com.mineauz.minigames)1 MinigameTimer (au.com.mineauz.minigames.MinigameTimer)1 MinigameManager (au.com.mineauz.minigames.managers.MinigameManager)1 au.com.mineauz.minigames.menu (au.com.mineauz.minigames.menu)1 TreasureHuntModule (au.com.mineauz.minigames.minigame.modules.TreasureHuntModule)1 ItemReward (au.com.mineauz.minigames.minigame.reward.ItemReward)1 RewardGroup (au.com.mineauz.minigames.minigame.reward.RewardGroup)1 RewardsModule (au.com.mineauz.minigames.minigame.reward.RewardsModule)1 StandardRewardScheme (au.com.mineauz.minigames.minigame.reward.scheme.StandardRewardScheme)1 MinigamePlayer (au.com.mineauz.minigames.objects.MinigamePlayer)1 List (java.util.List)1 ChatColor (org.bukkit.ChatColor)1 Location (org.bukkit.Location)1 Material (org.bukkit.Material)1 Chest (org.bukkit.block.Chest)1 Sign (org.bukkit.block.Sign)1 SignChangeEvent (org.bukkit.event.block.SignChangeEvent)1