commit 3122900e5a3057046fb5566becfad1dc038fd095 Author: karu Date: Wed Nov 3 19:38:44 2010 +0200 Added: Occupations example diff --git a/example_profile.php b/example_profile.php index cbada89..86575dc 100644 --- a/example_profile.php +++ b/example_profile.php @@ -114,6 +114,116 @@ function render_guild($xml){ return $content; } +function render_occupation_progress($bag){ + $content = '

Basic Occupation

'; + // rpjob_200 .. rpjob_207 + $rpjob_sheets = array( + 8870958 => 200, + 8863022 => 201, + 8878894 => 202, + 8850478 => 203, + 8854830 => 204, + 8844590 => 205, + 8882734 => 206, + 8855854 => 207, + ); + $rpjob_words = array( + 200 => 'Apprentice Butcher', + 201 => 'Apprentice Florist', + 202 => 'Apprentice Water-Carrier', + 203 => 'Apprentice Magnetic Cartographer', + 204 => 'Apprentice Toolmaker', + 205 => 'Apprentice Medic', + 206 => 'Apprentice Larvester', + 207 => 'Apprentice Scrollmaker', + ); + + $progress = array(); + $active = array(); + foreach($bag->item as $item){ + $val = (string)$item; + if(substr($val, 0, 1) == '#'){ + $sheetid=intval(substr($val,1)); + if($sheetid == 8847918){ // 'Basic Occupation' + $active[] = intval($item['q']); + }else if(isset($rpjob_sheets[$sheetid])){ + $job = $rpjob_sheets[$sheetid]; + $q = intval($item['q']); + $progress[$job] = array( + 'grade' => floor($q/10), + 'xp' => isset($item['s']) ? intval($item['s']) : 1, + ); + } + } + } + + if(empty($progress)){ + $content.='

occupations not found

'; + }else{ + $content.='

currently active

'; + $content.=''; + foreach($active as $rpjob){ + if(!isset($progress[$rpjob])){ + $content.=rpjob_render_row($rpjob, $rpjob_words[$rpjob], 'progress info not available'); + }else{ + $grade = $progress[$rpjob]['grade']; + $xp = $progress[$rpjob]['xp']; + + $content.=rpjob_render_row($rpjob, $rpjob_words[$rpjob], $grade, $xp); + // remove active job from list + unset($progress[$rpjob]); + } + } + $content.='
'; + if(!empty($progress)){ + // done in the past + $content.='

Inactive

'; + $content.=''; + foreach(array_keys($progress) as $rpjob){ + if(!isset($progress[$rpjob])){ + $content.=rpjob_render_row($rpjob, $rpjob_words[$rpjob], 'progress info not available'); + }else{ + $grade = $progress[$rpjob]['grade']; + $xp = $progress[$rpjob]['xp']; + + $content.=rpjob_render_row($rpjob, $rpjob_words[$rpjob], $grade, $xp); + } + } + $content.='
'; + } + } + + return $content; +} + +function rpjob_render_row($rpjob, $name, $grade=false, $xp=false, $xpMax=false){ + $row = ''; + $row.= ''.ryzom_item_icon_image('rpjob_'.$rpjob.'.sitem').''; + $row.= ''; + $row.= ''.$name; + if($xp === false){ + $row.='
error:'.$grade.'
'; + }else{ + $row.= ' - Grade: '.$grade; + if($grade < 6){ + $xpMax = 30+($grade-1)*60; + $p=($xp/$xpMax*100); + $row.= ($xp==1 && $grade==6) ? '' : '
XP: '.$xp.' / '.$xpMax.''; + $row.=''; + $row.=''; + $row.='
 
'; + }else{ + $row.='
 '; + $row.=''; + $row.=''; + $row.='
maximum grade reached
'; + } + } + $row.= ''; + $row.= ''; + return $row; +} + /** * memberGrade will convert memebr grade string value to int for sorting * @@ -171,6 +281,11 @@ function render_character($xml, $key) { $inv_xml = ryzom_character_simplexml($key, 'items'); + // occupation progress + if(isset($inv_xml->inventories->bag)) { + $content .= render_occupation_progress($inv_xml->inventories->bag); + } + if(isset($inv_xml->inventories->bag)) { $content .= '

Bag

'; $content .= '

(leave the mouse on an item to display its custom text, if any)

';