My work around for this was way too hacky in bypassing the 'error' of 'already leveled creature today'. I'm curious as to HoF's answer.
Perhaps you can glean something out of what I've got (though I toned down the message variable to cut out most of my profile stuff that'd be too custom, left in the usual data) -
Note that this is JUST the click function in levelup.php, not the whole file. Don't use it as is, try to understand it. @w@ Good luck!
PHP:
public function click(){
$mysidia = Registry::get("mysidia");
$date = new DateTime;
$ip = secure($_SERVER['REMOTE_ADDR']);
/*... First check if the system to levelup pets is enabled ...*/
if($this->settings->system != "enabled") { throw new NoPermissionException("disabled"); }
/*... Then check if the user has already visited the pet today ...*/
elseif($this->adopt->hasVoter($mysidia->user, $date)){
if($this->adopt->hasNextLevel()){
$nextLevel = $this->adopt->getNextLevel();
$requiredClicks = $nextLevel->getRequiredClicks();
}
$gender_lookup = $mysidia->db->select("owned_adoptables", array("gender"), "aid = '{$this->adopt->getAdoptID()}'")->fetchColumn();
if ($gender_lookup == "m") { $gender = "Male"; $pronoun = "him"; } else { $gender = "Female"; $pronoun = "her"; }
if ($mysidia->user->username == $this->adopt->getOwner()){ $manage_btn = "<a class='btn btn-sm btn-info' href='../../yournovu/manage/{$this->adopt->getAdoptID()}'><i class='fa fa-gear'></i> Manage Your Novu</a>"; } else { $manage_btn = ""; }
if($this->adopt->hasNextLevel()){
$level = $this->adopt->getNextLevel();
$levelupClicks = $this->adopt->getLevelupClicks();
$toNext = "(LVL ".$level->getLevel()." in ".$levelupClicks." more EXP)";
}
else { $toNext = "(MAX)"; }
if($this->adopt->getTradeStatus() == "fortrade") { $tradestatus = "<b>For Trade</b>"; }
else { $tradestatus = "<b>Not For Trade</b>"; }
$message = "<div class='adopt_profile'> <h2>{$this->adopt->getName()}</h2> ";
// If you've already seen the pet today:
if ($this->adopt->hasVoter($mysidia->user, $date)){
$message .= "<div style='float: right; margin-right: 15%; margin-top: -15px;'><b>Thanks!</b> You played with this Novu today!</div>";
}
// If you haven't seen the pet today:
if (!$this->adopt->hasVoter($mysidia->user, $date)){
$message .= "<div style='display: inline;'><span class='button'><i class='fa fa-paw'></i> Play</span></div>";
}
$message .= "{$manage_btn}
<ul>
<li>Travels With: <a href='/profile/view/{$this->adopt->getOwner()}'>{$this->adopt->getOwner()}</a></li>
<li>Birthday: {$this->adopt->birthday}</li>
<li>Species: {$this->adopt->getType()}</li>
<li>Gender: {$gender}</li>
<li>LVL: {$this->adopt->getCurrentLevel()} {$toNext}</li>
<li>Total EXP: {$this->adopt->getTotalClicks()}</li>
<li>Trade Status: {$tradestatus}</li>
</ul>
";
throw new LevelupException($message);
}
/*... But do this if the pet is frozen! ...*/
elseif($this->adopt->isFrozen() == "yes") { throw new LevelupException("frozen"); }
/*... This one, if enabled, would prevent users from visiting a pet too much a day ...*/
# elseif($mysidia->user->getVotes() > $this->settings->number) { throw new LevelupException("number"); }
/*... If this setting were on in the backend, it would prevent the users from visiting their own pets ...*/
# elseif($this->settings->owner == "disabled" and $this->adopt->getOwner() == $mysidia->user->username){ throw new LevelupException("owner");}
/*... If the visitor has not seen the pet today, this will be displayed and the pet will level up! ...*/
else{
$newClicks = $this->adopt->getTotalClicks() + 1;
$this->adopt->setTotalClicks($newClicks, "update");
$mysidia->db->insert("vote_voters", array("void" => NULL, "date" => $date->format('Y-m-d'), "username" => $mysidia->user->username, "ip" => $ip, "adoptableid" => $mysidia->input->get("aid")));
$ago = date('Y-m-d', strtotime('-40 days'));
$mysidia->db->delete("vote_voters", "date < '{$ago}'");
if($this->adopt->hasNextLevel()){
$nextLevel = $this->adopt->getNextLevel();
$requiredClicks = $nextLevel->getRequiredClicks();
if($requiredClicks and $newClicks >= $requiredClicks) { $this->adopt->setCurrentLevel($nextLevel->getLevel(), "update"); }
}
$reward = $mysidia->user->clickreward($this->settings->reward);
$mysidia->user->changecash($reward);
$this->setField("adopt", $this->adopt);
$this->setField("reward", new Integer($reward));
}
}
There are numerous reasons you can't use this as-is, mostly because some of it's been modified in ways unique to my site. I've change a few core page urls, so this part, for example -
if ($mysidia->user->username == $this->adopt->getOwner()){ $manage_btn = "<a class='btn btn-sm btn-info' href='../../yournovu/manage/{$this->adopt->getAdoptID()}'><i class='fa fa-gear'></i> Manage Your Novu</a>"; } else { $manage_btn = ""; }
- has things linking to a
yournovu/manage/ page, because my adoptables are called Novu, rather than whatever the original url for that link should be. I forgot. @w@ Stuff like that is different. I also don't know if the system originally kept track of pet birthdays, so that may break, etc.
And, all in all, I DON'T recommend what I've done to get the profile page to work. (I also added in some Javascript elsewhere that deletes the error title itself but that's not included.)
And why don't I like my solution? Because it's still using what was there -
throw new LevelupException($message);
- and I just changed the $message. It's still an Exception being thrown and I'd love to rewrite the entire thing and avoid using exceptions but I don't know how. It's expecting an error to be thrown if things are just so, and I'm just making it look like there wasn't an error.
.
.
.
Basically, HoF, I think what we want (for future releases) are profile pages for our pets that are the same no matter what - whether you've visited the pet or not, whether it's yours or not, and whether it's frozen or not. Rather than change the entire page, just add in a small memo to the pet's profile that says "Thanks for visiting this pet", a link back to the management page if it's your pet, and/or a notification that the pet didn't gain experience because the owner has it frozen.