Public Stud Breeding Mod

This mod changes the Breeding feature and enables public studs for which the stud owner will earn currency, and changes the breeding feature a bit so that you select a female first, and then select a male to pair her with.

Note that styling is done using things present in my theme and the W3SCSS theme library, so you likely will need to customize aesthetic pieces to your needs.

Many thanks to Missy Master for helping me test this, and inspiring me to actually work on it.

Requirements

Before you start, note that this requires changing the protected/private variables in classes/class_ownedadoptables.php to public.

It also requires the use of this classes/class_database.php mod from Dinocanid and IntoRain:

Using Math to Update the Database


Step 1:

Database

Go into your phpMyAdmin and your owned_adoptables table, then add 2 columns with the following info:

Name: stud

Type: varchar

Length: 3

default: as defined (no)


Name: studfee

Type: int

Length: 5

default: as defined: 0


Step 2:

Add the following function to myadopts.php (I put mine at the end of the trade function):

public function stud(){

$mysidia = Registry::get("mysidia");

if($mysidia->input->post("submit")){

$newstat = $mysidia->input->post("stud");

$newfee = $mysidia->input->post("studfee");

$mysidia->db->update("owned_adoptables", array("stud" => $newstat), "aid = '{$this->adopt->getAdoptID()}'");

$mysidia->db->update("owned_adoptables", array("studfee" => $newfee), "aid = '{$this->adopt->getAdoptID()}'");

}

$this->setField("aid", new Integer($this->adopt->getAdoptID()));

$this->setField("adopt", $this->adopt);

}

And then add this function to view/myadoptsview.php:

