Mysidia Adoptables Support Forum

Mysidia Adoptables Support Forum (http://www.mysidiaadoptables.com/forum/index.php)
-   Questions and Supports (http://www.mysidiaadoptables.com/forum/forumdisplay.php?f=18)
-   -   Mys 1.3.4 Pet Lineages? (http://www.mysidiaadoptables.com/forum/showthread.php?t=5014)

Abronsyth 02-12-2016 09:26 PM

Okay, I sort of figured as much but when you said in the database that I was concerned, haha.

So I'm looking in owned_adoptables, but it seems that the Offsprings column is recording the number of offspring each adopt has produced, but not the actual IDs of the offspring...I'm not sure if this is the normal behavior, or how to alter it. I assume I could change something in class_breeding.php (maybe) to update that column each time a cat is bred to include the new offspring IDs, but I'm not sure how to make it then so that the new IDs are added as a list, and not replacing the data already there.

Kyttias 02-12-2016 11:14 PM

Hmmm!!! I might have changed something significant for my own site, haha... hang on.

Alright, I don't know what the default $offsprings field is actually used for. I re-purposed it. Since I don't feel comfortable asking you to do the same in case it breaks an Mysidia feature you're using but I'm not, we're going to make some tweaks.

First, let's create a new column in adopts_owned_adoptables called descendants. We're going to have it be varchar 500, but even that may not be big enough if your site gets too large.

Second, let's first go back to the code we were working on before. Instead of looking for the column offsprings, we'll change it to look for descendants.

PHP Code:

$babies = array();
$descendants explode(","$adopt->descendants);
if (
$descendants != ""){
    foreach(
$descendants as $offspring){
        if (
$offspring != 0){
            
$babies[] = "<a href='../../levelup/click/{$offspring}'><img src='../../levelup/siggy/{$offspring}' width='12%' height='12%'/></a>";
        }
    }
    
$children implode(""$babies);
    if (empty(
$children)){ $children "None"; } 


So here's the bad news - Mysidia actually doesn't keep track of your kids. That's something I taught MINE to do. I had completely forgotten, but I'm not surprised, it was over six months ago... woops! So this will keep track of future kids, but anything prior to this won't be linked to it's kids.

In breeding.php find:

PHP Code:

            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);
            } 

We need to add to this if statement. Immediately after, or before if you'd rather, $this->setField("links", $links); but definitely before the closing bracket, we'll be adding this:

PHP Code:

/* Kyt: Descendants Mod!! */
$newbabies = array();
foreach(
$offsprings as $offspring){ 
    
$newbabies[] = $offspringID;
    
$offspringID++;
}

if (
$female->descendants != 0){ $mothersOffspring $female->descendants; } else { $mothersOffspring ""; }
if (
$male->descendants != 0){ $fathersOffspring $male->descendants; } else { $fathersOffspring ""; }

for(
$i 0$i count($newbabies); $i++){
    
$mothersOffspring .= $newbabies[$i].",";
    
$fathersOffspring .= $newbabies[$i].",";
}

$updatedMotherOffspring preg_replace('/^(0,)+/'''$mothersOffspring);
$updatedFatherOffpsring preg_replace('/^(0,)+/'''$fathersOffspring);

$mysidia->db->update("owned_adoptables", array("descendants" => $updatedMotherOffspring), "aid = '{$female->aid}'");
$mysidia->db->update("owned_adoptables", array("descendants" => $updatedFatherOffpsring), "aid = '{$male->aid}'");
/* Descendants Mod End!! */ 

Again, make extra sure it's inside that if statement.

Get back to me with the results?

...the long and the short of it is, I made this exact feature for myself six months ago but kind of just built it in while I was working on my new breeding system and never finished actually making the whole family tree visual part. x'D I was more than happy to help because I knew I was mostly done with mine and it was the push I needed to finish.

Here's mine:
http://orig02.deviantart.net/3a71/f/...as-d9rj8nb.png

Abronsyth 02-13-2016 11:16 AM

OK, now the only issue I am encountering is for some reason it added +1 to the ID of the offspring (which causes it to not work). So the offspring ID should be 25422, but it's showing 25423 on the parent's page.

When I manually changed it in the database to the correct ID, it works perfectly, though! So that's a plus!

Kyttias 02-13-2016 02:55 PM

When your babies are born, you get to see them, right? It should be storing the IDs of the ones seen. Try combining for the foreach loops. (I have mine combined.)

Put $newbabies = array(); before the existing foreach loop above the mod.
Add $newbabies[] = $offspringID; to the inside of the old foreach loop.
Go ahead and delete the loop inside my mod (and $newbabies = array(); before it, of course).

Basically, this function was already build a list of image links to your babies from their ID numbers. All I'm doing is taking the same list of IDs and putting them in the database. They should not be different! The pets seen at birth should be the same ones seen in their family tree.

Abronsyth 02-17-2016 11:37 AM

OK, so I bred two pets and these are the offspring IDs;
25753, 25754, 25756

But this is what is in the descendants column;
25756,25757,25758,

breeding.php;
PHP Code:

<?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);
                
$male = new OwnedAdoptable($mysidia->input->post("male"), $mysidia->user->username);
                
$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);
/* Kyt: Descendants Mod!! */
$newbabies = array();
foreach(
$offsprings as $offspring){ 
    
$newbabies[] = $offspringID;
    
$offspringID++;
}

