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
Finally, you will replace the public function breed with this:
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:
