1
This commit is contained in:
parent
4dc79e44dd
commit
0df61ca158
@ -126,7 +126,7 @@ CREATE TABLE `t_bag` (
|
|||||||
`createtime` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间',
|
`createtime` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间',
|
||||||
`modifytime` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间',
|
`modifytime` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间',
|
||||||
PRIMARY KEY (`idx`),
|
PRIMARY KEY (`idx`),
|
||||||
UNIQUE KEY `item_uuid` (`account_id`, `item_id`),
|
KEY `item_id` (`item_id`),
|
||||||
KEY `account_id` (`account_id`)
|
KEY `account_id` (`account_id`)
|
||||||
) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
|
) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
|
||||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
namespace models;
|
namespace models;
|
||||||
|
|
||||||
require_once('mt/Item.php');
|
require_once('mt/Item.php');
|
||||||
|
require_once('mt/ChipQuality.php');
|
||||||
|
|
||||||
use mt;
|
use mt;
|
||||||
use phpcommon\SqlHelper;
|
use phpcommon\SqlHelper;
|
||||||
@ -44,8 +45,10 @@ class Bag extends BaseModel {
|
|||||||
public static function toDto($row)
|
public static function toDto($row)
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
|
'item_uniid' => $row['idx'],
|
||||||
'item_id' => $row['item_id'],
|
'item_id' => $row['item_id'],
|
||||||
'item_num' => $row['item_num'],
|
'item_num' => $row['item_num'],
|
||||||
|
'attr' => emptyReplace(json_decode($row['rand_attr'], true), array()),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,29 +81,54 @@ class Bag extends BaseModel {
|
|||||||
if (myself()->_isVirtualItem($itemId)) {
|
if (myself()->_isVirtualItem($itemId)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if ($itemNum <= 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
$itemMeta = mt\Item::get($itemId);
|
$itemMeta = mt\Item::get($itemId);
|
||||||
if (!$itemMeta) {
|
if (!$itemMeta) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
SqlHelper::upsert
|
if ($itemMeta['cannot_stack']) {
|
||||||
(myself()->_getSelfMysql(),
|
$randAttr = array();
|
||||||
't_bag',
|
if (mt\Item::isRandAttrItem($itemMeta)) {
|
||||||
array(
|
$qualityMeta = mt\ChipQuality::getByQuality($itemMeta['quality']);
|
||||||
'account_id' => myself()->_getAccountId(),
|
if ($qualityMeta) {
|
||||||
'item_id' => $itemId
|
$randAttr = mt\ChipQuality::getRandAttr($qualityMeta);
|
||||||
),
|
}
|
||||||
array(
|
}
|
||||||
'item_num' => function () use($itemNum) { return "item_num + {$itemNum}";},
|
SqlHelper::insert
|
||||||
'modifytime' => myself()->_getNowTime(),
|
(myself()->_getSelfMysql(),
|
||||||
),
|
't_bag',
|
||||||
array(
|
array(
|
||||||
'account_id' => myself()->_getAccountId(),
|
'account_id' => myself()->_getAccountId(),
|
||||||
'item_id' => $itemId,
|
'item_id' => $itemId,
|
||||||
'item_num' => $itemNum,
|
'item_num' => 1,
|
||||||
'createtime' => myself()->_getNowTime(),
|
'rand_attr' => json_encode($randAttr),
|
||||||
'modifytime' => myself()->_getNowTime()
|
'createtime' => myself()->_getNowTime(),
|
||||||
)
|
'modifytime' => myself()->_getNowTime()
|
||||||
);
|
)
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
SqlHelper::upsert
|
||||||
|
(myself()->_getSelfMysql(),
|
||||||
|
't_bag',
|
||||||
|
array(
|
||||||
|
'account_id' => myself()->_getAccountId(),
|
||||||
|
'item_id' => $itemId
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'item_num' => function () use($itemNum) { return "item_num + {$itemNum}";},
|
||||||
|
'modifytime' => myself()->_getNowTime(),
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'account_id' => myself()->_getAccountId(),
|
||||||
|
'item_id' => $itemId,
|
||||||
|
'item_num' => $itemNum,
|
||||||
|
'createtime' => myself()->_getNowTime(),
|
||||||
|
'modifytime' => myself()->_getNowTime()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function decItem($itemId, $itemNum)
|
public static function decItem($itemId, $itemNum)
|
||||||
|
66
webapp/mt/ChipQuality.php
Normal file
66
webapp/mt/ChipQuality.php
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace mt;
|
||||||
|
|
||||||
|
require_once('mt/AttrHelper.php');
|
||||||
|
require_once('mt/StrHelper.php');
|
||||||
|
|
||||||
|
use phpcommon;
|
||||||
|
|
||||||
|
class ChipQuality {
|
||||||
|
|
||||||
|
public static function get($id)
|
||||||
|
{
|
||||||
|
return getXVal(self::getMetaList(), $id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getByQuality($quality)
|
||||||
|
{
|
||||||
|
self::mustBeQualityHash();
|
||||||
|
return getXVal(self::$qualityHash, $quality, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getRandAttr($qualityMeta)
|
||||||
|
{
|
||||||
|
$nums = explode(':', $qualityMeta['rand_attrs_num']);
|
||||||
|
$attrs = StrHelper::parseList($qualityMeta['rand_attrs'], array('|', ':'));
|
||||||
|
$num = rand($nums[0], $nums[1]);
|
||||||
|
shuffle($attrs);
|
||||||
|
$result = array();
|
||||||
|
$i = 0;
|
||||||
|
foreach ($attrs as $item) {
|
||||||
|
if ($i < $num) {
|
||||||
|
array_push($result,
|
||||||
|
array(
|
||||||
|
'attr_id' => $item[0],
|
||||||
|
'type' => $item[1],
|
||||||
|
'val' => rand($item[2], $item[3])
|
||||||
|
));
|
||||||
|
}
|
||||||
|
++$i;
|
||||||
|
}
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static function getMetaList()
|
||||||
|
{
|
||||||
|
if (!self::$metaList) {
|
||||||
|
self::$metaList = getMetaTable('chipQuality@chipQuality.php');
|
||||||
|
}
|
||||||
|
return self::$metaList;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static function mustBeQualityHash()
|
||||||
|
{
|
||||||
|
if (!self::$qualityHash) {
|
||||||
|
self::$qualityHash = array();
|
||||||
|
foreach (self::getMetaList() as $meta) {
|
||||||
|
self::$qualityHash[$meta['quality']] = $meta;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected static $metaList;
|
||||||
|
protected static $qualityHash;
|
||||||
|
|
||||||
|
}
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
namespace mt;
|
namespace mt;
|
||||||
|
|
||||||
require('mt/AttrHelper.sql');
|
require_once('mt/AttrHelper.php');
|
||||||
|
|
||||||
use phpcommon;
|
use phpcommon;
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ class HeroQuality {
|
|||||||
public static function getByQuality($quality)
|
public static function getByQuality($quality)
|
||||||
{
|
{
|
||||||
self::mustBeQualityHash();
|
self::mustBeQualityHash();
|
||||||
return getXVal(self::$qualityHash, $level, null);
|
return getXVal(self::$qualityHash, $quality, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getRandAttr($initMeta, $nextMeta, $oldAttr, &$newAttr)
|
public static function getRandAttr($initMeta, $nextMeta, $oldAttr, &$newAttr)
|
||||||
|
@ -77,6 +77,8 @@ class Item {
|
|||||||
const WEEKLY_BUY_LIMIT = 2;
|
const WEEKLY_BUY_LIMIT = 2;
|
||||||
const TOTAL_BUY_LIMIT = 3;
|
const TOTAL_BUY_LIMIT = 3;
|
||||||
|
|
||||||
|
const MATERIAL_CHIP_SUBTYPE = 3;
|
||||||
|
|
||||||
public static function get($id)
|
public static function get($id)
|
||||||
{
|
{
|
||||||
return getXVal(self::getMetaList(), $id, null);
|
return getXVal(self::getMetaList(), $id, null);
|
||||||
@ -183,6 +185,12 @@ class Item {
|
|||||||
return $costItems;
|
return $costItems;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function isRandAttrItem($itemMeta)
|
||||||
|
{
|
||||||
|
return $itemMeta['type'] == self::MATERIAL_TYPE &&
|
||||||
|
$itemMeta['sub_type'] == self::MATERIAL_CHIP_SUBTYPE;
|
||||||
|
}
|
||||||
|
|
||||||
public static function isBagItem($type, $subType)
|
public static function isBagItem($type, $subType)
|
||||||
{
|
{
|
||||||
return in_array($type, array(
|
return in_array($type, array(
|
||||||
|
30
webapp/mt/StrHelper.php
Normal file
30
webapp/mt/StrHelper.php
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace mt;
|
||||||
|
|
||||||
|
use phpcommon;
|
||||||
|
|
||||||
|
class StrHelper {
|
||||||
|
|
||||||
|
public static function parseList($val, $separators)
|
||||||
|
{
|
||||||
|
$values = array();
|
||||||
|
if (!empty($val) && count($separators) > 0) {
|
||||||
|
function parse($data, $separators, $i, &$arr) {
|
||||||
|
$strs = explode($separators[$i], $data);
|
||||||
|
foreach ($strs as $str) {
|
||||||
|
if ($i + 1 < count($separators)) {
|
||||||
|
$item = array();
|
||||||
|
parse($str, $separators, $i + 1, $item);
|
||||||
|
array_push($arr, $item);
|
||||||
|
} else {
|
||||||
|
array_push($arr, $str);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
parse($val, $separators, 0, $values);
|
||||||
|
}
|
||||||
|
return $values;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user