/** * Change a pet's color to the paintbrush's color (if available). * * Changes the pet's pet_specie_color_id and destroys the item. * * If a pet doesn't have the specific color built out in * pet_specie_pet_specie_color, a failure message will be shown and the * item will not be destroyed. * * @param Pet $pet * @return string The success (or failure) message. **/ public function paint(Pet $pet) { $color = new PetSpecie_PetSpecieColor($this->db); $color = $color->findOneBy(array('pet_specie_id' => $pet->getPetSpecieId(), 'pet_specie_color_id' => $this->getPetSpecieColorId())); // It's possible that that particular color is not built out for // that species (ie, nobody f*****g drew it). Handle that. if ($color == null) { return "You put the brush down, realizing that this color is not available for your pet."; } elseif ($pet->getPetSpecieColorId() == $color->getPetSpecieColorId()) { return "You frown and notice that {$pet->getPetName()} is already painted in {$color->getColorName()}."; } $pet->setPetSpecieColorId($color->getPetSpecieColorId()); $pet->save(); $this->updateQuantity($this->getQuantity() - 1); return "{$pet->getPetName()} looks snazzy in <strong>{$color->getColorName()}</strong>!"; }
} else { $color = new PetSpecie_PetSpecieColor($db); $color = $color->findOneBy(array(array('table' => 'pet_specie_color', 'column' => 'color_img', 'value' => $color_id), array('table' => 'pet_specie', 'column' => 'pet_specie_id', 'value' => $specie->getPetSpecieId()), array('table' => 'pet_specie_color', 'column' => 'base_color', 'value' => 'Y'))); if ($color == null) { $ERRORS[] = 'Invalid color specified.'; } } // end pet exists if (sizeof($ERRORS) > 0) { draw_errors($ERRORS); } else { // Add pet. $pet = new Pet($db); $pet->setUserId($User->getUserId()); $pet->setPetSpecieId($specie->getPetSpecieId()); $pet->setPetSpecieColorId($color->getPetSpecieColorId()); $pet->setPetName($pet_name); $pet->setHunger($specie->getMaxHunger()); $pet->setHappiness($specie->getMaxHappiness()); $pet->setCreatedAt($pet->sysdate()); $pet->save(); // If the user has no other pets, make this the active one. if (sizeof($User->grabPets()) == 0) { $pet->makeActive(); } // Session mog $_SESSION['hilight_pet_id'] = $pet->getUserPetId(); // Redirect redirect('pets'); } // end no errors; DO IT