mirror of
https://github.com/Sarjuuk/aowow.git
synced 2025-11-29 15:58:16 +08:00
Setup/Scripts
* restructure setup to allow for self contained setup steps to self register (just the sql for now) * should ease adding new scripts in future
This commit is contained in:
@@ -7,16 +7,6 @@ if (!CLI)
|
||||
die('not in cli mode');
|
||||
|
||||
|
||||
/* deps:
|
||||
* ?_items finalized
|
||||
* ?_spell finalized
|
||||
* dbc_spellitemenchantment
|
||||
*/
|
||||
|
||||
$customData = array(
|
||||
);
|
||||
$reqDBC = ['spellitemenchantment'];
|
||||
|
||||
class ItemStatSetup extends ItemList
|
||||
{
|
||||
private $statCols = [];
|
||||
@@ -138,140 +128,148 @@ class ItemStatSetup extends ItemList
|
||||
}
|
||||
}
|
||||
|
||||
function item_stats(array $ids = [])
|
||||
SqlGen::register(new class extends SetupScript
|
||||
{
|
||||
$offset = 0;
|
||||
protected $command = 'item_stats'; // and enchantment stats
|
||||
|
||||
CLI::write(' - applying stats for enchantments');
|
||||
$enchStats = enchantment_stats();
|
||||
CLI::write(' '.count($enchStats).' enchantments parsed');
|
||||
CLI::write(' - applying stats for items');
|
||||
protected $tblDependancyAowow = ['items', 'spell'];
|
||||
protected $dbcSourceFiles = ['spellitemenchantment'];
|
||||
|
||||
while (true)
|
||||
private function enchantment_stats() : array
|
||||
{
|
||||
$items = new ItemStatSetup($offset, SqlGen::$stepSize, $ids, $enchStats);
|
||||
if ($items->error)
|
||||
break;
|
||||
$statCols = DB::Aowow()->selectCol('SELECT `COLUMN_NAME` FROM `INFORMATION_SCHEMA`.`COLUMNS` WHERE `TABLE_NAME` LIKE "%item_stats"');
|
||||
$enchants = DB::Aowow()->select('SELECT *, id AS ARRAY_KEY FROM dbc_spellitemenchantment');
|
||||
$spells = [];
|
||||
$spellStats = [];
|
||||
|
||||
$max = max($items->getFoundIDs());
|
||||
$num = count($items->getFoundIDs());
|
||||
|
||||
CLI::write(' * sets '.($offset + 1).' - '.($max));
|
||||
|
||||
$offset = $max;
|
||||
|
||||
$items->writeStatsTable();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function enchantment_stats()
|
||||
{
|
||||
$statCols = DB::Aowow()->selectCol('SELECT `COLUMN_NAME` FROM `INFORMATION_SCHEMA`.`COLUMNS` WHERE `TABLE_NAME` LIKE "%item_stats"');
|
||||
$enchants = DB::Aowow()->select('SELECT *, id AS ARRAY_KEY FROM dbc_spellitemenchantment');
|
||||
$spells = [];
|
||||
$spellStats = [];
|
||||
|
||||
foreach ($enchants as $eId => $e)
|
||||
{
|
||||
for ($i = 1; $i <=3; $i++)
|
||||
foreach ($enchants as $eId => $e)
|
||||
{
|
||||
// trigger: onEquip + valid SpellId
|
||||
if ($e['object'.$i] > 0 && $e['type'.$i] == 3)
|
||||
$spells[] = $e['object'.$i];
|
||||
}
|
||||
}
|
||||
|
||||
if ($spells)
|
||||
$spellStats = (new SpellList(array(['id', $spells], CFG_SQL_LIMIT_NONE)))->getStatGain();
|
||||
|
||||
$result = [];
|
||||
foreach ($enchants as $eId => $e)
|
||||
{
|
||||
// parse stats
|
||||
$result[$eId] = [];
|
||||
for ($h = 1; $h <= 3; $h++)
|
||||
{
|
||||
$obj = (int)$e['object'.$h];
|
||||
$val = (int)$e['amount'.$h];
|
||||
|
||||
switch ($e['type'.$h])
|
||||
for ($i = 1; $i <=3; $i++)
|
||||
{
|
||||
case 6: // TYPE_TOTEM +AmountX as DPS (Rockbiter)
|
||||
$result[$eId]['dps'] = $val; // we do not use dps as itemMod, so apply it directly
|
||||
$obj = null;
|
||||
break;
|
||||
case 2: // TYPE_DAMAGE +AmountX damage
|
||||
$obj = ITEM_MOD_WEAPON_DMG;
|
||||
break;
|
||||
// case 1: // TYPE_COMBAT_SPELL proc spell from ObjectX (amountX == procChance)
|
||||
// case 7: // TYPE_USE_SPELL Engineering gadgets
|
||||
case 3: // TYPE_EQUIP_SPELL Spells from ObjectX (use of amountX?)
|
||||
if (!empty($spellStats[$obj]))
|
||||
foreach ($spellStats[$obj] as $mod => $val)
|
||||
if ($str = Game::$itemMods[$mod])
|
||||
Util::arraySumByKey($result[$eId], [$str => $val]);
|
||||
// trigger: onEquip + valid SpellId
|
||||
if ($e['object'.$i] > 0 && $e['type'.$i] == 3)
|
||||
$spells[] = $e['object'.$i];
|
||||
}
|
||||
}
|
||||
|
||||
$obj = null;
|
||||
break;
|
||||
case 4: // TYPE_RESISTANCE +AmountX resistance for ObjectX School
|
||||
switch ($obj)
|
||||
{
|
||||
case 0: // Physical
|
||||
$obj = ITEM_MOD_ARMOR;
|
||||
break;
|
||||
case 1: // Holy
|
||||
$obj = ITEM_MOD_HOLY_RESISTANCE;
|
||||
break;
|
||||
case 2: // Fire
|
||||
$obj = ITEM_MOD_FIRE_RESISTANCE;
|
||||
break;
|
||||
case 3: // Nature
|
||||
$obj = ITEM_MOD_NATURE_RESISTANCE;
|
||||
break;
|
||||
case 4: // Frost
|
||||
$obj = ITEM_MOD_FROST_RESISTANCE;
|
||||
break;
|
||||
case 5: // Shadow
|
||||
$obj = ITEM_MOD_SHADOW_RESISTANCE;
|
||||
break;
|
||||
case 6: // Arcane
|
||||
$obj = ITEM_MOD_ARCANE_RESISTANCE;
|
||||
break;
|
||||
default:
|
||||
$obj = null;
|
||||
}
|
||||
break;
|
||||
case 5: // TYPE_STAT +AmountX for Statistic by type of ObjectX
|
||||
if ($obj < 2) // [mana, health] are on [0, 1] respectively and are expected on [1, 2] ..
|
||||
$obj++; // 0 is weaponDmg .. ehh .. i messed up somewhere
|
||||
if ($spells)
|
||||
$spellStats = (new SpellList(array(['id', $spells], CFG_SQL_LIMIT_NONE)))->getStatGain();
|
||||
|
||||
break; // stats are directly assigned below
|
||||
case 8: // TYPE_PRISMATIC_SOCKET Extra Sockets AmountX as socketCount (ignore)
|
||||
$result[$eId]['nsockets'] = $val; // there is no itemmod for sockets, so apply it directly
|
||||
default: // TYPE_NONE dnd stuff; skip assignment below
|
||||
$obj = null;
|
||||
$result = [];
|
||||
foreach ($enchants as $eId => $e)
|
||||
{
|
||||
// parse stats
|
||||
$result[$eId] = [];
|
||||
for ($h = 1; $h <= 3; $h++)
|
||||
{
|
||||
$obj = (int)$e['object'.$h];
|
||||
$val = (int)$e['amount'.$h];
|
||||
|
||||
switch ($e['type'.$h])
|
||||
{
|
||||
case 6: // TYPE_TOTEM +AmountX as DPS (Rockbiter)
|
||||
$result[$eId]['dps'] = $val; // we do not use dps as itemMod, so apply it directly
|
||||
$obj = null;
|
||||
break;
|
||||
case 2: // TYPE_DAMAGE +AmountX damage
|
||||
$obj = ITEM_MOD_WEAPON_DMG;
|
||||
break;
|
||||
// case 1: // TYPE_COMBAT_SPELL proc spell from ObjectX (amountX == procChance)
|
||||
// case 7: // TYPE_USE_SPELL Engineering gadgets
|
||||
case 3: // TYPE_EQUIP_SPELL Spells from ObjectX (use of amountX?)
|
||||
if (!empty($spellStats[$obj]))
|
||||
foreach ($spellStats[$obj] as $mod => $val)
|
||||
if ($str = Game::$itemMods[$mod])
|
||||
Util::arraySumByKey($result[$eId], [$str => $val]);
|
||||
|
||||
$obj = null;
|
||||
break;
|
||||
case 4: // TYPE_RESISTANCE +AmountX resistance for ObjectX School
|
||||
switch ($obj)
|
||||
{
|
||||
case 0: // Physical
|
||||
$obj = ITEM_MOD_ARMOR;
|
||||
break;
|
||||
case 1: // Holy
|
||||
$obj = ITEM_MOD_HOLY_RESISTANCE;
|
||||
break;
|
||||
case 2: // Fire
|
||||
$obj = ITEM_MOD_FIRE_RESISTANCE;
|
||||
break;
|
||||
case 3: // Nature
|
||||
$obj = ITEM_MOD_NATURE_RESISTANCE;
|
||||
break;
|
||||
case 4: // Frost
|
||||
$obj = ITEM_MOD_FROST_RESISTANCE;
|
||||
break;
|
||||
case 5: // Shadow
|
||||
$obj = ITEM_MOD_SHADOW_RESISTANCE;
|
||||
break;
|
||||
case 6: // Arcane
|
||||
$obj = ITEM_MOD_ARCANE_RESISTANCE;
|
||||
break;
|
||||
default:
|
||||
$obj = null;
|
||||
}
|
||||
break;
|
||||
case 5: // TYPE_STAT +AmountX for Statistic by type of ObjectX
|
||||
if ($obj < 2) // [mana, health] are on [0, 1] respectively and are expected on [1, 2] ..
|
||||
$obj++; // 0 is weaponDmg .. ehh .. i messed up somewhere
|
||||
|
||||
break; // stats are directly assigned below
|
||||
case 8: // TYPE_PRISMATIC_SOCKET Extra Sockets AmountX as socketCount (ignore)
|
||||
$result[$eId]['nsockets'] = $val; // there is no itemmod for sockets, so apply it directly
|
||||
default: // TYPE_NONE dnd stuff; skip assignment below
|
||||
$obj = null;
|
||||
}
|
||||
|
||||
if ($obj !== null)
|
||||
if ($str = Game::$itemMods[$obj]) // check if we use these mods
|
||||
Util::arraySumByKey($result[$eId], [$str => $val]);
|
||||
}
|
||||
|
||||
if ($obj !== null)
|
||||
if ($str = Game::$itemMods[$obj]) // check if we use these mods
|
||||
Util::arraySumByKey($result[$eId], [$str => $val]);
|
||||
$updateCols = ['type' => TYPE_ENCHANTMENT, 'typeId' => $eId];
|
||||
foreach ($result[$eId] as $k => $v)
|
||||
{
|
||||
if (!in_array($k, $statCols) || !$v || $k == 'id')
|
||||
continue;
|
||||
|
||||
$updateCols[$k] = number_format($v, 2, '.', '');
|
||||
}
|
||||
|
||||
DB::Aowow()->query('REPLACE INTO ?_item_stats (?#) VALUES (?a)', array_keys($updateCols), array_values($updateCols));
|
||||
}
|
||||
|
||||
$updateCols = ['type' => TYPE_ENCHANTMENT, 'typeId' => $eId];
|
||||
foreach ($result[$eId] as $k => $v)
|
||||
{
|
||||
if (!in_array($k, $statCols) || !$v || $k == 'id')
|
||||
continue;
|
||||
|
||||
$updateCols[$k] = number_format($v, 2, '.', '');
|
||||
}
|
||||
|
||||
DB::Aowow()->query('REPLACE INTO ?_item_stats (?#) VALUES (?a)', array_keys($updateCols), array_values($updateCols));
|
||||
return $result;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
public function generate(array $ids = []) : bool
|
||||
{
|
||||
$offset = 0;
|
||||
|
||||
CLI::write(' - applying stats for enchantments');
|
||||
$enchStats = enchantment_stats();
|
||||
CLI::write(' '.count($enchStats).' enchantments parsed');
|
||||
CLI::write(' - applying stats for items');
|
||||
|
||||
while (true)
|
||||
{
|
||||
$items = new ItemStatSetup($offset, SqlGen::$sqlBatchSize, $ids, $enchStats);
|
||||
if ($items->error)
|
||||
break;
|
||||
|
||||
$max = max($items->getFoundIDs());
|
||||
$num = count($items->getFoundIDs());
|
||||
|
||||
CLI::write(' * sets '.($offset + 1).' - '.($max));
|
||||
|
||||
$offset = $max;
|
||||
|
||||
$items->writeStatsTable();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user