if (
$female->descendants != 0){ $mothersOffspring $female->descendants; } else { $mothersOffspring ""; }
if (
$male->descendants != 0){ $fathersOffspring $male->descendants; } else { $fathersOffspring ""; }

for(
$i 0$i count($newbabies); $i++){
    
$mothersOffspring .= $newbabies[$i].",";
    
$fathersOffspring .= $newbabies[$i].",";
}

$updatedMotherOffspring preg_replace('/^(0,)+/'''$mothersOffspring);
$updatedFatherOffpsring preg_replace('/^(0,)+/'''$fathersOffspring);

$mysidia->db->update("owned_adoptables", array("descendants" => $updatedMotherOffspring), "aid = '{$female->aid}'");
$mysidia->db->update("owned_adoptables", array("descendants" => $updatedFatherOffpsring), "aid = '{$male->aid}'");
/* Descendants Mod End!! */
            
}
            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("name""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("name""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);
    }
}
?>

Maybe I put something together wrong..?

Kyttias 02-17-2016 12:08 PM

Yes, that appears to be counting the next three exactly... yeah, just combine the foreach loops like I said in my last post. Here, I made the edit:

PHP Code:

<?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);
                
$male = new OwnedAdoptable($mysidia->input->post("male"), $mysidia->user->username);
                
$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;
                
$newbabies = array(); // Kyt: Added line for Descendants Mod!!
                
foreach($offsprings as $offspring){
                    
$newbabies[] = $offspringID// Kyt: Added line for Descendants Mod!!
                    
$image $offspring->getEggImage("gui");
                    
$links->add(new Link("myadopts/manage/{$offspringID}"$image));
                    
$offspringID++;
                }
                
$this->setField("links"$links);
/* Kyt: Descendants Mod!! */
if ($female->descendants != 0){ $mothersOffspring $female->descendants; } else { $mothersOffspring ""; }
if (
$male->descendants != 0){ $fathersOffspring $male->descendants; } else { $fathersOffspring ""; }

for(
$i 0$i count($newbabies); $i++){
    
$mothersOffspring .= $newbabies[$i].",";
    
$fathersOffspring .= $newbabies[$i].",";
}

$updatedMotherOffspring preg_replace('/^(0,)+/'''$mothersOffspring);
$updatedFatherOffpsring preg_replace('/^(0,)+/'''$fathersOffspring);

$mysidia->db->update("owned_adoptables", array("descendants" => $updatedMotherOffspring), "aid = '{$female->aid}'");
$mysidia->db->update("owned_adoptables", array("descendants" => $updatedFatherOffpsring), "aid = '{$male->aid}'");
/* Descendants Mod End!! */
            
}
            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("name""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("name""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);
    }
}
?>


Abronsyth 02-17-2016 01:05 PM

Okay, excellent, it seems to be fully functioning now!

Aaand one of my users just presented to me an error that occurs with direct inbreeding. If the parents of a pet are siblings, then the grandparents only show for the mother, and for the father it says both grandparents are Unknown. I have no idea why this is..? (Maybe the script is opposed to inbreeding, haha)

Kyttias 02-17-2016 01:09 PM

Hmmm... make sure all the numbers line up in the database? Can I see the kitties involved?

Abronsyth 02-18-2016 02:46 PM

Here's one of the cats whose parents are siblings (from the same litter):
http://catisserie.net/levelup/click/25715


It would seem that it did not add the grandparent B information in the database, only A.

tahbikat 02-27-2016 07:06 PM

*o* I might try to cop this if you guys don't mind... lol


All times are GMT -5. The time now is 02:16 AM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.