I was able to do it, or at least it works fine on my end. (If it doesn't work, I forgot something) This is what I did:
First go to phpMyAdmin and add another column in adopts_alchemy called item3 with the exact same settings as item and item2.
PHP Code:
<?php
class ACPAlchemyController extends AppController{
const PARAM = "alid";
public function __construct(){
parent::__construct();
$mysidia = Registry::get("mysidia");
if($mysidia->usergroup->getpermission("canmanagesettings") != "yes"){
throw new NoPermissionException("You do not have permission to manage alchemy.");
}
}
public function index(){
parent::index();
$mysidia = Registry::get("mysidia");
$stmt = $mysidia->db->select("alchemy");
$num = $stmt->rowCount();
if($num == 0) throw new InvalidIDException("default_none");
$this->setField("stmt", new DatabaseStatement($stmt));
}
public function add(){
$mysidia = Registry::get("mysidia");
if($mysidia->input->post("submit")){
$this->dataValidate();
$mysidia->db->insert("alchemy", array("alid" => NULL, "item" => $mysidia->input->post("item"), "item2" => $mysidia->input->post("item2"),
"newitem" => $mysidia->input->post("newitem"), "chance" => $mysidia->input->post("chance"), "recipe" => $mysidia->input->post("recipe"), "item3" => $mysidia->input->post("item3")));
}
$this->loadItemMap();
}
public function edit(){
$mysidia = Registry::get("mysidia");
if(!$mysidia->input->get("alid")){
// An item has yet been selected, return to the index page.
$this->index();
return;
}
elseif($mysidia->input->post("submit")){
$this->dataValidate();
$mysidia->db->update("alchemy", array("item" => $mysidia->input->post("item"), "item2" => $mysidia->input->post("item2"),"item3" => $mysidia->input->post("item3"), "newitem" => $mysidia->input->post("newitem"),
"chance" => $mysidia->input->post("chance"), "recipe" => $mysidia->input->post("recipe")), "alid='{$mysidia->input->get("alid")}'");
return;
}
else{
$alchemy = $mysidia->db->select("alchemy", array(), "alid='{$mysidia->input->get("alid")}'")->fetchObject();
if(!is_object($alchemy)) throw new InvalidIDException("nonexist");
$this->setField("alchemy", new DataObject($alchemy));
$this->loadItemMap();
}
}
public function delete(){
$mysidia = Registry::get("mysidia");
if(!$mysidia->input->get("alid")){
// An item has yet been selected, return to the index page.
$this->index();
return;
}
$mysidia->db->delete("alchemy", "alid='{$mysidia->input->get("alid")}'");
}
public function settings(){
$mysidia = Registry::get("mysidia");
$alchemySettings = new AlchemySetting($mysidia->db);
if($mysidia->input->post("submit")){
$settings = array('system', 'chance', 'recipe', 'cost', 'license', 'usergroup');
foreach($settings as $name){
if($mysidia->input->post($name) != ($alchemySettings->$name)) $mysidia->db->update("alchemy_settings", array("value" => $mysidia->input->post($name)), "name='{$name}'");
}
return;
}
$this->setField("alchemySettings", $alchemySettings);
}
private function dataValidate(){
$mysidia = Registry::get("mysidia");
if(!$mysidia->input->post("item") or !is_numeric($mysidia->input->post("item"))) throw new BlankFieldException("item");
if(!$mysidia->input->post("item2") or !is_numeric($mysidia->input->post("item2"))) throw new BlankFieldException("item2");
if(!$mysidia->input->post("item3") or !is_numeric($mysidia->input->post("item3"))) throw new BlankFieldException("item3");
if($mysidia->input->action() == "add"){
$whereClause = "(item = {$mysidia->input->post("item")} and item2 = {$mysidia->input->post("item2")} and item3 = {$mysidia->input->post("item3")}) OR (item = {$mysidia->input->post("item2")} and item2 = {$mysidia->input->post("item")} and item = {$mysidia->input->post("item3")})";
$alchemy = $mysidia->db->select("alchemy", array(), $whereClause)->fetchObject();
if(is_object($alchemy)) throw new DuplicateIDException("duplicate");
}
if(!$mysidia->input->post("newitem")) throw new BlankFieldException("newitem");
if($mysidia->input->post("chance") < 0 or $mysidia->input->post("chance") > 100) throw new InvalidActionException("chance");
header("Refresh:3; URL='../../index'");
return TRUE;
}
private function loadItemMap(){
$mysidia = Registry::get("mysidia");
$stmt = $mysidia->db->select("items", array("id", "itemname"));
$map = $mysidia->db->fetchMap($stmt);
$this->setField("itemMap", $map);
$stmt2 = $mysidia->db->select("items", array("id", "itemname"), "function = 'Recipe'");
$map2 = $mysidia->db->fetchMap($stmt2);
$this->setField("recipeMap", $map2);
}
}
?>
(alchemy.php)
PHP Code:
<?php
use Resource\Native\String;
use Resource\Collection\LinkedHashMap;
class ACPAlchemyView extends View{
public function index(){
parent::index();
$mysidia = Registry::get("mysidia");
$stmt = $this->getField("stmt")->get();
$document = $this->document;
$fields = new LinkedHashMap;
$fields->put(new String("alid"), NULL);
$fields->put(new String("item"), new String("getItemImage"));
$fields->put(new String("item2"), new String("getItemImage"));
$fields->put(new String("item3"), new String("getItemImage"));
$fields->put(new String("newitem"), new String("getItemImage"));
$fields->put(new String("alid::edit"), new String("getEditLink"));
$fields->put(new String("alid::delete"), new String("getDeleteLink"));
$AlchemyTable = new TableBuilder("alchemy");
$AlchemyTable->setAlign(new Align("center", "middle"));
$AlchemyTable->buildHeaders("ID", "Item1", "Item2","Item3", "New Item", "Edit", "Delete");
$AlchemyTable->setHelper(new ItemTableHelper);
$AlchemyTable->buildTable($stmt, $fields);
$document->add($AlchemyTable);
}
public function add(){
$mysidia = Registry::get("mysidia");
$document = $this->document;
if($mysidia->input->post("submit")){
$document->setTitle($this->lang->added_title);
$document->addLangvar($this->lang->added);
return;
}
$document->setTitle($this->lang->add_title);
$document->addLangvar($this->lang->add);
$itemMap = $this->getField("itemMap");
$recipeMap = $this->getField("recipeMap");
$alchemyForm = new Form("createalchemy", "add", "post");
$title = new Comment("Create new Alchemy Practice:");
$title->setBold();
$title->setUnderlined();
$alchemyForm->add($title);
$alchemyForm->add(new Comment("Select first ingredient item: ", FALSE));
$items = new DropdownList("item");
$items->add(new Option("None Selected", "none"));
if($itemMap->size() > 0){
$iterator = $itemMap->iterator();
while($iterator->hasNext()){
$item = $iterator->nextEntry();
$items->add(new Option($item->getValue(), $item->getKey()));
}
}
$alchemyForm->add($items);
$alchemyForm->add(new Comment("Select second ingredient item: ", FALSE));
$items2 = new DropdownList("item2");
$items2->add(new Option("None Selected", "none"));
if($itemMap->size() > 0){
$iterator = $itemMap->iterator();
while($iterator->hasNext()){
$item2 = $iterator->nextEntry();
$items2->add(new Option($item2->getValue(), $item2->getKey()));
}
}
$alchemyForm->add($items2);
$alchemyForm->add(new Comment("Select third ingredient item: ", FALSE));
$items3 = new DropdownList("item3");
$items3->add(new Option("None Selected", "none"));
if($itemMap->size() > 0){
$iterator = $itemMap->iterator();
while($iterator->hasNext()){
$item3 = $iterator->nextEntry();
$items3->add(new Option($item3->getValue(), $item3->getKey()));
}
}
$alchemyForm->add($items3);
$alchemyForm->add(new Comment("Select newly produced item: ", FALSE));
$newitems = new DropdownList("newitem");
$newitems->add(new Option("None Selected", "none"));
if($itemMap->size() > 0){
$iterator = $itemMap->iterator();
while($iterator->hasNext()){
$newitem = $iterator->nextEntry();
$newitems->add(new Option($newitem->getValue(), $newitem->getKey()));
}
}
$alchemyForm->add($newitems);
$alchemyForm->add(new Comment("Chance for Alchemy to work: ", FALSE));
$alchemyForm->add(new TextField("chance", 100, 6));
$alchemyForm->add(new Comment("Select recipe item: ", FALSE));
$recipes = new DropdownList("recipe");
$recipes->add(new Option("None Selected", "none"));
if($recipeMap->size() > 0){
$iterator = $recipeMap->iterator();
while($iterator->hasNext()){
$recipe = $iterator->nextEntry();
$recipes->add(new Option($recipe->getValue(), $recipe->getKey()));
}
}
$alchemyForm->add($recipes);
$alchemyForm->add(new Button("Create New Alchemy Practice", "submit", "submit"));
$document->add($alchemyForm);
}
public function edit(){
$mysidia = Registry::get("mysidia");
$document = $this->document;
if(!$mysidia->input->get("alid")){
// An item has yet been selected, return to the index page.
$this->index();
return;
}
elseif($mysidia->input->post("submit")){
$document->setTitle($this->lang->edited_title);
$document->addLangvar($this->lang->edited);
return;
}
else{
$alchemy = $this->getField("alchemy")->get();
$document->setTitle($this->lang->edit_title);
$document->addLangvar($this->lang->edit);
$title = new Comment("Edit Alchemy Practice:");
$title->setBold();
$title->setUnderlined();
$alchemyForm = new Form("edititem", $mysidia->input->get("alid"), "post");
$alchemyForm->add($title);
$alchemyForm->add(new Comment("Select first ingredient item: ", FALSE));
$itemMap = $this->getField("itemMap");
$recipeMap = $this->getField("recipeMap");
$items = new DropdownList("item");
$items->add(new Option("None Selected", "none"));
if($itemMap->size() > 0){
$iterator = $itemMap->iterator();
while($iterator->hasNext()){
$item = $iterator->nextEntry();
$items->add(new Option($item->getValue(), $item->getKey()));
}
}
$items->select($alchemy->item);
$alchemyForm->add($items);
$alchemyForm->add(new Comment("Select second ingredient item: ", FALSE));
$items2 = new DropdownList("item2");
$items2->add(new Option("None Selected", "none"));
if($itemMap->size() > 0){
$iterator = $itemMap->iterator();
while($iterator->hasNext()){
$item2 = $iterator->nextEntry();
$items2->add(new Option($item2->getValue(), $item2->getKey()));
}
}
$items2->select($alchemy->item2);
$alchemyForm->add($items2);
$alchemyForm->add(new Comment("Select third ingredient item: ", FALSE));
$items3 = new DropdownList("item3");
$items3->add(new Option("None Selected", "none"));
if($itemMap->size() > 0){
$iterator = $itemMap->iterator();
while($iterator->hasNext()){
$item3 = $iterator->nextEntry();
$items3->add(new Option($item3->getValue(), $item3->getKey()));
}
}
$items3->select($alchemy->item3);
$alchemyForm->add($items3);
$alchemyForm->add(new Comment("Select newly produced item: ", FALSE));
$newitems = new DropdownList("newitem");
$newitems->add(new Option("None Selected", "none"));
if($itemMap->size() > 0){
$iterator = $itemMap->iterator();
while($iterator->hasNext()){
$newitem = $iterator->nextEntry();
$newitems->add(new Option($newitem->getValue(), $newitem->getKey()));
}
}
$newitems->select($alchemy->newitem);
$alchemyForm->add($newitems);
$alchemyForm->add(new Comment("Chance for Alchemy to work: ", FALSE));
$alchemyForm->add(new TextField("chance", $alchemy->chance, 6));
$alchemyForm->add(new Comment("Select recipe item: ", FALSE));
$recipes = new DropdownList("recipe");
$recipes->add(new Option("None Selected", "none"));
if($recipeMap->size() > 0){
$iterator = $recipeMap->iterator();
while($iterator->hasNext()){
$recipe = $iterator->nextEntry();
$recipes->add(new Option($recipe->getValue(), $recipe->getKey()));
}
}
$recipes->select($alchemy->recipe);
$alchemyForm->add($recipes);
$alchemyForm->add(new Button("Edit Alchemy Practice", "submit", "submit"));
$document->add($alchemyForm);
}
}
public function delete(){
$mysidia = Registry::get("mysidia");
$document = $this->document;
if(!$mysidia->input->get("alid")){
// An entry has yet been selected, return to the index page.
$this->index();
return;
}
$document->setTitle($this->lang->delete_title);
$document->addLangvar($this->lang->delete);
}
public function settings(){
$mysidia = Registry::get("mysidia");
$document = $this->document;
if($mysidia->input->post("submit")){
$document->setTitle($this->lang->settings_changed_title);
$document->addLangvar($this->lang->settings_changed);
return;
}
$alchemySettings = $this->getField("alchemySettings");
$document->setTitle($this->lang->settings_title);
$document->addLangvar($this->lang->settings);
$settingsForm = new FormBuilder("settingsform", "settings", "post");
$alchemySystem = new LinkedHashMap;
$alchemySystem->put(new String("Enabled"), new String("enabled"));
$alchemySystem->put(new String("Disabled"), new String("disabled"));
$alchemyChance = clone $alchemySystem;
$alchemyRecipe = clone $alchemySystem;
$settingsForm->buildComment("Alchemy System Enabled: ", FALSE)->buildRadioList("system", $alchemySystem, $alchemySettings->system)
->buildComment("Alchemy Success/Failure Enabled: ", FALSE)->buildRadioList("chance", $alchemyChance, $alchemySettings->chance)
->buildComment("Alchemy Recipe Usage Enabled: ", FALSE)->buildRadioList("recipe", $alchemyRecipe, $alchemySettings->recipe)
->buildComment("Alchemy Cost: ", FALSE)->buildTextField("cost", $alchemySettings->cost)
->buildComment("Alchemy License Item: ", FALSE)->buildTextField("license", $alchemySettings->license)
->buildComment("Usergroup(s) permitted to use alchemy(separate by comma): ", FALSE)->buildTextField("usergroup", ($alchemySettings->usergroup == "all")?$alchemySettings->usergroup:implode(",", $alchemySettings->usergroup))
->buildButton("Change Alchemy Settings", "submit", "submit");
$document->add($settingsForm);
}
}
?>
(alchemyview.php)
PHP Code:
<?php
use Resource\Native\String;
use Resource\Collection\ArrayList;
class Alchemy extends Model{
// The item class.
protected $alid;
protected $item;
protected $item2;
protected $item3;
protected $newItem;
protected $chance;
protected $recipe;
protected $validator;
protected $settings;
public function __construct($iid, $iid2, $iid3, AlchemySetting $settings){
$mysidia = Registry::get("mysidia");
$this->item = new PrivateItem($iid);
$this->item2 = new PrivateItem($iid2);
$this->item3 = new PrivateItem($iid3);
$this->settings = $settings;
$this->loadValidator();
$whereClause = "(item = {$this->item->id} and item2 = {$this->item2->id} and item3 = {$this->item3->id}) OR (item = {$this->item2->id} and item2 = {$this->item->id} and item3 = {$this->item3->id})";
$alchemy = $mysidia->db->select("alchemy", array(), $whereClause)->fetchObject();
if(!is_object($alchemy)) throw New ItemException("alchemy_invalid");
$this->alid = $alchemy->alid;
$this->newItem = new StockItem($alchemy->newitem);
$this->chance = $alchemy->chance;
$this->recipe = ($alchemy->recipe and $alchemy->recipe != "none")?new Item($alchemy->recipe):NULL;
$this->usergroup = $alchemy->usergroup;
}
public function getItem(){
return $this->item;
}
public function getItem2(){
return $this->item2;
}
public function getItem3(){
return $this->item3;
}
public function getNewItem(){
return $this->newItem;
}
public function getChance(){
return $this->chance;
}
public function getRecipe(){
return $this->recipe;
}
public function getUsergroup(){
return $this->usergroup;
}
public function mix(){
$this->validator->validate();
$this->consume();
$this->produce();
}
public function consume(){
$this->item->remove();
$this->item2->remove();
$this->item3->remove();
}
public function produce(){
$mysidia = Registry::get("mysidia");
$mysidia->user->changecash(-1*$this->settings->cost);
$this->newItem->append(1, $mysidia->user->username);
}
protected function loadValidator(){
$validations = new ArrayList;
$validations->add(new String("items"));
$validations->add(new String("license"));
$validations->add(new String("cost"));
$validations->add(new String("recipe"));
$validations->add(new String("usergroup"));
$validations->add(new String("chance"));
$this->validator = new AlchemyValidator($this, $this->settings, $validations);
}
protected function save($field, $value){
return FALSE;
}
}
?>
(class_alchemy.php)
PHP Code:
<?php
use Resource\Collection\ArrayList;
class AlchemyValidator extends Validator{
private $alchemy;
private $settings;
private $validations;
private $status;
public function __construct(Alchemy $alchemy, AlchemySetting $settings, ArrayList $validations){
$this->alchemy = $alchemy;
$this->settings = $settings;
$this->validations = $validations;
}
public function getValidations(){
return $this->validations;
}
public function setValidations(ArrayList $validations, $overwrite = FALSE){
if($overwrite) $this->validations = $validations;
else{
$iterator = $validations->iterator();
while($iterator->hasNext()){
$this->validations->append($iterator->next());
}
}
}
public function getStatus(){
return $this->status;
}
public function setStatus($status = ""){
$this->status = $status;
}
public function validate(){
$iterator = $this->validations->iterator();
while($iterator->hasNext()){
$validation = $iterator->next();
$method = "check{$validation->capitalize()}";
$this->$method();
}
return TRUE;
}
private function checkItems(){
if(!$this->alchemy->getItem() or !$this->alchemy->getItem2() or !$this->alchemy->getItem3()) throw new ItemException("alchemy_empty");
else{
if($this->alchemy->getItem()->quantity < 1 or $this->alchemy->getItem2()->quantity < 1 or $this->alchemy->getItem3()->quantity < 1){
throw new ItemException("alchemy_insufficient");
}
return TRUE;
}
}
private function checkChance(){
if($this->settings->chance == "disabled") return TRUE;
$chance = $this->alchemy->getChance();
$rand = rand(0, 99);
if($rand < $chance) return TRUE;
else{
$this->alchemy->consume();
throw new ItemException("alchemy_chance");
}
}
private function checkCost(){
if($this->settings->cost == 0) return TRUE;
$mysidia = Registry::get("mysidia");
if($mysidia->user->money >= $this->settings->cost) return TRUE;
else throw new ItemException("alchemy_cost");
}
private function checkLicense(){
if(!$this->settings->license) return TRUE;
$mysidia = Registry::get("mysidia");
$license = new PrivateItem($this->settings->license, $mysidia->user->username);
if($license->quantity >= 1) return TRUE;
else throw new ItemException("alchemy_license");
}
private function checkRecipe(){
if($this->settings->recipe == "disabled" or !$this->alchemy->getRecipe()) return TRUE;
$mysidia = Registry::get("mysidia");
$recipe = new PrivateItem($this->alchemy->getRecipe()->itemname, $mysidia->user->username);
if($recipe->quantity >= 1) return TRUE;
else throw new ItemException("alchemy_recipe");
}
private function checkUsergroup(){
if($this->settings->usergroup == "all") return TRUE;
$mysidia = Registry::get("mysidia");
foreach($this->settings->usergroup as $usergroup){
if($mysidia->user->usergroup->gid == $usergroup) return TRUE;
}
throw new ItemException("alchemy_usergroup");
}
}
?>
(class_alchemyvalidator)
PHP Code:
<?php
//Language variables used for AdminCP/Inventory Page
$lang['default_title'] = "Manage Alchemy";
$lang['default'] = "Here is a list of practices that can be used for alchemy<br><br>";
$lang['default_none'] = "Currently there is no alchemy practices possible for your site.";
$lang['nonexist'] = "The item does not exist in your database.";
$lang['add_title'] = "Create new Alchemy Practices";
$lang['add'] = "This page allows you to create a new possible alchemy practices for your users to use.
Please fill in the form below and hit the <i>Create New Alchemy Practice</i> button below when you're ready.<br>";
$lang['added_title'] = "Alchemy Practice Created Successfully";
$lang['added'] = "Successfully created new alchemy practice. You may <a href='../index'>go back to the Admin CP index page</a>.";
$lang['edit_title'] = "Edit Alchemy Practices";
$lang['edit'] = "This page allows you to edit an existing alchemy practice.
Please fill in the form below and hit the <i>Edit Alchemy Practice</i> button below when you're ready.";
$lang['edited_title'] = "Alchemy edited Successfully";
$lang['edited'] = "Successfully modified an existing alchemy practice. You may <a href='../../index'>go back to the Admin CP index page</a>.";
$lang['delete_title'] = "Alchemy Practice Remoced";
$lang['delete'] = "You have successfully deleted this practice from Alchemy Library.";
$lang['settings_title'] = "Changing Alchemy Settings";
$lang['settings'] = "Here you can modify settings for the alchemy system.<br>";
$lang['settings_changed_title'] = "Settings Changed Successfully";
$lang['settings_changed'] = "You have successfully modified the alchemy system settings.";
$lang['item'] = "You did not specify the first ingredient item for alchemy, or that the item entered was invalid.";
$lang['item2'] = "You did not specify the second ingredient item for alchemy, or that the item entered was invalid.";
$lang['item3'] = "You did not specify the third ingredient item for alchemy, or that the item entered was invalid.";
$lang['item2'] = "You did not specify the resulting new item for alchemy, or that the item entered was invalid.";
$lang['duplicate'] = "An alchemy practice with the two ingredient items specified already exists, please go back and edit the fields.";
$lang['chance'] = "The textfield chance must contain an integer between 0 to 100. Please go back and try again.";
$lang['alchemy_title'] = "Welcome to the Alchemy Service";
$lang['alchemy'] = "You come upon a quaint, older building in the middle of the Mysgardia Kingdom. You see various types of mages here, utilizing the workstations to magically craft powerful new items. A few of the Mysgardian Kingdom's forces stand idly by, keeping watch and discouraging anyone from stealing.<br /><br />";
$lang['alchemy_choose'] = " You select your first item:";
$lang['alchemy_choose2'] = "Then you select your second:";
$lang['alchemy_choose3'] = "Then you select your third:";
$lang['alchemy_disabled'] = "Unfortunately the admin has disabled the Alchemy System for this site, you may send him/her a message for more information.<br /><br /> <a href='/inventory/alchemy'><button type='button'>Return</button></a>";
$lang['alchemy_success'] = "Congratulations!";
$lang['alchemy_newitem'] = "You have successfully produced a new item ";
$lang['alchemy_newitem2'] = " by using Alchemy. You may now manage it in your inventory, or continue to use the alchemy system.<br /><br />
<a href='/inventory/alchemy'><button type='button'>Return</button></a>";
$lang['alchemy_invalid'] = "The specified item combination is invalid, it does not produce a new item...<br /><br /> <a href='/inventory/alchemy'><button type='button'>Return</button></a>";
$lang['alchemy_empty'] = "You have not entered three valid items for performing alchemy.<br /><br /> <a href='/inventory/alchemy'><button type='button'>Return</button></a>";
$lang['alchemy_insufficient'] = "You do not have the necessary items for producing a new item through alchemy.<br /><br /> <a href='/inventory/alchemy'><button type='button'>Return</button></a>";
$lang['alchemy_chance'] = "The alchemy fails! How unfortunate, maybe you should try again?<br /><br /> <a href='/inventory/alchemy'><button type='button'>Return</button></a>";
$lang['alchemy_cost'] = "Apparently you do not have enough money to afford the alchemy service, please come back later.<br /><br /> <a href='/inventory/alchemy'><button type='button'>Return</button></a>";
$lang['alchemy_license'] = "You appear to lack the license required to perform alchemy, please make sure you have the license in your inventory first.<br /><br /> <a href='/inventory/alchemy'><button type='button'>Return</button></a>";
$lang['alchemy_recipe'] = "It seems that you do not have the recipe to produce an item from the two selected items.<br /><br /> <a href='/inventory/alchemy'><button type='button'>Return</button></a>";
$lang['alchemy_usergroup'] = "Unfortunately, the admin has specified that only certain users can perform alchemy, you may consult him/her by sending a message.<br /><br /> <a href='/inventory/alchemy'><button type='button'>Return</button></a>";
?>
(lang_alchemy.php)
PHP Code:
<?php
class InventoryController extends AppController{
const PARAM = "confirm";
public function __construct(){
parent::__construct("member");
}
public function index(){
$mysidia = Registry::get("mysidia");
$inventory = new Inventory($mysidia->user);
if($inventory->gettotal() == 0) throw new InvalidIDException("inventory_empty");
$this->setField("inventory", $inventory);
}
public function uses(){
$mysidia = Registry::get("mysidia");
$document = $mysidia->frame->getDocument();
$item = new PrivateItem($mysidia->input->post("itemname"), $mysidia->user->username);
if($item->iid == 0) throw new ItemException("use_none");
if($mysidia->input->post("aid")){
if(!$item->checktarget($mysidia->input->post("aid")) or $mysidia->input->post("validation") != "valid"){
throw new ItemException("use_fail");
}
elseif(!$item->randomchance()){
$item->remove();
throw new ItemException("use_effect");
}
else{
$message = $item->apply($mysidia->input->post("aid"));
$this->setField("message", $message);
}
return;
}
$stmt = $mysidia->db->select("owned_adoptables", array("aid", "name"), "owner = '{$mysidia->user->username}'");
$map = $mysidia->db->fetchMap($stmt);
$this->setField("petMap", $map);
}
public function sell(){
$mysidia = Registry::get("mysidia");
$item = new PrivateItem($mysidia->input->post("itemname"), $mysidia->user->username);
if($item->iid == 0) throw new ItemException("sell_none");
if(!$mysidia->input->post("quantity")) throw new ItemException("sell_empty");
elseif($item->quantity < $mysidia->input->post("quantity")) throw new ItemException("sell_quantity");
else $item->sell($mysidia->input->post("quantity"));
}
public function toss(){
$mysidia = Registry::get("mysidia");
$item = new PrivateItem($mysidia->input->post("itemname"), $mysidia->user->username);
if($item->iid == 0) throw new ItemException("toss_none");
if($mysidia->input->get("confirm")){
$item->toss();
return;
}
}
public function alchemy(){
$mysidia = Registry::get("mysidia");
$settings = new AlchemySetting($mysidia->db);
if($settings->system == "disabled") throw new ItemException("alchemy_disabled");
if($mysidia->input->post("iid") and $mysidia->input->post("iid2") and $mysidia->input->post("iid3")){
$alchemy = new Alchemy($mysidia->input->post("iid"), $mysidia->input->post("iid2"), $mysidia->input->post("iid3"), $settings);
$alchemy->mix();
$this->setField("alchemy", $alchemy);
return;
}
$stmt = $mysidia->db->select("inventory", array("iid", "itemname"), "owner = '{$mysidia->user->username}'");
$map = $mysidia->db->fetchMap($stmt);
$this->setField("itemMap", $map);
$this->setField("settings", $settings);
}
}
?>
(inventory.php)
PHP Code:
<?php
use Resource\Collection\LinkedList;
class InventoryView extends View{
public function index(){
$mysidia = Registry::get("mysidia");
$document = $this->document;
$document->setTitle($mysidia->lang->inventory);
$document->addLangvar("You may manage these items as you like, or go to the alchemy page to make your own items: <br>");
$document->add(new Link("inventory/alchemy", "Use the Alchemy Service Now!"));
$document->add(new Comment("<br><br>"));
$inventory = $this->getField("inventory");
$inventoryTable = new TableBuilder("inventory");
$inventoryTable->setAlign(new Align("center", "middle"));
$inventoryTable->buildHeaders("Image", "Category", "Name", "Description", "Quantity", "Use", "Sell", "Toss");
$inventoryTable->setHelper(new ItemTableHelper);
$iids = $inventory->getiids();
for($i = 0; $i < $iids->length(); $i++){
$item = $inventory->getitem($iids[$i]);
$cells = new LinkedList;
$cells->add(new TCell($inventory->getitemimage($item->imageurl)));
$cells->add(new TCell($item->category));
$cells->add(new TCell($item->itemname));
$cells->add(new TCell($item->description));
$cells->add(new TCell($item->quantity));
$cells->add(new TCell($inventoryTable->getHelper()->getUseForm($item)));
$cells->add(new TCell($inventoryTable->getHelper()->getSellForm($item)));
$cells->add(new TCell($inventoryTable->getHelper()->getTossForm($item)));
$inventoryTable->buildRow($cells);
}
$document->add($inventoryTable);
}
public function uses(){
$mysidia = Registry::get("mysidia");
$document = $this->document;
if($mysidia->input->post("aid")){
$message = (string)$this->getField("message");
$document->setTitle($mysidia->lang->global_action_complete);
$document->addLangvar($message);
return;
}
$petMap = $this->getField("petMap");
$document->setTitle($mysidia->lang->select_title);
$document->addLangvar($mysidia->lang->select);
$chooseFrom = new Form("chooseform", "uses", "post");
$adoptable = new DropdownList("aid");
$adoptable->add(new Option("None Selected", "none"));
if($petMap->size() > 0){
$iterator = $petMap->iterator();
while($iterator->hasNext()){
$adopt = $iterator->nextEntry();
$adoptable->add(new Option($adopt->getValue(), $adopt->getKey()));
}
}
$chooseFrom->add($adoptable);
$chooseFrom->add(new PasswordField("hidden", "itemname", $mysidia->input->post("itemname")));
$chooseFrom->add(new PasswordField("hidden", "validation", "valid"));
$chooseFrom->add(new Button("Choose this Adopt", "submit", "submit"));
$document->add($chooseFrom);
}
public function sell(){
$mysidia = Registry::get("mysidia");
$document = $this->document;
$document->setTitle($this->lang->global_transaction_complete);
$document->addLangvar("{$this->lang->sell}");
}
public function toss(){
$mysidia = Registry::get("mysidia");
$document = $this->document;
if($mysidia->input->get("confirm")){
$document->setTitle($this->lang->global_action_complete);
$document->addLangvar("{$this->lang->toss}{$mysidia->input->post("itemname")}{$this->lang->toss2}");
return;
}
$document->setTitle($this->lang->toss_confirm);
$document->addLangvar($this->lang->toss_warning);
$confirmForm = new FormBuilder("confirmform", "toss/confirm", "post");
$confirmForm->buildPasswordField("hidden", "action", "toss")
->buildPasswordField("hidden", "itemname", $mysidia->input->post("itemname"))
->buildButton("Please Toss", "confirm", "confirm");
$document->add($confirmForm);
}
public function alchemy(){
$mysidia = Registry::get("mysidia");
$document = $this->document;
if($mysidia->input->post("iid") and $mysidia->input->post("iid2") and $mysidia->input->post("iid3")){
$alchemy = $this->getField("alchemy");
$newitem = $alchemy->getNewItem()->itemname;
$document->setTitle($this->lang->alchemy_success);
$document->addLangvar($this->lang->alchemy_newitem.$newitem.$this->lang->alchemy_newitem2);
return;
}
$document->setTitle($this->lang->alchemy_title);
$document->addLangvar($this->lang->alchemy);
$itemMap = $this->getField("itemMap");
$settings = $this->getField("settings");
$alchemyFrom = new Form("alchemyform", "alchemy", "post");
$alchemyFrom->add(new Comment("<b>Cost of performing Alchemy: {$settings->cost} {$mysidia->settings->cost}</b><br>"));
$alchemyFrom->add(new Comment($mysidia->lang->alchemy_choose));
$items = new DropdownList("iid");
$items->add(new Option("None Selected", "none"));
if($itemMap->size() > 0){
$iterator = $itemMap->iterator();
while($iterator->hasNext()){
$item = $iterator->nextEntry();
$items->add(new Option($item->getValue(), $item->getKey()));
}
}
$alchemyFrom->add($items);
$alchemyFrom->add(new Comment($mysidia->lang->alchemy_choose2));
$items2 = new DropdownList("iid2");
$items2->add(new Option("None Selected", "none"));
if($itemMap->size() > 0){
$iterator = $itemMap->iterator();
while($iterator->hasNext()){
$item2 = $iterator->nextEntry();
$items2->add(new Option($item2->getValue(), $item2->getKey()));
}
}
$alchemyFrom->add($items2);
$alchemyFrom->add(new Comment($mysidia->lang->alchemy_choose3));
$items3 = new DropdownList("iid3");
$items3->add(new Option("None Selected", "none"));
if($itemMap->size() > 0){
$iterator = $itemMap->iterator();
while($iterator->hasNext()){
$item3 = $iterator->nextEntry();
$items3->add(new Option($item3->getValue(), $item3->getKey()));
}
}
$alchemyFrom->add($items3);
$alchemyFrom->add(new Button("Let's mix the items now!", "submit", "submit"));
$document->add($alchemyFrom);
}
}
?>
(inventoryview.php)
PHP Code:
<?php
//Language variables used for Inventory Page
$lang['inventory'] = "Here is the list of every item you own";
$lang['inventory_empty'] = "You currently do not have any items in inventory.";
$lang['select_title'] = "Select an adoptable";
$lang['select'] = "Now you need to choose an adoptable to use this item:<br>";
$lang['item_error'] = "An error has occurred while manipulating item";
$lang['use_none'] = "It appears that you do not have this item in your inventory.";
$lang['use_fail'] = "It seems that item can not be used on the adoptable selected.";
$lang['use_effect'] = "The item refuses to take effect, what a waste of money and effort!";
$lang['sell_empty'] = "You have yet to specify the quantity of items to sell...<br>";
$lang['sell_none'] = "It appears that you do not have this item in your inventory.";
$lang['sell_quantity'] = "It seems that you wish to sell more items than you already own, this action is invalid.<br>";
$lang['sell'] = "You have sold ";
$lang['sell2'] = "successfully and earned some money back.{$mysidia->input->post("cost")}<br>";
$lang['toss_confirm'] = "Confirm your Action";
$lang['toss_warning'] = "Are you sure you wish to toss {$mysidia->input->post("itemname")}?<br>
It will be permanently removed from your inventory, and this action cannot be undone!<br>";
$lang['toss_none'] = "It appears that you do not have this item in your inventory.";
$lang['toss'] = "You have successfully removed ";
$lang['toss2'] = " from your inventory.";
$lang['alchemy_title'] = "Welcome to the Alchemy Service";
$lang['alchemy'] = "stuff goes here.<br /><br />";
$lang['alchemy_choose'] = " You select your first item:";
$lang['alchemy_choose2'] = "Then you select your second:";
$lang['alchemy_choose3'] = "Then you select your third:";
$lang['alchemy_disabled'] = "Unfortunately the admin has disabled the Alchemy System for this site, you may send him/her a message for more information.<br /><br /> <a href='/inventory/alchemy'><button type='button'>Return</button></a>";
$lang['alchemy_success'] = "Congratulations!";
$lang['alchemy_newitem'] = "You have successfully produced a new item ";
$lang['alchemy_newitem2'] = " by using Alchemy. You may now manage it in your inventory, or continue to use the alchemy system.<br /><br />
<a href='/inventory/alchemy'><button type='button'>Return</button></a>";
$lang['alchemy_invalid'] = "The specified item combination is invalid, it does not produce a new item...<br /><br /> <a href='/inventory/alchemy'><button type='button'>Return</button></a>";
$lang['alchemy_empty'] = "You have not entered two valid items for performing alchemy.<br /><br /> <a href='/inventory/alchemy'><button type='button'>Return</button></a>";
$lang['alchemy_insufficient'] = "You do not have the necessary items for producing a new item through alchemy.<br /><br /> <a href='/inventory/alchemy'><button type='button'>Return</button></a>";
$lang['alchemy_chance'] = "The alchemy fails! How unfortunate, maybe you should try again?<br /><br /> <a href='/inventory/alchemy'><button type='button'>Return</button></a>";
$lang['alchemy_cost'] = "Apparently you do not have enough money to afford the alchemy service, please come back later.<br /><br /> <a href='/inventory/alchemy'><button type='button'>Return</button></a>";
$lang['alchemy_license'] = "You appear to lack the license required to perform alchemy, please make sure you have the license in your inventory first.<br /><br /> <a href='/inventory/alchemy'><button type='button'>Return</button></a>";
$lang['alchemy_recipe'] = "It seems that you do not have the recipe to produce an item from the two selected items.<br /><br /> <a href='/inventory/alchemy'><button type='button'>Return</button></a>";
$lang['alchemy_usergroup'] = "Unfortunately, the admin has specified that only certain users can perform alchemy, you may consult him/her by sending a message.<br /><br /> <a href='/inventory/alchemy'><button type='button'>Return</button></a>";
?>
(lang_inventory.php)
|