Thread: Mys 1.3.4 Alchemy Mod
View Single Post
  #2  
Old 01-29-2014, 11:36 AM
Hall of Famer's Avatar
Hall of Famer Hall of Famer is offline
Administrator, Lead Coder
 
Join Date: Dec 2008
Location: South Brunswick
Posts: 4,448
Gender: Male
Credits: 334,668
Hall of Famer is on a distinguished road
Default

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:
/admincp/alchemy.php
/admincp/view/alchemyview.php
/classes/class_alchemy.php
/classes/class_alchemysetting.php
/classes/class_alchemyvalidator.php
/lang/admincp/lang_alchemy.php

You may do the same for the lang file: 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 /classes/class_adminsidebar.php and find these line:

PHP Code:
        $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 Code:
        $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 /classes/class_itemtablehelper.php and find the constructor:
PHP Code:
    public function __construct(){
        
parent::__construct();      
    } 
insert these two methods right below the constructor definition:
PHP Code:
    /**
     * The getItem method, fetches the item type.
     * @param int  $item
     * @access public
     * @return String
     */    
    
public function getItem($item){
        if(empty(
$item)) return "N/A";
        else return 
$item;        
    }
    
    
/**
     * The getItemImage method, fetches the item image.
     * @param id  $item
     * @access public
     * @return Image
     */
    
public function getItemImage($item){    
        
$item = new Item($item);
        
$image = new Image($item->imageurl$item->itemname);
        return 
$image;            
    } 
Then go to script file /inventory.php and find the method toss() at:

PHP Code:
    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;
        }        
    } 
Add a new method alchemy() right below it:

PHP Code:
    
    
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")){
            
$alchemy = new Alchemy($mysidia->input->post("iid"), $mysidia->input->post("iid2"), $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);
    } 
Now open the file /view/inventoryview.php and find these lines:

PHP Code:
        $mysidia Registry::get("mysidia");
        
$document $this->document;
        
$document->setTitle($mysidia->lang->inventory); 
Add the three new lines below:

PHP Code:
        $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>")); 
Next, find the toss() method at:
PHP Code:
    
    
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);            
    } 
Append the alchemy() method right below it:

PHP Code:
    public function alchemy(){
        
$mysidia Registry::get("mysidia");
        
$document $this->document;
        
        if(
$mysidia->input->post("iid") and $mysidia->input->post("iid2")){
            
$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 Button("Let's mix the items now!""submit""submit"));
        
$document->add($alchemyFrom);        
    } 
At last, open the file /functions/functions_items.php and add a new function to the bottom of the script(right above the php closing tag). It does not really do anything other than preventing some kind of bugs/error messages from possibly emerging:

PHP Code:
function items_recipe($item$adopt){
  
$note "The item {$item->itemname} is a recipe item, which cannot be used on any adoptable and can only be useful if you are performing alchemy.";
  return 
$note;

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.
__________________


Mysidia Adoptables, a free and ever-improving script for aspiring adoptables/pets site.
Reply With Quote