<?php
class Completeq1View extends View{
public function index(){
$mysidia = Registry::get("mysidia");
$document = $this->document;
$document->setTitle("Turn in 10 Rock Cones");
// Allow user to complete quest if they have not yet.
if ($mysidia->user->quest1 = "no") {
$document->add(new Comment("<center>Text Text Text<center>", FALSE));
$this->takeItem("Rock Cone",10);
}
else{
$document->add(new Comment("The man furrows his brows at you, <b>sorry, no reward if you don't have any rock cones.</b>", FALSE));
}
}
public function takeItem($item, $qty){
$mysidia = Registry::get("mysidia");
$owned = $mysidia->db->select("inventory", array("quantity"), "itemname ='{$item}' and owner ='{$mysidia->user->username}'")->fetchColumn();
if ($owned >= $qty){
// If the user owns $qty amount or more...
if ($owned == $qty){
$amount = 100;
$mysidia->user->changecash($amount);
$document->add(new Comment("<center>You return to the scientit's camp and present the head scientist with 10 rock cones.<br>
<b>Wow, thank you! Here are some kibs!</b><br>
You've obtained {$amount} kibs!</center>", FALSE));
// Update that they have done the quest
$mysidia->db->update("users", array("quest1" => "yes"), "username = '{$mysidia->user->username}'");
// If the user has exactly $qty left, delete the whole row.
$mysidia->db->delete("inventory", "itemname='{$item}' and owner='{$mysidia->user->username}'");
$amount = 100;
$mysidia->user->changecash($amount);
$document->add(new Comment("<center>You return to the scientit's camp and present the head scientist with 10 rock cones.<br>
<b>Wow, thank you! Here are some kibs!</b><br>
You've obtained {$amount} kibs!</center>", FALSE));
// Update that they have done the quest
$mysidia->db->update("users", array("quest1" => "yes"), "username = '{$mysidia->user->username}'");
} else {
// Subtract $qty from user's inventory.
$owned_left = $owned - $qty;
$mysidia->db->update("inventory", array("quantity" => $owned_left), "itemname ='{$item}' and owner='{$mysidia->user->username}'");
}
} else {
throw new Exception("Sorry, you only have {$owned} {$item}, you need {$qty}!");
}
}
}
?>