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

Language PHP Lines 238
MD5 Hash d25be648deef42e649910b26e54d88a2 Estimated Cost $4,672 (why?)
Repository https://bitbucket.org/SirCotare/ryzom View Raw File View Project SPDX
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
<?php
	class AchTask extends Parentum {
		#########################
		# PHP 5.3 compatible
		# InDev_trait replaces this in PHP 5.4
		protected $dev;

		function inDev() {
			return ($this->dev == 1);
		}

		function getDev() {
			return $this->dev;
		}

		function setInDev($tf) {
			if($tf == true) {
				$this->setDev(1);
			}
			else {
				$this->setDev(0);
			}

			$this->update();
		}

		function setDev($d) {
			$this->dev = $d;
		}
		#########################

		protected $achievement;
		protected $value;
		protected $name;
		protected $done;
		protected $template;
		protected $parent_id;
		protected $inherit_obj;
		private $heritage_list;
		protected $tie_race;
		protected $tie_cult;
		protected $tie_civ;

		function AchTask($data,$parent) {
			global $DBc,$_USER,$_CONF;

			parent::__construct();

			#$this->heritage_list = array();
			
			$this->setParent($parent);
			$this->setID($data['at_id']);
			$this->achievement = $data['at_achievement'];
			$this->value = $data['at_value'];
			$this->name = $data['atl_name'];
			$this->done = $data['apt_date'];
			$this->dev = $data['at_dev'];
			$this->template = $data['atl_template'];
			$this->parent_id = $data['at_parent'];
			$this->inherit_obj = $data['at_inherit'];

			if($this->inherit_obj == 1) {
				$this->heritage_list = new AVLTree();
			}
			else {
				$this->heritage_list = null;
			}

			if($this->name == null) {
				$res = $DBc->sqlQuery("SELECT * FROM ach_task_lang WHERE atl_lang='".$_CONF['default_lang']."' AND atl_task='".$this->id."'");
				$this->name = $res[0]['atl_name'];
				$this->template = $res[0]['atl_template'];
			}

			$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");

			$sz = sizeof($res);
			for($i=0;$i<$sz;$i++) {
				$this->addChild($this->makeChild($res[$i]));
			}

			//load ties
			$res = $DBc->sqlQuery("SELECT attr_race FROM ach_task_tie_race WHERE attr_task='".$this->id."'");
			$sz = sizeof($res);

			$this->tie_race = array();
			for($i=0;$i<$sz;$i++) {
				$this->tie_race[] = $res[$i]['attr_race'];
			}

			$res = $DBc->sqlQuery("SELECT attcult_cult FROM ach_task_tie_cult WHERE attcult_task='".$this->id."'");
			$sz = sizeof($res);

			$this->tie_cult = array();
			for($i=0;$i<$sz;$i++) {
				$this->tie_cult[] = $res[$i]['attcult_cult'];
			}

			$res = $DBc->sqlQuery("SELECT attciv_civ FROM ach_task_tie_civ WHERE attciv_task='".$this->id."'");
			$sz = sizeof($res);

			$this->tie_civ = array();
			for($i=0;$i<$sz;$i++) {
				$this->tie_civ[] = $res[$i]['attciv_civ'];
			}
		}

		function loadHeritage() {
			if($this->inherit_obj == 0) {
				return false;
			}
			$child = $this->parent->getChildDataByID($this->parent_id);
			if($child == null) {
				return false;
			}
			$iter = $child->getIterator();
			while($iter->hasNext()) {
				$curr = $iter->getNext();
				$this->addChild($curr);
				$this->heritage_list->insert($curr);
			}
		}
		
		#@override Parentum::makeChild()
		protected function makeChild($a) {
			return new AchObjective($a,$this);
		}

		function getHeritage() {
			return $this->inherit_obj;
		}

		function isInherited($id) {
			if($this->getHeritage() == 0) {
				return false;
			}
			if($this->heritage_list == null) {
				return false;
			}
			return ($this->heritage_list->find($id) != null);
		}

		function hasTieRace() {
			return (sizeof($this->tie_race) != 0);
		}

		function hasTieCult() {
			return (sizeof($this->tie_cult) != 0);
		}

		function hasTieCiv() {
			return (sizeof($this->tie_civ) != 0);
		}

		function isTiedRace($r) {
			if(sizeof($this->tie_race) == 0) {
				return true;
			}
			return in_array($r,$this->race);
		}

		function isTiedCult($c) {
			if(sizeof($this->tie_cult) == 0) {
				return true;
			}
			return in_array($c,$this->tie_cult);
		}

		function isTiedCiv($c) {
			if(sizeof($this->tie_civ) == 0) {
				return true;
			}
			return in_array($c,$this->tie_civ);
		}

		function getAchievement() {
			return $this->achievement;
		}

		function getValue() {
			return $this->value;
		}

		function getDisplayName() {
			if(substr($this->name,0,1) == "!") {
				return substr($this->name,1);
			}
			return $this->parent->fillTemplate(explode(";",$this->name));
		}

		function getName() {
			return $this->name;
		}

		function objDrawable() {
			$iter = $this->getIterator();
			while($iter->hasNext()) {
				$curr = $iter->getNext();
				if($curr->getDisplay() != "hidden") {
					return true;
				}
			}

			return false;
		}

		function isDone() {
			return ($this->done > 0);
		}

		function getDone() {
			return $this->done;
		}

		function fillTemplate($insert = array()) {
			if($this->template == null) {
				return implode(";",$insert);
			}
			else {
				$tmp = $this->template;
				$match = array();
				preg_match_all('#\[([0-9]+)\]#', $this->template, $match);
				foreach($match[0] as $key=>$elem) {
					$tmp = str_replace("[".$match[1][$key]."]",$insert[$key],$tmp);
				}
				return $tmp;
			}
		}
		
		function getTemplate() {
			return $this->template;
		}

		function getParentID() {
			return $this->parent_id;
		}
	}
?>
Back to Top