Advertisement
Gabriel_Violet_Dream

Spell.php

Mar 13th, 2012
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.08 KB | None | 0 0
  1. class Spell extends CActiveRecord
  2. {
  3.  
  4.     public $info = false;
  5.  
  6.     public static function model($className = __CLASS__)
  7.     {
  8.         return parent::model($className);
  9.     }
  10.  
  11.     public function tableName()
  12.     {
  13.         return 'wow_spells';
  14.     }
  15.  
  16.     public function formatInfo()
  17.     {
  18.         $regExp = "/\\$+(?:([\/,*])?([0-9]*);)?([d+\;(\d*)?([1-9]*)([A-z])([1-3]*)(([A-z, ]*)\:([A-z, ]*)\;)?/";
  19.  
  20.         $info = $this->tooltip_loc0;
  21.         $attributes = $this->attributes;
  22.        
  23.         //TODO: rewrite after support $this in PHP 5.4.0
  24.  
  25.         $this->info = preg_replace_callback($regExp, function ($match) use ($attributes)
  26.             {
  27.                 $select   = '';
  28.                 $match[5] = ($match[5]) ? $match[5] : '1';
  29.                 $match[4] = strtolower($match[4]);
  30.  
  31.                 switch($match[4])
  32.                 {
  33.                     case 'z':
  34.                         return "[Home]";
  35.                     case 'l':
  36.                         return $match[8];
  37.                     case 'g':
  38.                         return $match[7];
  39.                     case 'h':
  40.                         $select = 'procChance';
  41.                         break;
  42.                     case 'u':
  43.                         return '';
  44.                     case 'v':
  45.                         $select = 'affected_target_level';
  46.                         break;
  47.                     case 'q':
  48.                         $select = 'effect' . $match[5] . 'MiscValue';
  49.                         break;
  50.                     case 'i':
  51.                         $select = 'spellTargets';
  52.                         break;
  53.                     case 'b':
  54.                         $select = 'effect' . $match[5] . 'PointsPerComboPoint';
  55.                         break;
  56.                     case 'm': case 's':
  57.                         $select = 'effect' . $match[5] . 'BasePoints';
  58.                         break;
  59.                     case 'a':
  60.                         $select = 'effect' . $match[5] . 'radius';
  61.                         break;
  62.                     case 'd':
  63.                         $select = 'durationID';
  64.                         break;
  65.                     case 'o':
  66.                         $select = 'durationID, effect' . $match[5] . 'Amplitude, effect' . $match[5] . 'BasePoints';
  67.                         break;
  68.                     case 't':
  69.                         $select = 'effect' . $match[5] . 'Amplitude';
  70.                         break;
  71.                     case 'n':
  72.                         $select = 'procCharges';
  73.                         break;
  74.                     case 'x':
  75.                         $select = 'effect' . $match[5] . 'ChainTarget';
  76.                         break;
  77.                     default:
  78.                         break;
  79.                 }
  80.  
  81.                 if($match[3])
  82.                 {
  83.                     $command = Yii::app()->db->createCommand()
  84.                         ->select($select)
  85.                         ->from('wow_spells')
  86.                         ->where('spellID = :spellID');
  87.                     if($match[4] == 'o')
  88.                         $value   = $command->queryRow(false, array(':spellID' => $match[3]));
  89.                     else
  90.                         $value     = $command->queryScalar(array(':spellID' => $match[3]));
  91.                 }
  92.                 elseif($match[4] == 'o')
  93.                     $value     = array($attributes['durationID'], $attributes['effect' . $match[5] . 'Amplitude'], $attributes['effect' . $match[5] . 'BasePoints']);
  94.                 else
  95.                     $value = $attributes[$select];
  96.  
  97.                 if(is_array($value))
  98.                     $value = Spell::GetRealDuration($value[0], $value[1], $match[5]) * ($value[2] + 1);
  99.  
  100.                 if($match[4] == 's' or $match[4] == 'm')
  101.                     $value += 1;
  102.                 elseif($match[4] == 'i' and !$value)
  103.                     $value = 'nearby';
  104.                 elseif($match[4] == 'a')
  105.                     $value = Spell::GetRadius($value, $match[5]);
  106.                 elseif($match[4] == 'd')
  107.                     $value = Spell::GetDuration($value). ' sec';
  108.                 elseif($match[4] == 't')
  109.                     $value /= 1000;
  110.  
  111.                 if($match[2])
  112.                     if($match[1] == "/")
  113.                         $value = abs(($value + 1) / $match[2]);
  114.                     else if($match[1] == "*")
  115.                         $value = abs(($value + 1) * $match[2]);
  116.  
  117.                 return $value;
  118.             }, $info);
  119.     }
  120.  
  121.     public static function GetDuration($durationId)
  122.     {
  123.         return Yii::app()->db->createCommand("SELECT durationBase FROM wow_spellduration WHERE durationID = $durationId")->queryScalar() / 1000;
  124.     }
  125.  
  126.     public static function GetRealDuration($durationId, $amplitude, $effIdx)
  127.     {
  128.         return self::GetDuration($durationId) / ($amplitude ? ($amplitude / 1000) : 5);
  129.     }
  130.  
  131.     public static function GetRadius($radiusId, $effIdx)
  132.     {
  133.         return Yii::app()->db->createCommand("SELECT radiusBase FROM wow_spellradius WHERE radiusID = $radiusId")->queryScalar();
  134.     }
  135. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement