From e386724f945143ab702a6219483e177d618c2940 Mon Sep 17 00:00:00 2001 From: Ceikry Date: Fri, 20 Mar 2020 21:58:44 -0500 Subject: [PATCH] Shooting star improvements --- .../free/gather/GatheringSkillPulse.java | 11 ++- .../entity/state/impl/DoubleOrePulse.java | 70 +++++++++++++++++++ .../object/ShootingStarPlugin.java | 30 +++++++- 3 files changed, 108 insertions(+), 3 deletions(-) create mode 100644 Server/src/org/crandor/game/node/entity/state/impl/DoubleOrePulse.java diff --git a/Server/src/org/crandor/game/content/skill/free/gather/GatheringSkillPulse.java b/Server/src/org/crandor/game/content/skill/free/gather/GatheringSkillPulse.java index 098fda984..18bf1ded5 100644 --- a/Server/src/org/crandor/game/content/skill/free/gather/GatheringSkillPulse.java +++ b/Server/src/org/crandor/game/content/skill/free/gather/GatheringSkillPulse.java @@ -18,12 +18,14 @@ import org.crandor.game.node.entity.player.link.diary.DiaryType; import org.crandor.game.node.item.Item; import org.crandor.game.node.object.GameObject; import org.crandor.game.node.object.ObjectBuilder; +import org.crandor.game.world.GameWorld; import org.crandor.game.world.map.Location; import org.crandor.tools.RandomFunction; import org.crandor.tools.StringUtils; import java.util.ArrayList; import java.util.List; +import java.util.Random; import java.util.concurrent.TimeUnit; /** @@ -175,8 +177,15 @@ public final class GatheringSkillPulse extends SkillPulse { } else { player.getPacketDispatch().sendMessage("You get some " + ItemDefinition.forId(reward).getName().toLowerCase() + "."); } - // Calculate if the player should receive a bonus gem + // Calculate if the player should receive a bonus gem or bonus ore or both if (!isMiningEssence && isMining) { + //check for bonus ore from shooting star buff + if(isMining && (player.getAttribute("SS Mining Bonus", GameWorld.getTicks()) > GameWorld.getTicks())){ + if(RandomFunction.getRandom(7) == 5) { + player.getPacketDispatch().sendMessage("...you manage to mine a second ore thanks to the Star Sprite."); + player.getInventory().add(item); + } + } int chance = 282; boolean altered = false; if (player.getEquipment().getNew(EquipmentContainer.SLOT_RING).getId() == 2572) { diff --git a/Server/src/org/crandor/game/node/entity/state/impl/DoubleOrePulse.java b/Server/src/org/crandor/game/node/entity/state/impl/DoubleOrePulse.java new file mode 100644 index 000000000..c3d66f72f --- /dev/null +++ b/Server/src/org/crandor/game/node/entity/state/impl/DoubleOrePulse.java @@ -0,0 +1,70 @@ +package org.crandor.game.node.entity.state.impl; + +import org.crandor.game.node.entity.Entity; +import org.crandor.game.node.entity.player.Player; +import org.crandor.game.node.entity.state.StatePulse; +import org.crandor.game.world.GameWorld; + +import java.nio.ByteBuffer; + +/** + * Pulse for checking remaining time on a shooting star mining bonus and informing the player + * @author ceik + */ + +public class DoubleOrePulse extends StatePulse { + Player player; + Entity entity; + int ticks,currentTick; + public DoubleOrePulse(Entity entity, int ticks, int currentTick){ + super(entity,1); + this.ticks = ticks; + this.currentTick = currentTick; + this.player = entity.asPlayer(); + this.entity = entity; + } + @Override + public boolean isSaveRequired(){return currentTick < ticks;} + + @Override + public void save(ByteBuffer buffer){ + buffer.putInt(ticks); + buffer.putInt(currentTick); + } + + @Override + public StatePulse parse(Entity entity, ByteBuffer buffer){ + return new DoubleOrePulse(entity, buffer.getInt(), buffer.getInt()); + } + + @Override + public void start() { + if (currentTick == GameWorld.getTicks()) { + if (entity instanceof Player) { + if((int) entity.asPlayer().getAttribute("SS Mining Bonus") > GameWorld.getTicks()){ + entity.asPlayer().sendMessage("Your mining bonus is now active!"); + } + } + } + super.start(); + } + + @Override + public boolean pulse() { + int ticksLeft = (int)player.getAttribute("SS Mining Bonus") - GameWorld.getTicks(); + int minutes = (int)Math.ceil((ticksLeft * .6) / 60); + if(ticksLeft % 500 == 0L){ + player.sendMessage("You have " + minutes + " minutes of your mining bonus left"); + } + if(ticksLeft == 0){ + if((int)ticks <= GameWorld.getTicks()){ + player.sendMessage("Your mining bonus has run out!"); + } + } + return !(ticks >= GameWorld.getTicks()); + } + @Override + public StatePulse create(Entity entity, Object... args) { + return new DoubleOrePulse(entity, entity.asPlayer().getAttribute("SS Mining Bonus"), GameWorld.getTicks()); + } +} diff --git a/Server/src/plugin/interaction/object/ShootingStarPlugin.java b/Server/src/plugin/interaction/object/ShootingStarPlugin.java index 5a1f1b736..82ac7df6a 100644 --- a/Server/src/plugin/interaction/object/ShootingStarPlugin.java +++ b/Server/src/plugin/interaction/object/ShootingStarPlugin.java @@ -9,8 +9,11 @@ import org.crandor.game.content.skill.Skills; import org.crandor.game.content.skill.free.gather.SkillingTool; import org.crandor.game.interaction.OptionHandler; import org.crandor.game.node.Node; +import org.crandor.game.node.entity.impl.PulseManager; import org.crandor.game.node.entity.npc.NPC; import org.crandor.game.node.entity.player.Player; +import org.crandor.game.node.entity.state.StatePulse; +import org.crandor.game.node.entity.state.impl.DoubleOrePulse; import org.crandor.game.node.item.Item; import org.crandor.game.node.object.GameObject; import org.crandor.game.node.object.ObjectBuilder; @@ -69,6 +72,11 @@ public class ShootingStarPlugin extends OptionHandler { {"Mage Arena bank", Location.create(3093, 3962, 0)} }; + /** + * Checks whether or not a discovery/first mine award has been given + */ + public static boolean isDiscovered = false; + /** * The star dust item id. */ @@ -107,6 +115,7 @@ public class ShootingStarPlugin extends OptionHandler { /** * The star updating pulse. */ + private static final Pulse pulse = new Pulse(1) { @Override @@ -343,6 +352,7 @@ public class ShootingStarPlugin extends OptionHandler { object = null; crashSite = null; ticks = 0; + isDiscovered = false; } } @@ -469,14 +479,25 @@ public class ShootingStarPlugin extends OptionHandler { @Override public boolean checkRequirements() { + tool = SkillingTool.getPickaxe(player); if (star == null || object == null || !object.isActive()) { return false; } + //checks if the star has been discovered and if not, awards the bonus xp. Xp can be awarded regardless of mining level as per the wiki. + if(!isDiscovered) { + player.getSkills().addExperience(Skills.MINING, 75 * player.getSkills().getStaticLevel(Skills.MINING)); + Repository.sendNews(player.getUsername() + " is the discoverer of the crashed star near " + crashSite + "!"); + isDiscovered = true; + if (player.getSkills().getLevel(Skills.MINING) < star.getMiningLevel()) { + return false; + } else { + return true; + } + } if (player.getSkills().getLevel(Skills.MINING) < star.getMiningLevel()) { player.getDialogueInterpreter().sendDialogue("You need a Mining level of at least " + star.getMiningLevel() + " in order to mine this layer."); return false; } - tool = SkillingTool.getPickaxe(player); if (tool == null) { player.getPacketDispatch().sendMessage("You do not have a pickaxe to use."); return false; @@ -737,7 +758,7 @@ public class ShootingStarPlugin extends OptionHandler { end(); break; case 50: - int dust = player.getInventory().getAmount(STAR_DUST); + int dust = player.getInventory().getAmount(STAR_DUST) > 200 ? 200 : player.getInventory().getAmount(STAR_DUST); if (player.getInventory().remove(new Item(STAR_DUST, dust))) { int cosmicRunes = (int) (Math.ceil(0.76 * dust) * AMPLIFIER); int astralRunes = (int) (Math.ceil(0.26 * dust) * AMPLIFIER); @@ -748,7 +769,12 @@ public class ShootingStarPlugin extends OptionHandler { player.getInventory().add(new Item(GOLD_ORE, goldOre), player); player.getInventory().add(new 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.setAttribute("SS Mining Bonus",System.currentTimeMillis() + TimeUnit.MINUTES.toMillis(15)); player.getSavedData().getGlobalData().setStarSpriteDelay(System.currentTimeMillis() + TimeUnit.DAYS.toMillis(1)); + int endTick = GameWorld.getTicks() + 1500; + player.setAttribute("SS Mining Bonus",endTick); + DoubleOrePulse orePulse = new DoubleOrePulse(player,endTick,GameWorld.getTicks()); + orePulse.run(); } stage = 52; break;