For advanced users who have heavily modified sites, you may follow the procedure below to install this mod on your site. Ignore this post if your site works fine with simply uploading/overwriting files.
First of all, upload and run the installer script at yoursite.com/install/alchemy.php. This step is identical for all users, unless you wish to create tables/insert rows into database manually, but will be a pain with this mod.
Second, upload the following new files to your server. Most of these files do not exist in the base script so you wont run into file overwriting problems. The new files are:
/controller/admincp/alchemycontroller.php
/view/admincp/alchemyview.php
/model/domainmodel/alchemy.php
/model/settings/alchemysetting.php
/service/validator/alchemyvalidator.php
/lang/admincp/lang_alchemy.php
You may do the same for the lang file: /lang/main/lang_inventory.php since I assume nobody has ever modified it. If the answer is opposite however, you may wish to search through the differences of the two lang files to see how to append new lang vars to your site. It shouldnt be difficult.
Alright then, in the next step you will need to modify some old script files. I hope you are ready. Now go to file /model/viewmodel/adminsidebar.php and find these line(these are related to the menu for inventory items):
PHP:
$components->add(new Division(new Comment("Inventory", FALSE)));
$inventory = new Division;
$inventory->add(new Link("admincp/inventory/add", "Give Item to User"));
$inventory->add(new Link("admincp/inventory/edit", "Edit User Inventory"));
$inventory->add(new Link("admincp/inventory/delete", "Delete Users items"));
$components->add($inventory);
Add below:
PHP:
$components->add(new Division(new Comment("Alchemy", FALSE)));
$alchemy = new Division;
$alchemy->add(new Link("admincp/alchemy/add", "Create new Alchemy Practice"));
$alchemy->add(new Link("admincp/alchemy/edit", "Edit Alchemy Practices"));
$alchemy->add(new Link("admincp/alchemy/delete", "Remove Alchemy Practices"));
$alchemy->add(new Link("admincp/alchemy/settings", "Change Alchemy Settings"));
$components->add($alchemy);
Next, go to file /services/helper/itemtablehelper.php and find this method:
PHP:
/**
* The buildItemNameList method, builds a dropdown list for available item names.
* @param String $name
* @access public
* @return DropdownList
*/
public function buildItemNameList($name){
$mysidia = Registry::get("mysidia");
$itemList = new DropdownList($name);
$stmt = $mysidia->db->select("items", ["itemname", "id"], "1 ORDER BY id");
$items = $mysidia->db->fetchMap($stmt);
$itemList->add(new Option("Select an Item", "none"));
$itemList->fill($items);
return $itemList;
}
Add another 2 methods below the ending }:
PHP:
/**
* The buildRecipeNameList method, builds a dropdown list for available recipe item names.
* @param String $name
* @access public
* @return DropdownList
*/
public function buildRecipeNameList($name){
$mysidia = Registry::get("mysidia");
$itemList = new DropdownList($name);
$stmt = $mysidia->db->select("items", ["itemname", "id"], "`function` = 'Recipe' ORDER BY id");
$items = $mysidia->db->fetchMap($stmt);
$itemList->add(new Option("Select a Recipe", "none"));
$itemList->fill($items);
return $itemList;
}
/**
* The buildInventoryItemList method, builds a dropdown list for available items in the user's inventory.
* @param String $name
* @access public
* @return DropdownList
*/
public function buildInventoryItemList($name){
$mysidia = Registry::get("mysidia");
$itemList = new DropdownList($name);
$stmt = $mysidia->db->join("items", "items.id = inventory.item")
->select("inventory", ["itemname", "id"], "owner = '{$mysidia->user->getID()}'");
$items = $mysidia->db->fetchMap($stmt);
$itemList->add(new Option("Select an Item", "none"));
$itemList->fill($items);
return $itemList;
}
Now we need to go to the file /controller/main/inventorycontroller.php. First locate these lines at the top of the script:
PHP:
namespace Controller\Main;
use Model\DomainModel\ItemException;
use Model\DomainModel\OwnedItem;
use Resource\Collection\ArrayList;
use Resource\Core\AppController;
use Resource\Core\Registry;
use Resource\Exception\InvalidIDException;
use Resource\Native\MysString;
Replace by:
PHP:
namespace Controller\Main;
use ArrayObject, Exception;
use Model\DomainModel\Alchemy;
use Model\DomainModel\ItemException;
use Model\DomainModel\OwnedItem;
use Model\Settings\AlchemySettings;
use Resource\Collection\ArrayList;
use Resource\Core\AppController;
use Resource\Core\Registry;
use Resource\Exception\InvalidActionException;
use Resource\Exception\InvalidIDException;
use Resource\Exception\NoPermissionException;
use Resource\Native\MysString;
use Service\Validator\AlchemyValidator;
This allows us to import the new classes we've added for the Alchemy Mod, as well as some other built-in classes needed for the alchemy action. Next, we need to add the alchemy action. Find the method toss($confirm) which should look like this:
PHP:
public function toss($confirm = NULL){
$mysidia = Registry::get("mysidia");
$item = new OwnedItem($mysidia->input->post("item"), $mysidia->user->getID());
if(!$item->inInventory()) throw new ItemException("toss_none");
if($confirm){
$item->toss();
}
$this->setField("item", $item);
$this->setField("confirm", $confirm ? new MysString("confirm") : NULL);
}
Add the new method alchemy after it:
PHP:
public function alchemy(){
$mysidia = Registry::get("mysidia");
$alchemySettings = new AlchemySettings($mysidia->db);
if($alchemySettings->system == "disabled") throw new ItemException("alchemy_disabled");
if($mysidia->input->post("iid") && $mysidia->input->post("iid2")){
try{
$alchemy = new Alchemy($mysidia->input->post("iid"), $mysidia->input->post("iid2"));
$alchemyValidator = new AlchemyValidator($alchemy, $alchemySettings, new ArrayObject(["license", "items", "recipe", "usergroup", "cost", "chance"]));
$alchemyValidator->validate();
$newItem = $alchemy->mix($alchemySettings->cost);
$this->setField("newItem", $newItem);
}
catch(Exception $e){
throw new InvalidActionException($e->getMessage());
}
return;
}
$this->setField("settings", $alchemySettings);
}
With this, we've added the action for users to perform alchemy. But we are not done yet, we need to add a view to this action. Go to file /view/main/inventoryview.php file and find these lines at the top:
PHP:
namespace View\Main;
use Resource\Collection\LinkedList;
use Resource\Core\Model;
use Resource\Core\Registry;
use Resource\Core\View;
use Resource\GUI\Component\Button;
use Resource\GUI\Component\Option;
use Resource\GUI\Component\PasswordField;
use Resource\GUI\Container\DropdownList;
use Resource\GUI\Container\Form;
use Resource\GUI\Container\TCell;
use Resource\GUI\Element\Align;
use Service\Builder\FormBuilder;
use Service\Builder\TableBuilder;
use Service\Helper\ItemTableHelper;
Replace by:
PHP:
namespace View\Main;
use Resource\Collection\LinkedList;
use Resource\Core\Model;
use Resource\Core\Registry;
use Resource\Core\View;
use Resource\GUI\Component\Button;
use Resource\GUI\Component\Link;
use Resource\GUI\Component\Option;
use Resource\GUI\Component\PasswordField;
use Resource\GUI\Container\DropdownList;
use Resource\GUI\Container\Form;
use Resource\GUI\Container\TCell;
use Resource\GUI\Document\Comment;
use Resource\GUI\Element\Align;
use Service\Builder\FormBuilder;
use Service\Builder\TableBuilder;
use Service\Helper\ItemTableHelper;
Now we need to add the view for alchemy action. Again, find the method for toss at here:
PHP:
public function toss(){
$mysidia = Registry::get("mysidia");
$document = $this->document;
$item = $this->getField("item");
$confirm = $this->getField("confirm");
if($confirm){
$document->setTitle($this->lang->global_action_complete);
$document->addLangvar("{$this->lang->toss}{$item->getItemname()}{$this->lang->toss2}");
return;
}
$document->setTitle($this->lang->toss_confirm);
$document->addLangvar("{$this->lang->toss_warning}{$item->getItemname()}?<br>{$this->lang->toss_warning2}");
$confirmForm = new FormBuilder("confirmform", "toss/confirm", "post");
$confirmForm->buildPasswordField("hidden", "action", "toss")
->buildPasswordField("hidden", "item", $mysidia->input->post("item"))
->buildButton("Please Toss", "confirm", "confirm");
$document->add($confirmForm);
}
And add the action for alchemy after toss method:
PHP:
public function alchemy(){
$mysidia = Registry::get("mysidia");
$document = $this->document;
if($mysidia->input->post("iid") && $mysidia->input->post("iid2")){
$newItem = $this->getField("newItem");
$document->setTitle($this->lang->alchemy_success);
$document->addLangvar($this->lang->alchemy_newitem . $newItem->getItemname() . $this->lang->alchemy_newitem2);
return;
}
$document->setTitle($this->lang->alchemy_title);
$document->addLangvar($this->lang->alchemy);
$settings = $this->getField("settings");
$alchemyForm = new FormBuilder("alchemyform", "alchemy", "post");
$alchemyForm->add(new Comment("<b>Cost of performing Alchemy: {$settings->cost} {$mysidia->settings->cost}</b><br>"));
$alchemyForm->add(new Comment($mysidia->lang->alchemy_choose));
$alchemyForm->buildDropdownList("iid", "InventoryItemList");
$alchemyForm->add(new Comment($mysidia->lang->alchemy_choose2));
$alchemyForm->buildDropdownList("iid2", "InventoryItemList");
$alchemyForm->add(new Button("Let's mix the items now!", "submit", "submit"));
$document->add($alchemyForm);
}
We are almost done. The last step is optional, but may be helpful for the user experience of your site. Simply find the index view of inventory:
PHP:
$document = $this->document;
$document->setTitle($this->lang->inventory);
And add three more lines below these to provide a link of alchemy page to users visiting their inventory:
PHP:
$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>"));
You are done with the modifications now, it was easier than you thought right? Anyway you may run into some problems, and in this case please post in this thread to let me know. I will find out where the errors are and fix them for you as soon as I get a chance.