public function stud(){

$mysidia = Registry::get("mysidia");

$aid = $this->getField("aid")->getValue();

$image = $this->getField("image");

$document = $this->document;

$document->setTitle("Change Stud Status");

$gender_lookup = $mysidia->db->select("owned_adoptables", array("gender"), "aid = '{$aid}'")->fetchColumn();

$status = $mysidia->db->select("owned_adoptables", array("stud"), "aid = '{$aid}'")->fetchColumn();

$fee = $mysidia->db->select("owned_adoptables", array("studfee"), "aid = '{$aid}'")->fetchColumn();

if($mysidia->input->post("submit")){

$document->setTitle("Stud Updated");

$document->add(new Comment("Stud status has been updated.<br><a href='../../myadopts/manage/{$aid}'>Back</a>"));

return;

}

if($gender_lookup == 'f'){

$document->add(new Comment("Females cannot be studded. <br> <a href='../../myadopts/manage/{$aid}'>Back</a>"));

}

else{

$document->add(new Comment("<img src='../../levelup/siggy/{$aid}'/><br><b>Currently Up For Stud:</b> {$status}<br>

<br><form class='w3-form' action='../../myadopts/stud/{$aid}' method='post'>

<p>

<label>No</label>

<input class='w3-radio' type='radio' name='stud' value='no' checked></p>

<p>

<label>Yes</label>

<input class='w3-radio' type='radio' name='stud' value='yes'></p>

<label for='cost'>Studding Fee:</label><br>

<input type='number' name='studfee' min='1' size='5' value='{$fee}' required></input>

<input type='submit' name='submit' value='Submit' class='w3-button w3-green'>

</form>

"));}

}

Now you'll need to add a way to get to the Stud page, so wherever you have your management links, add this link:

../../myadopts/stud/{$aid}

That done, save and close those pages. Now go test and make sure everything is working! (If not you can contact me on the Mysidia Discord!)

Step 3:

Now it is time to move on to the breeding files. We have three files to edit: breeding.php, breedingview.php, and class_breedingvalidator.php.

In classes/class_breedingvalidator.php change private function checkOwner to this:

private function checkOwner(){

$mysidia = Registry::get("mysidia");

if($this->female->getOwner() != $mysidia->user->username){

banuser($mysidia->user->username);

throw new BreedingException("owner");

}

return TRUE;

}

Now save that and open breeding.php. Replace the file with this:

<?php


use Resource\Native\Integer;

use Resource\Native\String;

use Resource\Native\Null;

use Resource\Collection\LinkedList;


class BreedingController 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);

$maleowner = $mysidia->db->select("owned_adoptables", array("owner"), "aid='{$mysidia->input->post("male")}'")->fetchColumn();

$male = new OwnedAdoptable($mysidia->input->post("male"), $maleowner);

$breeding = new Breeding($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->breed($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);

$female = $mysidia->db->select("owned_adoptables", array("aid"), "owner = '{$mysidia->user->username}' AND gender = 'f' AND currentlevel >= {$settings->level} AND lastbred <= '{$lasttime}'");

$this->setField("female", new DatabaseStatement($female));

$maleprivate = $mysidia->db->select("owned_adoptables", array("aid"), "owner = '{$mysidia->user->username}' AND gender = 'm' AND currentlevel >= {$settings->level} AND lastbred <= '{$lasttime}'");

$this->setField("maleprivate", new DatabaseStatement($maleprivate));

$stud = $mysidia->db->select("owned_adoptables", array("aid"), "gender = 'm' AND currentlevel >= {$settings->level} AND lastbred <= '{$lasttime}' AND stud = 'yes'");

$this->setField("stud", new DatabaseStatement($stud));

}

}

?>


Save, and move into view/breedingview.php, now I've already done a fair share of customization to make this pretty for MY site, so you will have to modify it to work with your site, aesthetically. I also do NOT use a cost for breeding or an item for breeding. Please take this into consideration.

Replace the file with this:

<?php


use Resource\Collection\LinkedList;

use Resource\Collection\LinkedHashMap;


class BreedingView extends View{

public function index(){

$mysidia = Registry::get("mysidia");

$document = $this->document;

if($mysidia->input->post("submit")){

$type = $mysidia->input->post("type");

$studfee = $mysidia->db->select("owned_adoptables", array("studfee"), "aid='{$mysidia->input->post("male")}'")->fetchColumn();

$maleowner = $mysidia->db->select("owned_adoptables", array("owner"), "aid='{$mysidia->input->post("male")}'")->fetchColumn();

$malename = $mysidia->db->select("owned_adoptables", array("name"), "aid='{$mysidia->input->post("male")}'")->fetchColumn();

if($type == 'stud'){

$mysidia->db->update_decrease("users", array("money"), $studfee, "username = '{$mysidia->user->username}'");

$mysidia->db->update_increase("users", array("money"), $studfee, "username = '{$maleowner}'");

$pm = new PrivateMessage();

$pm->setsender('SYSTEM');

$pm->setrecipient($maleowner);

$pm->setmessage("Stud Used", "{$mysidia->user->username} used your stud, {$malename}, for a breeding. Your earned {$studfee} Coins.");

$pm->post();

}

$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 adoptables from breeding center."));

$document->add(new Comment("Click on one of the links below to manage your new egg(s) now!"));

$iterator = $links->iterator();

while($iterator->hasNext()) $document->add($iterator->next());

}

else{

$document->setTitle($this->lang->fail_title);

$document->addLangvar($this->lang->fail);

}

return;

}


if($mysidia->input->post("malechosen")){

}

if($mysidia->input->post("privatemale")){

$document->setTitle("Confirm Pairing");

$femaleid = $mysidia->input->post("female");

$female = new OwnedAdoptable($femaleid);

$maleid = $mysidia->input->post("male");

$male = new OwnedAdoptable($maleid);

$document->add(new Comment("You have chosen to breed {$female->name} with {$male->name}. Since you own both of these gryphons, this breeding is free.<br>

<table style='width:90%;text-align:center;'>

<tr><th><b>Female</b></th><th><b>Male</b></th></tr>

<tr>

<td><a href='../../levelup/publicprofile/{$femaleid}'><img src='../../levelup/siggy/{$femaleid}'/></a></td>

<td><a href='../../levelup/publicprofile/{$maleid}'><img src='../../levelup/siggy/{$maleid}'/></a></td>

</tr>

</table>

<br>

<form action='../../breeding' method='post'>

<input type='hidden' name='female' value='{$femaleid}'>

<input type='hidden' name='type' value='private'>

<input type='hidden' name='male' value='{$maleid}'>

<input type='submit' name='submit' value='Confirm'>

</form>"));

return;

}

if($mysidia->input->post("studmale")){

$studfee = $mysidia->db->select("owned_adoptables", array("studfee"), "aid='{$mysidia->input->post("male")}'")->fetchColumn();

$cash = $mysidia->db->select("users", array("money"), "username='{$mysidia->user->username}'")->fetchColumn();

if($cash < $studfee){

$document->setTitle("Not Enough Cash");

$document->add(new Comment("Using this stud costs {$studfee}, but you only have {$cash} on hand. <br><a href='../../breeding'>Back</a>"));

return;

}

$document->setTitle("Confirm Pairing");

$femaleid = $mysidia->input->post("female");

$female = new OwnedAdoptable($femaleid);

$maleid = $mysidia->input->post("male");

$male = new OwnedAdoptable($maleid);

$document->add(new Comment("You have chosen to breed {$female->name} with {$male->name}. The owner of the male, {$male->owner}, charges a stud fee of {$male->studfee} Coins to use their male.<br>

<table style='width:90%;text-align:center;'>

<tr><th><b>Female</b></th><th><b>Male</b></th></tr>

<tr>

<td><a href='../../levelup/publicprofile/{$femaleid}'><img src='../../levelup/siggy/{$femaleid}'/></a></td>

<td><a href='../../levelup/publicprofile/{$maleid}'><img src='../../levelup/siggy/{$maleid}'/></a></td>

</tr>

</table>

<br>

<form action='../../breeding' method='post'>

<input type='hidden' name='female' value='{$femaleid}'>

<input type='hidden' name='male' value='{$maleid}'>

<input type='hidden' name='type' value='stud'>

<input type='submit' name='submit' value='Confirm and Pay'>

</form>"));

return;

}

if($mysidia->input->post("femalechosen")){

$document->setTitle("Choose Male");

$femaleid = $mysidia->input->post("female");

$femalename = $mysidia->db->select("owned_adoptables", array("name"), "aid='{$femaleid}'")->fetchColumn();

$adoptf = new OwnedAdoptable($femaleid);

$document->add(new Comment("<b>Female:</b><br><a href='../../levelup/publicprofile/{$femaleid}'><img src='../../levelup/siggy/{$femaleid}'/></a><br>

<br>You've selected {$adoptf->name} (ID: {$femaleid}) to breed. Now you must choose a male.<br> You can either choose to use one of your males, for free, or use a public stud, for a fee.<br><br><i>Or</i> <a href='../../breeding'>Choose Different Female</a><br><br>

<form style='width:90%;' action='../../breeding' method='post'>

<label>Your Males</label>

<select name='male'>"));

$maleprivate = $this->getField("maleprivate")->get();

if($maleprivate->rowCount() == 0){

$document->add(new Comment("</select><br>You Don't Own Any Males."));

return;

}

while($aid = $maleprivate->fetchColumn()){

$adopt = new OwnedAdoptable($aid);

$document->add(new Comment("<option value='{$adopt->aid}'>ID {$adopt->aid}: {$adopt->name}</option>"));

}

$document->add(new Comment("</select>

<input type='hidden' name='female' value='{$femaleid}'>

<input type='submit' name='privatemale' value='Choose'></form><br>

<form style='width:90%;' action='../../breeding' method='post'>

<label>Studs</label>

<select name='male'>"));

$stud = $this->getField("stud")->get();

if($stud->rowCount() == 0){

$document->add(new Comment("<option value='none' disabled>No Studs</option></select>"));

return;

}

while($aid = $stud->fetchColumn()){

$adopt = new OwnedAdoptable($aid);

$document->add(new Comment("<option value='{$adopt->aid}'>ID {$adopt->aid}: {$adopt->name} (cost: {$adopt->studfee} coins)</option>"));

}

$document->add(new Comment("</select>

<input type='hidden' name='female' value='{$femaleid}'>

<input type='submit' name='studmale' value='Choose'></form>"));

return;

}

$cost = $this->getField("cost")->getValue();

$femaleMap = $this->getField("femaleMap");

$maleMap = $this->getField("maleMap");

$document->setTitle("Breeding");

$document->add(new Comment("Welcome to the Breeding Center, here you can breed two gryphons to produce a clutch of eggs."));

$document->addLangvar($this->lang->warning);

$document->add(new Comment("<br>Now, select your female to breed:

<form style='width:90%;' action='../../breeding' method='post'>

<select name='female'>"));

$female = $this->getField("female")->get();

if($female->rowCount() == 0){

$document->add(new Comment("</select><br>You Don't Own Any Females."));

return;

}

while($aid = $female->fetchColumn()){

$adopt = new OwnedAdoptable($aid);

$document->add(new Comment("<option value='{$adopt->aid}'>ID {$adopt->aid}: {$adopt->name}</option>"));

}

$document->add(new Comment("</select><input type='submit' name='femalechosen' value='Choose'></form>"));

}

}

?>


Save, and test it out! Features include preventing users from using a stud if they can't afford it, and sending the stud owner a message to let them know a stud was used!