Skip to content

Commit

Permalink
Merge pull request #236 from rathena/hotfix/mobdb-renewal-tables
Browse files Browse the repository at this point in the history
Fixes #180 renewal mob_db tables usage
  • Loading branch information
sanasol committed Apr 7, 2019
2 parents e55e4be + efcfaf2 commit aeed8e3
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 47 deletions.
54 changes: 29 additions & 25 deletions modules/item/view.php
Expand Up @@ -45,19 +45,23 @@
if ($item) {
$title = "Viewing Item ($item->name)";
$isCustom = (bool)preg_match('/item_db2$/', $item->origin_table);

if($server->isRenewal) {
$item = $this->itemFieldExplode($item, 'attack', ':', array('attack','matk'));
$item = $this->itemFieldExplode($item, 'equip_level_min', ':', array('equip_level_min','equip_level_max'));
}

$mobDB = "{$server->charMapDatabase}.monsters";
$fromTables = array("{$server->charMapDatabase}.mob_db", "{$server->charMapDatabase}.mob_db2");
if($server->isRenewal) {
$fromTables = array("{$server->charMapDatabase}.mob_db_re", "{$server->charMapDatabase}.mob_db2_re");
} else {
$fromTables = array("{$server->charMapDatabase}.mob_db", "{$server->charMapDatabase}.mob_db2");
}
$mobTable = new Flux_TemporaryTable($server->connection, $mobDB, $fromTables);

$col = 'ID AS monster_id, iName AS monster_name, LV AS monster_level, ';
$col .= 'Race AS monster_race, (Element%10) AS monster_element, (Element/20) AS monster_ele_lv, MEXP AS mvp_exp, ';

// Normal drops.
$col .= 'Drop1id AS drop1_id, Drop1per AS drop1_chance, ';
$col .= 'Drop2id AS drop2_id, Drop2per AS drop2_chance, ';
Expand All @@ -68,17 +72,17 @@
$col .= 'Drop7id AS drop7_id, Drop7per AS drop7_chance, ';
$col .= 'Drop8id AS drop8_id, Drop8per AS drop8_chance, ';
$col .= 'Drop9id AS drop9_id, Drop9per AS drop9_chance, ';

// Card drops.
$col .= 'DropCardid AS dropcard_id, DropCardper AS dropcard_chance, ';

// MVP rewards.
$col .= 'MVP1id AS mvpdrop1_id, MVP1per AS mvpdrop1_chance, ';
$col .= 'MVP2id AS mvpdrop2_id, MVP2per AS mvpdrop2_chance, ';
$col .= 'MVP3id AS mvpdrop3_id, MVP3per AS mvpdrop3_chance';

$sql = "SELECT $col FROM $mobDB WHERE ";

// Normal drops.
$sql .= 'Drop1id = ? OR ';
$sql .= 'Drop2id = ? OR ';
Expand All @@ -89,40 +93,40 @@
$sql .= 'Drop7id = ? OR ';
$sql .= 'Drop8id = ? OR ';
$sql .= 'Drop9id = ? OR ';

// Card drops.
$sql .= 'DropCardid = ? OR ';

// MVP rewards.
$sql .= 'MVP1id = ? OR ';
$sql .= 'MVP2id = ? OR ';
$sql .= 'MVP3id = ? ';

$sth = $server->connection->getStatement($sql);
$res = $sth->execute(array_fill(0, 13, $itemID));

$dropResults = $sth->fetchAll();
$itemDrops = array();
$dropNames = array(
'drop1', 'drop2', 'drop3', 'drop4', 'drop5', 'drop6', 'drop7', 'drop8', 'drop9',
'dropcard', 'mvpdrop1', 'mvpdrop2', 'mvpdrop3'
);

// Sort callback.
function __tmpSortDrops($arr1, $arr2)
{
if ($arr1['drop_chance'] == $arr2['drop_chance']) {
return strcmp($arr1['monster_name'], $arr2['monster_name']);
}

return $arr1['drop_chance'] < $arr2['drop_chance'] ? 1 : -1;
}

foreach ($dropResults as $drop) {
foreach ($dropNames as $dropName) {
$dropID = $drop->{$dropName.'_id'};
$dropChance = $drop->{$dropName.'_chance'};

if ($dropID == $itemID) {
$dropArray = array(
'monster_id' => $drop->monster_id,
Expand All @@ -134,7 +138,7 @@ function __tmpSortDrops($arr1, $arr2)
'drop_id' => $itemID,
'drop_chance' => $dropChance
);

if (preg_match('/^dropcard/', $dropName)) {
$adjust = ($drop->mvp_exp) ? $server->dropRates['CardBoss'] : $server->dropRates['Card'];
$dropArray['type'] = 'card';
Expand All @@ -148,37 +152,37 @@ function __tmpSortDrops($arr1, $arr2)
case 0: // Healing
$adjust = ($drop->mvp_exp) ? $server->dropRates['HealBoss'] : $server->dropRates['Heal'];
break;

case 2: // Useable
case 18: // Cash Useable
$adjust = ($drop->mvp_exp) ? $server->dropRates['UseableBoss'] : $server->dropRates['Useable'];
break;

case 4: // Weapon
case 5: // Armor
case 8: // Pet Armor
$adjust = ($drop->mvp_exp) ? $server->dropRates['EquipBoss'] : $server->dropRates['Equip'];
break;

default: // Common
$adjust = ($drop->mvp_exp) ? $server->dropRates['CommonBoss'] : $server->dropRates['Common'];
break;
}

$dropArray['type'] = 'normal';
}

$dropArray['drop_chance'] = $dropArray['drop_chance'] * $adjust / 10000;

if ($dropArray['drop_chance'] > 100) {
$dropArray['drop_chance'] = 100;
}

$itemDrops[] = $dropArray;
}
}
}

