• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[Wurst] Quest

Chaosy

Tutorial Reviewer
Level 40
Joined
Jun 9, 2011
Messages
13,183

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.

Wurst:
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()
Wurst:
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

Wurst:
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)
 

Attachments

  • WurstRunMap.w3x
    35 KB · Views: 218
Last edited:
Level 23
Joined
Jan 1, 2009
Messages
1,608
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
 
Top