name = Util::localizedString($this->template, 'name');
// item is scaling; overwrite other values
if ($this->template['ScalingStatDistribution'] > 0 && $this->template['ScalingStatValue'] > 0)
{
$this->ssd = DB::Aowow()->selectRow("SELECT * FROM ?_scalingstatdistribution WHERE id = ?", $this->template['ScalingStatDistribution']);
// stats and ratings
for ($i = 1; $i <= 10; $i++)
{
if ($this->ssd['statMod'.$i] <= 0)
{
$this->template['stat_type'.$i] = 0;
$this->template['stat_value'.$i] = 0;
}
else
{
$this->template['stat_type'.$i] = $this->ssd['statMod'.$i];
$this->template['stat_value'.$i] = intVal(($this->getSSDMod('stats') * $this->ssd['modifier'.$i]) / 10000);
}
}
// armor: only replace if set
if ($ssvArmor = $this->getSSDMod('armor'))
$this->template['armor'] = $ssvArmor;
// If set dpsMod in ScalingStatValue use it for min (70% from average), max (130% from average) damage
if ($extraDPS = $this->getSSDMod('dps'))
{
$average = $extraDPS * $this->template['delay'] / 1000;
$this->template['dmg_min1'] = number_format(0.7 * $average); // dmg_2 not used for heirlooms
$this->template['dmg_max1'] = number_format(1.3 * $average);
}
// Apply Spell Power from ScalingStatValue if set
if ($spellBonus = $this->getSSDMod('spell'))
{
$this->template['stat_type10'] = ITEM_MOD_SPELL_POWER;
$this->template['stat_value10'] = $spellBonus;
}
}
// create json values; zero-values are filtered later
$this->json['id'] = $this->Id;
$this->json['name'] = (ITEM_QUALITY_HEIRLOOM - $this->template['Quality']).$this->name;
$this->json['icon'] = $this->template['icon'];
$this->json['classs'] = $this->template['class'];
$this->json['subclass'] = $this->template['subclass'];
$this->json['slot'] = $this->template['InventoryType'];
$this->json['slotbak'] = $this->template['InventoryType'];
$this->json['level'] = $this->template['ItemLevel'];
$this->json['reqlevel'] = $this->template['RequiredLevel'];
$this->json['displayid'] = $this->template['displayid'];
$this->json['commondrop'] = ($this->template['RandomProperty'] > 0 || $this->template['RandomSuffix'] > 0) ? 'true' : null; // string required :(
$this->json['holres'] = $this->template['holy_res'];
$this->json['firres'] = $this->template['fire_res'];
$this->json['natres'] = $this->template['nature_res'];
$this->json['frores'] = $this->template['frost_res'];
$this->json['shares'] = $this->template['shadow_res'];
$this->json['arcres'] = $this->template['arcane_res'];
$this->json['armorbonus'] = $this->template['ArmorDamageModifier'];
$this->json['armor'] = $this->template['armor'];
$this->json['itemset'] = $this->template['itemset'];
$this->json['socket1'] = $this->template['socketColor_1'];
$this->json['socket2'] = $this->template['socketColor_2'];
$this->json['socket3'] = $this->template['socketColor_3'];
$this->json['nsockets'] = ($this->json['socket1'] > 0 ? 1 : 0) + ($this->json['socket2'] > 0 ? 1 : 0) + ($this->json['socket3'] > 0 ? 1 : 0);
$this->json['socketbonus'] = $this->template['socketBonus'];
$this->json['scadist'] = $this->template['ScalingStatDistribution'];
$this->json['scaflags'] = $this->template['ScalingStatValue'];
if ($this->template['class'] == ITEM_CLASS_WEAPON || $this->template['class'] == ITEM_CLASS_AMMUNITION)
{
$this->json['dmgtype1'] = $this->template['dmg_type1'];
$this->json['dmgmin1'] = $this->template['dmg_min1'] + $this->template['dmg_min2'];
$this->json['dmgmax1'] = $this->template['dmg_max1'] + $this->template['dmg_max2'];
$this->json['dps'] = !$this->template['delay'] ? 0 : number_format(($this->json['dmgmin1'] + $this->json['dmgmax1']) / (2 * $this->template['delay'] / 1000), 1);
$this->json['speed'] = number_format($this->template['delay'] / 1000, 2);
if (in_array($this->json['subclass'], [2, 3, 18, 19]))
{
$this->json['rgddmgmin'] = $this->json['dmgmin1'];
$this->json['rgddmgmax'] = $this->json['dmgmax1'];
$this->json['rgdspeed'] = $this->json['speed'];
$this->json['rgddps'] = $this->json['dps'];
}
else if ($this->template['class'] != ITEM_CLASS_AMMUNITION)
{
$this->json['mledmgmin'] = $this->json['dmgmin1'];
$this->json['mledmgmax'] = $this->json['dmgmax1'];
$this->json['mlespeed'] = $this->json['speed'];
$this->json['mledps'] = $this->json['dps'];
}
if ($this->json['classs'] == ITEM_CLASS_WEAPON && in_array($this->json['subclass'], [5, 6, 10]) && $this->json['dps'] > 54.8)
$this->json['feratkpwr'] = max(0, round((($this->json['dmgmin1'] + $this->json['dmgmax1']) / (2 * $this->template['delay'] / 1000) - 54.8) * 14, 0));
}
}
// use if you JUST need the name
public static function getName($id)
{
$n = DB::Aowow()->selectRow('
SELECT
t.name,
l.*
FROM
item_template t,
locales_item l
WHERE
t.entry = ?d AND
t.entry = l.entry',
$id
);
return Util::localizedString($n, 'name');
}
public static function getEquivalentSetPieces($id)
{
return DB::Aowow()->selectCol('
SELECT
a.entry
FROM
item_template a,
item_template b
WHERE
b.entry = ?d AND
a.InventoryType = b.InventoryType AND
a.itemset = b.itemset',
$id
);
}
// end static use
public function getListviewData()
{
return array(
'id' => $this->Id,
'name' => $this->name,
);
}
public function addGlobalsToJScript(&$gItems)
{
$gItems[$this->Id] = array(
'name' => $this->name,
'quality' => $this->template['Quality'],
'icon' => $this->template['icon'],
);
}
/*
enhance (set by comparison tool or formatet external links)
ench: enchantmentId
sock: bool (extraScoket (gloves, belt))
gems: array (:-separated itemIds)
rand: >0: randomPropId; <0: randomSuffixId
interactive (set to place javascript/anchors to manipulate level and ratings or link to filters (static tooltips vs popup tooltip))
*/
public function createTooltip($enhance = [], $interactive = false)
{
if (!empty($this->tooltip))
return $this->tooltip;
if (isset($enhance['rand']))
{
$rndEnch = DB::Aowow()->selectRow('SELECT * FROM ?_itemrandomenchant WHERE Id = ?d', $enhance['rand']);
$this->name .= ' '.Util::localizedString($rndEnch, 'name');
$randEnchant['stats'] = '';
for ($i = 1; $i < 6; $i++)
{
if ($rndEnch['enchantId'.$i] <= 0)
continue;
$enchant = DB::Aowow()->selectRow('SELECT * FROM ?_itemenchantment WHERE Id = ?d', $rndEnch['enchantId'.$i]);
if ($rndEnch['allocationPct'.$i] > 0)
{
$amount = intVal($rndEnch['allocationPct'.$i] * $this->generateEnchSuffixFactor() / 10000);
$randEnchant['stats'] .= ''.str_replace('$i', $amount, Util::localizedString($enchant, 'text')).'
';
}
else
$randEnchant['stats'] .= ''.Util::localizedString($enchant, 'text').'
';
}
}
// IMPORTAT: DO NOT REMOVE THE HTML-COMMENTS! THEY ARE REQUIRED TO UPDATE THE TOOLTIP CLIENTSIDE
$x = '';
// upper table: stats
$x .= '
| ';
// name; quality
$x .= ''.$this->name.'';
// heroic tag
if (($this->template['Flags'] & ITEM_FLAG_HEROIC) && $this->template['Quality'] == ITEM_QUALITY_EPIC)
$x .= ' '.Lang::$item['heroic'].''; // requires map (todo: reparse ?_zones for non-conflicting data; generate Link to zone) if ($this->template['Map']) { $map = DB::Aowow()->selectRow('SELECT * FROM ?_zones WHERE mapid=?d LIMIT 1', $this->template['Map']); $x .= ' '.Util::localizedString($map, 'name'); } // requires area if ($this->template['area']) { $area = DB::Aowow()->selectRow('SELECT * FROM ?_areatable WHERE Id=?d LIMIT 1', $this->template['area']); $x .= ' '.Util::localizedString($area, 'name'); } // conjured if ($this->template['Flags'] & ITEM_FLAG_CONJURED) $x .= ' '.Lang::$game['conjured']; // bonding if (($this->template['Flags'] & ITEM_FLAG_ACCOUNTBOUND) && $this->template['Quality'] == ITEM_QUALITY_HEIRLOOM) $x .= ' '.Lang::$item['bonding'][0]; else if ($this->template['bonding']) $x .= ' '.Lang::$item['bonding'][$this->template['bonding']]; // unique || unique-equipped || unique-limited if ($this->template['maxcount'] == 1) $x .= ' '.Lang::$item['unique']; else if ($this->template['Flags'] & ITEM_FLAG_UNIQUEEQUIPPED) $x .= ' '.Lang::$item['uniqueEquipped']; else if ($this->template['ItemLimitCategory']) { $limit = DB::Aowow()->selectRow("SELECT * FROM ?_itemlimitcategory WHERE id = ?", $this->template['ItemLimitCategory']); $x .= ' '.($limit['isGem'] ? Lang::$item['uniqueEquipped'] : Lang::$item['unique']).': '.Util::localizedString($limit, 'name').' ('.$limit['count'].')'; } // max duration if ($this->template['duration'] > 0) $x .= " ".Lang::$item['duration'] . ' '. Util::formatTime($this->template['duration'] * 1000) . ($this->template['duration'] < 0 ? ' ('.Lang::$game['realTime'].')' : null); // required holiday if ($this->template['HolidayId']) { $hDay = DB::Aowow()->selectRow("SELECT * FROM ?_holidays WHERE id = ?", $this->template['HolidayId']); $x .= ' '.Lang::$game['requires'].' '.Util::localizedString($hDay, 'name').''; } // maxcount if ($this->template['maxcount'] > 1) $x .= ' ('.$this->template['maxcount'].')'; // item begins a quest if ($this->template['startquest']) $x .= ' '.Lang::$item['startQuest'].''; // containerType (slotCount) if ($this->template['ContainerSlots'] > 1) { // word order differs <_< if (in_array(User::$localeId, [LOCALE_FR, LOCALE_ES, LOCALE_RU])) $x .= ' '.sprintf(Lang::$item['bagSlotString'], Lang::$item['bagFamily'][$this->template['BagFamily']], $this->template['ContainerSlots']); else $x .= ' '.sprintf(Lang::$item['bagSlotString'], $this->template['ContainerSlots'], Lang::$item['bagFamily'][$this->template['BagFamily']]); } if (in_array($this->template['class'], [ITEM_CLASS_ARMOR, ITEM_CLASS_WEAPON, ITEM_CLASS_AMMUNITION])) { $x .= '
'; // Weapon Stats if (isset($this->json['speed'])) { // regular weapon if ($this->template['class'] != ITEM_CLASS_AMMUNITION) { $x .= '
'; $x .= '('.$this->json['dps'].' '.Lang::$item['dps'].') '; // display FeralAttackPower if set if (isset($this->json['feratkpwr'])) $x .= '('.$this->json['feratkpwr'].' '.Lang::$item['fap'].') '; } // ammunition else $x .= Lang::$item['addsDps'].' '.number_format(($this->json['dmgmin1'] + $this->json['dmgmax1']) / 2, 1).' '.Lang::$item['dps2'].' '; } // Armor if ($this->template['class'] == ITEM_CLASS_ARMOR && $this->template['ArmorDamageModifier'] > 0) $x .= ''.($this->template['armor'] + $this->template['ArmorDamageModifier']).' '.Lang::$item['armor'].' '; else if ($this->template['armor']) $x .= ''.$this->template['armor'].' '.Lang::$item['armor'].' '; // Block if ($this->template['block']) $x .= ''.$this->template['block'].' '.Lang::$item['block'].' '; // Random Enchantment if (($this->template['RandomProperty'] || $this->template['RandomSuffix']) && !isset($enhance['rand'])) $x .= ''.Lang::$item['randEnchant'].' '; // Item is a gem (don't mix with sockets) if ($this->template['GemProperties']) { $gemText = DB::Aowow()->selectRow('SELECT e.* FROM ?_itemenchantment e, ?_gemproperties p WHERE (p.Id = ?d and e.Id = p.itemenchantmentID)', $this->template['GemProperties']); $x .= Util::localizedString($gemText, 'text').' '; } // if random enchantment is set, prepend stats from it if (isset($enhance['rand'])) $x .= $randEnchant['stats']; // itemMods (display stats and save ratings for later use) for ($j = 1; $j <= 10; $j++) { $type = $this->template['stat_type'.$j]; $qty = $this->template['stat_value'.$j]; if (!$qty || $type <= 0) continue; // base stat if ($type >= ITEM_MOD_AGILITY && $type <= ITEM_MOD_STAMINA) $x .= '+'.$qty.' '.Lang::$item['statType'][$type].' '; else // rating with % for reqLevel $green[] = $this->parseRating($type, $qty, $this->template['RequiredLevel'], $interactive); } // magic resistances foreach (Util::$resistanceFields as $j => $rowName) if ($rowName && $this->template[$rowName] != 0) $x .= '+'.$this->template[$rowName].' '.Lang::$game['resistances'][$j].' '; // Enchantment if (isset($enhance['ench'])) { $enchText = DB::Aowow()->selectRow('SELECT * FROM ?_itemenchantment WHERE Id = ?', $enhance['ench']); $x .= ''.Util::localizedString($enchText, 'text').' '; } else // enchantment placeholder $x .= ''; // Sockets w/ Gems if (isset($enhance['gems'])) { $gems = DB::Aowow()->select(' SELECT it.entry AS ARRAY_KEY, ia.icon, ae.*, colorMask FROM item_template it JOIN ?_item_template_addon ia ON ia.id = it.entry JOIN ?_gemproperties ag ON ag.Id = it.GemProperties JOIN ?_itemenchantment ae ON ae.Id = ag.itemEnchantmentID WHERE it.entry IN (?a)', $enhance['gems'] ); } else $enhance['gems'] = []; // zero fill empty sockets $sockCount = $this->json['nsockets'] + (isset($enhance['sock']) ? 1 : 0); while ($sockCount > count($enhance['gems'])) $enhance['gems'][] = 0; $enhance['gems'] = array_reverse($enhance['gems']); $hasMatch = 1; // fill native sockets for ($j = 1; $j <= 3; $j++) { if (!$this->template['socketColor_'.$j]) continue; for ($i = 0; $i < 4; $i++) if (($this->template['socketColor_'.$j] & (1 << $i))) $colorId = $i; $pop = array_pop($enhance['gems']); $col = $pop ? 1 : 0; $hasMatch &= $pop ? (($gems[$pop]['colorMask'] & (1 << $colorId)) ? 1 : 0) : 0; $icon = $pop ? sprintf(Util::$bgImagePath['tiny'], strtolower($gems[$pop]['icon'])) : null; $text = $pop ? Util::localizedString($gems[$pop], 'text') : Lang::$item['socket'][$colorId]; if ($interactive) $x .= ''.$text.' '; else $x .= ''.$text.' '; } // fill extra socket if (isset($enhance['sock'])) { $pop = array_pop($enhance['gems']); $col = $pop ? 1 : 0; $icon = $pop ? sprintf(Util::$bgImagePath['tiny'], strtolower($gems[$pop]['icon'])) : null; $text = $pop ? Util::localizedString($gems[$pop], 'text') : Lang::$item['socket'][-1]; if ($interactive) $x .= ''.$text.' '; else $x .= ''.$text.' '; } else // prismatic socket placeholder $x .= ''; if ($this->template['socketBonus']) { $sbonus = DB::Aowow()->selectRow('SELECT * FROM ?_itemenchantment WHERE Id = ?d', $this->template['socketBonus']); $x .= ''.Lang::$item['socketBonus'].': '.Util::localizedString($sbonus, 'text').' '; } // durability if ($this->template['MaxDurability']) $x .= Lang::$item['durability'].' '.$this->template['MaxDurability'].' / '.$this->template['MaxDurability'].' '; // required classes if ($classes = Lang::getClassString($this->template['AllowableClass'])) $x .= Lang::$game['classes'].': '.$classes.' '; // required races if ($races = Lang::getRaceString($this->template['AllowableRace'])) $x .= Lang::$game['races'].': '.$races['name'].' '; // required honorRank (not used anymore) if ($this->template['requiredhonorrank']) $x .= Lang::$game['requires'].': '.Lang::$game['pvpRank'][$this->template['requiredhonorrank']].' '; // required CityRank..? // what the f.. // required level if (($this->template['Flags'] & ITEM_FLAG_ACCOUNTBOUND) && $this->template['Quality'] == ITEM_QUALITY_HEIRLOOM) $x .= sprintf(Lang::$game['reqLevelHlm'], ' 1'.Lang::$game['valueDelim'].MAX_LEVEL.' ('.($interactive ? printf(Util::$changeLevelString, MAX_LEVEL) : ''.MAX_LEVEL).')').' '; else if ($this->template['RequiredLevel'] > 1) $x .= sprintf(Lang::$game['reqLevel'], $this->template['RequiredLevel']).' '; // item level $x .= Lang::$item['itemLevel'].' '.$this->template['ItemLevel']; // required skill if ($this->template['RequiredSkill']) { $skillText = DB::Aowow()->selectRow('SELECT * FROM ?_skill WHERE skillID = ?d', $this->template['RequiredSkill']); $x .= ' '.Lang::$game['requires'].' '.Util::localizedString($skillText, 'name').''; if ($this->template['RequiredSkillRank']) $x .= ' ('.$this->template['RequiredSkillRank'].')'; } // required spell if ($this->template['requiredspell']) $x .= ' '.Lang::$game['requires'].' '.Spell::getName($this->template['requiredspell']).''; // required reputation w/ faction if ($this->template['RequiredReputationFaction']) $x .= ' '.Lang::$game['requires'].' template['RequiredReputationFaction'].'">'.Faction::getName($this->template['RequiredReputationFaction']).' - '.Lang::$game['rep'][$this->template['RequiredReputationRank']]; // locked if ($this->template['lockid']) { $lock = DB::Aowow()->selectRow(' SELECT * FROM ?_lock WHERE lockID = ?d', $this->template['lockid'] ); // only use first useful entry for ($j = 1; $j <= 5; $j++) { if ($lock['type'.$j] == 1) // opened by item { $l = Lang::$game['requires'].' '.Item::getName($lock['lockproperties'.$j]).''; break; } else if ($lock['type'.$j] == 2) // opened by skill { $lockText = DB::Aowow()->selectRow('SELECT ?# FROM ?_locktype WHERE id = ?d', $lock['lockproperties'.$j]); $l = Lang::$game['requires'].' '.Util::localizedString($lockText, 'name').' ('.$lock['requiredskill'.$j].')'; break; } } $x .= ' '.Lang::$item['locked'].' '.$l.''; } // upper table: done $x .= ' |
| ';
if (isset($green))
foreach ($green as $j => $bonus)
if ($bonus)
$x .= ''.$bonus.' '; // recipe handling (some stray Techniques have subclass == 0) if ($this->template['class'] == ITEM_CLASS_RECIPE && ($this->template['subclass'] == 1 || $this->template['BagFamily'] = 16)) { // todo: aaaand another one for optimization $craftSpell = new Spell($this->template['spellid_2']); $craftItem = new Item($craftSpell->template["effect1CreateItemId"]); $reagentItems = []; for ($i = 1; $i <= 8; $i++) if ($craftSpell->template["reagent".$i]) $reagentItems[$craftSpell->template["reagent".$i]] = $craftSpell->template["reagentCount".$i]; $reagents = new ItemList(array(['i.entry', array_keys($reagentItems)])); $reqReag = []; foreach ($reagents->container as $r) $reqReag[] = ''.$r->name.' ('.$reagentItems[$r->Id].')'; $x .= ''.Lang::$item['trigger'][0].' '.Util::localizedString($this->template, 'description').''; if (isset($craftItem->Id)) $x .= ' '.$craftItem->createTooltip(null, $interactive).' '; } // Item Set $tmpX = ''; $pieces = []; $itemset = DB::Aowow()->selectRow(' SELECT * FROM ?_itemset WHERE (item1=?d or item2=?d or item3=?d or item4=?d or item5=?d or item6=?d or item7=?d or item8=?d or item9=?d or item10=?d)', $this->Id, $this->Id, $this->Id, $this->Id, $this->Id, $this->Id, $this->Id, $this->Id, $this->Id, $this->Id ); if ($itemset) { $num = 0; // piece counter for ($i = 1; $i <= 10; $i++) { if ($itemset['item'.$i] <= 0) continue; $num++; $equivalents = Item::getEquivalentSetPieces($itemset['item'.$i]); $pieces[] = ''.Item::getName($itemset['item'.$i]).''; } $tmpX .= implode(' ', $pieces); $x .= ' '.Util::localizedString($itemset, 'name').' (0/'.$num.')'; if ($itemset['skillID']) // bonus requires skill to activate { $name = DB::Aowow()->selectRow('SELECT * FROM ?_skill WHERE skillID=?d', $itemset['skillID']); $x .= ' '.Lang::$game['requires'].' '.Util::localizedString($name, 'name').''; if ($itemset['skillLevel']) $x .= ' ('.$itemset['skillLevel'].')'; $x .= ' '; } // list pieces $x .= ' '.$tmpX.' '; // get bonuses $num = 0; for ($j = 1; $j <= 8; $j++) { if ($itemset['spell'.$j] <= 0) continue; // todo: get from static prop? $bonus = new Spell($itemset['spell'.$j]); $itemset['spells'][$num]['tooltip'] = $bonus->parseText('description', $this->template['RequiredLevel']); $itemset['spells'][$num]['entry'] = $itemset['spell'.$j]; $itemset['spells'][$num]['bonus'] = $itemset['bonus'.$j]; $num++; } // sort and list bonuses $x .= ''; for ($i = 0; $i < $num; $i++) { for ($j = $i; $j <= $num - 1; $j++) { if($itemset['spells'][$j]['bonus'] >= $itemset['spells'][$i]['bonus']) continue; $tmp = $itemset['spells'][$i]; $itemset['spells'][$i] = $itemset['spells'][$j]; $itemset['spells'][$j] = $tmp; } $x .= '('.$itemset['spells'][$i]['bonus'].') '.Lang::$item['set'].': '.$itemset['spells'][$i]['tooltip'].''; if ($i < $num - 1) $x .= ' '; } $x .= ''; } // funny, yellow text at the bottom if ($this->template['description']) $x .= '"'.Util::localizedString($this->template, 'description').'"'; // readable if ($this->template['PageText']) $x .= ' '.Lang::$item['readClick'].''; // charges (i guess checking first spell is enough (single charges not shown)) if ($this->template['spellcharges_1'] > 1) $x .= ' '.$this->template['spellcharges_1'].' '.Lang::$item['charges'].''; // list required reagents if (!empty($reqReag)) $x .= ''.Lang::$game['requires']." ".implode(", ", $reqReag).''; $x .= ' |