View Single Post
  #1  
Old 06-27-2017, 12:42 PM
Dinocanid's Avatar
Dinocanid Dinocanid is offline
Member
 
Join Date: Aug 2016
Location: Maryland, USA
Posts: 516
Gender: Unknown/Other
Credits: 63,732
Dinocanid is on a distinguished road
Default Public breeding - need some help

I think I've gotten really close to some sort of public breeding system that I'm looking forward to share, but I've run into a problem. Currently, you can reach the page through "site.com/levelup/breed/insertaid", which runs well and good, until you actually press the breed button; then you get this error:
Quote:
Adoptable ID breeding does not exist or does not belong to the owner specified...
After clicking the button, the url becomes "site.com/levelup/breed/breeding", and of course "breeding" is not a valid adopt id. Is there any way to make it "site.com/levelup/breed/insertaid/breeding" or "site.com/levelup/breeding"?

This is what it looks like:
PHP Code:
public function breed(){
        
$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 adoptables from breeding center."));
                
$document->add(new Comment("Click on one of the links below to manage your adoptables now!"));
                
$iterator $links->iterator();
                while(
$iterator->hasNext()) $document->add($iterator->next());            
            }
            else{
                
$document->setTitle("Fail!");
                
$document->addLangvar("Why it failed goes here");
            }            
            return;
        }
        
        
$adopt $this->getField("adopt");
        
$gender_lookup $mysidia->db->select("owned_adoptables", array("gender"), "aid = '{$adopt->getAdoptID()}'")->fetchColumn();
        if (
$gender_lookup == "m") { $gender "Male"$pronoun "him"; } else { $gender "Female"$pronoun "her"; }
        
        
$cost $this->getField("cost")->getValue();
        
$femaleMap $this->getField("femaleMap");
        
$maleMap $this->getField("maleMap");
        
$document->setTitle("Breeding Center");
        
$document->add(new Comment("<font color=red><h2>This is currently being tested! It doesn't work yet! </h2></font>"));
        
$document->add(new Comment("<img src='{$adopt->getImage()}'>"));
        
        
$document->add(new Comment("You currently have $ {$mysidia->user->getcash()}, the cost of breeding is: "));
        
$document->addLangvar(" $ {$settings->cost}");
        
        
$breedingForm = new Form("breedingform""breeding""post");
        
//If the requested pet is male!
        
        
if($gender == "Male"){
        
// $breedingForm->add(new Comment("<div class='besideright'>"));
        
if($femaleMap instanceof LinkedHashMap){
               
$female = new DropdownList("female");
            
$female->add(new Option("None Selected""none"FALSE));            
            
$female->fill($femaleMap);
            
        }
        else 
$female = new Comment(" None of your female adoptables can breed at the time.");
        
$breedingForm->add($female);
    
        }
        
        
//If the requested pet is female!    
        
if($gender == "Female"){
            
          if(
$maleMap instanceof LinkedHashMap){
            
$male = new DropdownList("male");
            
$male->add(new Option("None Selected""none"FALSE));
            
$male->fill($maleMap);
        }
        else 
$male = new Comment(" None of your male adoptables can breed at the time."FALSE);
        
$breedingForm->add($male);
            
        }
        
            
$breedingForm->add(new Comment("<br></br>"));
        
$breedingForm->add(new PasswordField("hidden""breed""yes"));
        
$breedingForm->add(new Button("Breed""submit""submit"));
        
$document->add($breedingForm);    
    } 
(levelupview)

PHP Code:
public function breed(){
        
$mysidia Registry::get("mysidia");
        
$this->setField("adopt"$this->adopt);
        
$gender_lookup $mysidia->db->select("owned_adoptables", array("gender"), "aid = '{$this->adopt->getAdoptID()}'")->fetchColumn();
        if (
$gender_lookup == "m") { $gender "Male";} else { $gender "Female";}
        
$settings = new BreedingSetting($mysidia->db);
        
$userStatus $mysidia->user->getstatus();
        if(
$settings->system != "enabled") throw new InvalidActionException("system");
        if(
$userStatus->canbreed == "no") throw new NoPermissionException("permission");
        
        
//If the requested pet is male!
        
if($gender "Male"){
        if(
$mysidia->input->post("submit")){
            if(
$mysidia->input->post("female") == "none"){
                  throw new 
InvalidIDException("none_select");
            }
            
            try{
                
$female = new OwnedAdoptable($mysidia->input->post("female"), $mysidia->user->username);
                
$male = new OwnedAdoptable($this->adopt->getAdoptID());
                
$breeding = new Breeding($female$male$settings); 
                
$validator $breeding->getValidator("fcase");
                
$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;
        }
    }
        
        
//If the requested pet is female!
        
if($gender "Female"){
        if(
$mysidia->input->post("submit")){
            if(
$mysidia->input->post("female") == "none"){
                  throw new 
InvalidIDException("none_select");
            }
            
            try{
                
$male = new OwnedAdoptable($mysidia->input->post("male"), $mysidia->user->username);
                
$female = new OwnedAdoptable($this->adopt->getAdoptID());
                
$breeding = new Breeding($female$male$settings); 
                
$validator $breeding->getValidator("mcase");
                
$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;
        }
        
//Stop here!!
            
        
}

        
$this->setField("cost", new Integer($breedcost));
        
$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);
    } 
(levelup)
__________________
Reply With Quote