From 20d979b1ece14651b6f95aa5d9fb58d8bafbc4f0 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Tue, 16 Jul 2024 14:07:07 +0800 Subject: [PATCH 1/7] 1 --- webapp/models/Nft.php | 1 + 1 file changed, 1 insertion(+) diff --git a/webapp/models/Nft.php b/webapp/models/Nft.php index 98aa21d3..f75ff077 100644 --- a/webapp/models/Nft.php +++ b/webapp/models/Nft.php @@ -28,6 +28,7 @@ class Nft extends BaseModel const EXPLORER_TYPE = 9; //Explorer const CANDY_TYPE = 10; //CANDY const GOLD_BULLION_TYPE = 11; //金砖 + const GCARD_HERO_TYPE = 12; //游戏内合成的nft英雄 const RING_TYPE = 19; //戒指 const AVATAR_TYPE = 30; //装饰 From 546dd97bd591304bdfc20c560369eff2ff15215c Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Tue, 16 Jul 2024 19:09:35 +0800 Subject: [PATCH 2/7] 1 --- .../controller/OutAppNftController.class.php | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/webapp/controller/OutAppNftController.class.php b/webapp/controller/OutAppNftController.class.php index 72ef94cc..51e3e2cf 100644 --- a/webapp/controller/OutAppNftController.class.php +++ b/webapp/controller/OutAppNftController.class.php @@ -442,4 +442,65 @@ class OutAppNftController extends BaseController { return $quality; } + public function getHeroList() + { + $accountId = getReqVal('account_id', ''); + $rows = SqlHelper::ormSelect( + myself()->_getMarketMysql(), + 't_hero', + array( + 'account_id' => $accountId, + ) + ); + $rspData = array( + 'rows' => array() + ); + foreach ($rows as $row) { + $info = array( + 'uniid' => '', + 'net_id' => 0, + 'contract_address' => '', + 'token_id' => '', + 'owner_address' => '', + 'meta_url' => '', + 'name' => '', + 'item_id' => 0, + 'type' => 0, + 'image' => '', + 'on_sale' => 0, + 'detail' => array() + ); + $heroDb = $row; + $info['uniid'] = $heroDb['idx']; + $heroAttrs = emptyReplace(json_decode($heroDb['wealth_attr'], true), array()); + $heroResult = \mt\EconomyAttribute::getAttrValue($heroAttrs); + $wealth = $heroResult['wealth']; + $wealth_rate = $heroResult['wealth_rate']; + $lucky = $heroResult['lucky']; + $lucky_rate = $heroResult['lucky_rate']; + $heroAbility = Hero::abilityInfo($heroDb); + $heroMeta = \mt\Hero::get($heroDb['hero_id']); + if ($heroMeta) { + $itemMeta = \mt\Item::get($heroDb['hero_id']); + $heroAtteMeta = \mt\EconomyAttribute::findByGrade($itemMeta['relationship'],$heroDb['quality']); + //$info['meta_url'] = NFT_META_URL . '/hero/meta/' . $nftDb['net_id'] . '/' . $nftDb['token_id']; + $info['name'] = $heroMeta['name']; + $info['item_id'] = $heroMeta['id']; + $info['type'] = Nft::HERO_TYPE; + $info['image'] = 'https://res2.counterfire.games/nft/meta/' . $heroMeta['id'] . '_' . $this->getRealHeroQuality($heroDb) . '.gif'; + $info['detail']['quality'] = $this->getRealHeroQuality($heroDb); + $info['detail']['max_mining_days'] = $heroAtteMeta['validTime']; + $info['detail']['wealth'] = floor($wealth * (1+$wealth_rate)); + $info['detail']['lucky'] = floor($lucky * (1+$lucky_rate)); + $info['detail']['hp'] = $heroAbility['hp']; + $info['detail']['atk'] = $heroAbility['attack']; + $info['detail']['def'] = $heroAbility['defence']; + $info['detail']['block'] = $heroAbility['block']; + $info['detail']['crit'] = $heroAbility['critical']; + } + array_push($rspData['rows'], $info); + } + myself()->_rspData($rspData); + } + } From 54e4a116953e484fd1d6ba09d22f33bb1029ba13 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Wed, 17 Jul 2024 14:26:47 +0800 Subject: [PATCH 3/7] 1 --- webapp/controller/OutAppNftController.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/webapp/controller/OutAppNftController.class.php b/webapp/controller/OutAppNftController.class.php index 51e3e2cf..4f1b1297 100644 --- a/webapp/controller/OutAppNftController.class.php +++ b/webapp/controller/OutAppNftController.class.php @@ -446,7 +446,7 @@ class OutAppNftController extends BaseController { { $accountId = getReqVal('account_id', ''); $rows = SqlHelper::ormSelect( - myself()->_getMarketMysql(), + myself()->_getMysql($accountId), 't_hero', array( 'account_id' => $accountId, From 5a2aab5bd247faac4bdc5d098364d89107016534 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Wed, 17 Jul 2024 14:31:06 +0800 Subject: [PATCH 4/7] 1 --- doc/AAMarket.py | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/AAMarket.py b/doc/AAMarket.py index d9227b43..3b695d1b 100644 --- a/doc/AAMarket.py +++ b/doc/AAMarket.py @@ -282,6 +282,7 @@ class AAMarket(object): 'permission': _common.LoginRequired, 'is_json_params': True, 'params': [ + ['to_address', '', '目标address'], ['!hero_uniids', [''], '英雄uniid列表(目前只支持1个)'], ], 'response': [ From fb3873c960f1acb0a098ebebb2b2996d7653b5a7 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Wed, 17 Jul 2024 16:59:18 +0800 Subject: [PATCH 5/7] 1 --- .../controller/BlockChainController.class.php | 4 +- .../controller/OutAppMintController.class.php | 110 ++++++++++++++++++ webapp/models/Hero.php | 37 ++++-- 3 files changed, 139 insertions(+), 12 deletions(-) create mode 100644 webapp/controller/OutAppMintController.class.php diff --git a/webapp/controller/BlockChainController.class.php b/webapp/controller/BlockChainController.class.php index 69439337..df13620d 100644 --- a/webapp/controller/BlockChainController.class.php +++ b/webapp/controller/BlockChainController.class.php @@ -124,6 +124,8 @@ class BlockChainController extends BaseAuthedController { switch ($type) { case 1: { + myself()->_rspErr(1, 'server internal error'); + return; $heroDb = Hero::find($uniid); if (!$heroDb) { myself()->_rspErr(1, 'hero not found'); @@ -145,7 +147,7 @@ class BlockChainController extends BaseAuthedController { myself()->_getNowTime(), myself()->_getAddress() ); - Hero::safeUpdateTokenId($heroDb['hero_uniid'], $tokenId); + Hero::safeUpdateTokenId(myself()->_getAccountId(), $heroDb['hero_uniid'], $tokenId); $heroDb = Hero::find($uniid); if (!$heroDb) { myself()->_rspErr(1, 'hero not found'); diff --git a/webapp/controller/OutAppMintController.class.php b/webapp/controller/OutAppMintController.class.php new file mode 100644 index 00000000..5c76ebb8 --- /dev/null +++ b/webapp/controller/OutAppMintController.class.php @@ -0,0 +1,110 @@ + $accountId, + 'uuid' => $uniid + ))); + $heroDb = Hero::findByAccountIdEx($accountId, $uniid); + if (!$heroDb) { + myself()->_rspErr(1, 'hero not found'); + return; + } + /* + if (!$heroDb['seal_type']) { + myself()->_rspErr(1, 'hero no seal'); + return; + }*/ + $isMint = true; + $tokenId = $heroDb['token_id']; + if ($heroDb['token_id'] && $heroDb['activate']) { + myself()->_rspErr(1, 'hero already on chain'); + return; + $isMint = false; + } else if (empty($tokenId) ){ + $tokenId = BuyRecord::genOrderId + ( + GAME_ID, + phpcommon\BC_FUNC_CREATION, + myself()->_getNowTime(), + $accountAddress + ); + Hero::safeUpdateTokenId($accountId, $heroDb['idx'], $tokenId); + $heroDb = Hero::findByAccountIdEx($accountId, $uniid); + if (!$heroDb) { + myself()->_rspErr(1, 'hero not found'); + return; + } + if ($heroDb['token_id'] != $tokenId) { + myself()->_rspErr(500, 'server internal error'); + return; + } + } + + $params = array( + 'c' => 'BcService', + 'a' => 'mintHero', + 'account_id' => $accountId, + 'account_address' => $accountAddress, + 'token_ids' => $tokenId, + 'nft_address' => NORMAL_HERO_CONTRACT_ADDRESS, + 'to_address' => $toAddress, + 'net_id' => NET_ID + ); + error_log(json_encode($params)); + { + $url = self::getWeb3ServiceUrl(); + $response = ''; + if (!phpcommon\HttpClient::get + ($url, + $params, + $response)) { + myself()->_rspErr(500, 'server internal error'); + die(); + return; + } + error_log($response); + $rspObj = json_decode($response, true); + if ($rspObj['errcode'] == 0) { + myself()->_rspData(array( + 'trans_id' => '', + 'trans_req' => $rspObj['trans_req'] + )); + } else { + myself()->_rspErr(500, 'server internal error'); + return; + } + } + } + + private static function getWeb3ServiceUrl() + { + $web3ServiceCluster = require_once('../config/web3service.cluster.php'); + return $web3ServiceCluster[rand() % count($web3ServiceCluster)]; + } + +} diff --git a/webapp/models/Hero.php b/webapp/models/Hero.php index cdb3932f..7430d483 100644 --- a/webapp/models/Hero.php +++ b/webapp/models/Hero.php @@ -72,6 +72,22 @@ class Hero extends BaseModel { return self::internalFind($accountId, User::findUserAddress($accountId), $heroUniId); } + public static function findByAccountIdEx($accountId, $heroUniId) + { + $row = SqlHelper::ormSelectOne( + myself()->_getMysql($accountId), + 't_hero', + array( + 'idx' => $heroUniId, + 'account_id' => $accountId, + ) + ); + if ($row) { + $row['hero_uniid'] = $row['idx']; + } + return $row; + } + public static function findByTokenId($tokenId) { $row = SqlHelper::ormSelectOne( @@ -671,18 +687,17 @@ class Hero extends BaseModel { } } - public static function safeUpdateTokenId($heroUniId, $tokenId) + public static function safeUpdateTokenId($accountId, $heroUniId, $tokenId) { - if (self::find($heroUniId)) { - myself()->_getSelfMysql()->execScript( - 'UPDATE t_hero SET token_id=:token_id ' . - 'WHERE idx=:idx AND token_id IS NULL;', - array( - ':idx' => $heroUniId, - ':token_id' => $tokenId, - ) - ); - } + myself()->_getMysql($accountId)->execScript( + 'UPDATE t_hero SET token_id=:token_id ' . + 'WHERE idx=:idx AND account_id=:account_id AND token_id IS NULL;', + array( + ':idx' => $heroUniId, + ':account_id' => $accountId, + ':token_id' => $tokenId, + ) + ); } public static function updateByTokenId($tokenId, $fieldsKv) From 203b393c8927debf20344c68742f537cd7dc80a5 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Wed, 17 Jul 2024 23:52:43 +0800 Subject: [PATCH 6/7] 1 --- webapp/controller/BaseAuthedController.class.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/webapp/controller/BaseAuthedController.class.php b/webapp/controller/BaseAuthedController.class.php index e515ca5d..2f38a71c 100644 --- a/webapp/controller/BaseAuthedController.class.php +++ b/webapp/controller/BaseAuthedController.class.php @@ -88,8 +88,9 @@ class BaseAuthedController extends BaseController { // } // } if (SERVER_ENV == _ONLINE) { - //phpcommon\sendError(1001, 'session expiration'); - //die(); + phpcommon\sendError(1001, 'session expiration'); + die(); + return; } $this->accountId = getReqVal('account_id', ''); $this->sessionId = getReqVal('session_id', ''); From f7768927b5a8a57176be32772380919d93bf9dda Mon Sep 17 00:00:00 2001 From: hujiabin <519660157@qq.com> Date: Thu, 18 Jul 2024 11:21:30 +0800 Subject: [PATCH 7/7] HERO SKIN --- doc/HeroSkin.py | 74 +++++++ doc/Other.py | 4 +- doc/_common.py | 11 +- sql/gamedb.sql | 13 +- sql/gamedb2006_migrate_240710_01.sql | 6 +- webapp/controller/BattleController.class.php | 2 +- webapp/controller/HeroController.class.php | 44 ---- .../controller/HeroSkinController.class.php | 155 +++++++++++++ webapp/controller/OtherController.class.php | 29 +++ webapp/controller/RankingController.class.php | 3 +- webapp/models/Hero.php | 20 +- webapp/models/HeroSkin.php | 205 +++++++++--------- webapp/models/User.php | 4 +- webapp/mt/DressAttribute.php | 20 ++ webapp/services/ShopService.php | 15 -- 15 files changed, 418 insertions(+), 187 deletions(-) create mode 100644 doc/HeroSkin.py create mode 100644 webapp/controller/HeroSkinController.class.php create mode 100644 webapp/mt/DressAttribute.php diff --git a/doc/HeroSkin.py b/doc/HeroSkin.py new file mode 100644 index 00000000..2a93d32c --- /dev/null +++ b/doc/HeroSkin.py @@ -0,0 +1,74 @@ +# -*- coding: utf-8 -*- + +import _common + +class HeroSkin(object): + + def __init__(self): + self.apis = [ + { + 'name': 'skinList', + 'desc': '皮肤列表', + 'group': 'HeroSkin', + 'url': 'webapp/index.php?c=HeroSkin&a=skinList', + 'params': [ + _common.ReqHead(), + ['skin_id', 0, '皮肤itemId'], + ], + 'response': [ + _common.RspHead(), + ['!skin_list', [_common.HeroSkin()], '英雄皮肤列表'] + ] + },{ + 'name': 'skinDetails', + 'desc': '皮肤详情', + 'group': 'HeroSkin', + 'url': 'webapp/index.php?c=HeroSkin&a=skinDetails', + 'params': [ + _common.ReqHead(), + ['skin_uniid', 0, '皮肤uniid'], + ], + 'response': [ + _common.RspHead(), + ['data', _common.HeroSkin(), '皮肤详情'] + ] + },{ + 'name': 'takeonSkin', + 'desc': '皮肤穿戴', + 'group': 'HeroSkin', + 'url': 'webapp/index.php?c=HeroSkin&a=takeonSkin', + 'params': [ + _common.ReqHead(), + ['hero_uniid', 0, '英雄uniid'], + ['skin_uniid', 0, '皮肤uniid'], + ], + 'response': [ + _common.RspHead(), + ] + },{ + 'name': 'demountSkin', + 'desc': '皮肤卸下', + 'group': 'HeroSkin', + 'url': 'webapp/index.php?c=HeroSkin&a=demountSkin', + 'params': [ + _common.ReqHead(), + ['hero_uniid', 0, '英雄uniid'], + ], + 'response': [ + _common.RspHead(), + ] + },{ + 'name': 'synSkin', + 'desc': '皮肤合成', + 'group': 'HeroSkin', + 'url': 'webapp/index.php?c=HeroSkin&a=synSkin', + 'params': [ + _common.ReqHead(), + ['skin_id', 0, '皮肤itemId'], + ], + 'response': [ + _common.RspHead(), + ['property_chg', _common.PropertyChg(), '属性变更'], + ] + }, + ] diff --git a/doc/Other.py b/doc/Other.py index 943df851..15d653f6 100644 --- a/doc/Other.py +++ b/doc/Other.py @@ -11,7 +11,7 @@ class Other(object): 'url': 'webapp/index.php?c=Other&a=tag', 'params': [ _common.ReqHead(), - ['types', '', '红点类型(!!!注意由于红点的计算量较大,最好并发分批取红点状态)","分割 1:英雄 2:芯片 3:背包 4:签到 5:算力'], + ['types', '', '红点类型(!!!注意由于红点的计算量较大,最好并发分批取红点状态)","分割 1:英雄 2:芯片 3:背包 4:签到 5:算力 6:皮肤'], ], 'response': [ _common.RspHead(), @@ -24,7 +24,7 @@ class Other(object): 'url': 'webapp/index.php?c=Other&a=cancelTag', 'params': [ _common.ReqHead(), - ['type', '', '1:英雄 2:芯片 3:背包 5:算力'], + ['type', '', '1:英雄 2:芯片 3:背包 5:算力 6:皮肤'], ['item_unnid', '', 'item_unnid'], ], 'response': [ diff --git a/doc/_common.py b/doc/_common.py index b9fe7529..2bd4eae7 100644 --- a/doc/_common.py +++ b/doc/_common.py @@ -329,9 +329,16 @@ class HeroSkin(object): def __init__(self): self.fields = [ + ['idx', 0, 'uniid'], + ['account_id', 0, 'account_id'], ['skin_id', 0, '英雄皮肤id'], - ['is_have', 0, '是否拥有 1:拥有 0:未拥有'], - ['use_state', 0, '选中状态 1:选中 0:未选中'], + ['hero_uniid', 0, '所穿戴的英雄 0=未穿戴'], + ['skin_state', 0, ' 0=封装,1=解封'], + ['used', 0, ' 0=未使用,1=使用中'], + ['is_old', 0, ' 0:展示红点 1:不用展示'], + ['!rand_attr', [Attr()], ' 战斗属性'], + ['lucky', 0, '幸运值'], + ['wealth', 0, '财富值'], ] class Item(object): diff --git a/sql/gamedb.sql b/sql/gamedb.sql index 18c3530b..fac2b5cc 100644 --- a/sql/gamedb.sql +++ b/sql/gamedb.sql @@ -194,15 +194,18 @@ CREATE TABLE `t_hero_skin` ( `idx` bigint NOT NULL AUTO_INCREMENT COMMENT '自增id', `account_id` varchar(60) CHARACTER SET utf8 NOT NULL COMMENT 'account_id', `skin_id` int(11) NOT NULL DEFAULT '0' COMMENT '英雄皮肤id', - `hero_id` int(11) NOT NULL DEFAULT '0' COMMENT '英雄id', - `skin_state` int(11) NOT NULL DEFAULT '0' COMMENT '英雄皮肤状态 0=已经购,1 = 试用状态', + `hero_uniid` int(11) NOT NULL DEFAULT '0' COMMENT '英雄uniid', + `skin_state` int(11) NOT NULL DEFAULT '0' COMMENT '英雄皮肤状态 0=封装,1=解封', + `used` int(11) NOT NULL DEFAULT '0' COMMENT '使用状态 0=未使用,1=使用中', `get_from` int(11) NOT NULL DEFAULT '0' COMMENT '获得方式 0 = 系统赠送 1 = 金币购买', `consume_num` int(11) NOT NULL DEFAULT '0' COMMENT '消耗货币的具体数量', `try_expire_at` int(11) NOT NULL DEFAULT '0' COMMENT '试用截止时间', + `rand_attr` mediumblob COMMENT '随机属性', + `wealth_attr` mediumblob COMMENT '财富值属性', + `is_old` tinyint(4) NOT NULL DEFAULT '0' COMMENT '0:展示红点 1:不用展示 ', `createtime` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间', `modifytime` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间', - PRIMARY KEY (`idx`), - UNIQUE KEY `account_id_skinid` (`account_id`, `skin_id`) + PRIMARY KEY (`idx`) ) ENGINE=InnoDB AUTO_INCREMENT=10000 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; /*!40101 SET character_set_client = @saved_cs_client */; @@ -1885,4 +1888,4 @@ CREATE TABLE `t_server_task_battle_count` ( `createtime` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间', `modifytime` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间', PRIMARY KEY (`idx`) -) ENGINE=InnoDB AUTO_INCREMENT=10000 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; +) ENGINE=InnoDB AUTO_INCREMENT=10000 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; diff --git a/sql/gamedb2006_migrate_240710_01.sql b/sql/gamedb2006_migrate_240710_01.sql index cd4852ce..2261fc62 100644 --- a/sql/gamedb2006_migrate_240710_01.sql +++ b/sql/gamedb2006_migrate_240710_01.sql @@ -7,7 +7,7 @@ CREATE TABLE `t_hero_skin` ( `idx` bigint NOT NULL AUTO_INCREMENT COMMENT '自增id', `account_id` varchar(60) CHARACTER SET utf8 NOT NULL COMMENT 'account_id', `skin_id` int(11) NOT NULL DEFAULT '0' COMMENT '英雄皮肤id', - `hero_id` int(11) NOT NULL DEFAULT '0' COMMENT '英雄id', + `hero_uniid` int(11) NOT NULL DEFAULT '0' COMMENT '英雄uniid', `skin_state` int(11) NOT NULL DEFAULT '0' COMMENT '英雄皮肤状态 0=封装,1=解封', `used` int(11) NOT NULL DEFAULT '0' COMMENT '使用状态 0=未使用,1=使用中', `get_from` int(11) NOT NULL DEFAULT '0' COMMENT '获得方式 0 = 系统赠送 1 = 金币购买', @@ -15,10 +15,10 @@ CREATE TABLE `t_hero_skin` ( `try_expire_at` int(11) NOT NULL DEFAULT '0' COMMENT '试用截止时间', `rand_attr` mediumblob COMMENT '随机属性', `wealth_attr` mediumblob COMMENT '财富值属性', + `is_old` tinyint(4) NOT NULL DEFAULT '0' COMMENT '0:展示红点 1:不用展示 ', `createtime` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间', `modifytime` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间', - PRIMARY KEY (`idx`), - UNIQUE KEY `account_id_skinid` (`account_id`, `skin_id`) + PRIMARY KEY (`idx`) ) ENGINE=InnoDB AUTO_INCREMENT=10000 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; insert into version (version) values(2024052101); diff --git a/webapp/controller/BattleController.class.php b/webapp/controller/BattleController.class.php index d9f38e77..b8673ac8 100644 --- a/webapp/controller/BattleController.class.php +++ b/webapp/controller/BattleController.class.php @@ -1013,7 +1013,7 @@ class BattleController extends BaseAuthedController { $info['is_valid_battle'] = 1; $info['hero_dto'] = Hero::toDto($heroDb); {//选用皮肤id - $skinDb = HeroSkin::findBx($heroDb['hero_id']); + $skinDb = HeroSkin::find($heroDb['skin_id']); if ($skinDb){ $info['hero_dto']['skin_id'] = $skinDb['skin_id']; } diff --git a/webapp/controller/HeroController.class.php b/webapp/controller/HeroController.class.php index 265a7cb7..a10c9edd 100644 --- a/webapp/controller/HeroController.class.php +++ b/webapp/controller/HeroController.class.php @@ -79,50 +79,6 @@ class HeroController extends BaseAuthedController { )); } - public function skinList() - { - $heroId = getReqVal('hero_id',0); - if (!$heroId){ - $this->_rspErr(1, "param null"); - return; - } - $itemMeta = \mt\Item::get($heroId); - if (!$itemMeta || $itemMeta['type']!=\mt\Item::HERO_TYPE){ - $this->_rspErr(1, "param error"); - return; - } - $skinList = array(); - $skinMeta = \mt\Item::getMetaListByType(\mt\Item::HERO_SKIN_TYPE); - if ($skinMeta){ - foreach ($skinMeta as $value){ - if ($value['playerid'] == $heroId){ - array_push($skinList,HeroSkin::toDto($value)); - } - } - } - $this->_rspData(array( - 'skin_list' => $skinList - )); - } - - public function takeonSkin() - { - $heroUniId = getReqVal('hero_uniid', 0); - $skinId = getReqVal('skin_id', 0); - $heroDb = Hero::find($heroUniId); - $heroSkinDb = HeroSkin::find($skinId); - if (!$heroDb) { - $this->_rspErr(1, "You don't have the hero yet"); - return; - } - $itemMeta = \mt\Item::get($skinId); - if ($itemMeta['isdefaultskin'] != 1 && !$heroSkinDb) { - $this->_rspErr(2, "You don't have the skin yet"); - return; - } - HeroSkin::takeonSkin( $skinId,$heroDb['hero_id']); - $this->_rspOk(); - } /* 升阶预览 diff --git a/webapp/controller/HeroSkinController.class.php b/webapp/controller/HeroSkinController.class.php new file mode 100644 index 00000000..6f8152b3 --- /dev/null +++ b/webapp/controller/HeroSkinController.class.php @@ -0,0 +1,155 @@ +_rspErr(1, 'skin_id error'); + return; + } + $skinList = array(); + HeroSkin::getSkinList($skinId,function ($row) use(&$skinList) { + array_push($skinList, $row); + }); + $this->_rspData(array( + 'skin_list' => $skinList + )); + } + + public function skinDetails() + { + $skinUniid = trim(getReqVal('skin_uniid', 0)); + if ( ! $skinUniid) { + $this->_rspErr(1, 'Please enter instructions'); + return; + } + $heroSkinDb = HeroSkin::find($skinUniid); + if (! $heroSkinDb){ + $this->_rspErr(1, "You don't have the hero yet"); + return; + } + $skin = HeroSkin::toDto($heroSkinDb); + $this->_rspData(array( + 'data' => $skin + )); + } + + public function takeonSkin() + { + $heroUniid = getReqVal('hero_uniid', 0); + $skinUniid = getReqVal('skin_uniid', 0); + $heroDb = Hero::find($heroUniid); + $heroSkinDb = HeroSkin::find($skinUniid); + if (!$heroDb) { + $this->_rspErr(1, "You don't have the hero yet"); + return; + } + if (!$heroSkinDb) { + $this->_rspErr(1, "You don't have the hero skin yet"); + return; + } + if ($heroDb['skin_id']){ + HeroSkin::update($heroDb['skin_id'],array( + 'used'=>HeroSkin::NO_USE, + 'hero_uniid'=>0, + 'modifytime'=>myself()->_getNowTime(), + )); + } + Hero::update($heroUniid,array( + 'skin_id' => $skinUniid, + 'modifytime'=>myself()->_getNowTime() + )); + HeroSkin::update($skinUniid,array( + 'used'=>HeroSkin::USED, + 'skin_state'=>HeroSkin::NO_LOCK, + 'hero_uniid'=>$heroUniid, + 'modifytime'=>myself()->_getNowTime(), + )); + $this->_rspOk(); + } + + public function demountSkin(){ + $heroUniid = getReqVal('hero_uniid', 0); + $heroDb = Hero::find($heroUniid); + if (!$heroDb) { + $this->_rspErr(1, "You don't have the hero yet"); + return; + } + if (!$heroDb['skin_id']){ + $this->_rspErr(1, "Useless operation"); + return; + } + Hero::update($heroUniid,array( + 'skin_id' => 0, + 'modifytime'=>myself()->_getNowTime() + )); + HeroSkin::update($heroDb['skin_id'],array( + 'used'=>HeroSkin::NO_USE, + 'skin_state'=>HeroSkin::NO_LOCK, + 'hero_uniid'=>0, + 'modifytime'=>myself()->_getNowTime(), + )); + $this->_rspOk(); + } + + public function synSkin(){ + $skinId = trim(getReqVal('skin_id', 0)); + $itemMeta = \mt\Item::get($skinId); + if ($itemMeta['type'] != \mt\Item::HERO_SKIN_TYPE){ + $this->_rspErr(1, 'skin_id error'); + return; + } + $dressMeta = mt\DressAttribute::get($skinId); + if (!$dressMeta){ + $this->_rspErr(1, 'skin_id error'); + return; + } + $needItem = explode(':',$dressMeta['needItem']); + $costItems = array( + array( + 'item_id' => $needItem[0], + 'item_num' => $needItem[1] + ), + ); + $lackItem = null; + if (!$this->_hasEnoughItems($costItems, $lackItem)) { + $this->_rspErr(3, $this->_getLackItemErrMsg($lackItem)); + return; + } + $this->_decItems($costItems); + $propertyChgService = new services\PropertyChgService(); + $propertyChgService->addBagChg(); + HeroSkin::addSkin($itemMeta); + $lastIdx = SqlHelper::getLastInsertId( myself()->_getSelfMysql()); + $skinDb = HeroSkin::find($lastIdx); + $propertyChgService->addHeroSkinChg(); + $event = array( + 'ID' => 'heroSkin', + 'SUB_ID' => 'synthesis', + 'SUB_KEY' => 'heroSkin_synthesis', + 'cost_fragment' => $costItems, + 'result' => 1, + 'outcome_skin' => $skinDb, + ); + LogService::burialPointEvent($event); + $this->_rspData(array( + 'property_chg' => $propertyChgService->toDto(), + )); + } +} diff --git a/webapp/controller/OtherController.class.php b/webapp/controller/OtherController.class.php index 95af1ee8..b629d701 100644 --- a/webapp/controller/OtherController.class.php +++ b/webapp/controller/OtherController.class.php @@ -20,6 +20,7 @@ require_once('models/RewardsCec.php'); require_once('models/GlobalData.php'); require_once('models/HashRate.php'); require_once('models/Hero.php'); +require_once('models/HeroSkin.php'); require_once('models/Chip.php'); require_once('models/Bag.php'); @@ -32,6 +33,7 @@ use models\RewardsCec; use models\GlobalData; use models\HashRate; use models\Hero; +use models\HeroSkin; use models\Chip; use models\Bag; @@ -41,6 +43,7 @@ class OtherController extends BaseAuthedController { const BAG = 3; const SIGN = 4; const HASH_RATE = 5; + const HERO_SKIN = 6; public function tag() { @@ -117,6 +120,20 @@ class OtherController extends BaseAuthedController { 'state' => $state, )); } + break; + case self::HERO_SKIN :{ + $res = myself()->_getSelfMysql()->execQueryOne("SELECT COUNT(idx) as totalNum FROM t_hero_skin WHERE account_id=:account AND is_old=:is_old LIMIT 1",array( + 'account' => myself()->_getAccountId(), + 'is_old' => 0, + )); + if ($res['totalNum']){ + $state = 1; + } + array_push($list,array( + 'type' => self::HERO_SKIN, + 'state' => $state, + )); + } } } @@ -182,6 +199,18 @@ class OtherController extends BaseAuthedController { } } break; + case self::HERO_SKIN :{ + $skinDb = HeroSkin::find($unnid); + if (!$skinDb){ + $this->_rspErr(1, 'param item_unnid error'); + return; + } + HeroSkin::update($unnid,array( + 'is_old' => 1 + )); + $propertyChgService->addHeroSkinChg(); + } + break; default:{ $this->_rspErr(4, 'param type error'); return; diff --git a/webapp/controller/RankingController.class.php b/webapp/controller/RankingController.class.php index 10c28643..654547c1 100644 --- a/webapp/controller/RankingController.class.php +++ b/webapp/controller/RankingController.class.php @@ -127,8 +127,7 @@ class RankingController extends BaseAuthedController { $heroDb = Hero::findByAccountId($row['account_id'],$row['hero_id']); if ($heroDb){ - $heroItemId = $heroDb['hero_id']; - $skinDb = HeroSkin::findByAccountId($row['account_id'],$heroItemId); + $skinDb = HeroSkin::findByAccountId($row['account_id'],$heroDb['skin_id']); $hero_skin = $skinDb ? $skinDb['skin_id']:0; } diff --git a/webapp/models/Hero.php b/webapp/models/Hero.php index cdb3932f..c6c3869d 100644 --- a/webapp/models/Hero.php +++ b/webapp/models/Hero.php @@ -258,7 +258,7 @@ class Hero extends BaseModel { if ($row['idx'] == $userDb['hero_id'] && self::findByAccountId(myself()->_getAccountId(),$userDb['hero_id'])){ $isSelect = 1; } - $skinDb = HeroSkin::findBx($row['hero_id']); + $skinDb = HeroSkin::find($row['skin_id']); // $attribute = self::celHeroWealthUpLimit($row); { $heroMeta = \mt\Item::get($row['hero_id']); @@ -381,6 +381,15 @@ class Hero extends BaseModel { } } } + if ($row['skin_id']){ + $skinDb= HeroSkin::find($row['skin_id']); + $skinAttrs = emptyReplace(json_decode($skinDb['wealth_attr'], true), array()); + $skinResult = \mt\EconomyAttribute::getAttrValue($skinAttrs); + $wealth += $skinResult['wealth']; + $wealth_rate += $skinResult['wealth_rate']; + $lucky += $skinResult['lucky']; + $lucky_rate += $skinResult['lucky_rate']; + } return array( "wealth" => floor($wealth * (1+$wealth_rate)), "lucky" => floor($lucky * (1+$lucky_rate)), @@ -584,14 +593,7 @@ class Hero extends BaseModel { public static function internalAddHero($conn, $heroMeta, $accountId, $tokenId,$quality = 1) { - $skinItemMeta = \mt\Item::getMetaListByType(\mt\Item::HERO_SKIN_TYPE); - if ($skinItemMeta){ - foreach ($skinItemMeta as $value){ - if ($value['playerid'] == $heroMeta['id'] && $value['isdefaultskin'] ==1){ - HeroSkin::addSkin($value); - } - } - } + $randAttr = self::getRandAttr($heroMeta['id']) ; $attribute = \mt\EconomyAttribute::getAttribute($heroMeta['relationship'], $quality); $seal_type = 0; diff --git a/webapp/models/HeroSkin.php b/webapp/models/HeroSkin.php index 5cb12459..942378b0 100644 --- a/webapp/models/HeroSkin.php +++ b/webapp/models/HeroSkin.php @@ -3,97 +3,28 @@ namespace models; require_once('mt/Hero.php'); +require_once('mt/DressAttribute.php'); +require_once('mt/BattleRandAttribute.php'); +require_once('mt/EconomyAttribute.php'); use mt; use phpcommon\SqlHelper; class HeroSkin extends BaseModel { - const GETED_STATE = 0; - const TRY_USING_STATE = 1; + const USED = 1; + const NO_USE = 0; - public static function find($skinId) - { - $row = SqlHelper::ormSelectOne( - myself()->_getSelfMysql(), - 't_hero_skin', - array( - 'account_id' => myself()->_getAccountId(), - 'skin_id' => $skinId - ) - ); - return $row; - } + const LOCK = 0; + const NO_LOCK = 1; - public static function findBx($heroId) - { - $row = SqlHelper::ormSelectOne( - myself()->_getSelfMysql(), - 't_hero_skin', - array( - 'account_id' => myself()->_getAccountId(), - 'hero_id' => $heroId - ) - ); - return $row; - } - public static function findByAccountId($accountId, $heroId) - { - $row = SqlHelper::ormSelectOne( - myself()->_getSelfMysql(), - 't_hero_skin', - array( - 'account_id' => $accountId, - 'hero_id' => $heroId - ) - ); - return $row; - } - - public static function takeonSkin($skinId,$heroId){ - $row = self::findBx($heroId); - SqlHelper::update( - myself()->_getSelfMysql(), - 't_hero_skin', - array( - 'account_id' => myself()->_getAccountId(), - 'skin_id' => $row['skin_id'] - ), - array( - 'hero_id'=>0 - ) - ); - SqlHelper::upsert( - myself()->_getSelfMysql(), - 't_hero_skin', - array( - 'account_id' => myself()->_getAccountId(), - 'skin_id' => $skinId - ), - array( - 'hero_id'=>$heroId - ), - array( - 'account_id' => myself()->_getAccountId(), - 'skin_id' => $skinId, - 'skin_state' => 0, - 'get_from' => 0, - 'consume_num' => 0, - 'try_expire_at' => 0, - 'hero_id' => $heroId, - 'createtime' => myself()->_getNowTime(), - 'modifytime' => myself()->_getNowTime() - ) - ); - } - - - public static function getSkinList($cb){ + public static function getSkinList($skinId,$cb){ SqlHelper::ormSelect( myself()->_getSelfMysql(), 't_hero_skin', array( - 'account_id' => myself()->_getAccountId() + 'account_id' => myself()->_getAccountId(), + 'skin_id' => $skinId ), function ($row) use($cb) { $cb($row); @@ -101,51 +32,121 @@ class HeroSkin extends BaseModel { ); } - - public static function toDto($meta) + public static function find($uniid) { - $row = self::find($meta['id']); - $is_have = 0; - $use_state = 0; - if ($row || $meta['isdefaultskin'] == 1){ - $is_have = 1; + $row = SqlHelper::ormSelectOne( + myself()->_getSelfMysql(), + 't_hero_skin', + array( + 'idx' => $uniid, + ) + ); + if ($row && $row['account_id'] != myself()->_getAccountId()) { + $row = null; } - if ($row && $row['hero_id']){ - $use_state = 1; + return $row; + } + + public static function findByAccountId($accountId, $uniid) + { + $row = SqlHelper::ormSelectOne( + myself()->_getSelfMysql(), + 't_hero_skin', + array( + 'idx' => $uniid, + ) + ); + if ($row && $row['account_id'] != $accountId) { + $row = null; } + return $row; + } + + public static function update($skinUniid,$fieldsKv){ + if (self::find($skinUniid)){ + SqlHelper::update( + myself()->_getSelfMysql(), + 't_hero_skin', + array( + 'idx' => $skinUniid, + ), + $fieldsKv + ); + } + } + + public static function toDto($row) + { + $attr = emptyReplace(json_decode($row['rand_attr'], true), array()); + return array( - 'skin_id'=>$meta['id'], - 'is_have' => $is_have, - 'use_state' => $use_state, + 'idx' => $row['idx'], + 'skin_uniid' => $row['idx'], + 'account_id' => $row['account_id'], + 'skin_id' => $row['skin_id'], + 'hero_uniid' => $row['hero_uniid'], + 'skin_state' => $row['skin_state'], + 'used' => $row['used'], + 'is_old' => $row['is_old'], + 'rand_attr' => $attr, + 'lucky' => self::getSkinLucky($row), + 'wealth' => self::getSkinWealth($row), ); } public static function addSkin($itemMeta) { - $heroId = 0; - if ($itemMeta['isdefaultskin'] == 1){ - $heroId = $itemMeta['playerid']; + $rand_attr = array(); + $wealth_attr = array(); + $dressMeta = mt\DressAttribute::get($itemMeta['id']); + if ($dressMeta) { + $randMeta = mt\BattleRandAttribute::getByWeight($dressMeta['battleAttribute']); + $rand_attr = mt\BattleRandAttribute::getRandAttr($randMeta); + $wealth_attr = \mt\EconomyAttribute::getAttribute($dressMeta['economyAttribute'], 1); } - SqlHelper::upsert( + SqlHelper::insert( myself()->_getSelfMysql(), 't_hero_skin', - array( - 'account_id' => myself()->_getAccountId(), - 'skin_id' => $itemMeta['id'] - ), - array(), array( 'account_id' => myself()->_getAccountId(), 'skin_id' => $itemMeta['id'], - 'skin_state' => 0, + 'skin_state' => self::LOCK, + 'used' => self::NO_USE, 'get_from' => 0, 'consume_num' => 0, 'try_expire_at' => 0, - 'hero_id' => $heroId, + 'rand_attr' => json_encode($rand_attr), + 'wealth_attr' => json_encode($wealth_attr), 'createtime' => myself()->_getNowTime(), 'modifytime' => myself()->_getNowTime() ) ); } + public static function getSkinWealth($row){ + return self::celEconomyAttribute($row)["wealth"]; + } + + public static function getSkinLucky($row){ + return self::celEconomyAttribute($row)["lucky"]; + } + + private static function celEconomyAttribute($row){ + + //最大财富值和幸运值计算 + $wealth = 0; + $wealth_rate = 0; + $lucky = 0; + $lucky_rate = 0; + $heroAttrs = emptyReplace(json_decode($row['wealth_attr'], true), array()); + $heroResult = \mt\EconomyAttribute::getAttrValue($heroAttrs); + $wealth += $heroResult['wealth']; + $wealth_rate += $heroResult['wealth_rate']; + $lucky += $heroResult['lucky']; + $lucky_rate += $heroResult['lucky_rate']; + return array( + "wealth" => floor($wealth * (1+$wealth_rate)), + "lucky" => floor($lucky * (1+$lucky_rate)), + ); + } } diff --git a/webapp/models/User.php b/webapp/models/User.php index 3c5df268..1a51bc90 100644 --- a/webapp/models/User.php +++ b/webapp/models/User.php @@ -212,7 +212,7 @@ class User extends BaseModel { $heroId = $heroDb['hero_id']; } $preset = HeroPreset::getHeroPreset($row['hero_id']); - $skinDb = HeroSkin::findBx($heroId); + $skinDb = HeroSkin::find($heroDb['skin_id']); $honorInfo = array(); if ($row['address']){ $honorInfo = UserHonor::info($row['address']); @@ -236,7 +236,7 @@ class User extends BaseModel { 'parachute' => $row['parachute'] ? $row['parachute'] : Parachute::$parachute, 'hero_uniId' => $row['hero_id'], 'hero_id' => $heroId, - 'hero_skin' =>$skinDb['skin_id'], + 'hero_skin' =>$skinDb ? $skinDb['skin_id']:0, 'hero_lv' =>$heroDb['hero_lv'], 'presetInfo' => $preset, 'is_leader' => 0, diff --git a/webapp/mt/DressAttribute.php b/webapp/mt/DressAttribute.php new file mode 100644 index 00000000..311ac9e5 --- /dev/null +++ b/webapp/mt/DressAttribute.php @@ -0,0 +1,20 @@ +