Merged Breeding Mod for 1.3.6

Forum
Last Post
Threads / Messages

Kesstryl

Member
Member
Joined
Feb 22, 2012
Messages
232
Points
28
Mysidian Dollar
11,985
I updated the Merged Breeding Mod from 1.3.4 posted by Milly Money, so I do not take credit for writing it.

Step 1. Start in service/applicationservice/breedingservice

In the namespaces at the top, add this:
use Resource\Core\Model;

Before the constructor, in the list of private variables, add this:
private $imageurl;

Add these three functions somewhere in the list of functions
Code:
    private function mergedBreed(){
        if($this->female->getClass() != $this->male->getClass()) throw new Exception("These species cannot breed."); 
        $name = "Child of {$this->female->getName()} & {$this->male->getName()}";
        if(!$this->imageurl) $this->imageurl = $this->getImageurl($name);
        $num = rand(1, $this->settings->number);
        for($i = 0; $i < $num; $i++){
            $this->offsprings->append(new Adoptable($this->female->getType()));
        }       
    }

Code:
    private function getImageurl($name){
        $mysidia = Registry::get("mysidia");
        $imagename = str_replace("&", "", $name);
        $imagename = str_replace("  ", " ", $imagename);
        $imagename = str_replace(" ", "_", $imagename);      
        $imagename = time() . chr(rand(65,90)) . chr(rand(65,90)) . ".png";
   
        $imageurl = "{$mysidia->path->getAbsolute()}picuploads/png/{$imagename}";
        $female_image = $this->female->getImage();
        $male_image = $this->male->getImage();
        $female_im = $this->createImage($female_image);
        imageAlphaBlending($female_im, true);
        imageSaveAlpha($female_im, true);
        imageinterlace($female_im, false);
        $male_im = $this->createImage($male_image);
        imageAlphaBlending($male_im, true);
        imageSaveAlpha($male_im, true);
        imageinterlace($male_im, false);
                 
        $xf = max(imagesx($male_im), imagesx($female_im));
        $yf = max(imagesy($male_im), imagesy($female_im));        
        $imclear = imagecreatetruecolor($xf, $yf);
        $cc0 = imagecolorallocate($imclear, 255, 255, 255);
        @imagefilledrectangle($imclear, 0, 0, $xf-1, $yf-1, $cc0);
        $cc1 = imagecolorallocate($male_im, 255, 255, 255);
        @imagecolortransparent($male_im, $cc1);
        $cc2 = imagecolorallocate($female_im, 255, 255, 255);
        @imagecolortransparent($female_im, $cc2);          
        $delta = 700;
        if(!imagecopymerge($imclear, $female_im, 0, 0, 0, 0, imagesx($female_im), imagesy($female_im), 100)) throw new Exception("error on the image copy");
        if(!imagecopymerge($imclear, $male_im, imagesx($male_im) - $delta, 0, imagesx($male_im) - $delta, 0, $delta, imagesy($male_im), 75)) throw new Exception("error on the image copy");
        @imagepng($imclear, "picuploads/png/" . $imagename);
        return $imageurl;
    }

Code:
    private function createImage($image){
        if(strtolower(substr($image, -3)) == "png") return @imagecreatefrompng($image);
          elseif(strtolower(substr($image, -3)) == "gif") return imagecreatefromgif($image);
        else return imagecreatefromjpeg($image);
    }

Finally, you will replace the public function breed with this:
Code:
    public function breed(){
        $mysidia = Registry::get("mysidia");
        foreach($this->offsprings as $adopt){
            $code = $adopt->generateCode();
            $gender = $adopt->getGender();
            $imageurl = $this->imageurl ?? NULL;
//            $imageurl = ($this->settings->method == "merged") ? $this->imageurl : NULL;
            var_dump($imageurl);
            $mysidia->db->insert("owned_adoptables", ["aid" => NULL, "adopt" => $adopt->getTypeID(), "name" => $adopt->getType(), "owner" => $mysidia->user->getID(), "currentlevel" => 0,
                                "totalclicks" => 0, "code" => $code, "imageurl" => $imageurl, "alternate" => 0, "tradestatus" => "notfortrade",
                                "isfrozen" => "no", "gender" => $gender, "offsprings" => 0, "lastbred" => 0]);
        }
        $this->validator->setStatus("complete");
    }
 
Last edited:
Step 2.

Go to controller/breedingcontroller

Scroll to where it says: if($settings->method == "advanced") $species = $breedingService->getBabySpecies();

And replace with this code snippet:
Code:
            if($settings->method == "advanced" || $settings->method == "merged") $species = $breedingService->getBabySpecies();

Step 3. Go to view/admincp/breedingview

Go way to the bottom where it says:

$breedingMethod->put(new MysString("Advanced"), new MysString("advanced"));

Add this under it
Code:
        $breedingMethod->put(new MysString("Merged"), new MysString("merged"));

In the settingsForm where it says:

->buildComment("Breeding Method(heuristic or advanced): ", FALSE)->buildRadioList("method", $breedingMethod, $breedingSettings->method)

Replace it with this:
Code:
             ->buildComment("Breeding Method(heuristic, advanced or merged):   ", FALSE)->buildRadioList("method", $breedingMethod, $breedingSettings->method)



Step 4. I don't think I needed to change anything else, but if it doesn't work, post a comment and I'll add the fix to this section
 
Last edited:
This looks nice, would be great to see more such mods converted to Mys v1.3.6 compatible version. One suggestion I can make is to attach a zip/archive file with the affected files so users can ‘install’ it quickly.
 
Thank you for doing this!! I have a lot of fun with this mod and the combinations are amazing. So good to see this compatible!
 
Able to test this thoroughly and installed it I believe correctly, but getting just a white page with 'NULL'. All the pets have the imageurl table with correct image urls in them. I went through and double checked all the inserts for the pages.

Not sure what's wrong, would really love to use this! :)
 
Able to test this thoroughly and installed it I believe correctly, but getting just a white page with 'NULL'. All the pets have the imageurl table with correct image urls in them. I went through and double checked all the inserts for the pages.

Not sure what's wrong, would really love to use this! :)
I know where I screwed up, it's in the very first code block for the mergeBreed function in the directions, I edited it to fix it.
 

Similar threads

  • Forum Contains New Posts
  • Forum Contains No New Posts

Forum statistics

Threads
4,317
Messages
33,331
Members
1,613
Latest member
Mama12121243
BETA
Top