c2ephp

agents/PRAY/AGNTBlock.php

Go to the documentation of this file.
00001 <?php
00002 require_once(dirname(__FILE__).'/../../sprites/C16File.php');
00003 require_once(dirname(__FILE__).'/../../sprites/S16File.php');
00004 require_once(dirname(__FILE__).'/TagBlock.php');
00005 
00007 class AGNTBlock extends TagBlock {
00008   
00010 
00021     public function AGNTBlock($prayfile,$name,$content,$flags) {
00022         parent::TagBlock($prayfile,$name,$content,$flags,PRAY_BLOCK_AGNT);
00023     }
00024 
00026 
00031     public function GetAgentName() {
00032         return $this->GetName();
00033     }
00035 
00039     public function GetAgentDescription($localisation='') {
00040         if($localisation == '') {
00041             return $this->GetTag('Agent Description');
00042         } else {
00043             $description = $this->GetTag('Agent Description-'.$localisation);
00044             if($description == '') {
00045                 $description = $this->GetTag('Agent Description'); 
00046             }
00047             return $description;
00048         }
00049     }
00051 
00054     public function GetAgentType() {
00055         return $this->GetTag('Agent Type');
00056     }
00058     public function GetScriptCount() {
00059         return $this->GetTag('Script Count');
00060     }
00062 
00066     public function GetScript($script=1) {
00067         if($script > 0 && $script <= $this->GetScriptCount()) {
00068             return $this->GetTag('Script '.$script);            
00069         }
00070         throw new Exception('Script doesn\'t exist!');
00071         
00072     }
00074     public function GetDependencyCount() {
00075         return $this->GetTag('Dependency Count');
00076     }
00078 
00082     public function GetDependency($dependency) {
00083         $file = $this->GetTag('Dependency '.$dependency);
00084         $category = $this->GetTag('Dependency Category '.$dependency);
00085         return new PrayDependency($category,$file);
00086     }
00088 
00090     public function GetDependencies() {
00091         $dependencies = array();
00092         for($i = 1; $i <= $this->GetDependencyCount(); $i++) {
00093             $dependencies[] = $this->GetDependency($i);
00094         }
00095         return $dependencies;
00096     }
00098 
00102     public function GetRemoveScript() {
00103         return $this->GetTag('Remove Script');
00104     }
00106 
00109     public function GetAgentAnimationFile() {
00110         return $this->GetTag('Agent Animation File');
00111     }
00114 
00119     public function GetAgentAnimationGallery() {
00120         return $this->GetTag('Agent Animation Gallery');
00121     }
00124 
00132     public function GetAgentAnimationFirstImage() {
00133         return $this->GetTag('Animation Sprite First Image');
00134     }
00136 
00139     public function GetAgentAnimationString() {
00140         return $this->GetTag('Agent Animation String');
00141     }
00143 
00154     public function GetAgentAnimationAsSpriteFrame() {
00155         $animationFile = $this->GetAgentAnimationFile();
00156         if($animationFile == '') {
00157             $animationFile = $this->GetAgentAnimationGallery();
00158             if($animationFile == '') {
00159                 throw new Exception('No animation file!');
00160             }
00161             $animationFile .= '.c16';
00162         }
00163         $animationFirstImage = $this->GetAgentAnimationFirstImage();
00164         $animationString = $this->GetAgentAnimationString();
00165         if($animationFirstImage == '') {
00166             $animationFirstImage = 0;
00167         }
00168         if($animationString == '') {
00169             $animationString = 0;
00170         }
00171         if(($position = strpos($animationString,' ')) !== false) {
00172             $animationString = substr($animationString,0,$position);
00173         }
00174         $prayfile = $this->GetPrayFile();
00175         if($prayfile == null) {
00176             throw new Exception('No PRAY file to get the icon from!');
00177         }
00178         $iconBlock = $prayfile->GetBlockByName($animationFile);
00179         if($iconBlock->GetType() != 'FILE') {
00180             throw new Exception('The block with the animation\'s filename is not a file block!');
00181         }
00182         $type = strtolower(substr($animationFile,-3));
00183         $icon = null;
00184         if($type == 'c16') {
00185             $icon = new C16File(new StringReader($iconBlock->GetData()));
00186         } else if($type == 's16') {
00187             $icon = new S16File(new StringReader($iconBlock->GetData()));
00188         }
00189         if($icon == null) {
00190             throw new Exception('For one reason or another, couldn\'t make a sprite file for the agent.');
00191         }
00192         return $icon->GetFrame($animationFirstImage+$animationString);
00193     }
00194 }
00195 ?>
 All Classes Files Functions Variables Enumerations