diff --git a/sql/gamedb.sql b/sql/gamedb.sql index 86acefb5..5054e1a7 100644 --- a/sql/gamedb.sql +++ b/sql/gamedb.sql @@ -126,7 +126,7 @@ CREATE TABLE `t_bag` ( `createtime` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间', `modifytime` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间', PRIMARY KEY (`idx`), - UNIQUE KEY `item_uuid` (`account_id`, `item_id`), + KEY `item_id` (`item_id`), KEY `account_id` (`account_id`) ) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; /*!40101 SET character_set_client = @saved_cs_client */; diff --git a/webapp/models/Bag.php b/webapp/models/Bag.php index bb5de328..1a5cf24c 100644 --- a/webapp/models/Bag.php +++ b/webapp/models/Bag.php @@ -3,6 +3,7 @@ namespace models; require_once('mt/Item.php'); +require_once('mt/ChipQuality.php'); use mt; use phpcommon\SqlHelper; @@ -44,8 +45,10 @@ class Bag extends BaseModel { public static function toDto($row) { return array( + 'item_uniid' => $row['idx'], 'item_id' => $row['item_id'], '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)) { return; } + if ($itemNum <= 0) { + return; + } $itemMeta = mt\Item::get($itemId); if (!$itemMeta) { return; } - 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() - ) - ); + if ($itemMeta['cannot_stack']) { + $randAttr = array(); + if (mt\Item::isRandAttrItem($itemMeta)) { + $qualityMeta = mt\ChipQuality::getByQuality($itemMeta['quality']); + if ($qualityMeta) { + $randAttr = mt\ChipQuality::getRandAttr($qualityMeta); + } + } + SqlHelper::insert + (myself()->_getSelfMysql(), + 't_bag', + array( + 'account_id' => myself()->_getAccountId(), + 'item_id' => $itemId, + 'item_num' => 1, + 'rand_attr' => json_encode($randAttr), + '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) diff --git a/webapp/mt/ChipQuality.php b/webapp/mt/ChipQuality.php new file mode 100644 index 00000000..bef844b8 --- /dev/null +++ b/webapp/mt/ChipQuality.php @@ -0,0 +1,66 @@ + $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; + +} diff --git a/webapp/mt/HeroLevel.php b/webapp/mt/HeroLevel.php index cee33a91..890ae5f5 100644 --- a/webapp/mt/HeroLevel.php +++ b/webapp/mt/HeroLevel.php @@ -2,7 +2,7 @@ namespace mt; -require('mt/AttrHelper.sql'); +require_once('mt/AttrHelper.php'); use phpcommon; diff --git a/webapp/mt/HeroQuality.php b/webapp/mt/HeroQuality.php index bbbe2a3a..f2fbda7c 100644 --- a/webapp/mt/HeroQuality.php +++ b/webapp/mt/HeroQuality.php @@ -14,7 +14,7 @@ class HeroQuality { public static function getByQuality($quality) { self::mustBeQualityHash(); - return getXVal(self::$qualityHash, $level, null); + return getXVal(self::$qualityHash, $quality, null); } public static function getRandAttr($initMeta, $nextMeta, $oldAttr, &$newAttr) diff --git a/webapp/mt/Item.php b/webapp/mt/Item.php index dd4f66ca..cc3602f6 100644 --- a/webapp/mt/Item.php +++ b/webapp/mt/Item.php @@ -77,6 +77,8 @@ class Item { const WEEKLY_BUY_LIMIT = 2; const TOTAL_BUY_LIMIT = 3; + const MATERIAL_CHIP_SUBTYPE = 3; + public static function get($id) { return getXVal(self::getMetaList(), $id, null); @@ -183,6 +185,12 @@ class Item { 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) { return in_array($type, array( diff --git a/webapp/mt/StrHelper.php b/webapp/mt/StrHelper.php new file mode 100644 index 00000000..221dd9d2 --- /dev/null +++ b/webapp/mt/StrHelper.php @@ -0,0 +1,30 @@ + 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; + } + +}