development rambling: Quest System

Forum
Last Post
Threads / Messages
Dev Ramblings: Quest System?
This may take a while, so this is mostly just going to be me jotting down notes and progress. Hope that's okay? So far I've made a database table:
  Spoiler: adopts_quests 
Code:
CREATE TABLE IF NOT EXISTS `adopts_quests` (
`quid` int(11) NOT NULL AUTO_INCREMENT,
`quest_name` varchar(80) NOT NULL,
`flavor_text` varchar(500) NOT NULL,
`objective` varchar(100) NOT NULL,
`completed_text` varchar(500) NOT NULL,
`repeatable` varchar(3) NOT NULL,
`cash_reward` smallint(6) NOT NULL,
`item_1` varchar(40) NOT NULL,
`item_1_qty` tinyint(4) NOT NULL,
`item_2` varchar(40) NOT NULL,
`item_2_qty` tinyint(4) NOT NULL,
`item_3` varchar(40) NOT NULL,
`item_3_qty` tinyint(4) NOT NULL,
`item_4` varchar(40) NOT NULL,
`item_4_qty` tinyint(4) NOT NULL,
PRIMARY KEY (`quid`)
)

But not much else. Quests will have a Title, Flavor Text, and then a reiterated Objective. For example:
Quest Name: Bees!
Flavor Text: Miss Porter needs honey to make her extra special candy. If you find a bee nest, she wants you to bring her back some honey.
Objective: Return with honey!​
When you return with the appropriate item or the action has been taken (there will be a Quest Log table built into the database as well, and it will keep track of quests you have actively doing, have completed, and ones that are available to you), either the page will know the quest is complete an immediately present you will completion text, or you'll have to press a button to turn in the text. You'll then be presented with Completed Text and possible rewards - cash and/or up to four different kinds of items, and any quantity of them you want to give the player.
Quest Name: Bees!
Completed Text: You present Miss Porter will delicious honey to make her extra special candy. "Is that honey? My, my! Good job!"
Rewards: 200 Cash, Special Honey Candy x3​
If a quest is repeatable, the option to begin the quest again should be available the next day (we'll save a timestamp in the Quest Log and check against it on page load). Speaking of, here's the quest log database:
  Spoiler: adopts_quest_logs 
Code:
CREATE TABLE IF NOT EXISTS `adopts_quest_logs` (
`quid` int(11) NOT NULL,
`user` varchar(20) NOT NULL,
`status` varchar(20) NOT NULL,
`stamp` datetime NOT NULL COMMENT 'Y-m-d H:i:s'
)

The status in the quest log will either be Completed, In-Progress, Repeatable, or Available. Available are for quests the user doesn't know they have access to yet, and have not started. If they visit a page that checks if the User has a QUID 'Available' to them, then the quest will reveal itself to the user and give them the opportunity to accept the quest and move into 'In-Progress' status.

My desire is for quests to be able to be started with a simple function call on just about any page. We'll also want a Quest Log page for users to view quests they're on anytime they need to, for reference.

To do this we're going to need to make a new class. I've got two methods in the class so far - one to set the status in the quest log, and one to pull up basic information.

  Spoiler: classes/class_quest.php 
PHP:
<?php
use Resource\Native\Object;
class Quest extends Object{

public function questLog($quid, $action, $repeatable){
$mysidia = Registry::get("mysidia");
$stamp = date("Y-m-d h:i:s");
$status = $mysidia->db->select("quest_logs", array("status"), "quid='{$quid}' and user='{$mysidia->user->username}'")->fetchColumn();
switch($action){
case "start":
if (!$status){
if ($repeatable == "Repeatable"){
$status = "Repeatable";
$mysidia->db->insert("quest_logs", array("quid" => $quid, "user" => $mysidia->user->username, "status" => $status, "stamp" => $stamp));
} else {
$status = "In-Progress";
$mysidia->db->insert("quest_logs", array("quid" => $quid, "user" => $mysidia->user->username, "status" => $status, "stamp" => $stamp));
}
}
if ($status == "Available"){
if ($repeatable == "Repeatable"){
$status = "Repeatable";
$mysidia->db->insert("quest_logs", array("quid" => $quid, "user" => $mysidia->user->username, "status" => $status, "stamp" => $stamp));
} else {
$status = "In-Progress";
$mysidia->db->update("quest_logs", array("status" => $status, "stamp" => $stamp), "quid = '{$quid}' AND user = '{$mysidia->user->username}'");
}
}
break;
case "complete":
if ($repeatable == "Repeatable"){
$status = "Repeatable";
$mysidia->db->update("quest_logs", array("status" => $status, "stamp" => $stamp), "quid = '{$quid}' AND user = '{$mysidia->user->username}'");
} else {
$status = "Complete";
$mysidia->db->update("quest_logs", array("status" => $status, "stamp" => $stamp), "quid = '{$quid}' AND user = '{$mysidia->user->username}'");
}
break;
case "unlock":
if (!$status){
$status = "Available";
$mysidia->db->insert("quest_logs", array("quid" => $quid, "user" => $mysidia->user->username, "status" => $status, "stamp" => $stamp));
}
break;
default:
throw new Exception("Invalid Quest operation!");
} # END switch($action)
} # END questLog method

public function questInfo($quid){
$mysidia = Registry::get("mysidia");
$questInfo = $mysidia->db->select("quests", array(), "quid ='1'")->fetchObject();
return $questInfo;
} # END questInfo method

} # END class Quest
?>

Quest Info
Where you wanna pull up quest info, you just gotta plant in a link to the class. ( $quest = new Quest(); ) Then ask it for the info using the quest's id number as it's stored in the database. ( $questinfo = $quest->questInfo(1); ) Now, you can pull up specific properties! For example, if you want the title of that quest, you could use ( {$questinfo->title} ).

Unlocking Quests
Some quests you may not want to be available until later. Normally, nothing eventful happens when you visit the river. But, say you just helped some critters in the woods. Well, at the river, everyone heard about your good deeds and want you to do a thing for them now, too. When you finished the quest at the woods, you 'unlocked' the quest at the river.

To unlock quest #5: $quest->questLog(5, "unlock");

In the database, a quest will appear in the quest_logs with the quid of 5, a status of available, accompanied with the user's name.

Starting Quests
We'll want to press a confirmation button for this (it would be rare that you would auto-start a quest for a user). I don't have this formulated up yet, but, you'll be able to call a start to quest #5 like this: $quest->questLog(5, "start");

If the quest is repeatable, you'll want to include a third parameter to say so - : $quest->questLog(5, "start", "repeatable");


Completing Quests
You'll be able to mark quest #5 as comlete like this: $quest->questLog(5, "complete");

If the quest is repeatable, you'll want to include a third parameter to say so - : $quest->questLog(5, "complete", "repeatable");

This will just set (non-repeatable) quests to 'Complete' in the quest log. On the other hand, I may not want to keep track of completed quests, and may opt to replace this with just deleting the row once the rewards have been dispensed.

Anyway, right now, completing won't reward anything, and that's all the progress I've made.

-

So I've got some forms to build and implementation areas to suggest.

There's more than one type of quest I need to incorporate. Not just 'bring me x' it's also 'go talk to so-and-so'. This is going to be complicated so I'm not totally sure how many hoops I'm going to have to make people jump through to implement it. At least I'm good at writing tutorials!

Anyway, these are just my rough thoughts so far, and are subject to change.

And... feedback is welcome. Since this is something I'd like to release to the community when it's nice and done, let me know your needs and desires from a quest system.

Comments

Seems like you're doing an amazing job!
Looks very promising.

This could go so very well with the Alchemy mod.
 
Ah, I was looking for this exact thing the other day, and today I stumble across it accidentally. This is definitely a feature I want on my own site, so I'd be interested in any progress you make on this- assuming you are still planning on finishing it, that is.
 
  • Forum Contains New Posts
  • Forum Contains No New Posts

Blog entry information

Author
Kyttias
Views
425
Comments
2
Last update

More entries in Mysidia

More entries from Kyttias

Forum statistics

Threads
4,267
Messages
33,048
Members
1,602
Latest member
BerrieMilk
BETA

Latest Threads

Latest Posts

Top