/** * 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>!"; }