khanat-opennel-code/code/web/app/app_achievements/_AchWebParser/class/Atom_class.php
SirCotare 9283736c91 #1470 This is a huge update. It contains all changes we made to the system on the
official ryzom servers. I removed non open source content though. So this version
is running on live servers and works!

--HG--
branch : gsoc2012-achievements
2012-12-10 15:07:13 +01:00

113 lines
No EOL
3.2 KiB
PHP

<?php
/*
* Class for Atoms.
* It's used to run the code from the ruleset and register listening to data.
* Also we have the functions to manipulate progress here.
*/
class Atom {
private $ruleset;
private $id;
private $objective;
private $user;
function Atom(&$data,$user) {
$this->ruleset = $data['atom_ruleset_parsed'];
$this->id = $data['atom_id'];
$this->objective = $data['atom_objective'];
$this->user = $user;
}
function register() { // register the atom's ruleset code
try {
return eval($this->ruleset);
}
catch(Exception $e) {
echo $e->getMessage();
}
return null;
}
function registerValue($name,$func) { // register to listen for a value
global $_DISPATCHER;
$tmp = new Callback($this,$func);
$_DISPATCHER->registerValue($name,$tmp);
}
function unregisterValue($name,$callback) { // unregister listening
global $_DISPATCHER;
$_DISPATCHER->unregisterValue($name,$callback);
}
function registerEntity($name,$func) { // register to listen for an entity
global $_DISPATCHER;
$tmp = new Callback($this,$func);
$_DISPATCHER->registerEntity($name,$tmp);
}
function unregisterEntity($name,$callback) { // unregister
global $_DISPATCHER;
$_DISPATCHER->unregisterEntity($name,$callback);
}
function grant($count = 1) { // grant an atom
global $DBc;
$DBc->sendSQL("INSERT INTO ach_player_atom (apa_atom,apa_player,apa_date,apa_expire,apa_state,apa_value) VALUES ('".$this->id."','".$this->user['cid']."','".time()."',null,'GRANT','".$count."')","NONE");
}
function deny() { // deny an atom
global $DBc;
$DBc->sendSQL("INSERT INTO ach_player_atom (apa_atom,apa_player,apa_date,apa_expire,apa_state) VALUES ('".$this->id."','".$this->user['cid']."','".time()."',null,'DENY','1')","NONE");
}
function reset_() { // reset progress for this atom
global $DBc;
$DBc->sendSQL("DELETE FROM ach_player_atom WHERE apa_atom='".$this->id."' AND apa_player='".$this->user['cid']."'","NONE");
}
function reset_all() { // reset progress for all atoms of the same objective
global $DBc;
$res = $DBc->sendSQL("SELECT atom_id FROM ach_atom WHERE atom_objective='".$this->objective."'","ARRAY");
$sz = sizeof($res);
for($i=0;$i<$sz;$i++) {
$DBc->sendSQL("DELETE FROM ach_player_atom WHERE apa_atom='".$res[$i]['atom_id']."' AND apa_player='".$this->user['cid']."'","NONE");
}
}
function unlock() { // unlock atom
global $DBc;
$DBc->sendSQL("DELETE FROM ach_player_atom WHERE apa_atom='".$this->id."' AND apa_player='".$this->user['cid']."' AND apa_state='DENY'","NONE");
}
function unlock_all() { // unlock all atoms of the same objective
global $DBc;
$res = $DBc->sendSQL("SELECT atom_id FROM ach_atom WHERE atom_objective='".$this->objective."'","ARRAY");
$sz = sizeof($res);
for($i=0;$i<$sz;$i++) {
$DBc->sendSQL("DELETE FROM ach_player_atom WHERE apa_atom='".$res[$i]['atom_id']."' AND apa_player='".$this->user['cid']."' AND apa_state='DENY'","NONE");
}
}
function getID() {
return $this->id;
}
function getObjective() {
return $this->objective;
}
}
?>