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);
}
}
}
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;
}
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);
}
}
}
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()));
}
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;
}
Aggregations