// Sort so that monsters are ordered by drop chance and name.
usort($itemDrops, '__tmpSortDrops');
}
Expand Down
6 changes: 5 additions & 1 deletion modules/logdata/feeding.php
Expand Up @@ -143,7 +143,11 @@

if ($mobIDs) {
$mobDB = "{$server->charMapDatabase}.monsters";
$fromTables = array("{$server->charMapDatabase}.mob_db", "{$server->charMapDatabase}.mob_db2");
if($server->isRenewal) {
$fromTables = array("{$server->charMapDatabase}.mob_db_re", "{$server->charMapDatabase}.mob_db2_re");
} else {
$fromTables = array("{$server->charMapDatabase}.mob_db", "{$server->charMapDatabase}.mob_db2");
}
$tempMobs = new Flux_TemporaryTable($server->connection, $mobDB, $fromTables);

$ids = array_keys($mobIDs);
Expand Down
24 changes: 14 additions & 10 deletions modules/logdata/pick.php
Expand Up @@ -25,17 +25,17 @@
$itemIDs = array();
$mobIDs = array();
$pickTypes = Flux::config('PickTypes');

foreach ($picks as $pick) {
$itemIDs[$pick->nameid] = null;

if ($pick->type == 'M' || $pick->type == 'L') {
$mobIDs[$pick->char_id] = null;
}
else {
$charIDs[$pick->char_id] = null;
}

if ($pick->card0) {
$itemIDs[$pick->card0] = null;
}
Expand All @@ -48,10 +48,10 @@
if ($pick->card3) {
$itemIDs[$pick->card3] = null;
}

$pick->pick_type = $pickTypes->get($pick->type);
}

if ($charIDs) {
$ids = array_keys($charIDs);
$sql = "SELECT char_id, name FROM {$server->charMapDatabase}.`char` WHERE char_id IN (".implode(',', array_fill(0, count($ids), '?')).")";
Expand All @@ -65,12 +65,16 @@
$charIDs[$id->char_id] = $id->name;
}
}

require_once 'Flux/TemporaryTable.php';

if ($mobIDs) {
$mobDB = "{$server->charMapDatabase}.monsters";
$fromTables = array("{$server->charMapDatabase}.mob_db", "{$server->charMapDatabase}.mob_db2");
if($server->isRenewal) {
$fromTables = array("{$server->charMapDatabase}.mob_db_re", "{$server->charMapDatabase}.mob_db2_re");
} else {
$fromTables = array("{$server->charMapDatabase}.mob_db", "{$server->charMapDatabase}.mob_db2");
}
$tempMobs = new Flux_TemporaryTable($server->connection, $mobDB, $fromTables);

$ids = array_keys($mobIDs);
Expand Down Expand Up @@ -108,15 +112,15 @@
$itemIDs[$id->id] = $id->name_japanese;
}
}

foreach ($picks as $pick) {
if (($pick->type == 'M' || $pick->type == 'L') && array_key_exists($pick->char_id, $mobIDs)) {
$pick->char_name = $mobIDs[$pick->char_id];
}
elseif (array_key_exists($pick->char_id, $charIDs)) {
$pick->char_name = $charIDs[$pick->char_id];
}

if (array_key_exists($pick->nameid, $itemIDs)) {
$pick->item_name = $itemIDs[$pick->nameid];
}
Expand Down
26 changes: 15 additions & 11 deletions modules/logdata/zeny.php
Expand Up @@ -22,29 +22,29 @@
$srcIDs = array();
$mobIDs = array();
$pickTypes = Flux::config('PickTypes');

foreach ($logs as $log) {
$charIDs[$log->char_id] = null;

if ($log->type == 'M') {
$mobIDs[$log->src_id] = null;
}
else {
$srcIDs[$log->src_id] = null;
}

$log->pick_type = $pickTypes->get($log->type);
}

if ($charIDs || $srcIDs) {
$charKeys = array_keys($charIDs);
$srcKeys = array_keys($srcIDs);

$sql = "SELECT char_id, name FROM {$server->charMapDatabase}.`char` ";
$sql .= "WHERE char_id IN (".implode(',', array_fill(0, count($charKeys) + count($srcKeys), '?')).")";
$sth = $server->connection->getStatement($sql);
$sth->execute(array_merge($charKeys, $srcKeys));

$ids = $sth->fetchAll();

// Map char_id to name.
Expand All @@ -57,12 +57,16 @@
}
}
}

require_once 'Flux/TemporaryTable.php';

if ($mobIDs) {
$mobDB = "{$server->charMapDatabase}.monsters";
$fromTables = array("{$server->charMapDatabase}.mob_db", "{$server->charMapDatabase}.mob_db2");
if($server->isRenewal) {
$fromTables = array("{$server->charMapDatabase}.mob_db_re", "{$server->charMapDatabase}.mob_db2_re");
} else {
$fromTables = array("{$server->charMapDatabase}.mob_db", "{$server->charMapDatabase}.mob_db2");
}
$tempMobs = new Flux_TemporaryTable($server->connection, $mobDB, $fromTables);

$ids = array_keys($mobIDs);
Expand All @@ -77,12 +81,12 @@
$mobIDs[$id->ID] = $id->iName;
}
}

foreach ($logs as $log) {
if (array_key_exists($log->char_id, $charIDs)) {
$log->char_name = $charIDs[$log->char_id];
}

if (($log->type == 'M') && array_key_exists($log->src_id, $mobIDs)) {
$log->src_name = $mobIDs[$log->char_id];
}
Expand Down

0 comments on commit aeed8e3

Please sign in to comment.