diff --git a/Server/src/main/java/core/cache/ServerStore.java b/Server/src/main/java/core/cache/AriosStore.java similarity index 99% rename from Server/src/main/java/core/cache/ServerStore.java rename to Server/src/main/java/core/cache/AriosStore.java index 207c511c6..45980957f 100644 --- a/Server/src/main/java/core/cache/ServerStore.java +++ b/Server/src/main/java/core/cache/AriosStore.java @@ -15,7 +15,7 @@ import core.cache.misc.buffer.ByteBufferUtils; * The server data storage. * @author Emperor */ -public final class ServerStore { +public final class AriosStore { /** * The storage. diff --git a/Server/src/main/java/core/game/content/activity/bountyhunter/BHScoreBoard.java b/Server/src/main/java/core/game/content/activity/bountyhunter/BHScoreBoard.java index 30613f9c5..5f3c1718b 100644 --- a/Server/src/main/java/core/game/content/activity/bountyhunter/BHScoreBoard.java +++ b/Server/src/main/java/core/game/content/activity/bountyhunter/BHScoreBoard.java @@ -2,7 +2,7 @@ package core.game.content.activity.bountyhunter; import java.nio.ByteBuffer; -import core.cache.ServerStore; +import core.cache.AriosStore; import core.cache.StoreFile; import core.cache.misc.buffer.ByteBufferUtils; import core.game.component.Component; @@ -53,7 +53,7 @@ public final class BHScoreBoard { * Initializes the score boards data. */ public static void init() { - StoreFile file = ServerStore.get("bh_scores"); + StoreFile file = AriosStore.get("bh_scores"); if (file == null) { // Indicates no cache exists yet. return; } @@ -82,7 +82,7 @@ public final class BHScoreBoard { ByteBufferUtils.putString(ROGUES.names[i], buffer); } buffer.flip(); - ServerStore.setArchive("bh_scores", buffer); + AriosStore.setArchive("bh_scores", buffer); } /** diff --git a/Server/src/main/java/core/game/content/holiday/ItemLimitation.java b/Server/src/main/java/core/game/content/holiday/ItemLimitation.java index 3c85a07a0..187ea676c 100644 --- a/Server/src/main/java/core/game/content/holiday/ItemLimitation.java +++ b/Server/src/main/java/core/game/content/holiday/ItemLimitation.java @@ -1,6 +1,6 @@ package core.game.content.holiday; -import core.cache.ServerStore; +import core.cache.AriosStore; import core.cache.def.impl.ItemDefinition; import java.nio.ByteBuffer; @@ -32,10 +32,10 @@ public final class ItemLimitation { * @return {@code True} if parsed. */ public boolean parse() { - if (ServerStore.get("hir_limits") == null) { + if (AriosStore.get("hir_limits") == null) { return true; } - ByteBuffer buffer = ServerStore.getArchive("hir_limits"); + ByteBuffer buffer = AriosStore.getArchive("hir_limits"); int length = buffer.get() & 0xFF; for (int i = 0; i < length; i++) { int itemId = buffer.getShort() & 0xFFFF; @@ -56,7 +56,7 @@ public final class ItemLimitation { buffer.putShort((short) (int) ITEMS.get(itemId)); } buffer.flip(); - ServerStore.setArchive("hir_limits", buffer); + AriosStore.setArchive("hir_limits", buffer); } /** diff --git a/Server/src/main/java/core/game/interaction/npc/ZaffPlugin.java b/Server/src/main/java/core/game/interaction/npc/ZaffPlugin.java deleted file mode 100644 index 757f2dfac..000000000 --- a/Server/src/main/java/core/game/interaction/npc/ZaffPlugin.java +++ /dev/null @@ -1,396 +0,0 @@ -package core.game.interaction.npc; - -import core.cache.def.impl.NPCDefinition; -import core.plugin.Initializable; -import core.game.content.dialogue.DialoguePlugin; -import core.game.content.dialogue.FacialExpression; -import core.game.interaction.OptionHandler; -import core.game.node.Node; -import core.game.node.entity.npc.NPC; -import core.game.node.entity.player.Player; -import core.game.node.entity.player.link.RunScript; -import core.game.node.entity.player.link.diary.DiaryType; -import core.game.node.entity.player.link.quest.Quest; -import core.game.node.item.Item; -import core.plugin.Plugin; - -/** - * Represents the plugin used for buying a battle staff from zeke. - * @author 'Vexia - * @version 1.0 - */ -@Initializable -public final class ZaffPlugin extends OptionHandler { - - /** - * The bacon ring. - */ - public static final Item BEACON_RING = new Item(11014); - - @Override - public Plugin newInstance(Object arg) throws Throwable { - NPCDefinition.setOptionHandler("buy-battlestaves", this); - new ZaffDialogue().init(); - new ZaffStaveDialogue().init(); - return this; - } - - @Override - public boolean handle(Player player, Node node, String option) { - player.getDialogueInterpreter().open(9679); - return true; - } - - /** - * Represents the dialogue plugin used for the zaff npc. - * @author 'Vexia - * @version 1.0 - */ - public static final class ZaffDialogue extends DialoguePlugin { - - /** - * Represents the staff item. - */ - @SuppressWarnings("unused") - private static final Item STAFF = new Item(11014, 1); - - /** - * The quest. - */ - private Quest quest; - - /** - * Constructs a new {@code ZaffDialogue} {@code Object}. - */ - public ZaffDialogue() { - /** - * empty. - */ - } - - /** - * Constructs a new {@code ZaffDialogue} {@code Object}. - * @param player the player. - */ - public ZaffDialogue(Player player) { - super(player); - } - - @Override - public DialoguePlugin newInstance(Player player) { - return new ZaffDialogue(player); - } - - @Override - public boolean open(Object... args) { - npc = (NPC) args[0]; - quest = player.getQuestRepository().getQuest("What Lies Below"); - interpreter.sendDialogues(npc, FacialExpression.HALF_GUILTY, "Would you like to buy or sell some staves or is there", "something else you need?"); - stage = 0; - return true; - } - - @Override - public boolean handle(int interfaceId, int buttonId) { - switch (stage) { - case 0: - if (quest.getStage(player) == 60) { - interpreter.sendOptions("Select an Option", "Yes, please.", "No, thank you.", "Rat Burgiss sent me."); - stage = 1; - break; - } else if (quest.getStage(player) == 80) { - interpreter.sendOptions("Select an Option", "Yes, please.", "No, thank you.", "We did it! We beat Surok!"); - stage = 1; - break; - } else if (quest.getStage(player) >= 70) { - interpreter.sendOptions("Select an Option", "Yes, please.", "No, thank you.", "Can I have another ring?"); - stage = 1; - break; - } - interpreter.sendOptions("Select an Option", "Yes, please.", "No, thank you."); - stage = 1; - break; - case 1: - switch (buttonId) { - case 1: - interpreter.sendDialogues(player, FacialExpression.HALF_GUILTY, "Yes, please."); - stage = 10; - break; - case 2: - interpreter.sendDialogues(player, FacialExpression.HALF_GUILTY, "No, thank you."); - stage = 20; - break; - case 3: - if (quest.getStage(player) == 60) { - player("Rat Burgiss sent me!"); - stage = 70; - break; - } else if (quest.getStage(player) == 80) { - player("We did it! We beat Surok!"); - stage = 200; - break; - } - interpreter.sendDialogues(player, FacialExpression.HALF_GUILTY, "Can I have another ring?"); - stage = 50; - break; - } - - break; - case 10: - end(); - npc.openShop(player); - break; - case 20: - interpreter.sendDialogues(npc, FacialExpression.HALF_GUILTY, "Well, 'stick' your head in again if you change your mind."); - stage = 21; - break; - case 21: - interpreter.sendDialogues(player, FacialExpression.HALF_GUILTY, "Huh, terrible pun. You just can't get the 'staff' these", "days!"); - stage = 22; - break; - case 22: - end(); - break; - case 50: - if (player.getInventory().contains(11014, 1)) - interpreter.sendDialogues(npc, FacialExpression.HALF_GUILTY, "Go and get the one that's in your inventory " + player.getUsername() + "!"); - else if (player.getBank().contains(11014, 1)) - interpreter.sendDialogues(npc, FacialExpression.HALF_GUILTY, "Go and get the one that's in your bank" + player.getUsername() + "!"); - else if (player.getEquipment().contains(11014, 1)) - interpreter.sendDialogues(npc, FacialExpression.HALF_GUILTY, "Go and get the one that's on your finger " + player.getUsername() + "!"); - else { - interpreter.sendDialogues(npc, FacialExpression.HALF_GUILTY, "Of course you can! Here you go " + player.getUsername() + "!"); - player.getInventory().add(BEACON_RING); - } - stage = 51; - break; - case 51: - end(); - break; - case 70: - npc("Ah, yes; You must be " + player.getUsername() + "! Rat sent word that you", "would be coming. Everything is prepared. I have created", "a spell that will remove the mind control spell."); - stage++; - break; - case 71: - player("Okay, what's the plan?"); - stage++; - break; - case 72: - npc("Listen carefully. For the spell to succeed, the king must", "be made very weak, if his mind is controlled, you will", "need to fight him until he is all but dead."); - stage++; - break; - case 73: - npc("Then and ONLY then, use your ring to summon me.", "I will teleport to you and cast the spell that will", "cure the king."); - stage++; - break; - case 74: - player("Why must I summon you? Can't you come with me?"); - stage++; - break; - case 75: - npc("I cannot. I must look after my shop here and", "I have lots to do. Rest assured, I will come when you", "summon me."); - stage++; - break; - case 76: - player("Okay, so what do I do now?"); - stage++; - break; - case 77: - npc("Take this beacon ring and some instructions."); - stage++; - break; - case 78: - npc("Once you have read the instructions. It will be time for", "you to arrest Surok."); - stage++; - break; - case 79: - player("Won't he be disinclined to acquiesce to that request?"); - stage++; - break; - case 80: - npc("Won't he what?"); - stage++; - break; - case 81: - player("Won't he refuse?"); - stage++; - break; - case 82: - npc("I very much expect so. It may turn nasty, so be on your", "guard. I hope we can stop him before he can cast his", "spell!", "Make sure you have that ring I gave you."); - stage++; - break; - case 83: - player("Okay, thanks, Zaff!"); - stage++; - break; - case 84: - player.getInventory().add(BEACON_RING); - quest.setStage(player, 70); - end(); - break; - case 200: - npc("Yes. You have done well, " + player.getUsername() + ". You are to be", "commended for you actions!"); - stage++; - break; - case 201: - player("It was all in the call of duty!"); - stage++; - break; - case 202: - player("What will happen with Surok now?"); - stage++; - break; - case 203: - npc("Well, when I disrupted Surok's spell, he will have been", "sealed in the library, but we still need to keep an", "eye on him, just in case."); - stage++; - break; - case 204: - npc("When you are ready, report back to Rat and he will", "reward you."); - stage++; - break; - case 205: - player("Okay, I will."); - stage++; - break; - case 206: - quest.setStage(player, 90); - end(); - break; - } - return true; - } - - @Override - public int[] getIds() { - return new int[] { 546 }; - } - } - - /** - * Represents the dialogue used to buy staves from zaff. - * @author 'Vexia - * @version 1.0 - */ - public final class ZaffStaveDialogue extends DialoguePlugin { - - /** - * The ammount of battlestaves. - */ - private int ammount; - - /** - * Constructs a new {@code ZaffBuyStavesDialogue} {@code Object}. - */ - public ZaffStaveDialogue() { - /** - * empty. - */ - } - - /** - * Constructs a new {@code ZaffBuyStavesDialogue} {@code Object}. - * @param player the player. - */ - public ZaffStaveDialogue(Player player) { - super(player); - } - - @Override - public DialoguePlugin newInstance(Player player) { - return new ZaffStaveDialogue(player); - } - - @Override - public boolean open(Object... args) { - interpreter.sendDialogues(player, FacialExpression.HALF_GUILTY, "Do you have any battlestaves?"); - stage = 0; - return true; - } - - @Override - public boolean handle(int interfaceId, int buttonId) { - switch (stage) { - case 0: - ammount = player.getSavedData().getGlobalData().getZaffAmount(); - if (player.getSavedData().getGlobalData().getZafTime() < System.currentTimeMillis()) { - ammount = getMaxStaffs(); - } - if (player.getSavedData().getGlobalData().getZafTime() > System.currentTimeMillis() && ammount <= 0) { - interpreter.sendDialogues(546, FacialExpression.HALF_GUILTY, "I'm very sorry! I seem to be out of battlestaves at the", "moment! I expect I'll get some more in by tomorrow,", "though."); - stage = 2; - break; - } - interpreter.sendDialogues(546, FacialExpression.HALF_GUILTY, "Battlestaves cost 8,000 gold pieces each. I have " + ammount + " left.", "How many would you like to buy?"); - stage = 1; - break; - case 1: - end(); - /*player.setAttribute("runscript", new RunScript() { - @Override - public boolean handle() { - int amt = (int) value; - if (amt > ammount) { - amt = ammount; - } - if (amt > player.getInventory().freeSlots()) { - amt = player.getInventory().freeSlots(); - } - if (amt == 0) { - return true; - } - if (7000 * amt > player.getInventory().getAmount(new Item(995))) { - player.getPacketDispatch().sendMessage("You don't have enough money to buy that many."); - return true; - } else { - Item remove = new Item(995, 7000 * amt); - if (!player.getInventory().containsItem(remove)) { - end(); - return true; - } - player.getInventory().remove(remove); - if (player.getInventory().add(new Item(1391, amt))) { - player.getSavedData().getGlobalData().setZafTime(System.currentTimeMillis() + (24 * 60 * 60 * 1000)); - player.getSavedData().getGlobalData().setZaffAmount(ammount - amt); - } - } - return true; - } - }); - interpreter.sendInput(false, "Zaff has " + ammount + " battlestaves..."); -*/ break; - //TODO: Come back and fix this later when achievement diaries can actually be completed kekkekekeke - case 2: - interpreter.sendDialogues(player, FacialExpression.HALF_GUILTY, "Oh, okay then. I'll try again another time."); - stage = 3; - break; - case 3: - end(); - break; - } - return true; - } - - /** - * Gets the max staffs to buy. - * @return the max staffs to buy. - */ - public int getMaxStaffs() { - int level = player.getAchievementDiaryManager().getDiary(DiaryType.VARROCK).getLevel(); - switch (level) { - case 2: - return 64; - case 1: - return 32; - case 0: - return 16; - default: - return 8; - } - } - - @Override - public int[] getIds() { - return new int[] { 9679 }; - } - } -} diff --git a/Server/src/main/java/core/game/interaction/npc/ZaffPlugin.kt b/Server/src/main/java/core/game/interaction/npc/ZaffPlugin.kt new file mode 100644 index 000000000..cf459799a --- /dev/null +++ b/Server/src/main/java/core/game/interaction/npc/ZaffPlugin.kt @@ -0,0 +1,456 @@ +package core.game.interaction.npc + +import api.Container +import api.ContentAPI +import api.InputType +import core.cache.def.impl.NPCDefinition +import core.plugin.Initializable +import core.game.interaction.OptionHandler +import core.plugin.Plugin +import core.game.interaction.npc.ZaffPlugin.ZaffDialogue +import core.game.interaction.npc.ZaffPlugin.ZaffStaveDialogue +import core.game.content.dialogue.DialoguePlugin +import core.game.node.entity.player.link.quest.Quest +import core.game.content.dialogue.FacialExpression +import core.game.interaction.npc.ZaffPlugin +import core.game.node.Node +import core.game.node.entity.npc.NPC +import core.game.node.entity.player.Player +import core.game.node.entity.player.link.diary.DiaryType +import core.game.node.item.Item +import org.json.simple.JSONObject +import org.rs09.consts.Items +import rs09.ServerStore +import rs09.ServerStore.getInt +import rs09.game.system.SystemLogger + +/** + * Represents the plugin used for buying a battle staff from zeke. + * @author 'Vexia + * @version 1.0 + */ +@Initializable +class ZaffPlugin : OptionHandler() { + @Throws(Throwable::class) + override fun newInstance(arg: Any?): Plugin { + NPCDefinition.setOptionHandler("buy-battlestaves", this) + ZaffDialogue().init() + ZaffStaveDialogue().init() + return this + } + + override fun handle(player: Player, node: Node, option: String): Boolean { + player.dialogueInterpreter.open(9679) + return true + } + + /** + * Represents the dialogue plugin used for the zaff npc. + * @author 'Vexia + * @version 1.0 + */ + class ZaffDialogue : DialoguePlugin { + /** + * The quest. + */ + private var quest: Quest? = null + + /** + * Constructs a new `ZaffDialogue` `Object`. + */ + constructor() { + /** + * empty. + */ + } + + /** + * Constructs a new `ZaffDialogue` `Object`. + * @param player the player. + */ + constructor(player: Player?) : super(player) {} + + override fun newInstance(player: Player?): DialoguePlugin { + return ZaffDialogue(player) + } + + override fun open(vararg args: Any): Boolean { + npc = args[0] as NPC + quest = player.questRepository.getQuest("What Lies Below") + interpreter.sendDialogues( + npc, + FacialExpression.HALF_GUILTY, + "Would you like to buy or sell some staves or is there", + "something else you need?" + ) + stage = 0 + return true + } + + override fun handle(interfaceId: Int, buttonId: Int): Boolean { + when (stage) { + 0 -> { + if (quest!!.getStage(player) == 60) { + interpreter.sendOptions( + "Select an Option", + "Yes, please.", + "No, thank you.", + "Rat Burgiss sent me." + ) + stage = 1 + } else if (quest!!.getStage(player) == 80) { + interpreter.sendOptions( + "Select an Option", + "Yes, please.", + "No, thank you.", + "We did it! We beat Surok!" + ) + stage = 1 + } else if (quest!!.getStage(player) >= 70) { + interpreter.sendOptions( + "Select an Option", + "Yes, please.", + "No, thank you.", + "Can I have another ring?" + ) + stage = 1 + } + interpreter.sendOptions("Select an Option", "Yes, please.", "No, thank you.") + stage = 1 + } + 1 -> when (buttonId) { + 1 -> { + interpreter.sendDialogues(player, FacialExpression.HALF_GUILTY, "Yes, please.") + stage = 10 + } + 2 -> { + interpreter.sendDialogues(player, FacialExpression.HALF_GUILTY, "No, thank you.") + stage = 20 + } + 3 -> { + if (quest!!.getStage(player) == 60) { + player("Rat Burgiss sent me!") + stage = 70 + } else if (quest!!.getStage(player) == 80) { + player("We did it! We beat Surok!") + stage = 200 + } + interpreter.sendDialogues(player, FacialExpression.HALF_GUILTY, "Can I have another ring?") + stage = 50 + } + } + 10 -> { + if(player.achievementDiaryManager.getDiary(DiaryType.VARROCK).levelRewarded.contains(true)){ + npcl(FacialExpression.FRIENDLY, "Would you like to hear about my battlestaves?") + stage = 1000 + } else { + end() + npc.openShop(player) + } + } + 20 -> { + interpreter.sendDialogues( + npc, + FacialExpression.HALF_GUILTY, + "Well, 'stick' your head in again if you change your mind." + ) + stage = 21 + } + 21 -> { + interpreter.sendDialogues( + player, + FacialExpression.HALF_GUILTY, + "Huh, terrible pun. You just can't get the 'staff' these", + "days!" + ) + stage = 22 + } + 22 -> end() + 50 -> { + if (player.inventory.contains(11014, 1)) interpreter.sendDialogues( + npc, + FacialExpression.HALF_GUILTY, + "Go and get the one that's in your inventory " + player.username + "!" + ) else if (player.bank.contains(11014, 1)) interpreter.sendDialogues( + npc, + FacialExpression.HALF_GUILTY, + "Go and get the one that's in your bank" + player.username + "!" + ) else if (player.equipment.contains(11014, 1)) interpreter.sendDialogues( + npc, + FacialExpression.HALF_GUILTY, + "Go and get the one that's on your finger " + player.username + "!" + ) else { + interpreter.sendDialogues( + npc, + FacialExpression.HALF_GUILTY, + "Of course you can! Here you go " + player.username + "!" + ) + player.inventory.add(BEACON_RING) + } + stage = 51 + } + 51 -> end() + 70 -> { + npc( + "Ah, yes; You must be " + player.username + "! Rat sent word that you", + "would be coming. Everything is prepared. I have created", + "a spell that will remove the mind control spell." + ) + stage++ + } + 71 -> { + player("Okay, what's the plan?") + stage++ + } + 72 -> { + npc( + "Listen carefully. For the spell to succeed, the king must", + "be made very weak, if his mind is controlled, you will", + "need to fight him until he is all but dead." + ) + stage++ + } + 73 -> { + npc( + "Then and ONLY then, use your ring to summon me.", + "I will teleport to you and cast the spell that will", + "cure the king." + ) + stage++ + } + 74 -> { + player("Why must I summon you? Can't you come with me?") + stage++ + } + 75 -> { + npc( + "I cannot. I must look after my shop here and", + "I have lots to do. Rest assured, I will come when you", + "summon me." + ) + stage++ + } + 76 -> { + player("Okay, so what do I do now?") + stage++ + } + 77 -> { + npc("Take this beacon ring and some instructions.") + stage++ + } + 78 -> { + npc("Once you have read the instructions. It will be time for", "you to arrest Surok.") + stage++ + } + 79 -> { + player("Won't he be disinclined to acquiesce to that request?") + stage++ + } + 80 -> { + npc("Won't he what?") + stage++ + } + 81 -> { + player("Won't he refuse?") + stage++ + } + 82 -> { + npc( + "I very much expect so. It may turn nasty, so be on your", + "guard. I hope we can stop him before he can cast his", + "spell!", + "Make sure you have that ring I gave you." + ) + stage++ + } + 83 -> { + player("Okay, thanks, Zaff!") + stage++ + } + 84 -> { + player.inventory.add(BEACON_RING) + quest!!.setStage(player, 70) + end() + } + 200 -> { + npc("Yes. You have done well, " + player.username + ". You are to be", "commended for you actions!") + stage++ + } + 201 -> { + player("It was all in the call of duty!") + stage++ + } + 202 -> { + player("What will happen with Surok now?") + stage++ + } + 203 -> { + npc( + "Well, when I disrupted Surok's spell, he will have been", + "sealed in the library, but we still need to keep an", + "eye on him, just in case." + ) + stage++ + } + 204 -> { + npc("When you are ready, report back to Rat and he will", "reward you.") + stage++ + } + 205 -> { + player("Okay, I will.") + stage++ + } + 206 -> { + quest!!.setStage(player, 90) + end() + } + + 1000 -> options("Yes, please.", "No, thanks.").also { stage++ } + 1001 -> when(buttonId){ + 1 -> { + end() + ContentAPI.openDialogue(player, 9679, npc) + } + 2 -> { + end() + npc.openShop(player) + } + } + } + return true + } + + override fun getIds(): IntArray { + return intArrayOf(546) + } + + companion object { + /** + * Represents the staff item. + */ + private val STAFF = Item(11014, 1) + } + } + + /** + * Represents the dialogue used to buy staves from zaff. + * @author 'Vexia + * @version 1.0 + */ + inner class ZaffStaveDialogue : DialoguePlugin { + /** + * The ammount of battlestaves. + */ + private var ammount = 0 + + /** + * Constructs a new `ZaffBuyStavesDialogue` `Object`. + */ + constructor() { + /** + * empty. + */ + } + + /** + * Constructs a new `ZaffBuyStavesDialogue` `Object`. + * @param player the player. + */ + constructor(player: Player?) : super(player) {} + + override fun newInstance(player: Player?): DialoguePlugin { + return ZaffStaveDialogue(player) + } + + override fun open(vararg args: Any): Boolean { + ammount = getStoreFile().getInt(player.username.toLowerCase()) + interpreter.sendDialogues(player, FacialExpression.HALF_GUILTY, "Do you have any battlestaves?") + stage = 0 + return true + } + + override fun handle(interfaceId: Int, buttonId: Int): Boolean { + when (stage) { + 0 -> { + if (ammount >= maxStaffs) { + interpreter.sendDialogues( + 546, + FacialExpression.HALF_GUILTY, + "I'm very sorry! I seem to be out of battlestaves at the", + "moment! I expect I'll get some more in by tomorrow,", + "though." + ) + stage = 2 + return true + } + interpreter.sendDialogues( + 546, + FacialExpression.HALF_GUILTY, + "Battlestaves cost 8,000 gold pieces each. I have ${maxStaffs - ammount} left.", + "How many would you like to buy?" + ) + stage = 1 + } + 1 -> end().also { ContentAPI.sendInputDialogue(player, InputType.NUMERIC, "Enter an amount:"){ value -> + ammount = getStoreFile().getInt(player.username.toLowerCase()) + var amt = value as Int + if(amt > maxStaffs - ammount) amt = maxStaffs - ammount + val coinage = amt * 8000 + if(!ContentAPI.inInventory(player, Items.COINS_995, coinage)){ + ContentAPI.sendDialogue(player, "You can't afford that many.") + return@sendInputDialogue + } + + if(amt == 0){ + return@sendInputDialogue + } + + if(ContentAPI.removeItem(player, Item(Items.COINS_995, coinage), Container.INVENTORY)){ + ContentAPI.addItem(player, Items.BATTLESTAFF_1392, amt) + ZaffPlugin.getStoreFile()[player.username.toLowerCase()] = amt + ammount + } + } } + 2 -> { + interpreter.sendDialogues( + player, + FacialExpression.HALF_GUILTY, + "Oh, okay then. I'll try again another time." + ) + stage = 3 + } + 3 -> end() + } + return true + } + + /** + * Gets the max staffs to buy. + * @return the max staffs to buy. + */ + val maxStaffs: Int + get() { + val level = player.achievementDiaryManager.getDiary(DiaryType.VARROCK).level + return when (level) { + 2 -> 64 + 1 -> 32 + 0 -> 16 + else -> 0 + } + } + + override fun getIds(): IntArray { + return intArrayOf(9679) + } + } + + companion object { + /** + * The bacon ring. + */ + val BEACON_RING = Item(11014) + + fun getStoreFile(): JSONObject { + return ServerStore.getArchive("daily-zaff") + } + } +} \ No newline at end of file diff --git a/Server/src/main/java/core/game/node/entity/player/link/spawn/PKScoreBoard.java b/Server/src/main/java/core/game/node/entity/player/link/spawn/PKScoreBoard.java index 804eb5c71..7e3721854 100644 --- a/Server/src/main/java/core/game/node/entity/player/link/spawn/PKScoreBoard.java +++ b/Server/src/main/java/core/game/node/entity/player/link/spawn/PKScoreBoard.java @@ -1,6 +1,6 @@ package core.game.node.entity.player.link.spawn; -import core.cache.ServerStore; +import core.cache.AriosStore; import core.cache.StoreFile; import core.cache.misc.buffer.ByteBufferUtils; import core.game.component.Component; @@ -52,7 +52,7 @@ public final class PKScoreBoard { * Initializes the score boards data. */ public static void init() { - StoreFile file = ServerStore.get("pk_scores"); + StoreFile file = AriosStore.get("pk_scores"); if (file == null) { //Indicates no cache exists yet. return; } @@ -73,7 +73,7 @@ public final class PKScoreBoard { ByteBufferUtils.putString(names[i], buffer); } buffer.flip(); - ServerStore.setArchive("pk_scores", buffer); + AriosStore.setArchive("pk_scores", buffer); } /** diff --git a/Server/src/main/java/core/game/system/SystemTermination.java b/Server/src/main/java/core/game/system/SystemTermination.java index 7f6ec1ebf..b05924516 100644 --- a/Server/src/main/java/core/game/system/SystemTermination.java +++ b/Server/src/main/java/core/game/system/SystemTermination.java @@ -6,6 +6,7 @@ import core.game.node.entity.player.Player; import core.game.node.entity.player.info.login.PlayerParser; import rs09.Server; import rs09.ServerConstants; +import rs09.ServerStore; import rs09.game.ge.OfferManager; import rs09.game.system.SystemLogger; import rs09.game.world.repository.Repository; @@ -94,6 +95,9 @@ public final class SystemTermination { SystemLogger.flushLogs(); SystemLogger.logInfo("[SystemTerminator] Saved Grand Exchange databases!"); Repository.getDisconnectionQueue().clear(); + SystemLogger.logInfo("[SystemTerminator] Saving Server Store..."); + ServerStore.save(); + SystemLogger.logInfo("[SystemTerminator] Server Store Saved!"); // ServerStore.dump(directory + "store/"); SystemLogger.logInfo("[SystemTerminator] Saved player accounts!"); } diff --git a/Server/src/main/kotlin/rs09/Server.kt b/Server/src/main/kotlin/rs09/Server.kt index 20691b8d6..13285503f 100644 --- a/Server/src/main/kotlin/rs09/Server.kt +++ b/Server/src/main/kotlin/rs09/Server.kt @@ -69,6 +69,9 @@ object Server { } startTime = System.currentTimeMillis() val t = TimeStamp() + SystemLogger.logInfo("Initializing Server Store...") + ServerStore.init() + SystemLogger.logInfo("Initialized ${ServerStore.counter} store files.") GameWorld.prompt(true) SQLManager.init() Runtime.getRuntime().addShutdownHook(ServerConstants.SHUTDOWN_HOOK) diff --git a/Server/src/main/kotlin/rs09/ServerStore.kt b/Server/src/main/kotlin/rs09/ServerStore.kt new file mode 100644 index 000000000..195a03c98 --- /dev/null +++ b/Server/src/main/kotlin/rs09/ServerStore.kt @@ -0,0 +1,120 @@ +package rs09 + +import org.json.simple.JSONArray +import org.json.simple.JSONObject +import org.json.simple.parser.JSONParser +import rs09.game.system.SystemLogger +import java.io.File +import java.io.FileReader +import java.io.FileWriter +import javax.script.ScriptEngineManager + +object ServerStore { + val fileMap = HashMap() + var counter = 0 + + fun init(){ + val dir = File(ServerConstants.DATA_PATH + File.separator + "serverstore") + if(!dir.exists()){ + dir.mkdirs() + return + } + + var parser: JSONParser + var reader: FileReader + + dir.listFiles()?.forEach { storeFile -> + val key = storeFile.nameWithoutExtension + + reader = FileReader(storeFile) + parser = JSONParser() + + try { + val data = parser.parse(reader) as JSONObject + fileMap[key] = data + counter++ + } catch (e: Exception){ + SystemLogger.logErr("Failed parsing ${storeFile.name} - stack trace below.") + e.printStackTrace() + return@forEach + } + } + } + + @JvmStatic + fun save() { + val dir = File(ServerConstants.DATA_PATH + File.separator + "serverstore") + if(!dir.exists()){ + dir.mkdirs() + return + } + + val manager = ScriptEngineManager() + val scriptEngine = manager.getEngineByName("JavaScript") + + fileMap.forEach { (name, data) -> + val path = dir.absolutePath + File.separator + name + ".json" + + scriptEngine.put("jsonString", data.toJSONString()) + scriptEngine.eval("result = JSON.stringify(JSON.parse(jsonString), null, 2)") + val prettyPrintedJson = scriptEngine["result"] as String + + FileWriter(path).use { it.write(prettyPrintedJson); it.flush(); it.close() } + } + } + + fun getArchive(name: String): JSONObject { + if(fileMap[name] == null){ + fileMap[name] = JSONObject() + } + + return fileMap[name]!! + } + + fun setArchive(name: String, data: JSONObject){ + fileMap[name] = data + } + + fun clearDailyEntries() { + fileMap.keys.toTypedArray().forEach { + if(it.toLowerCase().contains("daily")) fileMap[it]?.clear() + } + } + + fun clearWeeklyEntries() { + fileMap.keys.toTypedArray().forEach { + if(it.toLowerCase().contains("weekly")) fileMap[it]?.clear() + } + } + + fun JSONObject.getInt(key: String): Int { + return when(val value = this[key]){ + is Long -> value.toInt() + is Double -> value.toInt() + is Float -> value.toInt() + is Int -> value + is Nothing -> 0 + else -> 0 + } + } + + fun JSONObject.getString(key: String): String { + return this[key] as? String ?: "nothing" + } + + fun JSONObject.getLong(key: String): Long { + return this[key] as? Long ?: 0L + } + + fun JSONObject.getBoolean(key: String): Boolean { + return this[key] as? Boolean ?: false + } + + fun List.toJSONArray(): JSONArray{ + val jArray = JSONArray() + for(i in this){ + jArray.add(i) + } + return jArray + } +} \ No newline at end of file diff --git a/Server/src/main/kotlin/rs09/game/content/global/worldevents/penguinhns/LarryHandler.kt b/Server/src/main/kotlin/rs09/game/content/global/worldevents/penguinhns/LarryHandler.kt index e31a48ca4..8a5c30ec1 100644 --- a/Server/src/main/kotlin/rs09/game/content/global/worldevents/penguinhns/LarryHandler.kt +++ b/Server/src/main/kotlin/rs09/game/content/global/worldevents/penguinhns/LarryHandler.kt @@ -2,10 +2,12 @@ package rs09.game.content.global.worldevents.penguinhns import core.game.component.Component import core.game.content.dialogue.DialoguePlugin +import core.game.content.dialogue.FacialExpression import core.game.node.entity.player.Player import core.game.node.item.Item import core.game.system.task.Pulse import rs09.game.world.GameWorld +import rs09.tools.END_DIALOGUE class LarryHandler(player: Player? = null) : DialoguePlugin(player){ override fun open(vararg args: Any?): Boolean { @@ -19,7 +21,7 @@ class LarryHandler(player: Player? = null) : DialoguePlugin(player){ override fun handle(interfaceId: Int, buttonId: Int): Boolean { class HintPulse : Pulse(){ override fun pulse(): Boolean { - val hint = PenguinManager.penguins.random().hint + val hint = Penguin.values()[PenguinManager.penguins.random()].hint player.sendMessage("Here, I know one is...") player.sendMessage(hint) return true @@ -36,7 +38,13 @@ class LarryHandler(player: Player? = null) : DialoguePlugin(player){ 1 -> npc("Sure!").also { player.inventory.add(Item(13732));stage = 1000 } //Hint - 10 -> npc("Yes, but I will have to write it down","for you so these penguins don't overhear.").also { GameWorld.submit(HintPulse()); stage = 1000 } + 10 -> npc("Yes, give me just one moment...").also { stage++ } + + 11 -> { + val hint = Penguin.values()[PenguinManager.penguins.random()].hint + npcl(FacialExpression.FRIENDLY, "One is $hint") + stage = END_DIALOGUE + } //Point turn-in 20 -> if(player.getAttribute("phns:points",0) > 0) npc("Sure thing, what would you like to be","rewarded with?").also { stage++ } else npc("Uh, you don't have any points","to turn in.").also{stage = 1000} diff --git a/Server/src/main/kotlin/rs09/game/content/global/worldevents/penguinhns/NotebookHandler.kt b/Server/src/main/kotlin/rs09/game/content/global/worldevents/penguinhns/NotebookHandler.kt index 5a7e97b08..40424ea68 100644 --- a/Server/src/main/kotlin/rs09/game/content/global/worldevents/penguinhns/NotebookHandler.kt +++ b/Server/src/main/kotlin/rs09/game/content/global/worldevents/penguinhns/NotebookHandler.kt @@ -9,8 +9,7 @@ import core.plugin.Plugin class NotebookHandler : OptionHandler(){ override fun handle(player: Player?, node: Node?, option: String?): Boolean { val total = player?.getAttribute("phns:points",0) - val weekly = player?.getAttribute("phns:weekly",0) - player?.dialogueInterpreter?.sendDialogue("Total points: $total","Penguins spied this week: $weekly") + player?.dialogueInterpreter?.sendDialogue("Total points: $total") return true } diff --git a/Server/src/main/kotlin/rs09/game/content/global/worldevents/penguinhns/PenguinHNSEvent.kt b/Server/src/main/kotlin/rs09/game/content/global/worldevents/penguinhns/PenguinHNSEvent.kt index 8af9c1c4c..e28aa1c3d 100644 --- a/Server/src/main/kotlin/rs09/game/content/global/worldevents/penguinhns/PenguinHNSEvent.kt +++ b/Server/src/main/kotlin/rs09/game/content/global/worldevents/penguinhns/PenguinHNSEvent.kt @@ -1,6 +1,8 @@ package rs09.game.content.global.worldevents.penguinhns import core.game.system.task.Pulse +import org.json.simple.JSONObject +import rs09.ServerStore import rs09.game.content.global.worldevents.PluginSet import rs09.game.content.global.worldevents.WorldEvent import rs09.game.content.global.worldevents.WorldEvents @@ -16,7 +18,7 @@ class PenguinHNSEvent : WorldEvent("penguin-hns"){ } override fun checkTrigger(): Boolean { - return GameWorld.ticks - lastTrigger >= tickDelay + return PenguinManager.penguins.isEmpty() } override fun initialize() { @@ -26,24 +28,21 @@ class PenguinHNSEvent : WorldEvent("penguin-hns"){ PenguinSpyingHandler() ) super.initialize() - GameWorld.Pulser.submit(PenguinRegeneration()) + fireEvent() log("Penguin HNS initialized.") } override fun fireEvent() { - log("Reshuffling Penguins...") + log("Loading penguins...") manager.rebuildVars() lastTrigger = GameWorld.ticks - log("Penguins Reshuffled.") + log("Penguins loaded.") } - class PenguinRegeneration : Pulse(25){ - override fun pulse(): Boolean { - val event = WorldEvents.get("penguin-hns") - event ?: return true - - if(event.checkTrigger()) event.fireEvent() - return false + companion object { + @JvmStatic + fun getStoreFile() : JSONObject { + return ServerStore.getArchive("weekly-penguinhns") } } diff --git a/Server/src/main/kotlin/rs09/game/content/global/worldevents/penguinhns/PenguinManager.kt b/Server/src/main/kotlin/rs09/game/content/global/worldevents/penguinhns/PenguinManager.kt index d82a6833c..7fdd5bf62 100644 --- a/Server/src/main/kotlin/rs09/game/content/global/worldevents/penguinhns/PenguinManager.kt +++ b/Server/src/main/kotlin/rs09/game/content/global/worldevents/penguinhns/PenguinManager.kt @@ -1,28 +1,66 @@ package rs09.game.content.global.worldevents.penguinhns import core.game.node.entity.npc.NPC +import core.game.node.entity.player.Player import rs09.game.system.SystemLogger import core.game.world.map.Location +import org.json.simple.JSONArray +import org.json.simple.JSONObject +import rs09.ServerStore.toJSONArray import java.util.* class PenguinManager{ companion object { - var penguins = ArrayList() + var penguins: MutableList = ArrayList() var npcs = ArrayList() val spawner = PenguinSpawner() - var tagMapping = HashMap>() + var tagMapping: MutableMap = HashMap() + + fun registerTag(player: Player, location: Location){ + val ordinal = Penguin.forLocation(location)?.ordinal ?: -1 + if(tagMapping[ordinal] == null){ + tagMapping[ordinal] = JSONArray() + } + tagMapping[ordinal]?.add(player.username.toLowerCase()) + updateStoreFile() + } + + fun hasTagged(player: Player, location: Location): Boolean{ + return tagMapping[Penguin.forLocation(location)?.ordinal]?.contains(player.username.toLowerCase()) ?: false + } + + private fun updateStoreFile(){ + val jsonTags = JSONArray() + tagMapping.forEach { (ordinal,taggers) -> + SystemLogger.logInfo("$ordinal - ${taggers.first()}") + val tag = JSONObject() + tag["ordinal"] = ordinal + tag["taggers"] = taggers + jsonTags.add(tag) + } + + PenguinHNSEvent.getStoreFile()["tag-mapping"] = jsonTags + } } fun rebuildVars() { - for(p in npcs){ - p.clear() - p.isActive = false - } - npcs.clear() - penguins = spawner.spawnPenguins(6) - tagMapping.clear() - for(p in penguins){ - tagMapping.put(p.loc, ArrayList()) + if(PenguinHNSEvent.getStoreFile().isEmpty()) { + penguins = spawner.spawnPenguins(10) + PenguinHNSEvent.getStoreFile()["spawned-penguins"] = penguins.toJSONArray() + for (p in penguins) { + tagMapping.put(p, JSONArray()) + } + } else { + val spawnedOrdinals = (PenguinHNSEvent.getStoreFile()["spawned-penguins"] as JSONArray).map { it.toString().toInt() } + spawner.spawnPenguins(spawnedOrdinals) + + val storedTags = (PenguinHNSEvent.getStoreFile()["tag-mapping"] as? JSONArray)?.map { jRaw -> + val jObj = jRaw as JSONObject + jObj["ordinal"].toString().toInt() to (jObj["taggers"] as JSONArray) + }?.toMap()?.toMutableMap() ?: HashMap() + + tagMapping = storedTags + penguins = spawnedOrdinals.toMutableList() } } diff --git a/Server/src/main/kotlin/rs09/game/content/global/worldevents/penguinhns/PenguinSpawner.kt b/Server/src/main/kotlin/rs09/game/content/global/worldevents/penguinhns/PenguinSpawner.kt index 17f9f9263..ebcfec2a1 100644 --- a/Server/src/main/kotlin/rs09/game/content/global/worldevents/penguinhns/PenguinSpawner.kt +++ b/Server/src/main/kotlin/rs09/game/content/global/worldevents/penguinhns/PenguinSpawner.kt @@ -2,54 +2,66 @@ package rs09.game.content.global.worldevents.penguinhns import core.game.node.entity.npc.NPC import core.game.world.map.Location +import org.rs09.consts.NPCs import rs09.game.content.global.worldevents.WorldEvents class PenguinSpawner { - val CACTUS = 8107 - val CRATE = 8108 - val BARREL = 8104 - val BUSH = 8105 - val ROCK = 8109 - val TOADSTOOL = 8110 - class Penguin(val id: Int, val hint: String, val loc: Location) - val penguins = arrayListOf( - Penguin(CACTUS,"...located in the northern desert.",Location.create(3310, 3157, 0)), - Penguin(BUSH,"...located between Fremennik and barbarians.",Location.create(2532, 3588, 0)), - Penguin(BUSH,"...located where banana smugglers dwell.",Location.create(2740, 3233, 0)), - Penguin(BUSH,"...located south of Ardougne.",Location.create(2456, 3092, 0)), - Penguin(BUSH,"...located deep in the jungle.",Location.create(2832, 3053, 0)), - Penguin(ROCK,"...located where the Imperial Guard train.",Location.create(2852, 3578, 0)), - Penguin(ROCK,"...located in the kingdom of Misthalin.",Location.create(3356, 3416, 0)), - Penguin(CRATE,"...located in the kingdom of Misthalin.",Location.create(3112, 3332, 0)), - Penguin(BUSH,"...located where eagles fly.",Location.create(2326, 3516, 0)), - Penguin(BARREL,"...located where no weapons may go.",Location.create(2806, 3383, 0)), - Penguin(ROCK,"...located near some ogres.",Location.create(2631, 2980, 0)), - Penguin(BUSH,"...located south of Ardougne.",Location.create(2513, 3154, 0)), - Penguin(BUSH,"...located near a big tree surrounded by short people.",Location.create(2387, 3451, 0)), - Penguin(BUSH,"...located in the kingdom of Asgarnia.",Location.create(2951, 3511, 0)), - Penguin(ROCK,"...located in the Kingdom of Asgarnia.",Location.create(3013, 3501, 0)), - Penguin(ROCK,"...located between Fremennik and barbarians.",Location.create(2532, 3630, 0)), - Penguin(CRATE,"...located in the Kingdom of Misthalin.",Location.create(3305, 3508, 0)), - Penguin(TOADSTOOL,"...located in the kingdom of Misthalin.",Location.create(3156, 3178, 0)), - Penguin(BUSH,"...located in the northern desert.",Location.create(3350, 3311, 0)), - Penguin(BUSH,"...located somewhere in the kingdom of Kandarin.",Location.create(2633, 3501, 0)), - Penguin(BUSH,"...located south of Ardougne.",Location.create(2440, 3206, 0)), - Penguin(CACTUS,"...located in the southern desert.",Location.create(3259, 3052, 0)), - Penguin(BUSH,"...located where wizards study.",Location.create(3112, 3149, 0)), - Penguin(TOADSTOOL,"...located in the fairy realm.",Location.create(2409, 4462, 0)) - ) - fun spawnPenguins(amount: Int): ArrayList { - var event = WorldEvents.get("penguin-hns") as PenguinHNSEvent + fun spawnPenguins(amount: Int): ArrayList { var counter = 0 - val list = penguins.toMutableList() - val penguinList = ArrayList() + val availableOrdinals = (0 until Penguin.values().size).toMutableList() + val spawnedOrdinals = ArrayList() while(counter < amount){ - val peng = list.random() - penguinList.add(peng).also { NPC(peng.id,peng.loc).also {PenguinManager.npcs.add(it);it.isNeverWalks = true; it.isWalks = false}.init() } - list.remove(peng) + val peng = Penguin.values()[availableOrdinals.random()] + availableOrdinals.remove(peng.ordinal) + spawnedOrdinals.add(peng.ordinal) + NPC(peng.id,peng.location) + .also {PenguinManager.npcs.add(it);it.isNeverWalks = true; it.isWalks = false}.init() counter++ } - return penguinList + return spawnedOrdinals } -} \ No newline at end of file + + fun spawnPenguins(ordinals: List){ + ordinals.forEach { + val peng = Penguin.values()[it] + NPC(peng.id,peng.location) + .also { PenguinManager.npcs.add(it); it.isNeverWalks = true; it.isWalks = false }.init() + } + } +} + +enum class Penguin(val id: Int, val hint: String, val location: Location){ + CACTUS_1(NPCs.CACTUS_8107,"located in the northern desert.", Location(3310, 3157, 0)), + CACTUS_2(NPCs.CACTUS_8107,"located in the southern desert.",Location.create(3259, 3052, 0)), + BUSH_1(NPCs.BUSH_8105,"located between Fremennik and barbarians.",Location.create(2532, 3588, 0)), + BUSH_2(NPCs.BUSH_8105,"located where banana smugglers dwell.",Location.create(2740, 3233, 0)), + BUSH_3(NPCs.BUSH_8105,"located south of Ardougne.",Location.create(2456, 3092, 0)), + BUSH_4(NPCs.BUSH_8105,"located deep in the jungle.",Location.create(2832, 3053, 0)), + BUSH_5(NPCs.BUSH_8105,"located where eagles fly.",Location.create(2326, 3516, 0)), + BUSH_6(NPCs.BUSH_8105,"located south of Ardougne.",Location.create(2513, 3154, 0)), + BUSH_7(NPCs.BUSH_8105,"located near a big tree surrounded by short people.",Location.create(2387, 3451, 0)), + BUSH_8(NPCs.BUSH_8105,"located in the kingdom of Asgarnia.",Location.create(2951, 3511, 0)), + BUSH_9(NPCs.BUSH_8105,"located in the northern desert.",Location.create(3350, 3311, 0)), + BUSH_10(NPCs.BUSH_8105,"located somewhere in the kingdom of Kandarin.",Location.create(2633, 3501, 0)), + BUSH_11(NPCs.BUSH_8105,"located south of Ardougne.",Location.create(2440, 3206, 0)), + BUSH_12(NPCs.BUSH_8105,"located where wizards study.",Location.create(3112, 3149, 0)), + ROCK_1(NPCs.ROCK_8109,"located where the Imperial Guard train.",Location.create(2852, 3578, 0)), + ROCK_2(NPCs.ROCK_8109,"located in the kingdom of Misthalin.",Location.create(3356, 3416, 0)), + ROCK_3(NPCs.ROCK_8109,"located near some ogres.",Location.create(2631, 2980, 0)), + ROCK_4(NPCs.ROCK_8109,"located in the Kingdom of Asgarnia.",Location.create(3013, 3501, 0)), + ROCK_5(NPCs.ROCK_8109,"located between Fremennik and barbarians.",Location.create(2532, 3630, 0)), + CRATE_1(NPCs.CRATE_8108,"located in the kingdom of Misthalin.",Location.create(3112, 3332, 0)), + CRATE_2(NPCs.CRATE_8108,"located in the Kingdom of Misthalin.",Location.create(3305, 3508, 0)), + BARREL_1(NPCs.CRATE_8108,"located where no weapons may go.",Location.create(2806, 3383, 0)), + TOADSTOOL_1(NPCs.TOADSTOOL_8110,"located in the kingdom of Misthalin.",Location.create(3156, 3178, 0)), + TOADSTOOL_2(NPCs.TOADSTOOL_8110,"located in the fairy realm.",Location.create(2409, 4462, 0)); + + companion object { + private val locationMap = values().map { it.location.toString() to it }.toMap() + + fun forLocation(location: Location): Penguin?{ + return locationMap[location.toString()] + } + } +} diff --git a/Server/src/main/kotlin/rs09/game/content/global/worldevents/penguinhns/PenguinSpyingHandler.kt b/Server/src/main/kotlin/rs09/game/content/global/worldevents/penguinhns/PenguinSpyingHandler.kt index 7c078daad..cf90e6852 100644 --- a/Server/src/main/kotlin/rs09/game/content/global/worldevents/penguinhns/PenguinSpyingHandler.kt +++ b/Server/src/main/kotlin/rs09/game/content/global/worldevents/penguinhns/PenguinSpyingHandler.kt @@ -18,16 +18,17 @@ class PenguinSpyingHandler : PluginInteraction(8107,8108,8104,8105,8109,8110){ var stage = 0 val curPoints = player.getAttribute("phns:points",0) val weeklyPoints = player.getAttribute("phns:weekly",0) - val WEEKLY_CAP = 10 val ANIMATION = Animation(10355) override fun pulse(): Boolean { when(stage++){ 0 -> player.lock().also { player.animator.animate(ANIMATION) } - 1 -> player.sendMessage("You manage to spy on the penguin.").also { player.setAttribute("/save:phns:points",curPoints + 1);player.setAttribute("/save:phns:weekly",weeklyPoints + 1);player.unlock();} - 2 -> if(weeklyPoints + 1 >= WEEKLY_CAP) player.setAttribute("/save:phns:date", ((System.currentTimeMillis() * 0.001) + 604800).toLong()) - 3 -> return true + 1 -> player.sendMessage("You manage to spy on the penguin.").also { + player.setAttribute("/save:phns:points",curPoints + 1) + player.unlock() + } + 2 -> return true } return false } @@ -41,19 +42,12 @@ class PenguinSpyingHandler : PluginInteraction(8107,8108,8104,8105,8109,8110){ } } if(option?.name?.toLowerCase()?.equals("spy-on")!!){ - val currentDate = System.currentTimeMillis() * 0.001 - val playerDate: Long = player?.getAttribute("phns:date",0L)!! - if(currentDate < playerDate){ - player.sendMessage("You have already earned your maximum number of points this week.").also { return true } - } else if(playerDate != 0L){ - player.removeAttribute("phns:date") - player.removeAttribute("phns:weekly") - } - if(PenguinManager.tagMapping[npc?.location]?.contains(player.username)!!){ + player ?: return false + if(PenguinManager.hasTagged(player, npc!!.location)){ player.sendMessage("You've already tagged this penguin.") } else { GameWorld.submit(movePulse()) - PenguinManager.tagMapping[npc?.location]?.add(player.username) + PenguinManager.registerTag(player, npc!!.location) } return true } diff --git a/Server/src/main/kotlin/rs09/game/content/global/worldevents/shootingstar/ShootingStar.kt b/Server/src/main/kotlin/rs09/game/content/global/worldevents/shootingstar/ShootingStar.kt index 5c4d89176..f250d441a 100644 --- a/Server/src/main/kotlin/rs09/game/content/global/worldevents/shootingstar/ShootingStar.kt +++ b/Server/src/main/kotlin/rs09/game/content/global/worldevents/shootingstar/ShootingStar.kt @@ -5,6 +5,10 @@ import core.game.node.`object`.SceneryBuilder import core.game.node.entity.npc.NPC import core.game.node.entity.player.Player import core.game.world.map.Location +import rs09.ServerStore.getBoolean +import rs09.ServerStore.getInt +import rs09.ServerStore.getString +import rs09.game.system.SystemLogger import rs09.game.world.repository.Repository /** @@ -51,6 +55,7 @@ class ShootingStar(var level: ShootingStarType = ShootingStarType.values().rando var ticks = 0 var isSpawned = false var spriteSpawned = false + var firstStar = true /** * Degrades a ShootingStar (or removes the starObject and spawns a Star Sprite if it's the last star) @@ -62,12 +67,16 @@ class ShootingStar(var level: ShootingStarType = ShootingStarType.values().rando starSprite.location = starObject.location starSprite.init() spriteSpawned = true + ShootingStarEvent.getStoreFile().clear() return } level = getNextType() maxDust = level.totalStardust dustLeft = level.totalStardust + ShootingStarEvent.getStoreFile()["level"] = level.ordinal + ShootingStarEvent.getStoreFile()["isDiscovered"] = isDiscovered + val newStar = Scenery(level.objectId, starObject.location) SceneryBuilder.replace(starObject, newStar) starObject = newStar @@ -93,13 +102,26 @@ class ShootingStar(var level: ShootingStarType = ShootingStarType.values().rando * Rebuilds some of the variables with new information. */ fun rebuildVars(){ - level = ShootingStarType.values().random() - location = crash_locations.entries.random().key + if(firstStar && ShootingStarEvent.getStoreFile().isNotEmpty()){ + level = ShootingStarType.values()[ShootingStarEvent.getStoreFile().getInt("level")] + location = ShootingStarEvent.getStoreFile().getString("location") + isDiscovered = ShootingStarEvent.getStoreFile().getBoolean("isDiscovered") + } else { + level = ShootingStarType.values().random() + location = crash_locations.entries.random().key + isDiscovered = false + } + maxDust = level.totalStardust dustLeft = level.totalStardust starObject = Scenery(level.objectId, crash_locations.get(location)) - isDiscovered = false + + ShootingStarEvent.getStoreFile()["level"] = level.ordinal + ShootingStarEvent.getStoreFile()["location"] = location + ShootingStarEvent.getStoreFile()["isDiscovered"] = false + ticks = 0 + firstStar = false } fun clearSprite() { diff --git a/Server/src/main/kotlin/rs09/game/content/global/worldevents/shootingstar/ShootingStarEvent.kt b/Server/src/main/kotlin/rs09/game/content/global/worldevents/shootingstar/ShootingStarEvent.kt index ff11e467c..bbfe2df56 100644 --- a/Server/src/main/kotlin/rs09/game/content/global/worldevents/shootingstar/ShootingStarEvent.kt +++ b/Server/src/main/kotlin/rs09/game/content/global/worldevents/shootingstar/ShootingStarEvent.kt @@ -4,6 +4,8 @@ import core.game.content.global.worldevents.shootingstar.ScoreboardHandler import core.game.content.global.worldevents.shootingstar.ShootingStarScoreboard import core.game.content.global.worldevents.shootingstar.StarChartPlugin import core.game.system.task.Pulse +import org.json.simple.JSONObject +import rs09.ServerStore import rs09.game.content.global.worldevents.PluginSet import rs09.game.content.global.worldevents.WorldEvent import rs09.game.content.global.worldevents.WorldEvents @@ -81,4 +83,10 @@ class ShootingStarEvent : WorldEvent("shooting-stars") { return false //always returns false because it needs to run forever. } } + + companion object { + fun getStoreFile() : JSONObject { + return ServerStore.getArchive("shooting-star") + } + } } \ No newline at end of file diff --git a/Server/src/main/kotlin/rs09/game/content/global/worldevents/shootingstar/StarSpriteDialogue.kt b/Server/src/main/kotlin/rs09/game/content/global/worldevents/shootingstar/StarSpriteDialogue.kt index dfb237cb2..becbf5aa8 100644 --- a/Server/src/main/kotlin/rs09/game/content/global/worldevents/shootingstar/StarSpriteDialogue.kt +++ b/Server/src/main/kotlin/rs09/game/content/global/worldevents/shootingstar/StarSpriteDialogue.kt @@ -8,7 +8,10 @@ import core.game.node.entity.npc.NPC import core.game.node.entity.player.Player import core.game.node.item.Item import core.tools.RandomFunction +import org.json.simple.JSONObject import org.rs09.consts.Items +import rs09.ServerStore +import rs09.ServerStore.getBoolean import rs09.game.node.entity.state.newsys.states.ShootingStarState import rs09.tools.END_DIALOGUE import rs09.tools.secondsToTicks @@ -61,15 +64,15 @@ class StarSpriteDialogue(player: Player? = null) : DialoguePlugin(player) { override fun open(vararg args: Any): Boolean { npc = args[0] as NPC - if (player.getSavedData().getGlobalData().getStarSpriteDelay() > System.currentTimeMillis() || !player.getInventory().contains(ShootingStarOptionHandler.STAR_DUST, 1)) { - npc("Hello, strange creature.") - stage = 0 - } else if (ContentAPI.inInventory(player, Items.ANCIENT_BLUEPRINT_14651) && !ContentAPI.getAttribute(player, "star-ring:bp-shown", false)) { + if (ContentAPI.inInventory(player, Items.ANCIENT_BLUEPRINT_14651) && !ContentAPI.getAttribute(player, "star-ring:bp-shown", false)) { npcl(FacialExpression.NEUTRAL, "I see you got ahold of a blueprint of those silly old rings we used to make.") stage = 1000 } else if (ContentAPI.inInventory(player, Items.ANCIENT_BLUEPRINT_14651) && ContentAPI.getAttribute(player, "star-ring:bp-shown", false)) { - playerl(FacialExpression.HALF_ASKING, "So about those rings...") - stage = 2000 + playerl(FacialExpression.HALF_ASKING, "So about those rings...") + stage = 2000 + } else if (getStoreFile().getBoolean(player.username.toLowerCase()) || !player.getInventory().contains(ShootingStarOptionHandler.STAR_DUST, 1)) { + npc("Hello, strange creature.") + stage = 0 } else { npc("Thank you for helping me out of here.") stage = 50 @@ -193,7 +196,9 @@ class StarSpriteDialogue(player: Player? = null) : DialoguePlugin(player) { player.getInventory().add(Item(GOLD_ORE, goldOre), player) player.getInventory().add(Item(COINS, coins), player) npc("I have rewarded you by making it so you can mine", "extra ore for the next 15 minutes. Also, have $cosmicRunes", "cosmic runes, $astralRunes astral runes, $goldOre gold ore and $coins", "coins.") - player.getSavedData().getGlobalData().setStarSpriteDelay(System.currentTimeMillis() + TimeUnit.DAYS.toMillis(1)) + + getStoreFile()[player.username.toLowerCase()] = true //flag daily as completed + player.registerState("shooting-star")?.init() if(wearingRing){ @@ -271,4 +276,8 @@ class StarSpriteDialogue(player: Player? = null) : DialoguePlugin(player) { } } + fun getStoreFile(): JSONObject{ + return ServerStore.getArchive("daily-shooting-star") + } + } \ No newline at end of file diff --git a/Server/src/main/kotlin/rs09/game/content/jobs/JobManager.kt b/Server/src/main/kotlin/rs09/game/content/jobs/JobManager.kt index b405d407c..d9703f8ad 100644 --- a/Server/src/main/kotlin/rs09/game/content/jobs/JobManager.kt +++ b/Server/src/main/kotlin/rs09/game/content/jobs/JobManager.kt @@ -6,6 +6,9 @@ import core.game.node.entity.npc.NPC import core.game.node.entity.player.Player import core.game.node.item.GroundItemManager import core.game.node.item.Item +import org.json.simple.JSONObject +import rs09.ServerStore +import rs09.ServerStore.getInt import rs09.game.system.SystemLogger import java.util.concurrent.TimeUnit @@ -52,11 +55,6 @@ object JobManager { val amt = player.getAttribute("jobs:original_amount",0) val type = player.getAttribute("jobs:type",0) val jobId = player.getAttribute("jobs:id",0) - val dailyDone = player.getAttribute("jobs:dailyAmt",0) - if(dailyDone == 3){ - player.dialogueInterpreter.sendDialogue("You can only complete 3 jobs per day.") - return - } if(type == 0){ val it = Item(GatheringJobs.values()[jobId].itemId) var amount = player.inventory.getAmount(it) @@ -88,7 +86,11 @@ object JobManager { player.removeAttribute("jobs:amount") player.removeAttribute("jobs:original_amount") player.removeAttribute("jobs:type") - player.incrementAttribute("/save:jobs:dailyAmt",1) - System.out.println("Complete amount: ${player.getAttribute("jobs:dailyAmt",0)}") + + getStoreFile()[player.username.toLowerCase()] = getStoreFile().getInt(player.username.toLowerCase()) + 1 + } + + fun getStoreFile(): JSONObject { + return ServerStore.getArchive("daily-jobs-tracking") } } \ No newline at end of file diff --git a/Server/src/main/kotlin/rs09/game/content/jobs/WorkForInteractionListener.kt b/Server/src/main/kotlin/rs09/game/content/jobs/WorkForInteractionListener.kt index 2f7ace650..bfacf46eb 100644 --- a/Server/src/main/kotlin/rs09/game/content/jobs/WorkForInteractionListener.kt +++ b/Server/src/main/kotlin/rs09/game/content/jobs/WorkForInteractionListener.kt @@ -2,12 +2,17 @@ package rs09.game.content.jobs import GatheringJobs import SlayingJob +import api.ContentAPI import core.game.node.entity.npc.NPC import core.game.node.entity.player.Player import core.game.node.entity.player.link.diary.DiaryType import core.game.node.item.Item +import org.json.simple.JSONObject import org.rs09.consts.Items +import rs09.ServerStore +import rs09.ServerStore.getInt import rs09.game.interaction.InteractionListener +import rs09.game.system.SystemLogger import java.util.concurrent.TimeUnit /** @@ -58,9 +63,9 @@ class WorkForInteractionListener : InteractionListener() { var amount = 0 var jobId = 0 - if(player.getAttribute("jobs:reset_time",Long.MAX_VALUE) < System.currentTimeMillis()){ - player.setAttribute("/save:jobs:dailyAmt",0) - player.setAttribute("/save:jobs:reset_time",System.currentTimeMillis() + TimeUnit.HOURS.toMillis(24)) + if(JobManager.getStoreFile().getInt(player.username.toLowerCase()) == 3){ + ContentAPI.sendNPCDialogue(player, node.id,"You've hit your limit for the day. Come back tomorrow!") + return@on true } if(player.getAttribute("jobs:id",-1) != -1){ diff --git a/Server/src/main/kotlin/rs09/game/interaction/item/StarRingListener.kt b/Server/src/main/kotlin/rs09/game/interaction/item/StarRingListener.kt index d59350e4f..6f56800e6 100644 --- a/Server/src/main/kotlin/rs09/game/interaction/item/StarRingListener.kt +++ b/Server/src/main/kotlin/rs09/game/interaction/item/StarRingListener.kt @@ -5,7 +5,10 @@ import core.game.node.entity.player.Player import core.game.node.entity.player.link.TeleportManager import core.game.node.entity.skill.Skills import core.game.world.map.Location +import org.json.simple.JSONObject import org.rs09.consts.Items +import rs09.ServerStore +import rs09.ServerStore.getBoolean import rs09.game.content.dialogue.DialogueFile import rs09.game.content.global.worldevents.WorldEvents import rs09.game.content.global.worldevents.shootingstar.ShootingStar @@ -23,7 +26,7 @@ class StarRingListener : InteractionListener(){ if(star == null) ContentAPI.sendDialogue(player, "There is currently no active star.").also { return@on true } - if(ContentAPI.getAttribute(player, "ring-next-tele", 0L) > System.currentTimeMillis()){ + if(getStoreFile().getBoolean(player.username.toLowerCase())){ ContentAPI.sendDialogue(player, "The ring is still recharging.") return@on true } @@ -79,7 +82,13 @@ class StarRingListener : InteractionListener(){ fun teleport(player: Player, star: ShootingStar){ ContentAPI.teleport(player, star.crash_locations[star.location]!!.transform(0, -1, 0), TeleportManager.TeleportType.MINIGAME) - ContentAPI.setAttribute(player, "/save:ring-next-tele", System.currentTimeMillis() + TimeUnit.DAYS.toMillis(1)) + getStoreFile()[player.username.toLowerCase()] = true + } + } + + companion object { + fun getStoreFile(): JSONObject { + return ServerStore.getArchive("daily-star-ring") } } } \ No newline at end of file diff --git a/Server/src/main/kotlin/rs09/game/world/GameWorld.kt b/Server/src/main/kotlin/rs09/game/world/GameWorld.kt index ba4d60c62..5005ce006 100644 --- a/Server/src/main/kotlin/rs09/game/world/GameWorld.kt +++ b/Server/src/main/kotlin/rs09/game/world/GameWorld.kt @@ -1,7 +1,7 @@ package rs09.game.world import core.cache.Cache -import core.cache.ServerStore +import core.cache.AriosStore import core.cache.def.impl.SceneryDefinition import core.game.ge.GrandExchangeDatabase import core.game.node.entity.npc.drop.RareDropTable @@ -25,6 +25,7 @@ import rs09.game.world.callback.CallbackHub import rs09.game.world.repository.Repository import rs09.plugin.PluginManager import rs09.worker.MajorUpdateWorker +import java.text.SimpleDateFormat import java.util.* import java.util.function.Consumer @@ -90,11 +91,9 @@ object GameWorld { } } - private fun checkDay(): Boolean { - val calendar = Calendar.getInstance(TimeZone.getTimeZone("America/Toronto")) - val day = calendar[Calendar.DAY_OF_WEEK] - val hour = calendar[Calendar.HOUR_OF_DAY] - return day == Calendar.SATURDAY && hour == 1 || day == Calendar.SUNDAY && hour == 1 || day == Calendar.TUESDAY && hour == 10 + fun checkDay(): Int { + val weeklySdf = SimpleDateFormat("u") + return weeklySdf.format(Date()).toInt() } /** @@ -131,7 +130,7 @@ object GameWorld { fun prompt(run: Boolean, directory: String?){ SystemLogger.logInfo("Prompting ${settings?.name} Game World...") Cache.init(ServerConstants.CACHE_PATH) - ServerStore.init(ServerConstants.STORE_PATH) + AriosStore.init(ServerConstants.STORE_PATH) databaseManager = DatabaseManager(ServerConstants.DATABASE) databaseManager!!.connect() GrandExchangeDatabase.init() diff --git a/Server/src/main/kotlin/rs09/worker/MajorUpdateWorker.kt b/Server/src/main/kotlin/rs09/worker/MajorUpdateWorker.kt index d63df86fe..88a91785f 100644 --- a/Server/src/main/kotlin/rs09/worker/MajorUpdateWorker.kt +++ b/Server/src/main/kotlin/rs09/worker/MajorUpdateWorker.kt @@ -10,6 +10,7 @@ import kotlinx.coroutines.delay import kotlinx.coroutines.launch import rs09.Server import rs09.ServerConstants +import rs09.ServerStore import rs09.game.system.SystemLogger import rs09.game.world.GameWorld import rs09.game.world.repository.Repository @@ -21,6 +22,7 @@ import java.lang.Long.min import java.text.SimpleDateFormat import java.util.* import kotlin.collections.ArrayList +import kotlin.system.exitProcess /** * Handles the running of pulses and writing of masks, etc @@ -29,7 +31,7 @@ import kotlin.collections.ArrayList class MajorUpdateWorker { var started = false val sequence = UpdateSequence() - val sdf = SimpleDateFormat("HHmm") + val sdf = SimpleDateFormat("HHmmss") fun start() = GlobalScope.launch { started = true delay(600L) @@ -63,21 +65,28 @@ class MajorUpdateWorker { Server.heartbeat() //Handle daily restart if enabled - if(ServerConstants.DAILY_RESTART && sdf.format(Date()).toInt() == 0){ - Repository.sendNews(colorize("%RSERVER GOING DOWN FOR DAILY RESTART IN 5 MINUTES!")) - ServerConstants.DAILY_RESTART = false - ContentAPI.submitWorldPulse(object : Pulse(100) { - var counter = 0 - override fun pulse(): Boolean { - counter++ - if(counter == 5){ - SystemManager.flag(SystemState.TERMINATED) - return true + if(sdf.format(Date()).toInt() == 0){ + + if(GameWorld.checkDay() == 7) {//sunday + ServerStore.clearWeeklyEntries() + } + + ServerStore.clearDailyEntries() + if(ServerConstants.DAILY_RESTART ) { + Repository.sendNews(colorize("%RSERVER GOING DOWN FOR DAILY RESTART IN 5 MINUTES!")) + ServerConstants.DAILY_RESTART = false + ContentAPI.submitWorldPulse(object : Pulse(100) { + var counter = 0 + override fun pulse(): Boolean { + counter++ + if (counter == 5) { + exitProcess(0) + } + Repository.sendNews(colorize("%RSERVER GOING DOWN FOR DAILY RESTART IN ${5 - counter} MINUTE${if (counter < 4) "S" else ""}!")) + return false } - Repository.sendNews(colorize("%RSERVER GOING DOWN FOR DAILY RESTART IN ${5 - counter} MINUTE${if(counter < 4) "S" else ""}!")) - return false - } - }) + }) + } } val end = System.currentTimeMillis()