PageRenderTime 50ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/code/web/app/app_achievements/class/AchTask_class.php

https://bitbucket.org/mattraykowski/ryzomcore_demoshard
PHP | 286 lines | 214 code | 48 blank | 24 comment | 44 complexity | 525ca8e1706e9ac08e225df0509280e2 MD5 | raw file
Possible License(s): AGPL-3.0, GPL-3.0, LGPL-2.1
  1. <?php
  2. class AchTask extends Parentum implements Tieable {
  3. #########################
  4. # PHP 5.3 compatible
  5. # InDev_trait replaces this in PHP 5.4
  6. protected $dev;
  7. function inDev() {
  8. return ($this->dev == 1);
  9. }
  10. function getDev() {
  11. return $this->dev;
  12. }
  13. function setInDev($tf) {
  14. if($tf == true) {
  15. $this->setDev(1);
  16. }
  17. else {
  18. $this->setDev(0);
  19. }
  20. $this->update();
  21. }
  22. function setDev($d) {
  23. $this->dev = $d;
  24. }
  25. #########################
  26. protected $achievement;
  27. protected $value;
  28. protected $name;
  29. protected $done;
  30. protected $template;
  31. protected $parent_id;
  32. protected $inherit_obj;
  33. private $heritage_list;
  34. protected $tie_race;
  35. #protected $tie_cult;
  36. #protected $tie_civ;
  37. protected $tie_align;
  38. function AchTask($data,$parent) {
  39. global $DBc,$_USER,$_CONF;
  40. parent::__construct();
  41. #$this->heritage_list = array();
  42. $this->setParent($parent);
  43. $this->setID($data['at_id']);
  44. $this->achievement = $data['at_achievement'];
  45. $this->value = $data['at_value'];
  46. $this->name = $data['atl_name'];
  47. $this->done = $data['apt_date'];
  48. $this->dev = $data['at_dev'];
  49. $this->template = $data['atl_template'];
  50. $this->parent_id = $data['at_parent'];
  51. $this->inherit_obj = $data['at_inherit'];
  52. if($this->inherit_obj == 1) {
  53. $this->heritage_list = new AVLTree();
  54. }
  55. else {
  56. $this->heritage_list = null;
  57. }
  58. if($this->name == null) {
  59. $res = $DBc->sqlQuery("SELECT * FROM ach_task_lang WHERE atl_lang='".$_CONF['default_lang']."' AND atl_task='".$this->id."'");
  60. $this->name = $res[0]['atl_name'];
  61. $this->template = $res[0]['atl_template'];
  62. }
  63. $res = $DBc->sqlQuery("SELECT * FROM ach_objective LEFT JOIN (ach_objective_lang) ON (aol_lang='".$_USER->getLang()."' AND aol_objective=ao_id) LEFT JOIN (ach_player_objective) ON (apo_objective=ao_id AND apo_player='".$_USER->getID()."') LEFT JOIN (ach_achievement,ach_achievement_lang) ON (aa_id=ao_metalink AND aa_id=aal_achievement AND aal_lang='".$_USER->getLang()."') WHERE ao_task='".$this->id."' ORDER by aol_name ASC,aal_name ASC");
  64. $sz = sizeof($res);
  65. for($i=0;$i<$sz;$i++) {
  66. $this->addChild($this->makeChild($res[$i]));
  67. }
  68. //load ties
  69. $res = $DBc->sqlQuery("SELECT attr_race FROM ach_task_tie_race WHERE attr_task='".$this->id."'");
  70. $sz = sizeof($res);
  71. $this->tie_race = array();
  72. for($i=0;$i<$sz;$i++) {
  73. $this->tie_race[] = $res[$i]['attr_race'];
  74. }
  75. /*$res = $DBc->sqlQuery("SELECT attcult_cult FROM ach_task_tie_cult WHERE attcult_task='".$this->id."'");
  76. $sz = sizeof($res);
  77. $this->tie_cult = array();
  78. for($i=0;$i<$sz;$i++) {
  79. $this->tie_cult[] = $res[$i]['attcult_cult'];
  80. }
  81. $res = $DBc->sqlQuery("SELECT attciv_civ FROM ach_task_tie_civ WHERE attciv_task='".$this->id."'");
  82. $sz = sizeof($res);
  83. $this->tie_civ = array();
  84. for($i=0;$i<$sz;$i++) {
  85. $this->tie_civ[] = $res[$i]['attciv_civ'];
  86. }*/
  87. $res = $DBc->sqlQuery("SELECT atta_alignment FROM ach_task_tie_align WHERE atta_task='".$this->id."'");
  88. $sz = sizeof($res);
  89. $this->tie_align = array();
  90. for($i=0;$i<$sz;$i++) {
  91. $this->tie_align[] = $res[$i]['atta_alignment'];
  92. }
  93. }
  94. function loadHeritage() {
  95. if($this->inherit_obj == 0) {
  96. return false;
  97. }
  98. $child = $this->parent->getChildDataByID($this->parent_id);
  99. if($child == null) {
  100. return false;
  101. }
  102. $iter = $child->getIterator();
  103. while($iter->hasNext()) {
  104. $curr = $iter->getNext();
  105. $this->addChild($curr);
  106. $this->heritage_list->insert($curr);
  107. }
  108. return true;
  109. }
  110. #@override Parentum::makeChild()
  111. protected function makeChild($a) {
  112. return new AchObjective($a,$this);
  113. }
  114. function getHeritage() {
  115. return $this->inherit_obj;
  116. }
  117. function isInherited($id) {
  118. if($this->getHeritage() == 0) {
  119. return false;
  120. }
  121. if($this->heritage_list == null) {
  122. return false;
  123. }
  124. return ($this->heritage_list->find($id) != null);
  125. }
  126. function hasTieRace() {
  127. if($this->dev == 1) {
  128. return false;
  129. }
  130. return (sizeof($this->tie_race) != 0);
  131. }
  132. function hasTieAlign() {
  133. if($this->dev == 1) {
  134. return false;
  135. }
  136. return (sizeof($this->tie_align) != 0);
  137. }
  138. function hasTieRace_open() {
  139. return $this->hasTieRace();
  140. }
  141. function hasTieRace_done() {
  142. return $this->hasTieRace();
  143. }
  144. function hasTieAlign_open() {
  145. return $this->hasTieAlign();
  146. }
  147. function hasTieAlign_done() {
  148. return $this->hasTieAlign();
  149. }
  150. function hasTieRaceDev() {
  151. return (sizeof($this->tie_race) != 0);
  152. }
  153. function hasTieAlignDev() {
  154. return (sizeof($this->tie_align) != 0);
  155. }
  156. function isTiedRace($r) {
  157. if(sizeof($this->tie_race) == 0) {
  158. return true;
  159. }
  160. return in_array($r,$this->tie_race);
  161. }
  162. function isTiedAlign($cult,$civ) {
  163. if($cult == "%" || $civ == "%") {
  164. return true;
  165. }
  166. if(sizeof($this->tie_align) == 0) {
  167. return true;
  168. }
  169. return in_array(($cult.'|'.$civ),$this->tie_align);
  170. }
  171. function isTiedRace_open($r) {
  172. return $this->isTiedRace($r);
  173. }
  174. function isTiedRace_done($r) {
  175. return $this->isTiedRace($r);
  176. }
  177. function isTiedAlign_done($cult,$civ) {
  178. return $this->isTiedAlign($cult,$civ);
  179. }
  180. function isTiedAlign_open($cult,$civ) {
  181. return $this->isTiedAlign($cult,$civ);
  182. }
  183. function getAchievement() {
  184. return $this->achievement;
  185. }
  186. function getValue() {
  187. return $this->value;
  188. }
  189. function getDisplayName() {
  190. if(substr($this->name,0,1) == "!") {
  191. return substr($this->name,1);
  192. }
  193. return $this->parent->fillTemplate(explode(";",$this->name));
  194. }
  195. function getName() {
  196. return $this->name;
  197. }
  198. function objDrawable() {
  199. $iter = $this->getIterator();
  200. while($iter->hasNext()) {
  201. $curr = $iter->getNext();
  202. if($curr->getDisplay() != "hidden") {
  203. return true;
  204. }
  205. }
  206. return false;
  207. }
  208. function isDone() {
  209. return ($this->done > 0);
  210. }
  211. function getDone() {
  212. return $this->done;
  213. }
  214. function fillTemplate($insert = array()) {
  215. if($this->template == null) {
  216. return implode(";",$insert);
  217. }
  218. else {
  219. $tmp = $this->template;
  220. $match = array();
  221. preg_match_all('#\[([0-9]+)\]#', $this->template, $match);
  222. foreach($match[0] as $key=>$elem) {
  223. $tmp = str_replace("[".$match[1][$key]."]",$insert[$key],$tmp);
  224. }
  225. return $tmp;
  226. }
  227. }
  228. function getTemplate() {
  229. return $this->template;
  230. }
  231. function getParentID() {
  232. return $this->parent_id;
  233. }
  234. }
  235. ?>