1. Updated Resource Submission Rules: All model & skin resource submissions must now include an in-game screenshot. This is to help speed up the moderation process and to show how the model and/or texture looks like from the in-game camera.
    Dismiss Notice
  2. DID YOU KNOW - That you can unlock new rank icons by posting on the forums or winning contests? Click here to customize your rank or read our User Rank Policy to see a list of ranks that you can unlock. Have you won a contest and still havn't received your rank award? Then please contact the administration.
    Dismiss Notice
  3. The Lich King demands your service! We've reached the 19th edition of the Icon Contest. Come along and make some chilling servants for the one true king.
    Dismiss Notice
  4. The 4th SFX Contest has started. Be sure to participate and have a fun factor in it.
    Dismiss Notice
  5. The poll for the 21st Terraining Contest is LIVE. Be sure to check out the entries and vote for one.
    Dismiss Notice
  6. The results are out! Check them out.
    Dismiss Notice
  7. Don’t forget to sign up for the Hive Cup. There’s a 555 EUR prize pool. Sign up now!
    Dismiss Notice
  8. The Hive Workshop Cup contest results have been announced! See the maps that'll be featured in the Hive Workshop Cup tournament!
    Dismiss Notice
  9. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

[Wurst] Quest

Discussion in 'Graveyard' started by Chaosy, Oct 21, 2017.

  1. Chaosy

    Chaosy

    Joined:
    Jun 9, 2011
    Messages:
    10,611
    Resources:
    18
    Maps:
    1
    Spells:
    11
    Tutorials:
    6
    Resources:
    18

    Quest


    Heavily based on Mckill's QuestUtils

    A little something I wrote while trying to learn Wurst.
    Overall pretty pleasant.

    Code is divided in 2 files
    • Quest
    • QuestItems
    The extension files only contain some API improvements to make the code look cleaner.

    Code (WurstScript):

    package Quest

    import QuestExtensions
    import QuestObjective

    public enum questState
        FAILED
        COMPLETED
        UNDISCOVERED
        DISCOVERED

    public class Quest
        quest q
        construct(boolean required)
            q = CreateQuest()
            q.setRequired(required)

        function setTitle(string title)
            q.setTitle(title)

        function setDescription(string title)
            q.setDescription(title)

        function setIcon(string path)
            q.setIcon(path)

        function isEnabled() returns boolean
            return q.isEnabled()

        function isCompleted() returns boolean
            return q.isCompleted()

        function setState(questState state)
            switch state
                case state.COMPLETED
                    q.completed(true)
                case state.FAILED
                    q.failed(true)
                case state.UNDISCOVERED
                    q.discovered(false)
                case state.DISCOVERED
                    q.discovered(true)

        function addObjective(string text) returns QuestObjective
            return new QuestObjective(q, text)
         
        ondestroy
            q.remove()
    Code (WurstScript):

    package QuestObjective

    import QuestObjectiveExtensions

    public class QuestObjective
        questitem qi
        quest parent
        construct(quest q, string text)
            parent = q
            qi = QuestCreateItem(parent)
            qi.description(text)

        function isCompleted() returns boolean
            return qi.isCompleted()
     
        function complete(boolean b)
            qi.complete(b)

    Demo


    Code (WurstScript):

    Quest farmQ
    QuestObjective farmObj

    init
        farmQ = new Quest(true)
        ..setTitle("Dope Quest")
        ..setIcon("ReplaceableTextures\\CommandButtons\\BTNDivineIntervention.blp")
        ..setDescription("A farmer's wife has been missing for a few days")
     
        farmObj = farmQ.addObjective("Find the farmer's wife")

        CreateTrigger()
        ..registerUnitInRange(CreateUnit(players[0], 'nvlw', 300, 300, 0), 250, null)
        ..addAction(() -> begin
            print("Wife found!")
            farmObj.complete(true)
            farmQ.setState(questState.COMPLETED)
        end)
     

    Attached Files:

    Last edited: Nov 30, 2017
  2. Frotty

    Frotty

    Wurst Reviewer

    Joined:
    Jan 1, 2009
    Messages:
    1,428
    Resources:
    11
    Models:
    3
    Tools:
    1
    Maps:
    5
    Tutorials:
    1
    Wurst:
    1
    Resources:
    11
    Oh, hi, only seeing this now tbh.
    Since Quests are a very essential thing, I think at least the QuestExtension should be added to the standard library, since we don't have any for them yet.
    Please make a pull request here GitHub - wurstscript/WurstStdlib2: WurstScript Standard Library Version 2 or paste the package then I can do it.

    Small notes on that:
    • To adhere to stdlib conventions, the "extenstions" package should be named "Quest.wurst" and the package containing extra functionality be named something like "Quest[Utils/Helper]"
    • I think QuestObjective could be in the same file as Quest
    • And the extension could also be merged
    • Enum questState should start with capital letter -> QuestState
    Of course this could also easily be expanded
    • Save Queststate in Quest so you can access it
    • Save the questitems in quest e.g. via LinkedList
     
  3. Cokemonkey11

    Cokemonkey11

    Wurst Reviewer

    Joined:
    May 9, 2006
    Messages:
    3,240
    Resources:
    18
    Tools:
    1
    Maps:
    5
    Spells:
    3
    Tutorials:
    2
    JASS:
    7
    Resources:
    18
    I guess the
    *Extenions
    packages are just APIs that provide the extension functions and nothing more?

    Looks good overall.
     
  4. Chaosy

    Chaosy

    Joined:
    Jun 9, 2011
    Messages:
    10,611
    Resources:
    18
    Maps:
    1
    Spells:
    11
    Tutorials:
    6
    Resources:
    18
  5. Frotty

    Frotty

    Wurst Reviewer

    Joined:
    Jan 1, 2009
    Messages:
    1,428
    Resources:
    11
    Models:
    3
    Tools:
    1
    Maps:
    5
    Tutorials:
    1
    Wurst:
    1
    Resources:
    11
    Creating a pull request - User Documentation

    Basically fork the repo(on website), apply your changes, commit(shell/vscode) and then request a merge(on website again).
    Or do you want me to do it for now?
    Thanks anyways, good stuff!
     
  6. Chaosy

    Chaosy

    Joined:
    Jun 9, 2011
    Messages:
    10,611
    Resources:
    18
    Maps:
    1
    Spells:
    11
    Tutorials:
    6
    Resources:
    18
    If it is no bother ;P
     
  7. Frotty

    Frotty

    Wurst Reviewer

    Joined:
    Jan 1, 2009
    Messages:
    1,428
    Resources:
    11
    Models:
    3
    Tools:
    1
    Maps:
    5
    Tutorials:
    1
    Wurst:
    1
    Resources:
    11
    Hey, this was merged, can I move it to GY?
     
  8. Chaosy

    Chaosy

    Joined:
    Jun 9, 2011
    Messages:
    10,611
    Resources:
    18
    Maps:
    1
    Spells:
    11
    Tutorials:
    6
    Resources:
    18
  9. Frotty

    Frotty

    Wurst Reviewer

    Joined:
    Jan 1, 2009
    Messages:
    1,428
    Resources:
    11
    Models:
    3
    Tools:
    1
    Maps:
    5
    Tutorials:
    1
    Wurst:
    1
    Resources:
    11
    nvm I can't