Jump to content

Search the Community

Showing results for tags 'efficent'.



More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • RuneLocus
    • News & Announcements
    • Information Booth
    • Website Support
    • Introductions
    • Chat
    • Forum Games
  • RuneScape Development
    • RSPS General
    • RuneScape Private Server (RS2)
    • RuneScape Private Server (503+)
    • RuneScape Private Server (EoC 742+)
  • Other
    • Digital Art
    • Gaming
    • Webdevelopment
    • Computers
  • Marketplace
    • RuneScape Market
    • RSPS Market
    • Others Market
    • Freelance Middleman Services
  • Super Secret Club's Topics

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Found 1 result

  1. I have created like 10 total quests with this and it works 100% and i have supported state saving which is easy just request help i you need it. A server successfully using this system : [url]http://www.runelocus.com/forums/showthread.php?94065-Asgarnia-Official-Release-Exclusive-on-Runelocus[/url] Step 1 : Create a new package, call it 'quest' and you should probably make it extend either a 'model' or 'content' base folder. Inside the newly created package, create a new Java interface : Quest [CODE] /** * * [MENTION=52317]auth[/MENTION]or Joshua Barry * */ public interface Quest { /** * Determines if the player has the requirements to complete this quest. * * [MENTION=75098]Para[/MENTION]m player The player attempting the quest. * [MENTION=184045]return[/MENTION] {@code true} if the player can complete the quest. */ public abstract boolean hasRequirements(Player player); /** * Determine what happens when the questing player dies. * * [MENTION=75098]Para[/MENTION]m player The player who has died. * [MENTION=184045]return[/MENTION] {@code true} if the player has died. */ public abstract boolean deathListener(Player player); /** * Determines what happens when the questing player kills another entity. * * [MENTION=75098]Para[/MENTION]m player The player who has killed the victim entity. * [MENTION=184045]return[/MENTION] */ public abstract boolean defeatListener(Player player); /** * Determines whether a player has clicked a specific button or not, and * what the outcome will be. * * [MENTION=75098]Para[/MENTION]m player * [MENTION=184045]return[/MENTION] */ public abstract boolean dialougeListener(Player player); /** * Start the quest. */ public abstract void start(Player player); /** * End the quest. */ public abstract void end(Player player); /** * Give the player the reward items. */ public abstract void giveRewards(Player player); /** * The list of rewards the player will receive upon quest completion. * * [MENTION=184045]return[/MENTION] */ public abstract Item[] getRewards(); /** * Gets the quest attribute name. * * [MENTION=184045]return[/MENTION] */ public abstract String getAttributeName(); /** * Gets the quest name. * * [MENTION=184045]return[/MENTION] */ public abstract String getQuestName(); /** * Gets the amount of quest points to award the player. * * [MENTION=184045]return[/MENTION] */ public abstract short getQuestPointAward(); /** * Gets the amount of experience gained. * * [MENTION=184045]return[/MENTION] */ public abstract double[][] getExperienceAward(); /** * Displayed on reward interface. * * [MENTION=184045]return[/MENTION] */ public abstract String getAdditionalMessage(); /** * Gets the value of the final quest. * * [MENTION=184045]return[/MENTION] */ public abstract short getFinalStage(); /** * Gets the quest button id. * * [MENTION=184045]return[/MENTION] */ public abstract short getQuestButton(); } [/CODE] Next, a Java class called QuestEntry [CODE] import java.util.Map.Entry; /** * A convenience class for simplifying quest retrieval from the quest database. * * [MENTION=52317]auth[/MENTION]or Joshua Barry * */ public class QuestEntry implements Entry<String, Integer> { /** * The name of this quest. */ private final String name; /** * The button id of the quest. The one found on the quest tab. */ private final int button; public QuestEntry(String name, int button) { this.name = name; this.button = button; } [MENTION=15855]Over[/MENTION]ride public String getKey() { return name; } [MENTION=15855]Over[/MENTION]ride public Integer getValue() { return button; } [MENTION=15855]Over[/MENTION]ride public Integer setValue(Integer value) { return button; } } [/CODE] Now this is an EXAMPLE of my QuestRepository which I have left [B][COLOR=#FF0000]unmodified[/COLOR][/B] to show how to add quests to the repository. [CODE] import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.Set; import com.asgarniars.rs2.content.quest.impl.CooksAssistant; import com.asgarniars.rs2.content.quest.impl.DoricsQuest; import com.asgarniars.rs2.content.quest.impl.DruidicRitual; import com.asgarniars.rs2.content.quest.impl.RuneMysteries; import com.asgarniars.rs2.content.quest.impl.SheepShearer; import com.asgarniars.rs2.content.quest.impl.TheRestlessGhost; import com.asgarniars.rs2.content.quest.impl.WaterfallQuest; import com.asgarniars.rs2.content.quest.impl.WitchsPotion; import com.asgarniars.rs2.model.players.Player; /** * * author Joshua Barry <Sneakyhearts> * */ public class QuestRepository { /** * The amount of quests available in revision #317 */ public static final int AMOUNT_OF_QUESTS = 103; /** * The mapping holding all quest data. */ public static final Map<QuestEntry, Quest> QUEST_DATABASE = new HashMap<QuestEntry, Quest>(); /** * p.s. static initializers are ugly */ static { QUEST_DATABASE.put(new QuestEntry("SheepShearer", 7344), new SheepShearer()); QUEST_DATABASE.put(new QuestEntry("RuneMysteries", 7335), new RuneMysteries()); QUEST_DATABASE.put(new QuestEntry("DoricsQuest", 7336), new DoricsQuest()); QUEST_DATABASE.put(new QuestEntry("TheRestlessGhost", 7337), new TheRestlessGhost()); QUEST_DATABASE.put(new QuestEntry("DruidicRitual", 7355), new DruidicRitual()); QUEST_DATABASE.put(new QuestEntry("WitchsPotion", 7348), new WitchsPotion()); QUEST_DATABASE.put(new QuestEntry("WaterfallQuest", 7350), new WaterfallQuest()); QUEST_DATABASE.put(new QuestEntry("CooksAssistant", 1), new CooksAssistant()); } /** * Grabs a quest from the mapping with the given button index. * * [MENTION=75098]Para[/MENTION]m button The quest button id. * [MENTION=184045]return[/MENTION] The {@code Quest} which id matches the id given, or {@code null} * if the quest didn't exist. */ public static Quest get(int button) { Set<QuestEntry> entries = QUEST_DATABASE.keySet(); for (Iterator<QuestEntry> it$ = entries.iterator(); it$.hasNext();) { QuestEntry entry = it$.next(); if (entry.getValue() == button) { return QUEST_DATABASE.get(entry); } } return null; } /** * Grab a quest from the mapping with the given name. * * [MENTION=75098]Para[/MENTION]m name The quest's name. * [MENTION=184045]return[/MENTION] The {@code Quest} whose name matches the one provided, or * {@code null} if the quest with the given name couldn't be found. */ public static Quest get(String name) { Set<QuestEntry> entries = QUEST_DATABASE.keySet(); for (Iterator<QuestEntry> it$ = entries.iterator(); it$.hasNext();) { QuestEntry entry = it$.next(); if (entry.getKey().equalsIgnoreCase(name)) { return QUEST_DATABASE.get(entry); } } return null; } /** * Handles the quest side bar interfaces and name * * [MENTION=75098]Para[/MENTION]m player The player. */ public static void handle(Player player) { for (Quest quest : QUEST_DATABASE.values()) { if (player.getQuestStorage().hasStarted(quest)) { player.getActionSender().changeInterfaceComponentColor(quest.getQuestButton(), 0x33FF66); } if (player.getQuestStorage().hasFinished(quest)) { player.getActionSender().changeInterfaceComponentColor(quest.getQuestButton(), 0x3366); } player.getActionSender().sendString(quest.getQuestName(), quest.getQuestButton()); } } } [/CODE] Another class called QuestStorage [CODE] import java.util.HashMap; import java.util.Map; /** * Quest storage, a repository to hold the state's and access to quests. * * [MENTION=52317]auth[/MENTION]or Joshua Barry * */ public class QuestStorage { /** * The current quest states. */ private final Map<Quest, Integer> states = new HashMap<Quest, Integer>(); /** * Gets the quest state. * * [MENTION=75098]Para[/MENTION]m questId The quest id to check. * [MENTION=184045]return[/MENTION] The quest state (0 at default). */ public int getState(int questId) { return states.get(QuestRepository.get(questId)); } /** * Gets the quest state by quest. * * [MENTION=75098]Para[/MENTION]m quest The quest to check. * [MENTION=184045]return[/MENTION] The quest state (0 at default). */ public int getState(Quest quest) { return states.get(quest); } /** * Checks if the player has finished a certain quest. * * [MENTION=75098]Para[/MENTION]m quest The quest id. * [MENTION=184045]return[/MENTION] {@code True} if so, {@code false} if not. */ public boolean hasFinished(Quest quest) { if (states.containsKey(quest)) { return quest != null && quest.getFinalStage() <= states.get(quest); } return false; } /** * Checks if the player has started a certain quest. * * [MENTION=75098]Para[/MENTION]m quest The quest's id. * [MENTION=184045]return[/MENTION] {@code true} if the player has started the quest, {@code false} * if not. */ public boolean hasStarted(Quest quest) { if (states.containsKey(quest)) { return states.get(quest) > 0 && states.get(quest) < quest.getFinalStage(); } return false; } /** * * [MENTION=75098]Para[/MENTION]m questId The quest to set the stage for. * [MENTION=75098]Para[/MENTION]m state the state to set. */ public void setState(Quest quest, int state) { states.put(quest, state); } } [/CODE] Step 2: create another package which extends 'quest' and call it 'impl' (implementation's) now you create your abstract base class : QuestStructure [CODE] package com.asgarniars.rs2.content.quest.impl; import com.asgarniars.rs2.content.dialogue.Dialogue; import com.asgarniars.rs2.content.dialogue.StatementDialogue; import com.asgarniars.rs2.content.dialogue.StatementType; import com.asgarniars.rs2.content.quest.Quest; import com.asgarniars.rs2.content.quest.QuestRepository; import com.asgarniars.rs2.content.skills.Skill; import com.asgarniars.rs2.model.items.Item; import com.asgarniars.rs2.model.items.ItemManager; import com.asgarniars.rs2.model.players.Player; /** * The foundation of a quest upon which all other quests should stand. * * [MENTION=52317]auth[/MENTION]or Joshua Barry * */ public abstract class QuestStructure implements Quest { [MENTION=15855]Over[/MENTION]ride public void start(Player player) { if (!this.hasRequirements(player)) { Dialogue dialogue = new StatementDialogue(StatementType.NORMAL, new String[] { "You do not meet the requirements for this quest." }); player.open(dialogue); return; } player.getQuestStorage().setState(this, 1); QuestRepository.handle(player); player.setAttribute(getAttributeName(), (byte) -1); } [MENTION=15855]Over[/MENTION]ride public void end(Player player) { player.setQuestPoints(player.getQuestPoints() + getQuestPointAward()); giveRewards(player); QuestRepository.handle(player); player.getActionSender().sendMessage("Congratulations! Quest complete!"); player.removeAttribute(getAttributeName()); player.removeAttribute("currentQuest"); } [MENTION=15855]Over[/MENTION]ride public void giveRewards(Player player) { StringBuilder rewardNames = new StringBuilder(); if (getRewards() != null) for (Item item : getRewards()) { if (player.getInventory().hasRoomFor(item)) { player.getInventory().addItem(item); rewardNames.append(ItemManager.getInstance().getItemName(item.getId()).concat("\\n")); } } StringBuilder experienceGains = new StringBuilder(); for (int x = 0; x < this.getExperienceAward().length; x++) { short skill = (short) getExperienceAward()[x][0]; double exp = getExperienceAward()[x][1]; experienceGains.append((int) exp + " " + Skill.getSkillName(skill) + " XP.\\n"); player.getSkill().addExperience(skill, exp); } StringBuilder additionalMessage = new StringBuilder(); if (getAdditionalMessage() != null) additionalMessage.append(getAdditionalMessage().concat("\\n")); player.getActionSender().sendString(getQuestPointAward() + " Quest Points\\n".concat(experienceGains.toString().concat(additionalMessage.toString())).concat(rewardNames.toString()), 4444); player.getActionSender().sendString("You have completed the " + getQuestName() + " Quest!", 301); player.getActionSender().sendConfig(101, player.getQuestPoints()); player.getActionSender().sendInterface(297); } } [/CODE] COMPLETE!!! now to see an example of a quest I created (all object interactions, dialogues are coded into other areas of server as per usual) [CODE] package com.asgarniars.rs2.content.quest.impl; import com.asgarniars.rs2.content.skills.Skill; import com.asgarniars.rs2.model.items.Item; import com.asgarniars.rs2.model.players.Player; /** * * [MENTION=52317]auth[/MENTION]or Joshua Barry * */ public class DruidicRitual extends QuestStructure { [MENTION=15855]Over[/MENTION]ride public boolean hasRequirements(Player player) { return player.isLoggedIn(); } [MENTION=15855]Over[/MENTION]ride public boolean deathListener(Player player) { return false; } [MENTION=15855]Over[/MENTION]ride public boolean defeatListener(Player player) { return false; } [MENTION=15855]Over[/MENTION]ride public boolean dialougeListener(Player player) { if (player.getQuestStorage().hasFinished(this)) end(player); return true; } [MENTION=15855]Over[/MENTION]ride public Item[] getRewards() { return null; } [MENTION=15855]Over[/MENTION]ride public String getAttributeName() { return "DruidicRitual"; } [MENTION=15855]Over[/MENTION]ride public String getQuestName() { return "Druidic Ritual"; } [MENTION=15855]Over[/MENTION]ride public short getQuestPointAward() { return 4; } [MENTION=15855]Over[/MENTION]ride public double[][] getExperienceAward() { return new double[][] { { Skill.HERBLORE, 250 } }; } [MENTION=15855]Over[/MENTION]ride public String getAdditionalMessage() { return "Access to the Herblore skill"; } [MENTION=15855]Over[/MENTION]ride public short getFinalStage() { return 4; } [MENTION=15855]Over[/MENTION]ride public short getQuestButton() { return 7355; } } [/CODE] [CENTER] [IMG]http://i.imgur.com/6KZL7Kf.png[/IMG] [IMG]http://i.imgur.com/uo0jwzN.png[/IMG] [IMG]http://i.imgur.com/zWddSwq.png[/IMG] [/CENTER]
×