use of gg.projecteden.nexus.models.perkowner.PerkOwnerService in project Nexus by ProjectEdenGG.
the class MinigamesCommand method getTokens.
@Path("tokens [user]")
void getTokens(@Arg("self") Nerd nerd) {
PerkOwnerService service = new PerkOwnerService();
PerkOwner perkOwner = service.get(nerd);
String username = nerd.getUuid().equals(player().getUniqueId()) ? "You have" : (perkOwner.getNickname() + " has");
send(PREFIX + username + " " + perkOwner.getTokens() + plural(" token", perkOwner.getTokens()));
}
use of gg.projecteden.nexus.models.perkowner.PerkOwnerService in project Nexus by ProjectEdenGG.
the class BankCommand method wallet.
@Path("[player]")
@Description("Displays all currencies owned by the player")
void wallet(@Arg("self") Nerd nerd) {
send(PREFIX + "&e" + nerd.getNickname() + "&3's Wallet: ");
// Store Credit
Contributor contributor = new ContributorService().get(nerd);
send("&3Store Credit: &e" + contributor.getCreditFormatted());
// Vote Points
Voter voter = new VoterService().get(nerd);
send("&3Vote Points: &e" + voter.getPoints());
// Event Store
EventUser eventUser = new EventUserService().get(nerd);
send("&3Event Tokens: &e" + eventUser.getTokens());
// Minigames
PerkOwner perkOwner = new PerkOwnerService().get(nerd);
send("&3Minigame Tokens: &e" + perkOwner.getTokens());
// Economy
send("&3Economy Balances: &e");
Banker banker = new BankerService().get(nerd);
Map<ShopGroup, BigDecimal> balances = banker.getBalances();
for (ShopGroup shopGroup : balances.keySet()) {
String name = StringUtils.camelCase(shopGroup);
String bal = banker.getBalanceFormatted(shopGroup);
send("&3 - " + name + ": &e" + bal);
}
line();
}
use of gg.projecteden.nexus.models.perkowner.PerkOwnerService in project Nexus by ProjectEdenGG.
the class CategoryMenu method init.
@Override
public void init(Player player, InventoryContents contents) {
addBackItem(contents, 1, 1, $ -> new PerkMenu().open(player));
if (menu.equals(BuyPerksMenu.class)) {
PerkOwner perkOwner = new PerkOwnerService().get(player);
contents.set(0, 8, ClickableItem.empty(new ItemBuilder(Material.EMERALD).name("&2&lBalance").lore("&f" + FORMATTER.format(perkOwner.getTokens()) + plural(" token", perkOwner.getTokens())).build()));
}
int col = 2;
for (PerkCategory perkCategory : PerkCategory.values()) {
contents.set(1, col, ClickableItem.from(perkCategory.getMenuItem(), $ -> {
try {
menu.getConstructor(PerkCategory.class).newInstance(perkCategory).open(player);
} catch (Exception e) {
throw new RuntimeException("Could not open menu");
}
}));
col += 1;
}
}
use of gg.projecteden.nexus.models.perkowner.PerkOwnerService in project Nexus by ProjectEdenGG.
the class PerkMenu method init.
@Override
public void init(Player player, InventoryContents contents) {
ClickableItem yourPerks = ClickableItem.from(new ItemBuilder(Material.PLAYER_HEAD).skullOwner(player).name("&6&lYour Perks").build(), e -> new CategoryMenu<>(PlayerPerksMenu.class).open(player));
ClickableItem buyPerks = ClickableItem.from(new ItemBuilder(Material.EMERALD).name("&a&lBuy Perks").build(), e -> new CategoryMenu<>(BuyPerksMenu.class).open(player));
contents.set(SlotPos.of(1, 3), yourPerks);
contents.set(SlotPos.of(1, 5), buyPerks);
PerkOwner perkOwner = new PerkOwnerService().get(player);
contents.set(0, 8, ClickableItem.empty(new ItemBuilder(Material.EMERALD).name("&2&lBalance").lore("&f" + FORMATTER.format(perkOwner.getTokens()) + plural(" token", perkOwner.getTokens())).build()));
}
use of gg.projecteden.nexus.models.perkowner.PerkOwnerService in project Nexus by ProjectEdenGG.
the class MultiplayerMechanic method giveRewards.
public final void giveRewards(@NotNull Match match) {
PerkOwnerService service = new PerkOwnerService();
if (RandomUtils.randomInt(1, 50) == 1) {
List<Minigamer> minigamers = new ArrayList<>(match.getMinigamers());
Collections.shuffle(minigamers);
// iterates until we find a player who is missing at least 1 collectible
for (Minigamer minigamer : minigamers) {
PerkOwner perkOwner = service.get(minigamer.getPlayer());
if (LocalDate.now().isBefore(perkOwner.getRandomGiftDate().plusWeeks(1)))
continue;
// get a random perk the player doesn't own
Map<PerkType, Double> weights = new HashMap<>();
List<PerkType> unownedPerks = Arrays.stream(PerkType.values()).filter(type -> !perkOwner.getPurchasedPerks().containsKey(type)).collect(Collectors.toList());
if (unownedPerks.isEmpty())
continue;
// weights should be inverse of the cost (i.e. cheapest is most common/highest number)
int maxPrice = (int) Utils.getMax(unownedPerks, PerkType::getPrice).getValue();
int minPrice = (int) Utils.getMin(unownedPerks, PerkType::getPrice).getValue();
unownedPerks.forEach(perkType -> weights.put(perkType, (double) (maxPrice - perkType.getPrice() + minPrice)));
PerkType perkType = RandomUtils.getWeightedRandom(weights);
// failsafe (this shouldn't happen but just in case)
if (perkType == null)
continue;
perkOwner.getPurchasedPerks().put(perkType, false);
perkOwner.setRandomGiftDate(LocalDate.now());
service.save(perkOwner);
Minigames.broadcast("&e" + minigamer.getNickname() + "&3 randomly won the collectible &e" + perkType.getPerk().getName());
break;
}
}
match.getMinigamers().forEach(minigamer -> {
PerkOwner perkOwner = new PerkOwnerService().get(minigamer.getPlayer());
// max of 1 in 2 chance of getting a reward (dependant on score)
int multiplier = getMultiplier(match, minigamer);
if (multiplier == 0)
return;
if (RandomUtils.randomInt(1, 2 * multiplier) == 1)
perkOwner.reward(match.getArena());
});
}
Aggregations