Skip to content
Permalink
Browse files
Yommy src flux + fixes
Both flux addons fixes for named item
  • Loading branch information
sanasol committed Aug 26, 2013
1 parent ba38e45 commit ed5d5ef1ce0f6481be1da7dda082ece16a44766d
@@ -115,4 +115,6 @@ CREATE TABLE IF NOT EXISTS `vending` (
```
![alt text](http://dsro.ru/gyazo/images/e56669e30bf1f420c9484f948e1d.png "Main page")
![alt text](http://dsro.ru/gyazo/images/d21beacb490bc2f4415285fee024.png "Search")
![alt text](http://dsro.ru/gyazo/images/d21beacb490bc2f4415285fee024.png "Search")
![alt text](http://dsro.ru/gyazo/images/399cb907803a06ce3e009b5f97d5.png "Map")
![alt text](http://dsro.ru/gyazo/images/1176fdc614a56dd53a176c839e1a.png "Named item")
@@ -5,7 +5,7 @@

function get_item_name($id, $server)
{
if($id>0)
if($id>255)
{
$sql = "SELECT name_japanese, slots FROM {$server->charMapDatabase}.`item_db` where id='{$id}'";
$sth = $server->connection->getStatement($sql);
@@ -16,10 +16,19 @@ function get_item_name($id, $server)
}
else
{
return "-";
return;
}
}

function get_char_name($id, $server)
{
$sql = "SELECT name FROM {$server->charMapDatabase}.`char` where char_id='{$id}'";
$sth = $server->connection->getStatement($sql);
$sth->execute();
$r = $sth->fetch();
return $r->name;
}

$bind = array();
$sqlpartial = '';
$iname = $params->get('item_name');
@@ -90,7 +90,12 @@
<?php if ($icon=$this->iconImage($char->nameid)) ?>
<td width="24"><img src="<?php echo htmlspecialchars($icon); ?>?nocache=<?php echo rand(); ?>" /></td>
<td>
<?php echo $this->linkToItem($char->nameid, get_item_name($char->nameid,$server)); ?>
<?php
$nick = "";
if($char->card0 == 254) { $nick_just = get_char_name($char->card2,$server); $nick = "<span style='color: blue;'>{$nick_just}'s</span> "; }
echo $nick;
echo $this->linkToItem($char->nameid,get_item_name($char->nameid,$server));
?>
</td>
<td>
<?php echo number_format($char->amount) ?>
@@ -108,7 +113,7 @@
<?php echo $this->linkToItem($char->card1, get_item_name($char->card1,$server)) ?>
</td>
<td>
<?php echo $this->linkToItem($char->card2, get_item_name($char->card2,$server)) ?>
<?php echo $this->linkToItem($char->card2, get_item_name(($char->card2 > 255 && $char->card0 != 254) ? $char->card2:0,$server)) ?>
</td>
<td>
<?php echo $this->linkToItem($char->card3, get_item_name($char->card3,$server)) ?>
@@ -0,0 +1,10 @@
Hercules Merchant Database for FluxCP
=======

For Yommy src
https://github.com/HerculesWS/StaffPlugins/blob/master/Yommy/Vend_SQL/Vend_SQL.c

![alt text](http://dsro.ru/gyazo/images/e56669e30bf1f420c9484f948e1d.png "Main page")
![alt text](http://dsro.ru/gyazo/images/d21beacb490bc2f4415285fee024.png "Search")
![alt text](http://dsro.ru/gyazo/images/399cb907803a06ce3e009b5f97d5.png "Map")
![alt text](http://dsro.ru/gyazo/images/1176fdc614a56dd53a176c839e1a.png "Named item")
@@ -0,0 +1,9 @@
<?php
return array(
'modules' => array(
'vending' => array(
'index' => AccountLevel::ANYONE
)
)
)
?>
@@ -0,0 +1,7 @@
<?php
return array(
'MenuItems' => array(
'Information' => array('Vending DB' => array('module' => 'vending'))
)
)
?>
@@ -0,0 +1,13 @@
<?php

function dword(&$buf, $offset=0)
{
return ord($buf{$offset++})+(ord($buf{$offset++})<<8)+(ord($buf{$offset++})<<16)+(ord($buf{$offset})<<24);
}

function byte(&$buf, $offset=0)
{
return ord($buf{$offset});
}

?>
@@ -0,0 +1,161 @@
<?php

require_once('bin.php');

class gat {
private $m;
private $r;
private $xs, $ys;

public function __construct($b) {
$this->xs = dword($b, 6);
$this->ys = dword($b, 10);
//printf("Loading map: %03d*%03d\n", $this->xs, $this->ys);

$n = $this->xs * $this->ys;
$i = 14;
$x = 0;
$y = 0;
$this->m = array();
for($xy = 0; $xy < $n; $xy++) {
$this->m[$x++][$y] = (dword($b, $i + 16) == 0 ? true : false);
if( $x == $this->xs ) {
$x = 0;
$y++;
}
$i += 20;
}
}

public function c($x, $y) {
if( $x < 0 || $x >= $this->xs || $y < 0 || $y >= $this->ys )
return false;
return $this->m[$x][$y];
}

public function near_free($x, $y, $mr=8) {
static $s = array( array(1,0), array(0,-1), array(-1,0), array(0,1) );
if( $this->c($x, $y) )
return array($x, $y);
for($r=1; $r<=$mr; $r++) {
$ax = $x - $r;
$ay = $y + $r;
for($j=0;$j<4;$j++) {
for($k=0;$k<2*$r;$k++) {
if( $this->c($ax, $ay) )
return array($ax, $ay);
$ax+=$s[$j][0];
$ay+=$s[$j][1];
}
}
}
return false;
}

public function init_room() {
$this->r = array();
$rooms = array();
$id = 1;
for($x=0;$x<$this->xs;$x++)
$this->r[$x][0] = false;
for($y=0;$y<$this->ys;$y++)
$this->r[0][$y] = false;
for($x=1; $x<$this->xs; $x++) {
for($y=1; $y<$this->ys; $y++) {
if( $this->c($x,$y) !== true ) {
$this->r[$x][$y] = false;
continue;
}
if( is_numeric($this->r[$x][$y-1]) ) {
$rid = $this->r[$x][$y-1];
$this->r[$x][$y] = $rid;
$rooms[$rid][] = array($x,$y);
if( is_numeric($this->r[$x-1][$y]) && ($o=$this->r[$x-1][$y])!=$rid ) {
foreach($rooms[$o] as $e)
{
$this->r[$e[0]][$e[1]] = $rid;
$rooms[$rid][] = array($e[0], $e[1]);
}
unset($rooms[$o]);
}
}
else if( is_numeric($this->r[$x-1][$y]) ) {
$rid = $this->r[$x-1][$y];
$this->r[$x][$y] = $rid;
$rooms[$rid][] = array($x,$y);
if( is_numeric($this->r[$x][$y-1]) && ($o=$this->r[$x][$y-1])!=$rid ) {
foreach($rooms[$o] as $e)
{
$this->r[$e[0]][$e[1]] = $rid;
$rooms[$rid][] = array($e[0], $e[1]);
}
unset($rooms[$o]);
printf("%d > %d\n", $rid, $o);
die('waiting...');
}
}
else {
$rooms[$id] = array( array($x, $y) );
$this->r[$x][$y] = $id++;
}
}
}
}

public function r($x,$y) {
if( $x < 0 || $x >= $this->xs || $y < 0 || $y >= $this->ys )
return false;
return $this->r[$x][$y];
}

public function draw_map($return=false,$scale=2, $xc, $yc) {
$im = imagecreatetruecolor($this->xs*$scale,$this->ys*$scale);

$c = imagecolorallocate($im, 255, 255, 255);
for($x=0;$x<($this->xs-1);$x++) {
for($y=0;$y<($this->ys-1);$y++) {
if( !$this->c($x, $y) )
continue;
imagefilledrectangle($im, $x*$scale-$scale/2,$y*$scale-$scale/2,$x*$scale+$scale/2,$y*$scale+$scale/2, $c);
}
}

$black = imagecolorallocate($im, 0, 0, 0);
$white = imagecolorallocate($im, 0, 255, 0);
imagefilledarc($im, $xc*$scale-$scale/2, ($this->ys*$scale)-($yc*$scale-$scale/2), 10, 10, 0, 360, $white, IMG_ARC_PIE);
imagearc($im, $xc*$scale-$scale/2, ($this->ys*$scale)-($yc*$scale-$scale/2), 10, 10, 0, 360, $black);

if( $return )
return $im;
imagepng($im, 'test2.png');
return true;
}

public function draw_map_room($return=false,$scale=2) {
$im = imagecreatetruecolor($this->xs*$scale,$this->ys*$scale);
//echo $this->xs*$scale.' '.$this->ys*$scale;
$w = imagecolorallocate($im, 255, 255, 255);
$rooms = array();
for($x=0;$x<($this->xs-1);$x++) {
for($y=0;$y<($this->ys-1);$y++) {
if( !$this->c($x, $y) )
continue;
if( !isset($this->r[$x][$y]) || !is_numeric($this->r[$x][$y]) ) {
die('Something went wrong..');
}
if( isset($rooms[$this->r[$x][$y]]) )
$c = $rooms[$this->r[$x][$y]];
else
$c=$rooms[$this->r[$x][$y]]=imagecolorallocate($im, rand(40,250), rand(40,250), rand(40,250));
imagefilledrectangle($im, $x*$scale-$scale/2,$y*$scale-$scale/2,$x*$scale+$scale/2,$y*$scale+$scale/2, $c);
}
}
if( $return )
return $im;
imagepng($im, 'test4.png');
return true;
}
}


?>
@@ -0,0 +1,13 @@
<?php
header("Content-type: image/png");
require("gat.php");
$p = new gat(file_get_contents($_GET["map"].".gat"));

$x = $_GET["x"];
$y = $_GET["y"];

$im = $p->draw_map(true, 1, $x, $y);

imagepng($im);
imagedestroy($im);
?>
Binary file not shown.
@@ -0,0 +1,92 @@
<?php
if (!defined('FLUX_ROOT')) exit;

$refine = array(0=>"-", "+1", "+2", "+3", "+4", "+5", "+6", "+7", "+8", "+9", "+10");

function get_item_name($id, $server)
{
if($id>255)
{
$sql = "SELECT name_japanese, slots FROM {$server->charMapDatabase}.`item_db` where id='{$id}'";
$sth = $server->connection->getStatement($sql);
$sth->execute();
$r = $sth->fetch();
$slots = ($r->slots > 0) ? "[{$r->slots}]":"";
return $r->name_japanese.$slots;
}
else
{
return "";
}
}

function get_char_name($id, $server)
{
$sql = "SELECT name FROM {$server->charMapDatabase}.`char` where char_id='{$id}'";
$sth = $server->connection->getStatement($sql);
$sth->execute();
$r = $sth->fetch();
return $r->name;
}

$bind = array();
$sqlpartial = '';
$iname = $params->get('item_name');

if ($iname) {
if(is_numeric($iname))
{
$sql = "SELECT id FROM {$server->charMapDatabase}.`item_db` where id='{$iname}'";
$sth = $server->connection->getStatement($sql);
$sth->execute();
$item = $sth->fetchAll();
}
else
{
$sql = "SELECT id FROM {$server->charMapDatabase}.`item_db` where UPPER(name_japanese) LIKE '%{$iname}%'";
$sth = $server->connection->getStatement($sql);
$sth->execute();
$item = $sth->fetchAll();
}
$itemsearch = array();
foreach($item as $search_id)
{
$itemsearch[] = $search_id->id;
}

$items = implode(",",$itemsearch);

if(count($itemsearch) >= 1)
{
$search_info = "<b>Perhaps you were looking for:</b> ";
$i=0;
foreach($itemsearch as $id){ if($i>10) break; $searchitems[] = $this->linkToItem($id, get_item_name($id,$server)); $i++;}
$search_info .= implode(", ",$searchitems);

$sqlpartial .= "where v.`nameid` in ({$items})";
}
}




$sql = "SELECT count(*) AS total FROM {$server->charMapDatabase}.`vending_stat` AS v $sqlpartial";
$sth = $server->connection->getStatement($sql);

$sth->execute($bind);

$sortable = array('shop', 'owner', 'nameid', 'amount', 'price', 'refine', 'card0', 'card1', 'card2', 'card3');

$paginator = $this->getPaginator($sth->fetch()->total);
$paginator->setSortableColumns($sortable);


$col = "v.*";

$sql = $paginator->getSQL("SELECT $col FROM {$server->charMapDatabase}.`vending_stat` AS v $sqlpartial");
$sth = $server->connection->getStatement($sql);

$sth->execute($bind);

$chars = $sth->fetchAll();
?>

0 comments on commit ed5d5ef

Please sign in to comment.