Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add itemlink module #372

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions lib/Flux/Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,13 @@ class Flux_Template {
*/
public $referer;

/**
* Base62 Dictionary
* @access public
* @var array
*/
public $base62_dict = array();

/**
* Construct new template onbject.
*
Expand Down Expand Up @@ -245,6 +252,10 @@ public function __construct(Flux_Config $config)
}
}

$base62 = str_split('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ');
for ($i = 0; ($i < count($base62)); $i++) {
$this->base62_dict[$base62[$i]] = $i;
}
}

/**
Expand Down Expand Up @@ -1521,5 +1532,25 @@ public function cap_value($amount, $min, $max)
{
return ($amount >= $max) ? $max : (($amount <= $min) ? $min : $amount);
}

/**
* Parse a Base62 String to an Integer
* Returns a pair of (int, int) where the first int is the parsed value
* and the second int is the index of the first character after the parsed
* value.
* @access public
*/
public function parseBase62Until($str, $idx, $until = 0)
{
$ret = 0;
$until = $until == 0 ? strlen($str) : $until + $idx;
while (($idx < $until) && array_key_exists($str[$idx], $this->base62_dict)) {
$ret *= 62;
$ret += $this->base62_dict[$str[$idx]];
$idx++;
}
return array($ret, $idx);
}

}
?>
142 changes: 142 additions & 0 deletions modules/itemlink/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
<?php
if (!defined('FLUX_ROOT')) exit;

require_once 'Flux/TemporaryTable.php';

// change this to your packetver
// values stolen from rathena, so if it doesnt work you might need to change it
$packetver = 20200724;

if ($packetver >= 20200724) {
$cardsep = ')';
$optsep = '+';
$optparamsep = ',';
$optvalsep = '-';
} else if ($packetver >= 20161116) {
$cardsep = '(';
$optsep = '*';
$optparamsep = '+';
$optvalsep = ',';
}


$itemlink = $params->get('itemlink');

$itemlink_len = strlen($itemlink);

// get substring 5 characters
$ret = $this->parseBase62Until($itemlink, 0, 5);
$equip = $ret[0];
$idx = $ret[1];

$isequip = substr($itemlink, 5, 1);

$idx = 6;

// nameid
$ret = $this->parseBase62Until($itemlink, $idx);
$nameid = $ret[0];
$idx = $ret[1];

if ($server->isRenewal) {
$fromTables = array("{$server->charMapDatabase}.item_db_re", "{$server->charMapDatabase}.item_db2_re");
} else {
$fromTables = array("{$server->charMapDatabase}.item_db", "{$server->charMapDatabase}.item_db2");
}
$tableName = "{$server->charMapDatabase}.items";
$tempTable = new Flux_TemporaryTable($server->connection, $tableName, $fromTables);
$itemDescTable = Flux::config('FluxTables.ItemDescTable');

$sql = "SELECT items.id AS item_id, name_english AS name, slots ";

if (Flux::config('ShowItemDesc')) {
$sql .= ', itemdesc ';
}

$sql .= "FROM {$server->charMapDatabase}.items ";
if (Flux::config('ShowItemDesc')) {
$sql .= "LEFT OUTER JOIN {$server->charMapDatabase}.$itemDescTable ON $itemDescTable.itemid = items.id ";
}
$sql .= "WHERE items.id = ? LIMIT 1";

$sth = $server->connection->getStatement($sql);
$sth->execute(array($nameid));

$item = $sth->fetch();

if (!$item) {
return;
}

$title = "Viewing Item Link for ($item->name)";


// refines
if ($itemlink[$idx] == '%') {
$idx++;
$ret = $this->parseBase62Until($itemlink, $idx);
$refine = $ret[0];
$idx = $ret[1];
} else {
$refine = 0;
}

// view
if ($itemlink[$idx] == '&') {
$idx++;
$ret = $this->parseBase62Until($itemlink, $idx);
$view = $ret[0];
$idx = $ret[1];
} else {
$view = 0;
}

// enchantgrade
if ($itemlink[$idx] == '\'') {
$idx++;
$ret = $this->parseBase62Until($itemlink, $idx);
$enchantgrade = $ret[0];
$idx = $ret[1];
} else {
$enchantgrade = 0;
}

// cards
$cards = [];
while ($idx < $itemlink_len && $itemlink[$idx] == $cardsep) {
$idx++;
$ret = $this->parseBase62Until($itemlink, $idx);

$sth = $server->connection->getStatement($sql);
$sth->execute(array($ret[0]));
$card = $sth->fetch();
$cards[] = $card;

$idx = $ret[1];
}

