diff --git a/doc/Gun.py b/doc/Gun.py index c29e42b7..ddaf6573 100644 --- a/doc/Gun.py +++ b/doc/Gun.py @@ -187,7 +187,7 @@ class Gun(object): { 'name': 'getUpgradeQualityList', 'desc': '获取升阶中的枪械列表', - 'group': 'Hero', + 'group': 'Gun', 'url': 'webapp/index.php?c=Hero&a=getUpgradeQualityList', 'params': [ _common.ReqHead(), diff --git a/doc/Hero.py b/doc/Hero.py index 05d6cc02..94613077 100644 --- a/doc/Hero.py +++ b/doc/Hero.py @@ -227,6 +227,22 @@ class Hero(object): _common.RspHead(), ['property_chg', _common.PropertyChg(), '属性变更'], ] + },{ + 'name': 'upgradeLv', + 'desc': '升级', + 'group': 'Hero', + 'url': 'webapp/index.php?c=Hero&a=upgradeLv', + 'params': [ + _common.ReqHead(), + ['hero_uniid', 0, '英雄唯一id'], + ['cost_hero_uniid', 0, '材料英雄id(非必选参数--4|9|14等级必选)'], + ], + 'response': [ + _common.RspHead(), + ['property_chg', _common.PropertyChg(), '属性变更'], + ['old_hero', _common.Hero(), '英雄-老'], + ['new_hero', _common.Hero(), '英雄-新'], + ] }, ] diff --git a/doc/_common.py b/doc/_common.py index 22329419..c85902af 100644 --- a/doc/_common.py +++ b/doc/_common.py @@ -78,7 +78,7 @@ class Gun(object): ['token_id', '', 'token id'], ['gun_uniid', 0, '枪唯一id'], ['gun_id', 0, '枪id'], - ['state', 0, '0:已购买 1:体验中'], + ['state', 0, '0:已购买 1:免费(GIFT标签)'], ['gun_lv', 0, '枪等级'], ['quality', 0, '品阶'], ['durability', 0, '耐久'], @@ -239,7 +239,7 @@ class Hero(object): ['hero_lv', 0, '英雄等级'], ['hero_tili', 0, '英雄体力'], ['hero_tili_max', 0, '英雄最大体力'], - ['state', 0, '0:已购买 1:体验中'], + ['state', 0, '0:已购买 1:免费(GIFT标签)'], ['skin_id', 0, '英雄皮肤id'], ['quality', 0, '品阶'], ['skill_lv1', 0, '主动技能等级'], @@ -798,7 +798,7 @@ class Chip(object): ['item_num', 0, '道具数量'], ['chip_grade', 0, '芯片等级'], ['chip_type', 0, '芯片类型:1 攻击;2 防御;3 辅助'], - ['state', 0, '状态:0 免费;1 常规'], + ['state', 0, '0:已购买 1:免费(GIFT标签)'], ['supper_state', 0, '是否锁定:0 正常;1 锁住 ---弃用字段'], ['inlay_state', 0, '镶嵌状态:0 未镶嵌;1 镶嵌了 ---弃用字段'], ['!rand_attr', [ChipAttr()], '属性'], diff --git a/webapp/controller/ChipController.class.php b/webapp/controller/ChipController.class.php index 2afc2561..a54768c5 100644 --- a/webapp/controller/ChipController.class.php +++ b/webapp/controller/ChipController.class.php @@ -146,7 +146,7 @@ class ChipController extends BaseAuthedController $this->_rspErr(1, "Unable to use nft chip"); return; } - if (!$chipDbParam['state']) { + if ($chipDbParam['state'] == Chip::FREE_STATE) { $this->_rspErr(1, "Unable to use free chip"); return; } @@ -184,7 +184,7 @@ class ChipController extends BaseAuthedController Chip::update2($idxMain, array( 'chip_grade' => $chipDbMain['chip_grade']+1, - 'state' => 1, + 'state' => Chip::GETED_STATE, 'rand_attr' => json_encode($rand_attr), ) ); diff --git a/webapp/controller/GunController.class.php b/webapp/controller/GunController.class.php index d3ee9798..8058a0d5 100644 --- a/webapp/controller/GunController.class.php +++ b/webapp/controller/GunController.class.php @@ -830,6 +830,10 @@ class GunController extends BaseAuthedController { $this->_rspErr(100, 'NFT cannot be a material'); return; } + if ($costGunDb['state'] == Gun::FREE_STATE){ + $this->_rspErr(100, 'Unable to use free gun'); + return; + } if ($gunDb['gun_lv'] != $costGunDb['gun_lv']){ $this->_rspErr(100, 'You need the same level to do it'); return; @@ -859,6 +863,7 @@ class GunController extends BaseAuthedController { Gun::update($gunUniId, array( 'gun_lv' => $gunDb['gun_lv'] + 1, + 'state' => 1, 'rand_attr' => json_encode($attrs), )); Gun::update($costGunUniId, diff --git a/webapp/controller/HeroController.class.php b/webapp/controller/HeroController.class.php index 3d27d598..65cec0e5 100644 --- a/webapp/controller/HeroController.class.php +++ b/webapp/controller/HeroController.class.php @@ -952,4 +952,81 @@ class HeroController extends BaseAuthedController { 'old_hero'=>Hero::toDto($oldHeroDb) )); } + + public function upgradeLv() + { + $heroUniId = getReqVal('hero_uniid', 0); + $costHeroUniId = getReqVal('cost_hero_uniid', 0); + $heroDb = Hero::find($heroUniId); + $oldHero = Hero::toDto($heroDb); + $costHeroDb = Hero::findEx($costHeroUniId); + if (!$heroDb) { + $this->_rspErr(100, 'param error or null'); + return; + } + if ($heroDb['hero_lv'] == Hero::LV_1 || + $heroDb['hero_lv'] == Hero::LV_2 || + $heroDb['hero_lv'] == Hero::LV_3 ){ + if (! $costHeroDb){ + $this->_rspErr(100, 'material param error or null'); + return; + } + if ($costHeroDb['token_id']){ + $this->_rspErr(100, 'NFT cannot be a material'); + return; + } + if ($costHeroDb['state'] == Hero::FREE_STATE){ + $this->_rspErr(100, 'Unable to use free hero'); + return; + } + if ($heroDb['hero_lv'] != $costHeroDb['hero_lv']){ + $this->_rspErr(100, 'You need the same level to do it'); + return; + } + } + $heroMeta = mt\Hero::get($heroDb['hero_id']); + if (!$heroMeta) { + $this->_rspErr(100, 'server internal error'); + return; + } + $nextLevelMeta = mt\HeroLevelAttr::getByLevel($heroDb['hero_lv'] + 1); + if (!$nextLevelMeta) { + $this->_rspErr(5, "It's already the highest level"); + return; + } + + //升级所需消耗 +// $costItems = array(); +// $lackItem = null; +// if (!$this->_hasEnoughItems($costItems, $lackItem)) { +// $this->_rspErr(3, $this->_getLackItemErrMsg($lackItem)); +// return; +// } +// $this->_decItems($costItems); + + $attrs = mt\HeroLevelAttr::addRandAttrNew($heroDb,1); + Hero::update($heroUniId, array( + 'hero_lv' => $heroDb['hero_lv'] + 1, + 'rand_attr' => json_encode($attrs), + 'state' => Hero::GETED_STATE, + 'skill_points' => $heroDb['skill_points']+$nextLevelMeta['skill_point'] + )); + if ($costHeroDb){ + Hero::update($costHeroUniId, array( + 'account_id' => myself()->_getAccountId() . '!!!', + )); + } + if ($heroDb['hero_lv'] + 1 > myself()->_getV(TN_HERO_MAX_LEVEL, 0)) { + myself()->_setV(TN_HERO_MAX_LEVEL, 0, $heroDb['hero_lv'] + 1); + } + $newHero = Hero::toDto(Hero::find($heroUniId)); + $propertyChgService = new services\PropertyChgService(); + $propertyChgService->addHeroChg(); + $propertyChgService->addUserChg(); + $this->_rspData(array( + 'property_chg' => $propertyChgService->toDto(), + 'old_hero' => $oldHero, + 'new_hero' => $newHero, + )); + } } diff --git a/webapp/controller/UserController.class.php b/webapp/controller/UserController.class.php index d4cd34e6..e6e2ea1e 100644 --- a/webapp/controller/UserController.class.php +++ b/webapp/controller/UserController.class.php @@ -729,8 +729,8 @@ class UserController extends BaseAuthedController { if ($heroMeta['normal_gift'] && !in_array($heroMeta['normal_gift'],$headList)){ array_push($headList,$heroMeta['normal_gift']); } - Hero::addHero($heroMeta); - Gun::addGun($gunMeta); + Hero::addFreeHero($heroMeta); + Gun::addFreeGun($gunMeta); $fields = array( 'hero_id' => $temp ? $temp[1] : 0, 'head_id' => $temp ? $temp[0] : 0, diff --git a/webapp/models/Chip.php b/webapp/models/Chip.php index 6818e759..7edb744a 100644 --- a/webapp/models/Chip.php +++ b/webapp/models/Chip.php @@ -18,6 +18,9 @@ use services\FormulaService; class Chip extends BaseModel { + const GETED_STATE = 0; + const FREE_STATE = 1; + const CHIP_LV_MAX = 3; public static function find($chipUniId) @@ -134,6 +137,7 @@ class Chip extends BaseModel $fieldsKv = array( 'item_id' => $itemMeta['id'], 'item_num' => 1, + 'state' => self::GETED_STATE, 'rand_attr' => json_encode($randAttr), 'chip_grade' => 1, 'chip_type' => $itemMeta['sub_type'], @@ -179,6 +183,16 @@ class Chip extends BaseModel return $dto; } + public static function addFreeChip($itemMeta) + { + + return self::internalAddItem( + myself()->_getSelfMysql(), + $itemMeta, + myself()->_getAccountId(), + null, + self::FREE_STATE); + } public static function addChip($itemMeta) { @@ -187,7 +201,8 @@ class Chip extends BaseModel myself()->_getSelfMysql(), $itemMeta, myself()->_getAccountId(), - null); + null, + self::GETED_STATE); } public static function addNftChip($itemMeta,$tokenId) @@ -197,10 +212,11 @@ class Chip extends BaseModel myself()->_getMysql($tokenId), $itemMeta, null, - $tokenId); + $tokenId, + self::GETED_STATE); } - public static function internalAddItem($conn, $itemMeta, $accountId, $tokenId) + public static function internalAddItem($conn, $itemMeta, $accountId, $tokenId,$state) { if (!$itemMeta) { return; @@ -223,6 +239,7 @@ class Chip extends BaseModel $fieldsKv = array( 'item_id' => $itemMeta['id'], 'item_num' => 1, + 'state' => $state, 'rand_attr' => json_encode($randAttr), 'chip_grade' => 1, 'chip_type' => $itemMeta['sub_type'], diff --git a/webapp/models/Gun.php b/webapp/models/Gun.php index 0907d789..1da5e03d 100644 --- a/webapp/models/Gun.php +++ b/webapp/models/Gun.php @@ -20,7 +20,7 @@ use models\ChipPlugin; class Gun extends BaseModel { const GETED_STATE = 0; - const TRY_STATE = 1; + const FREE_STATE = 1; const NO_LOCK = 0; const LEVEL_LOCK = 1; @@ -317,13 +317,24 @@ class Gun extends BaseModel { return $dto; } + public static function addFreeGun($gunMeta) + { + return self::internalAddGun( + myself()->_getSelfMysql(), + $gunMeta, + myself()->_getAccountId(), + null, + self::FREE_STATE); + } + public static function addGun($gunMeta) { return self::internalAddGun( myself()->_getSelfMysql(), $gunMeta, myself()->_getAccountId(), - null); + null, + self::GETED_STATE); } public static function addNftGun($gunMeta, $tokenId) @@ -332,10 +343,11 @@ class Gun extends BaseModel { myself()->_getMysql($tokenId), $gunMeta, null, - $tokenId); + $tokenId, + self::GETED_STATE); } - private static function internalAddGun($conn, $gunMeta, $accountId, $tokenId) + private static function internalAddGun($conn, $gunMeta, $accountId, $tokenId,$state) { $randAttr = array(); { @@ -348,7 +360,7 @@ class Gun extends BaseModel { 'gun_id' => $gunMeta['id'], 'gun_lv' => 1, 'quality' => 1, - 'state' => self::GETED_STATE, + 'state' => $state, 'durability' => FormulaService::Weapon_NFT_Maximum_Durability(1,FormulaService::Weapon_Advanced_Lucky_Value(1)), 'rand_attr' => json_encode($randAttr), 'lock_type' => self::NO_LOCK, @@ -396,7 +408,7 @@ class Gun extends BaseModel { 'gun_id' => $gunMeta['id'], 'gun_lv' => 1, 'quality' => 1, - 'state' => self::TRY_STATE, + 'state' => self::FREE_STATE, 'try_count' => $tryCount, 'durability' => $gunMeta['init_durability'], 'rand_attr' => json_encode($randAttr), diff --git a/webapp/models/Hero.php b/webapp/models/Hero.php index d85b0fac..0912e944 100644 --- a/webapp/models/Hero.php +++ b/webapp/models/Hero.php @@ -27,13 +27,17 @@ use models\ChipPlugin; class Hero extends BaseModel { const GETED_STATE = 0; - const TRY_STATE = 1; + const FREE_STATE = 1; const NO_LOCK = 0; const LEVEL_LOCK = 1; const QUALITY_LOCK = 2; const SEND_LOCK = 3; const COST_LOCK = 4; + //需要材料所需等级 + const LV_1 = 4; + const LV_2 = 9; + const LV_3 = 14; public static function find($heroUniId) { @@ -48,6 +52,11 @@ class Hero extends BaseModel { 'idx' => $heroUniId, ) ); + if ($row) { + if ($row['account_id'] != myself()->_getAccountId()) { + $row = null; + } + } return $row; } @@ -314,13 +323,24 @@ class Hero extends BaseModel { return $dto; } + public static function addFreeHero($heroMeta) + { + return self::internalAddHero( + myself()->_getSelfMysql(), + $heroMeta, + myself()->_getAccountId(), + null, + self::FREE_STATE); + } + public static function addHero($heroMeta) { return self::internalAddHero( myself()->_getSelfMysql(), $heroMeta, myself()->_getAccountId(), - null); + null, + self::GETED_STATE); } public static function addNftHero($heroMeta, $tokenId) @@ -329,10 +349,11 @@ class Hero extends BaseModel { myself()->_getMysql($tokenId), $heroMeta, null, - $tokenId); + $tokenId, + self::GETED_STATE); } - public static function internalAddHero($conn, $heroMeta, $accountId, $tokenId) + public static function internalAddHero($conn, $heroMeta, $accountId, $tokenId,$state) { $realHeroMeta = mt\Hero::get($heroMeta['id']); $randAttr = array(); @@ -341,7 +362,7 @@ class Hero extends BaseModel { 'hero_lv' => 1, 'quality' => 1, 'hero_tili' => FormulaService::Hero_NFT_Maximum_Physical_Strength(1,FormulaService::Hero_Advanced_Lucky_Value(1)), - 'state' => self::GETED_STATE, + 'state' => $state, 'skill_lv1' => 1, 'skill_lv2' => 1, 'rand_attr' => json_encode($randAttr), @@ -393,7 +414,7 @@ class Hero extends BaseModel { 'hero_lv' => 1, 'quality' => 1, 'hero_tili' => $realHeroMeta ? $realHeroMeta['tili'] : 0, - 'state' => self::TRY_STATE, + 'state' => self::FREE_STATE, 'try_count' => $tryCount, 'skill_lv1' => 1, 'skill_lv2' => 1,