Skip to content

Commit

Permalink
Compatibilized item module.
Browse files Browse the repository at this point in the history
- Restored editing, duplication, and viewing for pre-re and re item modules.
- Added default values for nullable entries in pre-re and re item modules.
- Added setting for Max Base Level in config/servers.php.
- Max Equip Level now defaults to Max Base Level.
- Cleaned up some typos and comments.
  • Loading branch information
Mumbles authored and Mumbles committed Nov 25, 2013
1 parent a55efb0 commit f3eed0e
Show file tree
Hide file tree
Showing 16 changed files with 338 additions and 151 deletions.
1 change: 1 addition & 0 deletions config/servers.php
Expand Up @@ -58,6 +58,7 @@
'DateTimezone' => null, // Specifies game server's timezone for this char/map pair. (See: http://php.net/timezones)
//'ResetDenyMaps' => 'sec_pri', // Defaults to 'sec_pri'. This value can be an array of map names.
//'Database' => 'ragnarok', // Defaults to DbConfig.Database
'MaxBaseLevel' => 150,
'ExpRates' => array(
'Base' => 100, // Rate at which (base) exp is given
'Job' => 100, // Rate at which job exp is given
Expand Down
2 changes: 2 additions & 0 deletions lib/Flux.php
Expand Up @@ -392,6 +392,7 @@ public static function parseServersConfigFile($filename)
//
// Char/Map normalization.
//
$maxBaseLevel = 150;
$expRates = array(
'Base' => 100,
'Job' => 100,
Expand All @@ -410,6 +411,7 @@ public static function parseServersConfigFile($filename)
'CardBoss' => 100,
'MvpItem' => 100
);
$charMapServer->setMaxBaseLevel($maxBaseLevel, $options);
$charMapServer->setExpRates($expRates, $options);
$charMapServer->setDropRates($dropRates, $options);
$charMapServer->setRenewal(true, $options);
Expand Down
9 changes: 9 additions & 0 deletions lib/Flux/Athena.php
Expand Up @@ -25,6 +25,14 @@ class Flux_Athena {
*/
public $serverName;

/**
* Maximum base level for characters.
*
* @access public
* @var int
*/
public $maxBaseLevel;

/**
* Experience rates for base, job, and mvp bonus. Values in percents.
* For example, 100 means 100% which is 1x offical rates.
Expand Down Expand Up @@ -171,6 +179,7 @@ public function __construct(Flux_Config $charMapConfig, Flux_LoginServer $loginS
$this->loginDatabase = $loginServer->config->getDatabase();

$this->serverName = $charMapConfig->getServerName();
$this->maxBaseLevel = (int)$charMapConfig->getMaxBaseLevel();
$this->expRates = $charMapConfig->getExpRates()->toArray();
$this->dropRates = $charMapConfig->getDropRates()->toArray();
$this->isRenewal = (boolean)$charMapConfig->getRenewal();
Expand Down
138 changes: 109 additions & 29 deletions modules/item/add.php
Expand Up @@ -14,7 +14,7 @@
$npcBuy = $params->get('npc_buy');
$npcSell = $params->get('npc_sell');
$weight = $params->get('weight');
$attack = $params->get('attack');
$atk = $params->get('atk');
$matk = $params->get('matk');
$defense = $params->get('defense');
$range = $params->get('range');
Expand All @@ -31,11 +31,103 @@
$equipScript = $params->get('equip_script');
$unequipScript = $params->get('unequip_script');

// Weight is defaulted to an zero value.
// NPC Buy/Sell is defaulted to twice/half the sell/buy price, or a zero value if both are null.
if (is_null($npcBuy) && is_null($npcSell)) {
$npcBuy = 0;
$npcSell = 0;
}
else if (is_null($npcBuy)) {
$npcBuy = $npcSell * 2;
}
else if (is_null($npcSell)) {
$npcSell = $npcBuy / 2;
}

// Weight is defaulted to a zero value.
if (is_null($weight)) {
$weight = 0;
}

// ATK is defaulted to a zero value.
if (is_null($atk)) {
$atk = 0;
}

// MATK is defaulted to a zero value.
if (is_null($matk)) {
$matk = 0;
}

// Defence is defaulted to a zero value.
if (is_null($defense)) {
$defense = 0;
}

// Range is defaulted to a zero value.
if (is_null($range)) {
$range = 0;
}

// Slots is defaulted to a zero value.
if (is_null($slots)) {
$slots = 0;
}

// Equip Jobs is defaulted to "All Jobs".
if (is_null($equipJobs)) {
$equipJobs = 0xffffffff;
}

// Equip Upper is defaulted to "No Restrictions".
if (is_null($equipJobs)) {
$equipJobs = 0x63;
}

// Equip Location is defaulted to a zero value.
if (is_null($equipLocs)) {
$equipLocs = 0;
}

// Weapon Level is defaulted to a zero value.
if (is_null($weaponLevel)) {
$weaponLevel = 0;
}

// Equip Level Minimum is defaulted to a zero value.
if (is_null($equipLevelMin)) {
$equipLevelMin = 0;
}

// Equip Level Maximum is defaulted to server default.
if (is_null($equipLevelMax)) {
$equipLevelMax = $server->maxBaseLevel;
}

// Refineable is defaulted to true for types 4 or 5.
if (is_null($refineable) && ($type == 4 || $type == 5)) {
$refineable = 1;
}

// View ID is defaulted to a zero value.
if (is_null($viewID)) {
$viewID = 0;
}

// Script is defaulted to blank text.
if (is_null($script)) {
$script = '';
}

// Equip Script is defaulted to blank text.
if (is_null($equipScript)) {
$equipScript = '';
}

// Unequip Script is defaulted to blank text.
if (is_null($unequipScript)) {
$unequipScript = '';
}

if (count($_POST) && $params->get('additem')) {
// Equip locations.
if ($equipLocs instanceOf Flux_Config) {
Expand All @@ -52,15 +144,17 @@
$equipJobs = $equipJobs->toArray();
}

// Sanitize to NULL: viewid, slots, npcbuy, npcsell, weight, attack, defense, range, weaponlevel, equipLevelMin
// Sanitize to NULL
$nullables = array(
'viewID', 'slots', 'npcBuy', 'npcSell', 'weight', 'attack', 'defense',
'range', 'weaponLevel', 'equipLevelMin', 'script', 'equipScript', 'unequipScript'
'viewID', 'slots', 'npcBuy', 'npcSell', 'weight', 'atk', 'defense', 'range',
'weaponLevel', 'equipLevelMin', 'equipLevelMax', 'script', 'equipScript', 'unequipScript'
);

// If renewal is enabled, sanitize matk and equipLevelMax to NULL
if($server->isRenewal) {
array_push($nullables, 'matk', 'equipLevelMax');
if ($server->isRenewal) {
array_push($nullables, 'matk');
}

foreach ($nullables as $nullable) {
if (trim($$nullable) == '') {
$$nullable = null;
Expand All @@ -82,7 +176,7 @@
$errorMessage = 'View ID must be a number.';
}
elseif (!$identifier) {
$errorMessage = 'You must specify an identifer.';
$errorMessage = 'You must specify an identifier.';
}
elseif (!$itemName) {
$errorMessage = 'You must specify an item name.';
Expand All @@ -99,8 +193,8 @@
elseif (!is_null($weight) && !ctype_digit($weight)) {
$errorMessage = 'Weight must be a number.';
}
elseif (!is_null($attack) && !ctype_digit($attack)) {
$errorMessage = 'Attack must be a number.';
elseif (!is_null($atk) && !ctype_digit($atk)) {
$errorMessage = 'ATK must be a number.';
}
elseif (!is_null($matk) && !ctype_digit($matk)) {
$errorMessage = 'MATK must be a number.';
Expand Down Expand Up @@ -172,42 +266,28 @@
$errorMessage = sprintf($errorMessage, $item->name_japanese, $item->origin_table, $item->id);
}
else {
$equipLevel = $equipLevelMin;
if($server->isRenewal && !is_null($equipLevelMax)) {
$equipLevel .= ':'. $equipLevelMax;
}

$cols = array('id', 'name_english', 'name_japanese', 'type', 'weight');
$bind = array($itemID, $identifier, $itemName, $type, $weight*10);
$vals = array(
'view' => $viewID,
'slots' => $slots,
'price_buy' => $npcBuy,
'price_sell' => $npcSell,
'atk' => $atk,
'defence' => $defense,
'`range`' => $range,
'weapon_level' => $weaponLevel,
'equip_level' => $equipLevel,
'equip_level_min'=> $equipLevelMin,
'equip_level_max'=> $equipLevelMax,
'script' => $script,
'equip_script' => $equipScript,
'unequip_script' => $unequipScript,
'refineable' => $refineable
);

if($server->isRenewal) {
if(!is_null($matk)) {
$atk = $attack .':'. $matk;
}
else {
$atk = $attack;
}
$vals = array_merge($vals, array(
'`atk:matk`' => $atk
));
}
else {
if ($server->isRenewal) {
$vals = array_merge($vals, array(
'attack' => $attack
'matk' => $matk
));
}

Expand Down
16 changes: 10 additions & 6 deletions modules/item/copy.php
Expand Up @@ -20,9 +20,9 @@

$col = "name_english, name_japanese, type, price_buy, price_sell, ";
$col .= "weight, defence, `range`, slots, equip_jobs, equip_upper, ";
$col .= "equip_genders, equip_locations, weapon_level, equip_level, refineable, ";
$col .= "equip_genders, equip_locations, weapon_level, equip_level_min, refineable, ";
$col .= "view, script, equip_script, unequip_script, ";
$col .= ($server->isRenewal) ? "`atk:matk` AS attack" : "attack";
$col .= ($server->isRenewal) ? "atk, matk" : "atk";

$sql = "SELECT $col FROM $tableName WHERE id = ? LIMIT 1";
$sth = $server->connection->getStatement($sql);
Expand Down Expand Up @@ -55,17 +55,21 @@
else {
$col = "id, name_english, name_japanese, type, price_buy, price_sell, ";
$col .= "weight, defence, `range`, slots, equip_jobs, equip_upper, ";
$col .= "equip_genders, equip_locations, weapon_level, equip_level, refineable, ";
$col .= "equip_genders, equip_locations, weapon_level, equip_level_min, refineable, ";
$col .= "view, script, equip_script, unequip_script, ";
$col .= ($server->isRenewal) ? "`atk:matk`" : "attack";
$col .= ($server->isRenewal) ? "atk, matk" : "atk";

$bind = array(
$copyID, $item->name_english, $item->name_japanese, $item->type, $item->price_buy, $item->price_sell,
$item->weight, $item->defence, $item->range, $item->slots, $item->equip_jobs, $item->equip_upper,
$item->equip_genders, $item->equip_locations, $item->weapon_level, $item->equip_level, $item->refineable,
$item->view, $item->script, $item->equip_script, $item->unequip_script, $item->attack
$item->equip_genders, $item->equip_locations, $item->weapon_level, $item->equip_level_min, $item->refineable,
$item->view, $item->script, $item->equip_script, $item->unequip_script, $item->atk
);

if ($server->isRenewal) {
array_push($bind, 'matk');
}

$sql = "INSERT INTO {$server->charMapDatabase}.item_db2 ($col) VALUES (".implode(',', array_fill(0, count($bind), '?')).")";
$sth = $server->connection->getStatement($sql);
$res = $sth->execute($bind);
Expand Down

0 comments on commit f3eed0e

Please sign in to comment.