// options
$options = [];
while ($idx < $itemlink_len && $itemlink[$idx] == $optsep) {
$option = [];
$idx++;
$ret = $this->parseBase62Until($itemlink, $idx);
$option['opt'] = $ret[0];
$idx = $ret[1];
if ($itemlink[$idx] != $optparamsep) {
break;
}
$idx++;
$ret = $this->parseBase62Until($itemlink, $idx);
$option['param'] = $ret[0];
$idx = $ret[1];
if ($itemlink[$idx] != $optvalsep) {
break;
}
$idx++;
$ret = $this->parseBase62Until($itemlink, $idx);
$option['val'] = $ret[0];
$idx = $ret[1];
array_push($options, $option);
}
?>
Binary file added themes/default/itemlink/emptysocket.png
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can images go into the img/ dir please?

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
78 changes: 78 additions & 0 deletions themes/default/itemlink/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php if (!defined('FLUX_ROOT')) exit; ?>

<?php if ($item): ?>
<?php $icon = $this->iconImage($nameid); ?>
<?php $image = $this->itemImage($nameid) ?>

<table class="vertical-table">
<tr>
<th colspan="<?php echo $image && $icon ? 1 : (($image || $icon) ? 2 : 3) ?>"> Item </th>
<?php if ($icon): ?>
<th><img src="<?php echo $icon ?>" /></td>
<?php endif ?>
<?php if ($image): ?>
<td rowspan="<?php echo $isequip ? 4 : 3 ?>" style="width: 150px; text-align: center; vertical-alignment: middle">
<img src="<?php echo $image ?>" />
</td>
<?php endif ?>
</tr>
<tr>
<th> Name </th>
<td>
<?php $itemname = $item->name . ($isequip ? " [$item->slots]" : "") ?>
<?php echo $this->linkToItem($nameid, $itemname) ?>
</td>
</tr>
<tr>
<th> Item ID </th>
<td> <?php echo htmlspecialchars($nameid) ?> </td>
</tr>
<tr>
<th> Refine </th>
<td> +<?php echo htmlspecialchars($refine) ?> </td>
</tr>
<?php if (Flux::config('ShowItemDesc')):?>
<tr>
<th> Description </th>
<td> <?php echo htmlspecialchars($item->itemdesc) ?> </td>
</tr>
<?php endif ?>
<?php if ($isequip): ?>
<tr>
<th colspan="<?php echo $image ? 4 : 3 ?>"> Slots </th>
</tr>
<?php foreach(range(1, 4) as $i): ?>
<tr>
<th> Slot <?php echo $i ?> </th>
<?php if (count($cards) >= $i && $cards[$i - 1]): ?>
<td class="display:flex, align-items: center; justify-content: center"><img src="<?php echo $this->iconImage($cards[$i - 1]->item_id) ?>" /></td>
<td colspan="<?php echo $image ? 4 : 3 ?>">
<?php echo $this->linkToItem($cards[$i - 1]->item_id, $cards[$i - 1]->name) ?>
</td>
<?php elseif ($item->slots >= $i): ?>
<td class="display:flex, align-items: center; justify-content: center"><img src="<?php echo $this->themePath('itemlink/emptysocket.png') ?>" /></td>
<td><span class="not-applicable">Empty</span></td>
<?php else: ?>
<td class="display:flex, align-items: center; justify-content: center"><img src="<?php echo $this->themePath('itemlink/nosocket.png') ?>" /></td>
<td><span class="not-applicable">None</span></td>
<?php endif ?>
<?php endforeach ?>
<?php if (count($options) > 0): ?>
<tr>
<th colspan="<?php echo $image ? 4 : 3 ?>"> Options </th>
</tr>
<?php foreach(range(1, 5) as $i): ?>
<?php if (count($options) >= $i && $options[$i - 1]): ?><tr>
<td colspan="<?php echo $image ? 4 : 3 ?>">
<?php echo htmlspecialchars($this->itemRandOption($options[$i - 1]['opt'], $options[$i - 1]['val'])) ?>
</td>
</tr>
<?php endif ?>
<?php endforeach ?>
<?php endif ?>
<?php endif ?>
</table>

<?php else: ?>
<p>Item not found</p>
<?php endif ?>
Binary file added themes/default/itemlink/nosocket.png
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can images go into the img/ dir please?

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.