From f242f30c86f69a10b596e088aa0b998a4ab06b0f Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Thu, 6 Jan 2022 19:13:13 +0800 Subject: [PATCH] 1 --- webapp/models/Gun.php | 186 +++++++++++++++++++++++---------------- webapp/models/Hero.php | 2 +- webapp/mt/GunLevel.php | 61 +++++++++++++ webapp/mt/GunQuality.php | 63 +++++++++++++ 4 files changed, 237 insertions(+), 75 deletions(-) create mode 100644 webapp/mt/GunLevel.php create mode 100644 webapp/mt/GunQuality.php diff --git a/webapp/models/Gun.php b/webapp/models/Gun.php index 2b050069..2cbe81d3 100644 --- a/webapp/models/Gun.php +++ b/webapp/models/Gun.php @@ -2,121 +2,159 @@ namespace models; -require_once('mt/Item.php'); +require_once('mt/Gun.php'); +require_once('mt/GunLevel.php'); require_once('mt/GunQuality.php'); +require_once('models/GunSkin.php'); use mt; use phpcommon\SqlHelper; class Gun extends BaseModel { - public static function find($itemId) + const GETED_STATE = 0; + const TRY_STATE = 1; + + const NO_LOCK = 1; + const LEVEL_LOCK = 1; + const QUALITY_LOCK = 2; + + public static function find($gunUniId) { $row = SqlHelper::ormSelectOne( myself()->_getSelfMysql(), 't_gun', array( 'account_id' => myself()->_getAccountId(), - 'gun_id' => $itemId, + 'idx' => $gunUniId, ) ); + if ($row) { + $row['gun_uniid'] = $row['idx']; + } + return $row; + } + + public static function getValidGun($gunId) + { + $row = SqlHelper::ormSelectOne( + myself()->_getSelfMysql(), + 't_gun', + array( + 'account_id' => myself()->_getAccountId(), + 'gun_id' => $gunId, + 'state' => self::GETED_STATE, + ) + ); + if ($row) { + $row['gun_uniid'] = $row['idx']; + } return $row; } public static function toDto($row) { $attr = emptyReplace(json_decode($row['rand_attr'], true), array()); - return array( + $lockType = 0; + $lockTime = 0; + if ($row['lock_type'] != 0 && $row['unlock_time'] - myself()->_getNowTime() > 0) { + $lockType = $row['lock_type']; + $lockTime = $row['unlock_time'] - myself()->_getNowTime(); + } + $tradeLocktime = max(0, $row['unlock_trade_time'] - myself()->_getNowTime()); + $dto = array( 'gun_uniid' => $row['idx'], 'gun_id' => $row['gun_id'], - 'state' => $row['state'], 'gun_lv' => $row['gun_lv'], + 'gun_tili' => $row['gun_tili'], + 'state' => $row['state'], 'quality' => $row['quality'], + 'attr' => $attr, 'try_count' => $row['try_count'], 'lock_type' => $lockType, 'lock_time' => $lockTime, 'trade_locktime' => $tradeLocktime, - 'attr' => $attr, ); + return $dto; } - public static function all() + public static function addGun($gunMeta) { - $itemList = array(); - SqlHelper::ormSelect( + $realGunMeta = mt\Gun::get($gunMeta['id']); + $randAttr = array(); + { + $initQualityMeta = mt\GunQuality::getByQuality(1); + if ($initQualityMeta) { + $randAttr = mt\GunQuality::getRandAttr($initQualityMeta); + } + } + SqlHelper::insert( myself()->_getSelfMysql(), - 't_bag', + 't_gun', array( - 'account_id' => myself()->_getAccountId() - ), - function ($row) use(&$itemList) { - if ($row['item_num'] > 0) { - array_push($itemList, Bag::toDto($row)); - } - } + 'account_id' => myself()->_getAccountId(), + 'gun_id' => $gunMeta['id'], + 'gun_lv' => 1, + 'quality' => 1, + 'state' => self::GETED_STATE, + 'rand_attr' => json_encode($randAttr), + 'lock_type' => self::NO_LOCK, + 'unlock_time' => 0, + 'unlock_trade_time' => 0, + 'createtime' => myself()->_getNowTime(), + 'modifytime' => myself()->_getNowTime() + ) ); - return $itemList; } - public static function getItemCount($itemId) + public static function addTryGun($gunMeta, $tryCount) { - $itemDb = self::find($itemId); - return $itemDb ? $itemDb['item_num'] : 0; - } - - public static function addItem($itemId, $itemNum) - { - if (myself()->_isVirtualItem($itemId)) { - return; - } - if ($itemNum <= 0) { - return; - } - $itemMeta = mt\Item::get($itemId); - if (!$itemMeta) { - return; - } - if ($itemMeta['cannot_stack']) { - $randAttr = array(); - if (mt\Item::isRandAttrItem($itemMeta)) { - $qualityMeta = mt\ChipQuality::getByQuality($itemMeta['quality']); - if ($qualityMeta) { - $randAttr = mt\ChipQuality::getRandAttr($qualityMeta); - } + $realGunMeta = mt\Gun::get($gunMeta['id']); + $randAttr = array(); + { + $initQualityMeta = mt\GunQuality::getByQuality(1); + if ($initQualityMeta) { + $randAttr = mt\GunQuality::getRandAttr($initQualityMeta); } - 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() - ) - ); } + SqlHelper::upsert( + myself()->_getSelfMysql(), + 't_gun', + array( + 'account_id' => myself()->_getAccountId(), + 'gun_id' => $gunMeta['id'] + ), + array( + ), + array( + 'account_id' => myself()->_getAccountId(), + 'gun_id' => $gunMeta['id'], + 'gun_lv' => 1, + 'quality' => 1, + 'gun_tili' => $realGunMeta ? $realGunMeta['tili'] : 0, + 'state' => self::TRY_STATE, + 'try_count' => $tryCount, + 'rand_attr' => json_encode($randAttr), + 'lock_type' => self::NO_LOCK, + 'unlock_time' => 0, + 'unlock_trade_time' => 0, + 'createtime' => myself()->_getNowTime(), + 'modifytime' => myself()->_getNowTime() + ) + ); + } + + public static function update($gunUniId, $fieldsKv) + { + SqlHelper::update + (myself()->_getSelfMysql(), + 't_gun', + array( + 'account_id' => myself()->_getAccountId(), + 'idx' => $gunUniId, + ), + $fieldsKv + ); } } diff --git a/webapp/models/Hero.php b/webapp/models/Hero.php index 2b1de921..fc1c78af 100644 --- a/webapp/models/Hero.php +++ b/webapp/models/Hero.php @@ -142,7 +142,7 @@ class Hero extends BaseModel { 'try_count' => $tryCount, 'skill_lv1' => 1, 'skill_lv2' => 1, - 'rand_attr' => '[]', + 'rand_attr' => json_encode($randAttr), 'lock_type' => self::NO_LOCK, 'unlock_time' => 0, 'unlock_trade_time' => 0, diff --git a/webapp/mt/GunLevel.php b/webapp/mt/GunLevel.php new file mode 100644 index 00000000..e006099b --- /dev/null +++ b/webapp/mt/GunLevel.php @@ -0,0 +1,61 @@ + $item[0], + 'type' => $item[1], + 'val' => rand($item[2], $item[3]) + )); + } + ++$i; + } + return $result; + } + + protected static function getMetaList() + { + if (!self::$metaList) { + self::$metaList = getMetaTable('gunQuality@gunQuality.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; + +}