diff --git a/CHANGELOG b/CHANGELOG index 13f7467ac..7916c5182 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -63,4 +63,6 @@ - Quest point cape/hood no longer unequip on login if wearing QP hood - Random Event Genie lamps now scale exp correctly - Void mace now consumes runes correctly -- Add remote kicking support to the Management Server \ No newline at end of file +- Add remote kicking support to the Management Server +- Added Christmas Event :) +< --- ABOVE Released December 4, 2021 https://gitlab.com/2009scape/2009scape/-/tags/Dec-4-2021 ---- > \ No newline at end of file diff --git a/Server/src/main/java/plugin/drops/mystery_box/MysteryBoxPlugin.java b/Server/src/main/java/plugin/drops/mystery_box/MysteryBoxPlugin.java deleted file mode 100644 index c22513b22..000000000 --- a/Server/src/main/java/plugin/drops/mystery_box/MysteryBoxPlugin.java +++ /dev/null @@ -1,84 +0,0 @@ -package plugin.drops.mystery_box; - -import core.cache.def.impl.ItemDefinition; -import core.game.interaction.OptionHandler; -import core.game.node.Node; -import core.game.node.entity.player.Player; -import core.game.node.item.Item; -import core.game.node.item.WeightedChanceItem; -import core.plugin.Plugin; -import core.plugin.PluginManifest; -import org.rs09.consts.Items; -import core.tools.RandomFunction; -import core.plugin.Initializable; -import core.tools.StringUtils; - -/** - * Handles the mystery box item. - * @author Ceikry - */ -@Initializable -@PluginManifest(name="MysteryBox") -public final class MysteryBoxPlugin extends OptionHandler { - - /** - * The rewards recieved from a mystery box. - */ - private static final WeightedChanceItem[] REWARDS = new WeightedChanceItem[] { - - new WeightedChanceItem(Items.UNCUT_DIAMOND_1617,1,10), - new WeightedChanceItem(Items.UNCUT_RUBY_1619,1,50), - new WeightedChanceItem(Items.UNCUT_SAPPHIRE_1623,1,60), - new WeightedChanceItem(Items.UNCUT_JADE_1627,1,150), - new WeightedChanceItem(Items.UNCUT_DRAGONSTONE_1631,1,1), - new WeightedChanceItem(Items.MOLTEN_GLASS_1776,25,5), - new WeightedChanceItem(Items.UNCUT_EMERALD_1621,1,60), - new WeightedChanceItem(Items.COINS_995,25,30), - new WeightedChanceItem(Items.COINS_995,250,50), - new WeightedChanceItem(Items.COINS_995,10,80), - new WeightedChanceItem(0,1,100), - new WeightedChanceItem(Items.UNCUT_OPAL_1625,1,150), - new WeightedChanceItem(Items.VIAL_OF_WATER_228,10,25), - new WeightedChanceItem(Items.VARROCK_TELEPORT_8007,10,5), - new WeightedChanceItem(Items.FALADOR_TELEPORT_8009,10,5) - }; - - @Override - public Plugin newInstance(Object arg) throws Throwable { - ItemDefinition.forId(6199).getHandlers().put("option:open", this); - return this; - } - - @Override - public boolean handle(Player player, Node node, String option) { - final Item item = RandomFunction.rollWeightedChanceTable(REWARDS); - String name = item.getName().toLowerCase(); - if(item.getId() == 0){ - name = "nothing"; - } - final Item box = (Item) node; - if (player.getInventory().remove(box, box.getSlot(), true)) { - String message; - player.lock(1); - if(name.equals("notithing")){ - message = "Inside the box you find nothing :("; - } else { - if(item.getAmount() > 1 && item.getId() != 995){ - name = name + "s"; - } - message = "Inside the box you find " + (item.getAmount() > 1 ? "some" : (StringUtils.isPlusN(name) ? "an" : "a")) + " " + name + "!"; - } - player.sendMessage(message); - if(item.getId() != 0) - player.getInventory().add(item); - } - return true; - } - - - @Override - public boolean isWalk() { - return false; - } - -} diff --git a/Server/src/main/kotlin/rs09/game/content/global/worldevents/holiday/christmas/GiftRollPlugin.kt b/Server/src/main/kotlin/rs09/game/content/global/worldevents/holiday/christmas/GiftRollPlugin.kt new file mode 100644 index 000000000..884f6c3f8 --- /dev/null +++ b/Server/src/main/kotlin/rs09/game/content/global/worldevents/holiday/christmas/GiftRollPlugin.kt @@ -0,0 +1,109 @@ +package rs09.game.content.global.worldevents.holiday.christmas + +import api.Container +import api.ContentAPI +import core.game.node.entity.player.Player +import core.game.node.entity.skill.Skills +import core.plugin.Initializable +import core.tools.RandomFunction +import org.rs09.consts.Items +import rs09.ServerStore +import rs09.ServerStore.getInt +import rs09.game.content.global.WeightBasedTable +import rs09.game.content.global.WeightedItem +import rs09.game.interaction.InteractionListener +import rs09.game.system.SystemLogger +import rs09.plugin.CorePluginTypes.XPGainPlugin +import rs09.tools.stringtools.colorize +import java.time.Month +import java.util.* + +@Initializable +class GiftRollPlugin : XPGainPlugin() { + override fun run(player: Player, skill: Int, amount: Double) { + val numDaily = getDailyGifts(player) + + val cooldown = player.getAttribute("christmas-cooldown", 0L) + if(System.currentTimeMillis() < cooldown) return + player.setAttribute("/save:christmas-cooldown", System.currentTimeMillis() + 5000L) + + if(System.currentTimeMillis() > cooldown && numDaily < 10 && RandomFunction.roll(15).also { player.debug("Rolling gift: $it") } && amount > 20) { + incrementDailyGifts(player) + + ContentAPI.addItemOrDrop(player, Items.MYSTERY_BOX_6199) + ContentAPI.sendMessage(player, colorize("%RMerry Christmas! %GYou randomly receive a mystery box while training ${Skills.SKILL_NAME[skill]}!")) + } + } + + private fun getDailyGifts(player: Player) : Int { + return ServerStore.getArchive("daily-xmas-gifts").getInt(player.name) + } + + fun incrementDailyGifts(player: Player) { + val start = getDailyGifts(player) + ServerStore.getArchive("daily-xmas-gifts")[player.name] = start + 1 + } + + override fun fireEvent(identifier: String?, vararg args: Any?): Any { + return Unit + } +} + +class XMASMboxHandler : InteractionListener() { + val MBOX = Items.MYSTERY_BOX_6199 + + override fun defineListeners() { + //disable if it's not december. + //Calendar.MONTH is 0-indexed, Month is 1-indexed. I know. It's dumb. Thanks oracle. + if(Calendar.getInstance().get(Calendar.MONTH) + 1 != Month.DECEMBER.value){ + SystemLogger.logInfo("${Calendar.getInstance().get(Calendar.MONTH)} - ${Month.DECEMBER.value}") + return + } + + on(MBOX, ITEM, "open"){player, used -> + val item = MBOX_LOOT.roll().first() + + if(ContentAPI.removeItem(player, used, Container.INVENTORY)) { + ContentAPI.sendDialogue(player, "You open the gift and find ${item.amount} ${item.name}!") + ContentAPI.addItemOrDrop(player, item.id, item.amount) + } + return@on true + } + } + + val MBOX_LOOT = WeightBasedTable.create( + WeightedItem(Items.TOY_HORSEY_2520, 1, 1, 0.025), + WeightedItem(Items.TOY_HORSEY_2522, 1, 1, 0.025), + WeightedItem(Items.TOY_HORSEY_2524, 1, 1, 0.025), + WeightedItem(Items.TOY_HORSEY_2526, 1, 1, 0.025), + WeightedItem(Items.TOY_KITE_12844, 1, 1, 0.025), + WeightedItem(Items.COAL_453, 1, 1, 0.025), + WeightedItem(Items.MOLTEN_GLASS_1776, 25, 100, 0.25), + WeightedItem(Items.FLAX_1780, 15, 70, 0.25), + WeightedItem(Items.UNCUT_SAPPHIRE_1624, 1, 5, 0.15), + WeightedItem(Items.UNCUT_EMERALD_1622, 1, 5, 0.15), + WeightedItem(Items.UNCUT_RUBY_1620, 1, 5, 0.15), + WeightedItem(Items.UNCUT_DIAMOND_1618, 1, 5, 0.15), + WeightedItem(Items.UNCUT_SAPPHIRE_1624, 100, 100, 0.0015), + WeightedItem(Items.UNCUT_EMERALD_1622, 100, 100, 0.0015), + WeightedItem(Items.UNCUT_RUBY_1620, 100, 100, 0.0015), + WeightedItem(Items.UNCUT_DIAMOND_1618, 100, 100, 0.0015), + WeightedItem(Items.PURE_ESSENCE_7937, 1, 50, 0.15), + WeightedItem(Items.PURE_ESSENCE_7937, 1000, 1000, 0.0015), + WeightedItem(Items.RANARR_SEED_5295, 1, 3, 0.065), + WeightedItem(Items.SNAPDRAGON_SEED_5300, 1, 3, 0.065), + WeightedItem(Items.GOLD_CHARM_12158, 1, 15, 0.15), + WeightedItem(Items.CRIMSON_CHARM_12160, 1, 15, 0.15), + WeightedItem(Items.BLUE_CHARM_12163, 1, 15, 0.15), + WeightedItem(Items.GREEN_CHARM_12159, 1, 15, 0.15), + WeightedItem(Items.SPIRIT_SHARDS_12183, 1, 100, 0.15), + WeightedItem(Items.PURPLE_SWEETS_10476, 1, 15, 0.25), + WeightedItem(Items.COINS_995, 100, 1000, 0.15), + WeightedItem(Items.COINS_995, 50000, 100000, 0.0015), + WeightedItem(Items.COINS_995, 1000000, 1000000, 0.0005), + WeightedItem(Items.NATURE_RUNE_561, 1, 10, 0.15), + WeightedItem(Items.ABYSSAL_WHIP_4151, 1, 1, 0.00005), + WeightedItem(Items.SANTA_HAT_1050, 1, 1, 0.00005), + + ).insertEasyClue(0.075).insertMediumClue(0.05).insertHardClue(0.025).insertRDTRoll(0.015) +} \ No newline at end of file