Mysidia Adoptables Support Forum  

Home Community Mys-Script Creative Off-Topic
Go Back   Mysidia Adoptables Support Forum > Mysidia Adoptables > Addons and Modifications > Mys v1.3.x Mods

Notices

Reply
 
Thread Tools Display Modes
  #1  
Old 01-28-2017, 10:38 PM
Chaos77777 Chaos77777 is offline
Member
 
Join Date: Jan 2017
Posts: 43
Gender: Male
Credits: 3,692
Chaos77777 is on a distinguished road
Default Hybrid Breeding

Hey guys, I'm going to attempt to show you how I managed to set up hybrid breeding. What I did was set up a second "Class" that adopts could breed in on a separate (more expensive) page. Basically, the normal breeding will only search for which "Class" your adopts are in. The hybrid breeding page will search for "HybridClass" I'll call it for this. Since I've heavily modded my site, I'm hoping I don't forget any steps. Please please please read very carefully and make a back up. This is for those who want to keep classes separate, but also allow for other things to breed outside of those classes. You'll have to set them up to be in the same "hybrid class"

Step 1. Set up your database with a second class under "prefix_adoptables" and call it "HybridClass", just copy the data from "Class". Do the same for "prefix_Owned_adopts" (Yes, you'll have to enter in the "HybridClass" for all of them.)

Step 2. Let's set it up so when you create a new adopt, it'll give you a spot to add in "HybridClass" straight from the create adopt page.
In admincp folder, open "adopt.php" find
PHP Code:
elseif(!$mysidia->input->post("class")) throw new BlankFieldException("class"); 
and add under it,
PHP Code:
elseif(!$mysidia->input->post("hybridclass")) throw new BlankFieldException("hybridclass"); 
And also, where you find
PHP Code:
$mysidia->db->insert("adoptables", array("id" => NULL"type" => $mysidia->input->post("type"), "class" => $mysidia->input->post("class"), "description" => $mysidia->input->post("description"), "eggimage" => $eggimage"whenisavail" => $mysidia->input->post("cba"),
                                                     
"alternates" => $mysidia->input->post("alternates"), "altoutlevel" => $mysidia->input->post("altoutlevel"), "altchance" => $mysidia->input->post("altchance"), "shop" => $mysidia->input->post("shop"), "cost" => $mysidia->input->post("cost"))); 
change it to
PHP Code:
$mysidia->db->insert("adoptables", array("id" => NULL"type" => $mysidia->input->post("type"), "class" => $mysidia->input->post("class"), "hybridclass" => $mysidia->input->post("hybridclass"),"description" => $mysidia->input->post("description"), "eggimage" => $eggimage"whenisavail" => $mysidia->input->post("cba"),
                                                     
"alternates" => $mysidia->input->post("alternates"), "altoutlevel" => $mysidia->input->post("altoutlevel"), "altchance" => $mysidia->input->post("altchance"), "shop" => $mysidia->input->post("shop"), "cost" => $mysidia->input->post("cost"))); 
Still in AdminCP, open up the "view" folder. Open "adoptview.php"
Find
PHP Code:
$basicInfo->add(new Comment("Adoptable Class: "FALSE));
        
$basicInfo->add(new TextField("class")); 
Add in, right under it
PHP Code:
$basicInfo->add(new Comment("Adoptable Hybrid Class: "FALSE));
        
$basicInfo->add(new TextField("hybridclass")); 
Now you'll be able to add in your own hybrid class whenever you make a new adopt!
Now we want breeding to add that hybridclass in new bred adopts too.

Step 3
Open up "class_breeding"
Add in
PHP Code:
public $hybridclass
Search and find
PHP Code:
$mysidia->db->insert("owned_adoptables", array("aid" => NULL"type" => $adopt->getType(), "name" => $adopt->getType(), "owner" => $mysidia->user->username"currentlevel" => 0"totalclicks" => 0"code" => $code
                                                           
"imageurl" => NULL"usealternates" => $alts"tradestatus" => 'fortrade'"isfrozen" => 'no'"gender" => $gender"offsprings" => 0"lastbred" => 0)); 
Change it to
PHP Code:
$mysidia->db->insert("owned_adoptables", array("aid" => NULL"type" => $adopt->getType(), "name" => $adopt->getType(), "class" =>$adopt->getClass(), "hybridclass" =>$adopt->getHybridClass"owner" => $mysidia->user->username"currentlevel" => 0"totalclicks" => 0"code" => $code
                                                           
"imageurl" => NULL"usealternates" => $alts"tradestatus" => 'fortrade'"isfrozen" => 'no'"gender" => $gender"offsprings" => 0"lastbred" => 0)); 
Step 4. Add it in everywhere else needed lol. I'm not sure what order I did these in, so I'm just trying to make sure I cover everything.

Somewhere in "class_adoptable" you'll want to add
PHP Code:
protected $hybridclass
and also
PHP Code:
public function getHybridClass(){
        return 
$this->class;
    } 
probably right after "getClass"

Step 5. Now we get to make our own page! Add in a php script in your main folder called "HybridBreeding.php"
Add this in
PHP Code:
<?php

use Resource\Native\Integer;
use 
Resource\Native\String;
use 
Resource\Native\Null;
use 
Resource\Collection\LinkedList;

class 
hybridBreedingController extends AppController{

    public function 
__construct(){
        
parent::__construct("member");
        
$mysidia Registry::get("mysidia");        
        
$userStatus $mysidia->user->getstatus();
        if(
$userStatus->canbreed == "no") throw new NoPermissionException("permission");        
    }
    
    public function 
index(){
        
$mysidia Registry::get("mysidia");
        
$settings = new BreedingSetting($mysidia->db);
        if(
$settings->system != "enabled") throw new InvalidActionException("system");
        
        if(
$mysidia->input->post("submit")){
            if(
$mysidia->input->post("female") == "none" or $mysidia->input->post("male") == "none"){
                  throw new 
InvalidIDException("none_select");
            }
            
            try{
                
$female = new OwnedAdoptable($mysidia->input->post("female"), $mysidia->user->username);
                
$male = new OwnedAdoptable($mysidia->input->post("male"), $mysidia->user->username);
                
$breeding = new HybridBreeding($female$male$settings); 
                
$validator $breeding->getValidator("all");
                
$validator->validate();
            }
            catch(
AdoptNotfoundException $ane){
                throw new 
InvalidIDException("none_exist");
            }
            catch(
BreedingException $bre){                
                
$status $bre->getmessage();
                
$validator->setStatus($status);
                throw new 
InvalidActionException($status);
            }
            
            if(
$settings->method == "advanced"$species $breeding->getBabySpecies();
            
$breeding->getBabyAdopts($species);
            
$breeding->hybridbreed($adopts);
            
$num $breeding->countOffsprings();
                        
            if(
$num 0){
                
$offsprings $breeding->getOffsprings();
                
$offspringID $mysidia->db->select("owned_adoptables", array("aid"), "1 ORDER BY aid DESC LIMIT 1")->fetchColumn() - $num 1;
                
$links = new LinkedList;
                foreach(
$offsprings as $offspring){
                    
$image $offspring->getEggImage("gui");
                    
$links->add(new Link("myadopts/manage/{$offspringID}"$image));
                    
$offspringID++;
                }
                
$this->setField("links"$links);
            }
            else 
$this->setField("links", new Null);
            
$this->setField("breeding"$breeding);        
            return;
        }

        
$this->setField("cost", new Integer($settings->cost));
        
$current = new DateTime;
        
$lasttime $current->getTimestamp() - (($settings->interval) * 24 60 60);
                
        
$stmt $mysidia->db->select("owned_adoptables", array("type""aid"), "owner = '{$mysidia->user->username}' AND gender = 'f' AND currentlevel >= {$settings->level} AND lastbred <= '{$lasttime}'");
        
$female = ($stmt->rowcount() == 0)?new Null:$mysidia->db->fetchMap($stmt);
        
$this->setField("femaleMap"$female);
  
        
$stmt $mysidia->db->select("owned_adoptables", array("type""aid"), "owner = '{$mysidia->user->username}' AND gender = 'm' AND currentlevel >= {$settings->level} AND lastbred <= '{$lasttime}'");
        
$male = ($stmt->rowcount() == 0)?new Null:$mysidia->db->fetchMap($stmt);
        
$this->setField("maleMap"$male);
    }
}
?>
Next, in the "view" folder, create a php script called "hybridbreedingview.php"
Add in
PHP Code:
<?php

use Resource\Collection\LinkedList;
use 
Resource\Collection\LinkedHashMap;

class 
HybridBreedingView extends View{
    
    public function 
index(){
        
$mysidia Registry::get("mysidia");
        
$document $this->document;        
        if(
$mysidia->input->post("submit")){
            
$links $this->getField("links"); 
            if(
$links instanceof LinkedList){
                
$breeding $this->getField("breeding");
                
$document->setTitle("Breeding is Successful!");
                
$document->add(new Comment("Congratulations! Breeding is successful, you have acquired {$breeding->countOffsprings()} baby from the hybrid breeding center."));
                
$document->add(new Comment("Click on one of the links below to manage your species now!"));
                
$iterator $links->iterator();
                while(
$iterator->hasNext()) $document->add($iterator->next());            
            }
            else{
                
$document->setTitle($this->lang->fail_title);
                
$document->addLangvar($this->lang->fail);
            }            
            return;
        }
        
        
$cost $this->getField("cost")->getValue();
        
$femaleMap $this->getField("femaleMap");
        
$maleMap $this->getField("maleMap");
        
$document->setTitle($this->lang->title);
        
$document->addLangvar($this->lang->default.$this->lang->money);
        
$document->addLangvar("{$settings->cost} {$mysidia->settings->cost}");
        
$document->addLangvar($this->lang->warning.$this->lang->select);
        
        
$breedingForm = new Form("hybridbreedingform""hybridbreeding""post");        
        
$breedingForm->add(new Comment("Female: "FALSE));
        if(
$femaleMap instanceof LinkedHashMap){
               
$female = new DropdownList("female");
            
$female->add(new Option("None Selected""none"));            
            
$female->fill($femaleMap);
        }
        else 
$female = new Comment($this->lang->femaleFALSE);
        
$breedingForm->add($female);  
    
        
$breedingForm->add(new Comment("Male: "FALSE));
        if(
$maleMap instanceof LinkedHashMap){
            
$male = new DropdownList("male");
            
$male->add(new Option("None Selected""none"));
            
$male->fill($maleMap);
        }
        else 
$male = new Comment($this->lang->maleFALSE);

        
$breedingForm->add($male);        
        
$breedingForm->add(new PasswordField("hidden""breed""yes"));
        
$breedingForm->add(new Button("Let's breed!""submit""submit"));
        
$document->add($breedingForm);    
    }
}
?>
Step 6. Since we don't want it taking everything (only some parts) from the breeding scripts, we need to make our own.
In the "classes" folder, create a php script called "hybridbreedingvalidator.php"
PHP Code:
<?php

class HybridBreedingValidator extends Validator{

    private 
$female;
    private 
$male;
    private 
$settings;
    private 
$validations;
    private 
$status;

    public function 
__construct(OwnedAdoptable $femaleOwnedAdoptable $maleBreedingSetting $settingsArrayObject $validations){
        
$this->female $female;
        
$this->male $male;        
        
$this->settings $settings;
        
$this->validations $validations;
    }
    
    public function 
getValidations(){
        return 
$this->validations;
    }
    
    public function 
setValidations(ArrayObject $validations$overwrite FALSE){
        if(
$overwrite$this->validations $validations;
        else{
            foreach(
$validations as $validation){
                
$this->validations->append($validations);
            }
        }
    }
    
    public function 
getStatus(){
        return 
$this->status;
    }

    public function 
setStatus($status ""){
        
$this->status $status;

        if(
$this->status == "chance" or $this->status == "complete"){
            
$mysidia Registry::get("mysidia");
            
$date = new DateTime;
            
$mysidia->user->changecash(-2000); 

            
$this->female->setOffsprings($this->female->getOffsprings() + 1"update");
            
$this->female->setLastBred($date->getTimestamp(), "update");
            
$this->male->setOffsprings($this->male->getOffsprings() + "update");
            
$this->male->setLastBred($date->getTimestamp(), "update"); 
        }    
    }

    public function 
validate(){   
        foreach(
$this->validations as $validation){
            
$method "check".ucfirst($validation);
            
$this->$method();
        }
        return 
TRUE;         
    }
  
    private function 
checkHybridClass(){
        
$femaleHybridClass explode(","$this->female->getHybridClass());
        
$maleHybridClass explode(","$this->male->getHybridClass());
        foreach(
$femaleHyrbidClass as $fhybridclass){
            foreach(
$maleHybridClass as $mhybridclass){
                if(
$fhybridclass == $mhybridclass) return TRUE;
            }
        }  
        throw new 
BreedingException("These species are not breedable.");
    }
    
    private function 
checkGender(){
        
$mysidia Registry::get("mysidia");
        if(
$this->female->getGender() != "f" or $this->male->getGender() != "m"){
            
banuser($mysidia->user->username);
            throw new 
BreedingException("gender");
        }
        return 
TRUE;        
    }
  
      private function 
checkOwner(){
        
$mysidia Registry::get("mysidia");
        if(
$this->female->getOwner() != $mysidia->user->username or $this->male->getOwner() != $mysidia->user->username){
            
banuser($mysidia->user->username);
            throw new 
BreedingException("owner");
        }
        return 
TRUE;
    }
  
    private function 
checkSpecies(){
        if(empty(
$this->settings->species)) return TRUE;
        foreach(
$this->settings->species as $type){
            if(
$this->female->getType() == $type or $this->male->getType() == $type) throw new BreedingException("species");
        }
        return 
TRUE;
    }
    
    private function 
checkInterval(){
        
$current = new DateTime;
        
$expirationTime $current->getTimestamp() - (($this->settings->interval) * 24 60 60);
        
        if(
$this->female->getLastBred() > $expirationTime or $this->male->getLastBred() > $expirationTime){
            throw new 
BreedingException("interval");      
        }
        return 
TRUE;
    }
    
    private function 
checkLevel(){
        if(
$this->female->getCurrentLevel() < $this->settings->level or $this->male->getCurrentLevel() < $this->settings->level){
            throw new 
BreedingException("level");
        }
        return 
TRUE;
    }
  
    private function 
checkCapacity(){
        if(
$this->female->getOffsprings() >= $this->settings->capacity or $this->male->getOffsprings() >= $this->settings->capacity){
            throw new 
BreedingException("capacity");
        }
        return 
TRUE;
    }
     
    private function 
checkNumber(){
        if(
$this->settings->number == 0) throw new BreedingException("number");
        return 
TRUE;        
    }

    private function 
checkChance(){
        
$rand rand(099);
        if(
$rand $this->settings->chance) return TRUE;
        throw new 
BreedingException("chance");
    }

    private function 
checkCost(){
        
$mysidia Registry::get("mysidia");
        if(
$mysidia->user->money 1000) throw new BreedingException("cost");
        return 
TRUE;
    }
    
    private function 
checkUsergroup(){
        if(
$this->settings->usergroup == "all") return TRUE;
        
$mysidia Registry::get("mysidia");
        
        foreach(
$this->settings->usergroup as $usergroup){
            if(
$mysidia->user->usergroup == $usergroup) return TRUE;   
        }
        throw new 
BreedingException("usergroup");
    }
    
    private function 
checkItem(){
        if(!
$this->settings->item) return TRUE;
        
$mysidia Registry::get("mysidia");
        
        foreach(
$this->settings->item as $item){
            
$item = new PrivateItem($item$mysidia->user->username);
            if(
$item->iid == 0) throw new BreedingException("item");
            if(
$item->consumable == "yes"$item->remove();            
        }
        return 
TRUE;
    }
}
?>
Next add a php file called "hybridbreeding.php"
PHP Code:
<?php

use Resource\Native\Object;

final class 
HybridBreeding extends Object{

    private 
$female;
    private 
$male;
      public 
$class;
      public 
$hybridclass;
    private 
$offsprings;
    private 
$settings;
    private 
$validator;
  
    public function 
__construct(OwnedAdoptable $femaleOwnedAdoptable $maleBreedingSetting $settings){
        
$this->female $female;
        
$this->male $male;
        
$this->offsprings = new ArrayObject;
        
$this->settings $settings;    
    }
    
    public function 
getValidator(){
        
$mysidia Registry::get("mysidia");
        if(
func_num_args() == 0) throw new InvalidActionException($mysidia->lang->global_action);
        
        if(
func_get_arg(0) == "all"$validations = new ArrayObject(array("hybridclass""gender""owner""species""interval""level""capacity""number""cost""usergroup""item""chance"));
        else 
$validations = new ArrayObject(func_get_args());
        
        
$this->validator = new HybridBreedingValidator($this->female$this->male$this->settings$validations);
        return 
$this->validator;
    }
    
    public function 
getBabySpecies(){
        
$mysidia Registry::get("mysidia");
        
$female $this->female->getSpecies();
        
$male $this->male->getSpecies();
        
$parentList "{$female}{$male}";
        
$parentList2 "{$male}{$female}";
        
        
$stmt $mysidia->db->select("breeding", array("bid"), "((mother ='{$female}' and father = '{$male}') or (mother ='{$female}' and father = '') or (mother ='' and father = '{$male}') or parent = '{$female}' or parent = '{$male}' or parent = '{$parentList}' or parent = '{$parentList2}') and level <= {$this->female->getCurrentLevel()} and available = 'yes'");
        if(
$stmt->rowCount() == 0) return;
        else{
            
$species = new ArrayObject;
            while(
$bid $stmt->fetchColumn()){
                
$adopt = new BreedAdoptable($bid);
                
$species->append($adopt);
            }
            return 
$species;
        }
    }
    
    public function 
getBabyAdopts($species ""){
        if(
$this->settings->method == "heuristic" or !$species$this->heuristicBreed();
        else 
$this->advancedBreed($species);
        return 
$this->offsprings;
    }
    
    private function 
heuristicBreed(){
        
$choices = array($this->female->getType(), $this->male->getType());
        
$num rand(1$this->settings->number);
        for(
$i 0$i $num$i++){
            
$rand rand(01);
            
$this->offsprings->append(new Adoptable($choices[$rand]));
        }
    }
    
    private function 
advancedBreed($species){
        
$speciesMap = new ArrayObject;
        
$probability = new Probability;
        
        foreach(
$species as $breed){
            
$speciesMap->offsetSet($breed->getBreedID(), $breed);
            
$probability->addEvent($breed->getBreedID(), $breed->getProbability());
        }
            
        
$num rand(1$this->settings->number);
        for(
$i 0$i $num$i++){
            
$bid $probability->randomEvent();
            
$adopt $speciesMap->offsetGet($bid);
            if(
$this->getSurvival($adopt)) $this->offsprings->append($adopt);
        }
    }
    
    public function 
getSurvival(BreedAdoptable $adopt){
        
$rand rand(099);
        if(
$rand $adopt->getSurvivalRate()) return TRUE;
        else return 
FALSE;        
    }
    
    public function 
countOffsprings(){
        return 
$this->offsprings->count();
    }

    public function 
getOffsprings(){
        return 
$this->offsprings;
    }
  
    public function 
hybridbreed(){

        
        
$mysidia Registry::get("mysidia");
        foreach(
$this->offsprings as $adopt){
            
$alts $adopt->getAltStatus();
            
$code $adopt->getCode();
            
$gender $adopt->getGender();
            
$mysidia->db->insert("owned_adoptables", array("aid" => NULL"type" => $adopt->getType(), "name" => $adopt_getType(), "class" => $adopt->getClass(), "hybridclass" => $adopt->getHybridClass(), "owner" => $mysidia->user->username"currentlevel" => 0"totalclicks" => 0"code" => $code
                                                           
"imageurl" => $adopt->getEggImage(), "usealternates" => $alts"tradestatus" => 'fortrade'"isfrozen" => 'no'"gender" => $gender"offsprings" => 0"lastbred" => 0));
        }
        
$this->validator->setStatus("complete");    
    }
}
?>
Step 7. Now we need the language.
In the "lang" folder, create a new php file called "lang_hybridbreeding.php]
PHP Code:
<?php

//Language variables used for Breeding Page

$lang['title'] = "Hybrid Breeding Center";
$lang['default'] = "You may cross breed your species and create hybrids here.<br>"
$lang['system'] = "The admin has disabled the breeding system, please contact him/her if you have any questions.";
$lang['money'] = "You currently have {$mysidia->user->getcash()} {$mysidia->settings->cost}, the cost of breeding is: 2000 ";
$lang['warning'] = "<br>Note that cross breeding hybrids may fail for various reasons. The parents may not breed properly, the offsprings may not survive easily, and more...<br><br>";
$lang['banned'] = "It appears that you have been banned from breeding your animals. Please contact an administrator for assistance.<br>";   
$lang['select'] = "<br>You may select the two animals that you'd like to cross breed:<br>"
$lang['error'] = "Breeding error has occurred!";
$lang['female'] = "None of your female animals can breed at the time.<br>";
$lang['male'] = "None of your male animals can breed at the time.<br>";
$lang['class'] = "Sorry, it seems that your two animals do not belong to the same breeding class.";
$lang['gender'] = "It appears that the female and/or male animals gender's have been modified. You have been banned for this action, please contact site administrator for more info.";  
$lang['owner'] = "It appears that at least one of the animals selected do not belong to yours. You have been banned for this action, please contact site administrator for more info.";
$lang['species'] = "Sorry, at least one of your animals belong to unbreedable species.";
$lang['interval'] = "Sorry, it appears that your animals need to wait at least another day to be able to breed again.";
$lang['level'] = "Sorry, one of your animals don't have the minimum level to breed. Keep getting clicks for them so they can grow."
$lang['capacity'] = "Sorry, at least one of your animals have reached their maximum breeding capacity. He/she is no longer capable of breeding offsprings.";
$lang['number'] = "Unfortunately, the admin has set the maximum number of offsprings possible to be 0. Please contact him/her for assistance.";
$lang['chance'] = "Unfortunately, breeding attempt was unsuccessful, please come back another time.";
$lang['cost'] = "It appears that you do not have enough money to pay for the breeding transaction.";
$lang['usergroup'] = "It seems that you do not belong to the certified usergroup to breed animals.";
$lang['item'] = "It seems that you lack the necessary item to breed animals.";
$lang['permission'] = "It appears that you have been banned for breeding.";
$lang['none_select'] = "You have yet to select a female and a male animals for breeding.";
$lang['none_exist'] = "The selected female or male animals ID does not seem to exist.";
$lang['fail_title'] = "Breeding has failed...";
$lang['fail'] = "This is too bad. Breeding is attempted but none of the baby animals have survived.";
            
?>
Step 8. Create a new hybrid adopt. Set up the parents you want to be able to make that hybrid in the "create new breed adopt" in the admincp. Make sure they're in the same "Hybrid class"

Last step.
Now set up a link to go to (yoursite.com)/hybridbreeding
I did set up the defaults to cost 2000. If you want that changed, you'll have to set that up yourself. Simply find "2000" in the lang and "class_hybridbreedingvalidator" files and change it to whatever you like. Since I don't know how to set that up to work from any kind of database, I just put it straight into the code.

If it messes anything up, I apologize, I tried my best to remove modded coding from the scripts I pasted.

Last edited by Chaos77777; 01-29-2017 at 12:06 AM.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 03:14 AM.

Currently Active Users: 406 (0 members and 406 guests)
Threads: 4,080, Posts: 32,024, Members: 2,016
Welcome to our newest members, jolob.
BETA





What's New?

What's Hot?

What's Popular?


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
vBCommerce I v2.0.0 Gold ©2010, PixelFX Studios
vBCredits I v2.0.0 Gold ©2010, PixelFX Studios
Emoticons by darkmoon3636