This commit is contained in:
hujiabin 2022-08-25 14:52:38 +08:00
parent 96307a8297
commit 31d259e1d6
5 changed files with 168 additions and 30 deletions

View File

@ -33,6 +33,19 @@ class Chip(object):
_common.RspHead(),
['!data', [_common.Chip()], '芯片列表']
]
},{
'name': 'chipDetails',
'desc': '芯片详情',
'group': 'Chip',
'url': 'webapp/index.php?c=Chip&a=chipDetails',
'params': [
_common.ReqHead(),
['token_id', '', '芯片token id'],
],
'response': [
_common.RspHead(),
['!data', [_common.Chip()], '芯片信息']
]
},{
'name': 'beforeInlay',
'desc': '芯片镶嵌前置,获取可镶嵌的芯片',

View File

@ -12,7 +12,7 @@ class RspHead(object):
def __init__(self, **kwargs):
self.fields = [
['errcode', 0, '错误码'],
['errcode', 0, '错误码/0 成功1 失败2余额不足'],
['errmsg', '', '错误描述'],
]
for (key, value) in kwargs.items():

View File

@ -555,3 +555,22 @@ CREATE TABLE `t_game_log` (
/*!40101 SET character_set_client = @saved_cs_client */;
-- Dump completed on 2015-08-19 18:51:22
DROP TABLE IF EXISTS `t_nft_active`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `t_nft_active` (
`idx` bigint NOT NULL AUTO_INCREMENT COMMENT '自增id',
`account_id` varchar(60) NOT NULL DEFAULT '' COMMENT '账号id',
`token_id` varchar(255) NOT NULL DEFAULT '' COMMENT 'token id',
`token_type` int(11) NOT NULL DEFAULT '0' COMMENT 'nft类型 1:英雄 2:枪支 3:芯片',
`createtime` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间',
`modifytime` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间',
PRIMARY KEY (`idx`),
UNIQUE KEY `token_id` (`token_id`),
KEY `account_id_token_type` (`account_id`,`token_type`)
) ENGINE=InnoDB AUTO_INCREMENT=10000 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
/*!40101 SET character_set_client = @saved_cs_client */;
-- Dump completed on 2015-08-19 18:51:22

View File

@ -8,6 +8,7 @@ require_once('mt/ChipAttr.php');
require_once('mt/AttrHelper.php');
require_once('services/FormulaService.php');
use models\Chip;
use models\Hero;
use models\Gun;
@ -52,6 +53,27 @@ class ChipController extends BaseAuthedController
));
}
public function chipDetails(){
$token_id = getReqVal('token_id','');
if (! $token_id){
$this->_rspErr(1,'Please enter instructions');
return ;
}
$chip = Chip::getChipByTokenId($token_id);
if ($chip['supper_state'] == 1){
$chip['strength_temporary'] = \services\FormulaService::Hero_Chip_NFT_Maximum_Physical_Strength($chip['chip_grade'],$chip['lucky_temporary']);
$chip['mint'] = \services\FormulaService::Chip_Need_Mint_Cost($chip['chip_grade']);
}
if ($chip['inlay_state'] == 1){
$tili = $chip['strength_max']-$chip['strength'];
$chip['mint'] = \services\FormulaService::Chip_Demount_Mint($tili);
}
$chip = Chip::toDto($chip);
$this->_rspData(array(
'data' => $chip,
));
}
public function beforeInlay(){
$type = getReqVal('type','');
if (! $type){
@ -79,13 +101,17 @@ class ChipController extends BaseAuthedController
return;
}
if ($type == 1){
$this->_doInlayHero($unique_id,$token_id);
if (! $this->_doInlayHero($unique_id,$token_id)){
return;
}
$hero = $this->_inLayNewAttr($unique_id);
$chip_core = $this->_chipCore($unique_id,$type);
$hero['chip_core'] = $chip_core;
$this->_rspData(['data'=>$hero]);
}else{
$this->_doInlayGun($unique_id,$token_id);
if (! $this->_doInlayGun($unique_id,$token_id)){
return;
}
$gun = $this->_inLayNewAttrGun($unique_id);
$chip_core = $this->_chipCore($unique_id,$type);
$gun['chip_core'] = $chip_core;
@ -103,13 +129,17 @@ class ChipController extends BaseAuthedController
return;
}
if ($type == 1){
$this->_doDemount($unique_id,$token_id);
if (!$this->_doDemount($unique_id,$token_id)){
return;
}
$hero = $this->_inLayNewAttr($unique_id);
$chip_core = $this->_chipCore($unique_id,$type);
$hero['chip_core'] = $chip_core;
$this->_rspData(['data'=>$hero]);
}else{
$this->_doDemountGun($unique_id,$token_id);
if (! $this->_doDemountGun($unique_id,$token_id)){
return;
}
$gun = $this->_inLayNewAttrGun($unique_id);
$chip_core = $this->_chipCore($unique_id,$type);
$gun['chip_core'] = $chip_core;
@ -128,15 +158,23 @@ class ChipController extends BaseAuthedController
return;
}
if ($type == 1){
$this->_doDemount($unique_id,$token_id_old);
$this->_doInlayHero($unique_id,$token_id_new);
if (! $this->_doDemount($unique_id,$token_id_old)){
return;
}
if (! $this->_doInlayHero($unique_id,$token_id_new)){
return;
}
$hero = $this->_inLayNewAttr($unique_id);
$chip_core = $this->_chipCore($unique_id,$type);
$hero['chip_core'] = $chip_core;
$this->_rspData(['data'=>$hero]);
}else{
$this->_doDemountGun($unique_id,$token_id_old);
$this->_doInlayGun($unique_id,$token_id_new);
if (! $this->_doDemountGun($unique_id,$token_id_old)){
return;
}
if (! $this->_doInlayGun($unique_id,$token_id_new)){
return;
}
$gun = $this->_inLayNewAttrGun($unique_id);
$chip_core = $this->_chipCore($unique_id,$type);
$gun['chip_core'] = $chip_core;
@ -289,6 +327,7 @@ class ChipController extends BaseAuthedController
$this->_upgraded($chip_main);
$chip_new = Chip::toDto(Chip::getChipByTokenId($token_id_main));
$chip_new['strength_temporary'] = \services\FormulaService::Hero_Chip_NFT_Maximum_Physical_Strength($chip_new['chip_grade'],$chip_new['lucky_temporary']);
$chip_new['mint'] = \services\FormulaService::Chip_Need_Mint_Cost($chip_new['chip_grade']);
$this->_rspData(['data'=>$chip_new]);
}
}
@ -311,6 +350,10 @@ class ChipController extends BaseAuthedController
$mint_cost = \services\FormulaService::Chip_Need_Mint_Cost($chip['chip_grade']);
$userObj = new User();
$user=$userObj->find(myself()->_getAccountId());
if ($mint_cost>$user['gold']){
$this->_rspErr(2, 'Be short of gold coins');
return;
}
User::update(['gold'=>$user['gold']-$mint_cost]);
Chip::update($chip['token_id'],$fieldsKv);
$this->_rspOk();
@ -429,10 +472,24 @@ class ChipController extends BaseAuthedController
}
public function test(){
// $cost = \services\FormulaService::Chip_Need_Mint_Cost(6);
$obg = new User();
$a=$obg->find(myself()->_getAccountId());
print_r($a);
// $a = \services\FormulaService::Do_Demount_Hero_Mint(620.2-612.738994);
// $nft = SqlHelper::ormSelect(
// myself()->_getSelfMysql(),
// 't_nft_active',
// array(
// 'account_id' => myself()->_getAccountId(),
// 'token_type' =>3,
// )
// );
// foreach ($nft as $item){
// $chip = Chip::getChipByTokenId($item['token_id']);
// $Hero_Chip_PSA_Value= \services\FormulaService::Hero_Chip_PSA_Value($chip['chip_grade']);
// $tili = $chip['strength']-$chip['strength_max']*$Hero_Chip_PSA_Value;
// Chip::update($chip['token_id'],['strength'=>$tili]);
// }
// print_r($a);
$this->chipDetails();
}
@ -441,7 +498,7 @@ class ChipController extends BaseAuthedController
$hero = Hero::find($hero_id);
if (! $chip || ! $hero){
$this->_rspErr(1, 'Not enough chip or hero');
return;
return false;
}
if (! $hero['chip_ids']){
$fieldsKv = ['chip_ids'=>$chip['idx']];
@ -458,6 +515,7 @@ class ChipController extends BaseAuthedController
}
Hero::update($hero_id,$fieldsKv);
Chip::updateChipInlayState($token_id,1);
return true;
}
private function _doInlayGun($gun_id,$token_id){
@ -465,7 +523,7 @@ class ChipController extends BaseAuthedController
$gun = Gun::find($gun_id);
if (! $chip || ! $gun){
$this->_rspErr(1, 'Not enough chip or gun');
return;
return false;
}
if (! $gun['chip_ids']){
$fieldsKv = ['chip_ids'=>$chip['idx']];
@ -482,6 +540,7 @@ class ChipController extends BaseAuthedController
}
Gun::update($gun_id,$fieldsKv);
Chip::updateChipInlayState($token_id,1);
return true;
}
private function _doDemount($unique_id,$token_id){
@ -489,14 +548,27 @@ class ChipController extends BaseAuthedController
$hero = Hero::find($unique_id);
if (! $chip || ! $hero){
$this->_rspErr(1, 'Not enough chip or hero');
return;
return false;
}
$chipIdsArr = explode('|',$hero['chip_ids']);
$k = array_search($chip['idx'],$chipIdsArr);
unset($chipIdsArr[$k]);
$fieldsKv = ['chip_ids'=>implode('|',$chipIdsArr)];
$tili = $chip['strength_max']-$chip['strength'];
if ($tili){
$mint = \services\FormulaService::Chip_Demount_Mint($tili);
$userObj = new User();
$user=$userObj->find(myself()->_getAccountId());
if ($mint>$user['gold']){
$this->_rspErr(2, 'Be short of gold coins');
return false;
}
User::update(['gold'=>$user['gold']-$mint]);
}
$where = ['inlay_state'=>0,'strength'=>$chip['strength_max']];
Hero::update($unique_id,$fieldsKv);
Chip::updateChipInlayState($token_id,0);
Chip::update($token_id,$where);
return true;
}
private function _doDemountGun($unique_id,$token_id){
@ -504,14 +576,28 @@ class ChipController extends BaseAuthedController
$gun = Gun::find($unique_id);
if (! $chip || ! $gun){
$this->_rspErr(1, 'Not enough chip or gun');
return;
return false;
}
$chipIdsArr = explode('|',$gun['chip_ids']);
$k = array_search($chip['idx'],$chipIdsArr);
unset($chipIdsArr[$k]);
$fieldsKv = ['chip_ids'=>implode('|',$chipIdsArr)];
$tili = $chip['strength_max']-$chip['strength'];
if ($tili){
$mint = \services\FormulaService::Chip_Demount_Mint($tili);
$userObj = new User();
$user=$userObj->find(myself()->_getAccountId());
if ($mint>$user['gold']){
$this->_rspErr(2, 'Be short of gold coins');
return false;
}
User::update(['gold'=>$user['gold']-$mint]);
}
$where = ['inlay_state'=>0,'strength'=>$chip['strength_max']];
Gun::update($unique_id,$fieldsKv);
Chip::updateChipInlayState($token_id,0);
Chip::update($token_id,$where);
return true;
}
private function _inLayNewAttr($hero_id){

View File

@ -271,18 +271,29 @@ class FormulaService extends BaseService {
return 0;
}
//CEG折扣比率
public static function CEG_Discount_Rate(){
//CEG_Discount_Rate=ROUND(CEG_Dynamic_Index /( CEG_Dynamic_Price / CEG_Base_Price),3)
return 1;
}
//英雄芯片劳力值
public static function Hero_Chip_Labor_Value(){
return 1;
}
//武器芯片劳力值
public static function Weapon_Chip_Labor_Value(){
return 1;
}
//芯片升星累计成本
public static function getChipCumulativeCost($grade){
//( SIGN(芯片星级<6)*(15*芯片星级*(芯片星级-1)+10)+SIGN(芯片星级>5)*SIGN(芯片星级<10)*(80*(芯片星级-4)*( 芯片星级-3)+50) +SIGN(芯片星级>9)*SIGN(芯片星级<14)*(370*(芯片星级-8)*( 芯片星级-7)*(2*芯片星级-15)/6+80*(芯片星级-8)+2100) +SIGN(芯片星级>13)*SIGN(芯片星级<16)*(600*(芯片星级-8)*(芯片星级-7)*(2*芯片星级-15)/6-14000)) *CEG_Discount_Rate
return (($grade<6?1:0)*(15*$grade*($grade-1)+10)+($grade>5?1:0)*($grade<10?1:0)*(80*($grade-4)*( $grade-3)+50) +($grade>9?1:0)*($grade<14?1:0)*(370*($grade-8)*( $grade-7)*(2*$grade-15)/6+80*($grade-8)+2100) +($grade>13?1:0)*($grade<16?1:0)*(600*($grade-8)*($grade-7)*(2*$grade-15)/6-14000)) *self::CEG_Discount_Rate();
//( SIGN(芯片星级<6)*((15*芯片星级+10)*(芯片星级-1)+10)+SIGN(芯片星级>5)*SIGN(芯片星级<10)*(80*(芯片星级-4)*( 芯片星级-3)+90) +SIGN(芯片星级>9)*SIGN(芯片星级<14)*(370*(芯片星级-8)*( 芯片星级-7)*(2*芯片星级-15)/6+80*(芯片星级-8)+2140) +SIGN(芯片星级>13)*SIGN(芯片星级<16)*(600*(芯片星级-8)*(芯片星级-7)*(2*芯片星级-15)/6-13960)) *CEG_Discount_Rate
/* return (($grade<6?1:0)*((15*$grade+10)*($grade-1)+10)+($grade>5?1:0)*($grade<10?1:0)*(80*($grade-4)*($grade-3)+90)+($grade>9?1:0)*($grade<14?1:0)*(370*($grade-8)*($grade-7)*(2*$grade-15)/6+80*($grade-8)+2140)+($grade>13?1:0)*($grade<16?1:0)*(600*($grade-8)*($grade-7)*(2*$grade-15)/6-13960))*self::getCegDiscountRate();*/
// return (($grade<6?1:0)*((15*$grade+10)*($grade-1)+10)+($grade>5?1:0)*($grade<10?1:0)*(80*($grade-4)*($grade-3)+90)+($grade>9?1:0)*($grade<14?1:0)*(370*($grade-8)*($grade-7)*(2*$grade-15)/6+80*($grade-8)+2140)+($grade>13?1:0)*($grade<16?1:0)*(600*($grade-8)*($grade-7)*(2*$grade-15)/6-13960))*self::CEG_Discount_Rate();
}
@ -305,16 +316,6 @@ class FormulaService extends BaseService {
return ($grade>4?1:0)*($lucky*round(1+0.04*$grade,3));
}
//英雄芯片劳力值
public static function Hero_Chip_Labor_Value(){
return 1;
}
//武器芯片劳力值
public static function Weapon_Chip_Labor_Value(){
return 1;
}
//芯片回本周期(参数单位:天)
public static function Chip_Payback_Period($grade){
//ROUND( -0.0095*芯片星数^3+0.0942*芯片星数^2+5.8425*芯片星数+24.7,0)
@ -327,11 +328,30 @@ class FormulaService extends BaseService {
return round(-0.0000507*pow($grade,3)+0.0024*pow($grade,2)-0.0512*$grade+0.785,4);
}
//每日英雄芯片体力值衰减百分比
public static function Hero_Chip_PSA_Value($grand){
//Hero_Chip_PSA_Value=MAX(0,ROUND((Chip_Payback_Period-Chip_Attenuation_Parameter* Hero_Chip_Labor_Value)/((1-Chip_Attenuation_Parameter /2)* Chip_Payback_Period ^2)/ROUND(1+0.04*英雄芯片星数,3),4))*(1+0.1*ROUND(SIN(Hero_Chip_Labor_Value),2))
$num = max(0,round((self::Chip_Payback_Period($grand)-self::Chip_Attenuation_Parameter($grand)*self::Hero_Chip_Labor_Value())/((1-self::Chip_Attenuation_Parameter($grand)/2)*pow(self::Chip_Payback_Period($grand),2))/round(1+0.04*$grand,3),4))*(1+0.1*round(sin(self::Hero_Chip_Labor_Value()),2));
return round($num,5);
}
//每日枪械芯片体力值衰减百分比
public static function Weapon_Chip_DA_Value($grand){
//Weapon_Chip_DA_Value=MAX(0,ROUND((Chip_Payback_Period-Chip_Attenuation_Parameter*Weapon_Chip_Labor_Value)/((1-Chip_Attenuation_Parameter/2)* Chip_Payback_Period^2)/ROUND(1+0.04*武器芯片星数,3),4))*(1+0.1*ROUND(SIN(Weapon_Chip_Labor_Value),2))
$num = max(0,round((self::Chip_Payback_Period($grand)-self::Chip_Attenuation_Parameter($grand)*self::Weapon_Chip_Labor_Value())/((1-self::Chip_Attenuation_Parameter($grand)/2)*pow(self::Chip_Payback_Period($grand),2))/round(1+0.04*$grand,3),4))*(1+0.1*round(sin(self::Weapon_Chip_Labor_Value()),2));
return round($num,5);
}
//芯片升级MINT费用
public static function Chip_Need_Mint_Cost($grand){
// 芯片升星累计MINT成本=(SIGN(chip星级>=5)*SIGN(chip星级<=10)*ROUND(91*chip星级*(chip星级-6.06)/100+1000/100,0)*100+SIGN(chip星级>=11)*SIGN(chip星级<=15)*ROUND(364.29*chip星级*(chip星级-17.847)/100+33446/100,0)*100)*CEG_Discount_Rate
return ($grand>=5?1:0)*($grand<=10?1:0)*round(91*$grand*($grand-6.06)/100+1000/100,0)*100+($grand>=11?1:0)*($grand<=15?1:0)*round(364.29*$grand*($grand-17.847)/100+33446/100,0)*100*self::CEG_Discount_Rate();
}
//芯片NFT拆卸MINT费用
public static function Chip_Demount_Mint($tili){
return round($tili*10*self::CEG_Discount_Rate());
}
}