Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <cfcomponent output="false">
- <cfset this.artifacts = []/>
- <cfset this.targets = []/>
- <cfset this.locations = []/>
- <cfset this.questTypes = []/>
- <cffunction name="init" access="public" returntype="Any">
- <cfset createDefaults()/>
- <cfreturn this/>
- </cffunction>
- <cffunction name="createDefaults" access="private">
- <cfset addElement("artifacts","Super Robot Gloves")/>
- <cfset addElement("artifacts","Golden Crown of Sum'Guy")/>
- <cfset addElement("artifacts","Sword of 10000 Truths")/>
- <cfset addElement("artifacts","Noobslayer Boots")/>
- <cfset addElement("targets","King BadGuy The 3rd")/>
- <cfset addElement("targets","Bardy McAnnoyingSong")/>
- <cfset addElement("targets","Tim")/>
- <cfset addElement("targets","Sir John NotaTrap")/>
- <cfset addElement("locations","Mt Death")/>
- <cfset addElement("locations","The Galaxy of Terror")/>
- <cfset addElement("locations","The Zone of No Return")/>
- <cfset addElement("locations","Teddy Bear Junction")/>
- <cfset addElement("questTypes","Assassination")/>
- <cfset addElement("questTypes","Fetch Quest")/>
- <cfset addElement("questTypes","Treasure")/>
- </cffunction>
- <cffunction name="addElement" access="public">
- <cfargument name="elementType" type="string" required="true">
- <cfargument name="elementName" type="string" required="true">
- <cfif !structkeyexists(this,arguments.elementType)>
- <cfthrow message="Invalid element type">
- </cfif>
- <cfif !arrayfind(this[arguments.elementType],arguments.elementName)>
- <cfset arrayAppend(this[arguments.elementType],arguments.elementName)/>
- </cfif>
- </cffunction>
- <cffunction name="generateQuest" access="public" returntype="String">
- <cfargument name="questType" type="string" required="false" default="">
- <cfset var qType = arguments.questType/>
- <cfset var questText = ""/>
- <cfset var simpleSwitch = randRange(1,2)/>
- <cfif !len(qType)>
- <cfset qType = randomQuestType()/>
- </cfif>
- <cfswitch expression="#qType#">
- <cfcase value="Assassination">
- <cfsavecontent variable="questText">
- <cfoutput>
- Brave adventurer! There is a terrible threat to our kingdom. You must find and slay #randomElement('targets')#. They were last seen near #randomElement('locations')#. Find them, slay them and untold riches shall be yours!
- </cfoutput>
- </cfsavecontent>
- </cfcase>
- <cfcase value="Fetch Quest">
- <cfsavecontent variable="questText">
- <cfif simpleSwitch eq 1>
- <cfoutput>
- Greetings! I was wondering if you could do me a favor. My good friend #randomElement('targets')# has crafted #randomElement('artifacts')# for me. Could you travel to #randomElement('locations')# and get it for me?
- </cfoutput>
- <cfelse>
- <cfoutput>
- My Friend! I'm glad you are here. Could do me a favor? I need you to deliver #randomElement('artifacts')# to my good friend #randomElement('targets')# in #randomElement('locations')#. KTHXBAI!
- </cfoutput>
- </cfif>
- </cfsavecontent>
- </cfcase>
- <cfcase value="Treasure">
- <cfsavecontent variable="questText">
- <cfoutput>
- Psst. Come closer. I have heard tale of #randomElement('artifacts')#. Rumor has it that it is located in #randomElement('locations')#. All that's left is for someone to claim it!
- </cfoutput>
- </cfsavecontent>
- </cfcase>
- </cfswitch>
- <cfreturn questText/>
- </cffunction>
- <cffunction name="randomElement" access="private" returntype="String">
- <cfargument name="elementType" type="string" required="true">
- <cfset createObject("java","java.util.Collections").Shuffle(this[arguments.elementType])/>
- <cfreturn this[arguments.elementType][1]/>
- </cffunction>
- <cffunction name="randomQuestType" access="private" returntype="String">
- <cfset createObject("java","java.util.Collections").Shuffle(this.questTypes)/>
- <cfreturn this.questTypes[1]/>
- </cffunction>
- </cfcomponent>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement