Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by oliver-jones · Sep 07, 2013 at 10:33 AM · questsmissions

Missions/Quests - Best Way?

Hello,

I want to have a load of quests within my game (It's a free roam game) - a quest can be from "Walk to the shop and pick some apples up", to "Go visit your friend John", etc...

Whats the best way to construct this? Will I just have a load of variables dedicated to these mission? :

 var mission_ShopApples_Complete : boolean = false;
 var mission_VisitJohn_Complete : boolean = false;

Then possible sub variables for that mission:

 var mission_ShopApples_Title : String = "Apple Pickup";
 var mission_ShopApples_Reward : String = "Money +100";
 
 var mission_VisitJohn_Title : String = "Visit John";
 var mission_VisitJohn_Reward : String = "XP +4";

Considering I could of 100's of 1000's of quests. Is this a decent way of doing it? Just having a long ass script holding all these mission statuses?

Thanks, Ollie

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
7
Best Answer

Answer by Jamora · Sep 07, 2013 at 12:08 PM

I doubt there is such a thing as a universal "best way" when it comes to game design questions. I have found that trying to uphold the OOP principles is a good idea. Especially quests are obviously single objects in the game world, so I contend that the OOP way is a very good way.

Abstract your quests. Have a class for the most abstract notion of a Quest. Determine what behavior and data each quest shares, then put that in the Quest class. Notce, that you will be handling all quests as this class, so unless it in here, you won't have direct access to it. You could make it something like

 public abstract class Quest{

     protected static List<Quest> questList = new ...;

     public static List<Quest> GetQuests(){ return new List<Quest>(questList); }

     /*
       The abstract keyword requires the extending class 
       to provide an implementation.
     */
     //gives the rewards
     public abstract bool FinishQuest();
     //Returns the quest giver's description
     public abstract string GetDescription();
     //returns the current objective
     public abstract string GetObjective();
 }

Then move on to each sub type of Quest: you could have "FetchQuest", "TalkQuest" etc. Each of these classes will extend Quest.

Notice, in the Quest class, there is no BeginQuest(). That is because each sub type of Quest will have their own static constructor.

 public class FetchQuest : Quest{
     
     private string description;
     private string objective;
     
     public override bool FinishQuest(){ /*give rewards*/}
     public override string GetDescription(){ return description; }
     //every abstract method must be implemented here

     private FetchQuest(string newDescription, string newObjective){
         description = newDescription;
         objective = newObjective;
     }    

     public static FetchQuest GetApplesFromStore(){
         objective = "Walk into the store and get Apples."
         description = "I'm so hungry and need some apples. You look like a strong warrior, fetch me some apples from the nearby store.";
         questList.Add(new FetchQuest(description, objective));
     }
 }

Now all you need to do to begin and store the quest is to call FetchQuest.GetApplesFromStore(); from your quest giver code. When you ever feel the need to see what quests are currently active, you cain gain acces to (a copy of; to prevent accidental changes) the quest list with Quest.GetQuests();

Someone could argue that this design is in violation of the Single Responsibility Principle, which states that an object should do only one thing. My Quest class obviously maintains the quest list and represents a quest. If you feel the need to abide by the SOLID principles, then by all means, use a singleton QuestManager which maintains all the 'administrative' quest stuff. You'll also need a Factory to create the quests, because creating a new quest and representing one are two different behaviors, right? This all would add levels of complexity so I felt it better not to include it in these examples.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Miya7 · Jan 19, 2015 at 08:51 PM 0
Share

Thanks for this

avatar image kriptite · Dec 26, 2016 at 08:56 PM 0
Share

Thanks bro, this helped us a lot!

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

19 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Mission system, Postal service delivery game 0 Answers

GUI message scripting need help to create a info box 0 Answers

Android Google Quest reward data file. How do I wright it in C#? 2 Answers

How to make a pedometer in UNITY 1 Answer

PacMan IA of ghost using nodes/waypoints 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges