Thread: Quest System

Page 1 of 2 12 LastLast
Results 1 to 10 of 11
  1. #1 Quest System 
    Registered Member Taylor Moon's Avatar
    Join Date
    Aug 2012
    Posts
    2,568
    Thanks given
    625
    Thanks received
    1,301
    Rep Power
    66
    Hi. I made a quest system, hope you like it.


    Code:
    package org.intel.game.quests;
    
    import org.intel.game.player.Player;
    import org.intel.game.player.controlers.Controller;
    
    /**
     * @author Taylor Moon
     * 
     * @since Dec 24, 2012 | Elixrr 2.0
     */
    public abstract class Quest {
    
    	/**
    	 * Contstructs this quest
    	 * 
    	 * @param questName
    	 *            The name of this quest
    	 * @param difficulty
    	 *            The difficulty of this quest
    	 */
    	public Quest(String questName, QuestDifficulty difficulty) {
    		this.questName = questName;
    		this.difficulty = difficulty;
    	}
    
    	/** The name of this quest */
    	protected String questName;
    
    	/** The difficulty of this quest */
    	protected QuestDifficulty difficulty;
    
    	/** The player associated with this quest */
    	protected Player player;
    
    	/** The controlers of this quest */
    	private Controller[] controller;
    
    	/** The reward given to the player when this quest has been completed */
    	private Object[] reward;
    
    	/** The progress of this quest at this moment */
    	private QuestProgress progress;
    
    	/**
    	 * Called when this quest is started. If the quest has already been
    	 * finished, or has already been started, the process will terminate
    	 */
    	public abstract void start();
    
    	/**
    	 * Typically called when the quest has been finished. Gives the player their
    	 * reward after completing this quest
    	 */
    	public abstract void giveReward();
    
    	/**
    	 * Called when this quest has been finished. This method usally invoked the
    	 * {@code giveReward}, not to be confused with {@code getReward}
    	 */
    	public abstract void finish();
    
    	/**
    	 * Starts one of the specified controllers in the array of previously set
    	 * controllers. If the player is already using the specified controller, or
    	 * the controller corresponding to the index is equal to <i>null</i>, the
    	 * return value will be <i>null</i>
    	 * 
    	 * @param index
    	 *            The index in the array of the controller you're attempting to
    	 *            start
    	 * @return The controller that was started when this method is called, or
    	 *         <i>null</i> reason stated above
    	 */
    	public final Controller startController(int index) {
    		if (player.getControlerManager().getControler()
    				.equals(controller[index]))
    			return null;
    		controller[index].start();
    		return controller[index];
    	}
    
    	/**
    	 * Sets the controllers that will be used during this quest.
    	 * 
    	 * @param controllers
    	 *            The controllers to set for this quest
    	 */
    	public final void setControllers(Controller[] controllers) {
    		controller = controllers;
    	}
    
    	/**
    	 * Returns the controllers associated with this quest. If there are no
    	 * <i>set</i> controllers, then it will return <i>null</i>
    	 * 
    	 * @return The controllers associated with this quest, or <i>null</i>
    	 */
    	public final Controller[] getControllers() {
    		return controller;
    	}
    
    	/**
    	 * Sets the reward that will be given to a player when this quest has been
    	 * completed. If the specified reward is equal to <i>null</i> then the
    	 * method will return <i>null</i>, and the reward will not be set
    	 * 
    	 * @param reward
    	 *            The object that the reward will be set to
    	 * @return The set reward, or <i>null</i>; reason stated above
    	 */
    	public final Object setReward(Object[] reward) {
    		if (reward == null)
    			return null;
    		this.reward = reward;
    		return reward;
    	}
    
    	/**
    	 * Returns the current quest progress of this quest. If the progress has not
    	 * yet been set, the method will return <i>null</i>
    	 * 
    	 * @return The previously set quest progress, or <i>null</i>; reason stated
    	 *         above
    	 */
    	public final QuestProgress getProgress() {
    		return progress;
    	}
    
    	/**
    	 * Sets the progress of the quest. If the specified progress is equal to
    	 * <i>null</i>, then the progress will not be set.
    	 * 
    	 * @param qp
    	 *            The progress of the quest
    	 */
    	public final void setProgress(QuestProgress qp) {
    		if (qp == null)
    			return;
    		progress = qp;
    	}
    
    	/**
    	 * Returns the reward that was previously set. If the reward has not yet
    	 * been set, or was somehow set to <i>null</i>, then the method will return
    	 * <i>null</i>
    	 * 
    	 * @return The previously set reward, or <i>null</i>; reason stated above
    	 */
    	public final Object[] reward() {
    		return reward;
    	}
    
    	/**
    	 * Returns the name of this quest. The quest name is assigned when the class
    	 * is constructed
    	 * 
    	 * @return The name of this quest
    	 */
    	public final String getQuestName() {
    		return questName;
    	}
    
    	/**
    	 * Returns the pre defined difficulty of this quest. The quest difficulty is
    	 * assigned when this class is constructed
    	 * 
    	 * @return The difficulty of this quest
    	 */
    	public final QuestDifficulty getDifficulty() {
    		return difficulty;
    	}
    
    }
    Code:
    package org.intel.game.quests;
    
    /**
     * @author Taylor Moon
     * 
     * @since Dec 24, 2012 | Elixrr 2.0
     */
    public enum QuestDifficulty {
    
    	/**
    	 * Represents an array of different quest difficulties.
    	 */
    	NOVICE, INTERMEDIATE, EXPERIENCED, MASTER, GRANDMASTER, SPECIAL
    
    }
    Code:
    package org.intel.game.quests;
    
    import java.io.IOException;
    import java.util.HashMap;
    
    import org.intel.utils.Logger;
    import org.intel.utils.Utils;
    
    /**
     * @author Taylor Moon
     * 
     * @since Dec 24, 2012 | Elixrr 2.0
     */
    public class QuestHandler {
    
    	/**
    	 * The list of quests in the implementation package
    	 */
    	protected static final HashMap<Object, Class<Quest>> QUESTS = new HashMap<Object, Class<Quest>>();
    
    	/**
    	 * Initiates this quest handler
    	 */
    	@SuppressWarnings({ "unchecked", "static-access" })
    	public static void init() {
    		try {
    			Class<?>[] classes = Utils.getClasses("org.intel.game.quests.impl");
    			if (classes == null)
    				return;
    			for (Class<?> c : classes) {
    				if (!c.getSuperclass().getName().equals("Quest"))
    					return;
    				QUESTS.put(c.getName(),
    						(Class<Quest>) c.forName(c.getCanonicalName()));
    			}
    		} catch (ClassNotFoundException | IOException e) {
    			e.printStackTrace();
    		}
    	}
    
    	/**
    	 * Returns the quest in the hashmap that corresponds to the specified key in
    	 * the parameter.
    	 * 
    	 * @param key
    	 *            The quest key
    	 * @return The quest corresponding to the key in the map
    	 */
    	protected final Quest getQuest(Object key) {
    		if (key instanceof Quest)
    			return (Quest) key;
    		Class<Quest> q = QUESTS.get(key);
    		if (q == null)
    			return null;
    		try {
    			return q.newInstance();
    		} catch (Throwable e) {
    			Logger.handle(e);
    		}
    		return null;
    	}
    
    }
    Code:
    package org.intel.game.quests;
    
    import java.util.ArrayList;
    
    import org.intel.game.player.Player;
    
    /**
     * @author Taylor Moon
     * 
     * @since Dec 24, 2012 | Elixrr 2.0
     */
    public class QuestManager extends QuestHandler {
    
    	/** The quest associated with the player */
    	private static final ArrayList<Quest> STARTED_QUESTS = new ArrayList<Quest>();
    	// Because a player could have 2 or more quests started but not finished
    
    	/** The player associated with this quest manager */
    	private static Player player;
    
    	/**
    	 * Processes the quest as a player is attempting to do it.
    	 */
    	public void process() {
    		for (Quest q : STARTED_QUESTS) {
    			while (player != null || !player.hasFinished()) {
    				if (q.getProgress().equals(QuestProgress.COMPLETE)) {
    					q.giveReward();
    					q.finish();
    					STARTED_QUESTS.remove(q);
    				}
    			}
    		}
    	}
    
    	/**
    	 * Starts a quest
    	 * 
    	 * @param questName
    	 *            The name of the quest you wish to start
    	 */
    	public void startQuest(String questName) {
    		Quest q = getQuest(questName);
    		if (q == null || STARTED_QUESTS.contains(q))
    			return;
    		STARTED_QUESTS.add(q);
    		q.start();
    	}
    
    	/**
    	 * Returns the player associated with this quest manager
    	 * 
    	 * @return The player
    	 */
    	public Player getPlayer() {
    		return player;
    	}
    
    	/**
    	 * Sets the player of this class to the specified player
    	 * 
    	 * @param p
    	 *            The player to set
    	 */
    	public void setPlayer(Player p) {
    		player = p;
    	}
    
    	/**
    	 * Returns an arraylist of quests that the player has started
    	 * 
    	 * @return The player's started quests.
    	 */
    	public ArrayList<Quest> getStartedQuests() {
    		return STARTED_QUESTS;
    	}
    
    }
    Code:
    package org.intel.game.quests;
    
    /**
     * @author Taylor Moon
     * 
     * @since Dec 24, 2012 | Elixrr 2.0
     */
    public enum QuestProgress {
    
    	/**
    	 * The types of progresses that a player has when a quest has been started
    	 * or not
    	 */
    	NOT_STARTED, STARTED, COMPLETE;
    
    }

    Things like completed quest configs, requirements, etc are still in development. But that's the skeleton.

    Reply With Quote  
     

  2. Thankful user:


  3. #2  
    Mug Club


    Join Date
    Jul 2011
    Age
    26
    Posts
    1,873
    Thanks given
    509
    Thanks received
    890
    Discord
    View profile
    Rep Power
    332
    This looks exactly like the one in Matrix already but with a disgusting amount of commenting.


    My Open Source Projects
    [Only registered and activated users can see links. ]
    [Only registered and activated users can see links. ]
    Reply With Quote  
     

  4. #3  
    Registered Member Taylor Moon's Avatar
    Join Date
    Aug 2012
    Posts
    2,568
    Thanks given
    625
    Thanks received
    1,301
    Rep Power
    66
    Quote Originally Posted by TitanPK View Post
    This looks exactly like the one in Matrix already but with a disgusting amount of commenting.
    Ever heard of organization? And no, there is almost zero resemblance to the one matrix had.
    Reply With Quote  
     

  5. #4  
    Developer

    Holy Symbol's Avatar
    Join Date
    Dec 2011
    Age
    23
    Posts
    1,762
    Thanks given
    1,047
    Thanks received
    232
    Rep Power
    232
    Meh, It looks ok
    Spoiler for big sig:


    Reply With Quote  
     

  6. #5  
    touched like seafood
    Tyluur's Avatar
    Join Date
    Jun 2010
    Age
    23
    Posts
    4,836
    Thanks given
    1,676
    Thanks received
    1,563
    Discord
    View profile
    Rep Power
    1386
    Code:
    public enum QuestDifficulty {
    
    	/**
    	 * Represents an array of different quest difficulties.
    	 */
    	NOVICE, INTERMEDIATE, EXPERIENCED, MASTER, GRANDMASTER, SPECIAL
    
    }
    Documentation not matching up with the code.

    Anyways, good effort.
    [Only registered and activated users can see links. ] | [Only registered and activated users can see links. ] | [Only registered and activated users can see links. ] (official dog of rune-server)
    Quote Originally Posted by blakeman8192 View Post
    Keep trying. Quitting is the only true failure.
    Reply With Quote  
     

  7. #6  
    Registered Member
    Join Date
    Dec 2011
    Posts
    0
    Thanks given
    87
    Thanks received
    74
    Rep Power
    0
    Not bad, cba to use it though. Rep++ though.


    Quote Originally Posted by Stevie View Post
    I know but there is like 5 servers with deadlypkers's source. it's being passed around like the school's whore.
    Quote Originally Posted by King J Scape View Post
    Not everything in life can be pretty, look at your self for an example.
    Have a nice day.
    [Spoil][/Spoil]
    Reply With Quote  
     

  8. #7  
    Registered Member
    Join Date
    Aug 2011
    Posts
    396
    Thanks given
    29
    Thanks received
    57
    Rep Power
    9
    Taylor, mind releasing cook assistent when your done so we get a idea of how to use this
    Reply With Quote  
     

  9. #8  
    Extreme Donator


    Join Date
    Jul 2009
    Age
    24
    Posts
    4,350
    Thanks given
    824
    Thanks received
    1,237
    Rep Power
    1789
    Quote Originally Posted by Tyluur View Post
    Code:
    public enum QuestDifficulty {
    
    	/**
    	 * Represents an array of different quest difficulties.
    	 */
    	NOVICE, INTERMEDIATE, EXPERIENCED, MASTER, GRANDMASTER, SPECIAL
    
    }
    Documentation not matching up with the code.

    Anyways, good effort.
    Lol yea, it's not an array, it's an enumeration.

    You can find my [Only registered and activated users can see links. ], for what I'm currently working on.
    Reply With Quote  
     

  10. #9  
    New Project
    Ben_U's Avatar
    Join Date
    Dec 2011
    Age
    28
    Posts
    1,715
    Thanks given
    109
    Thanks received
    359
    Rep Power
    66
    Quote Originally Posted by Tyluur View Post
    Code:
    public enum QuestDifficulty {
    
    	/**
    	 * Represents an array of different quest difficulties.
    	 */
    	NOVICE, INTERMEDIATE, EXPERIENCED, MASTER, GRANDMASTER, SPECIAL
    
    }
    Documentation not matching up with the code.

    Anyways, good effort.
    Glad to see your back.

    Awesome work Taylor!
    Reply With Quote  
     

  11. #10  
    Registered Member
    Lysergist's Avatar
    Join Date
    Jul 2012
    Posts
    914
    Thanks given
    370
    Thanks received
    536
    Discord
    View profile
    Rep Power
    138
    Why did you base it off of controllers?
    [Only registered and activated users can see links. ]
    Reply With Quote  
     

Page 1 of 2 12 LastLast

Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. [PI] Quest System
    By Dexter Morgan in forum Tutorials
    Replies: 10
    Last Post: 10-06-2011, 10:01 PM
  2. Quest System
    By Lil Str Kid in forum Tutorials
    Replies: 69
    Last Post: 10-04-2011, 04:46 PM
  3. Quest System
    By Infexis in forum Show-off
    Replies: 29
    Last Post: 02-02-2011, 08:43 PM
  4. New quest system - updated+sample quest
    By tj007razor in forum Tutorials
    Replies: 55
    Last Post: 12-05-2008, 01:47 PM
  5. [508]3M Quest System
    By MoonShade in forum Projects
    Replies: 19
    Last Post: 09-03-2008, 01:39 AM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •