This commit is contained in:
hujiabin 2024-01-25 16:04:16 +08:00
parent 388b493b02
commit 2cb9bc1bc8
8 changed files with 109 additions and 684 deletions

View File

@ -42,7 +42,6 @@ define('TN_TOTAL_RANK_NUM', 8015);
define('TN_TOTAL_DIAMOND_CONSUME', 8016);//钻石消耗
define('TN_TOTAL_CEG_CONSUME', 8017);//ceg消耗
define('TN_TOTAL_GATHER_GOLD', 8018);//收集金币
define('TN_SERVER_TASK_STATE', 8080);//服务器大事件状态 14v4 2吃鸡
define('TN_DAILY_BEGIN', 9001);
define('TN_DAILY_LOGINS', 9001);

View File

@ -55,234 +55,6 @@ class FragmentController extends BaseAuthedController
));
}
private function _verificationFragment($itemId,$type,$sub_type){
$itemMetaParam = mt\Item::get($itemId);
if (!$itemMetaParam){
$this->_rspErr(1,'param error ' .$itemId);
die;
}
if ($itemMetaParam['type'] != $type||
$itemMetaParam['sub_type'] != $sub_type){
$this->_rspErr(1,'param error (type) '.$itemId);
die;
}
$itemNum = Bag::getItemCount($itemId);
if ($itemNum < 1){
$this->_rspErr(1,'Insufficient quantity '.$itemId.' Number:'.$itemNum);
die;
}
}
public function syntheticFragmentOld(){
$type = getReqVal('type', 0);
$params = getReqVal('params','');
$param = getReqVal('param','');
$item_id = getReqVal('item_id','');
$paramArr = explode('|',$params);
if (count($paramArr) != 8){
$this->_rspErr(1,'Insufficient number of parameters');
return ;
}
switch ($type) {
case 1:
{
$meta = mt\Parameter::getByName('jigsaw_merge_h_price');
$mint = $meta ? $meta['param_value'] : 100;
if ($param){
//指定合成英雄
$itemMeta = mt\Item::get($item_id);
if (!$itemMeta){
$this->_rspErr(1,'item_id param error ' . $item_id);
return ;
}
if ($itemMeta['type'] != \mt\Item::HERO_TYPE){
$this->_rspErr(1,'item_id param error (type)' . $item_id);
return ;
}
$this->_verificationFragment($param,\mt\Item::FRAGMENT_TYPE,\mt\Item::HERO_FRAGMENT_SUBTYPE_PRO);
// $itemMetaParam = mt\Item::get($param);
// if (!$itemMetaParam){
// $this->_rspErr(1,'param error');
// return ;
// }
// if ($itemMetaParam['type'] != \mt\Item::FRAGMENT_TYPE ||
// $itemMetaParam['sub_type'] != \mt\Item::HERO_FRAGMENT_SUBTYPE_PRO){
// $this->_rspErr(1,'param error (type)');
// return ;
// }
// $itemNum = Bag::getItemCount($param);
// if ($itemNum < 1){
// $this->_rspErr(1,'Insufficient quantity '.$param);
// return ;
// }
$decItems = array();
array_push($decItems,$param);
foreach ($paramArr as $val){
$this->_verificationFragment($val,\mt\Item::FRAGMENT_TYPE,\mt\Item::HERO_FRAGMENT_SUBTYPE);
array_push($decItems,$val);
}
$costItems = array(
array(
'item_id' => V_ITEM_GOLD,
'item_num' => $mint
)
);
$lackItem = null;
if (!$this->_hasEnoughItems($costItems, $lackItem)) {
$this->_rspErr(3, $this->_getLackItemErrMsg($lackItem));
return;
}
//销毁碎片
foreach ($decItems as $item){
Bag::decItem($item,1);
}
$this->_decItems($costItems);
//生成英雄
Hero::addHero($itemMeta);
$propertyChgService = new services\PropertyChgService();
$propertyChgService->addUserChg();
$propertyChgService->addBagChg();
$propertyChgService->addHeroChg();
$this->_rspData(array(
'property_chg' => $propertyChgService->toDto(),
'item_id' => $itemMeta['id']
));
}else{
//随机合成英雄
$decItems = array();
foreach ($paramArr as $val){
$this->_verificationFragment($val,\mt\Item::FRAGMENT_TYPE,\mt\Item::HERO_FRAGMENT_SUBTYPE);
array_push($decItems,$val);
}
$costItems = array(
array(
'item_id' => V_ITEM_GOLD,
'item_num' => $mint
)
);
$lackItem = null;
if (!$this->_hasEnoughItems($costItems, $lackItem)) {
$this->_rspErr(3, $this->_getLackItemErrMsg($lackItem));
return;
}
//销毁碎片
foreach ($decItems as $item){
Bag::decItem($item,1);
}
$this->_decItems($costItems);
$itemMetaList = mt\Item::getMetaListByType(mt\Item::HERO_TYPE);
$key = rand(0,count($itemMetaList)-1);
$itemMeta = $itemMetaList[$key];
//生成英雄
Hero::addHero($itemMeta);
$propertyChgService = new services\PropertyChgService();
$propertyChgService->addUserChg();
$propertyChgService->addBagChg();
$propertyChgService->addHeroChg();
$this->_rspData(array(
'property_chg' => $propertyChgService->toDto(),
'item_id' => $itemMeta['id']
));
}
}
break;
case 2:
{
$meta = mt\Parameter::getByName('jigsaw_merge_w_price');
$mint = $meta ? $meta['param_value'] : 20;
if ($param){
//指定合成枪械
$itemMeta = mt\Item::get($item_id);
if (!$itemMeta){
$this->_rspErr(1,'item_id param error '. $item_id);
return ;
}
if ($itemMeta['type'] != \mt\Item::GUN_TYPE){
$this->_rspErr(1,'item_id param error (type) ' . $item_id);
return ;
}
$this->_verificationFragment($param,\mt\Item::FRAGMENT_TYPE,\mt\Item::GUN_FRAGMENT_SUBTYPE_PRO);
$decItems = array();
array_push($decItems,$param);
foreach ($paramArr as $val){
$this->_verificationFragment($val,\mt\Item::FRAGMENT_TYPE,\mt\Item::GUN_FRAGMENT_SUBTYPE);
array_push($decItems,$val);
}
$costItems = array(
array(
'item_id' => V_ITEM_GOLD,
'item_num' => $mint
)
);
$lackItem = null;
if (!$this->_hasEnoughItems($costItems, $lackItem)) {
$this->_rspErr(3, $this->_getLackItemErrMsg($lackItem));
return;
}
//销毁碎片
foreach ($decItems as $item){
Bag::decItem($item,1);
}
$this->_decItems($costItems);
//生成武器
Gun::addGun($itemMeta);
$propertyChgService = new services\PropertyChgService();
$propertyChgService->addUserChg();
$propertyChgService->addBagChg();
$propertyChgService->addGunChg();
$this->_rspData(array(
'property_chg' => $propertyChgService->toDto(),
'item_id' => $itemMeta['id']
));
}else{
//随机合成枪械
$decItems = array();
foreach ($paramArr as $val){
$this->_verificationFragment($val,\mt\Item::FRAGMENT_TYPE,\mt\Item::GUN_FRAGMENT_SUBTYPE);
array_push($decItems,$val);
}
$costItems = array(
array(
'item_id' => V_ITEM_GOLD,
'item_num' => $mint
)
);
$lackItem = null;
if (!$this->_hasEnoughItems($costItems, $lackItem)) {
$this->_rspErr(3, $this->_getLackItemErrMsg($lackItem));
return;
}
//销毁碎片
foreach ($decItems as $item){
Bag::decItem($item,1);
}
$this->_decItems($costItems);
$itemMetaList = mt\Item::getMetaListByType(mt\Item::GUN_TYPE);
$key = rand(0,count($itemMetaList)-1);
$itemMeta = $itemMetaList[$key];
//生成枪械
Gun::addGun($itemMeta);
$propertyChgService = new services\PropertyChgService();
$propertyChgService->addUserChg();
$propertyChgService->addBagChg();
$propertyChgService->addGunChg();
$this->_rspData(array(
'property_chg' => $propertyChgService->toDto(),
'item_id' => $itemMeta['id']
));
}
}
break;
default:
{
$this->_rspErr(1, 'type parameter error');
return;
}
}
}
public function showBaseByItemId(){
$item_id = getReqVal('item_id','');
$itemMeta = mt\Item::get($item_id);

View File

@ -19,30 +19,38 @@ class HashRateController extends BaseAuthedController
public function info(){
$mateList = \mt\AchievementsPower::getMetaList();
$currentPeriod= \mt\AchievementsCycle::getPeriod();
$hashRateDtoList = array();
foreach ($mateList as $mate) {
$temp = $this->hashRateService->hashRateTaskDto($mate ,$currentPeriod);
array_push($hashRateDtoList, $temp);
$currentPeriod= \mt\AchievementsCycle::getCurrentPeriod();
$info = array(
'list' => array(),
'obtain_start_time' => 0,
'obtain_end_time' => 0,
'income_start_time' => 0,
'income_end_time' => 0,
'state' => 0,
'myHashRate' => 0,
);
if ($currentPeriod){
foreach ($mateList as $mate) {
$temp = $this->hashRateService->hashRateTaskDto($mate ,$currentPeriod);
array_push($info['list'], $temp);
}
$obtain_start_time = strtotime($currentPeriod['obtain_start_time']);
$obtain_end_time = strtotime($currentPeriod['obtain_end_time']);
$income_start_time = strtotime($currentPeriod['income_start_time']);
$income_end_time = strtotime($currentPeriod['income_end_time']);
$info['obtain_start_time'] = $obtain_start_time;
$info['obtain_end_time'] = $obtain_end_time;
$info['income_start_time'] = $income_start_time;
$info['income_end_time'] = $income_end_time;
if(myself()->_getNowTime() >= $obtain_start_time && myself()->_getNowTime() <= $obtain_end_time){
$info['state'] = 1;
}elseif (myself()->_getNowTime() >= $income_start_time && myself()->_getNowTime() <= $income_end_time){
$info['state'] = 2;
}
$info['myHashRate'] = HashRate::getMyHashRate( $currentPeriod['id']);
}
$obtain_start_time = strtotime($currentPeriod['obtain_start_time']);
$obtain_end_time = strtotime($currentPeriod['obtain_end_time']);
$income_end_time = strtotime($currentPeriod['income_end_time']);
$state = 0;
if(myself()->_getNowTime() >= $obtain_start_time && myself()->_getNowTime() <= $obtain_end_time){
$state = 1;
}elseif ($obtain_end_time < myself()->_getNowTime()){
$state = 2;
}
$myHashRate = HashRate::getMyHashRate($currentPeriod['id']);
$this->_rspData(array(
'list' => $hashRateDtoList,
'obtain_start_time' => $obtain_start_time,
'obtain_end_time' => $obtain_end_time,
'income_end_time' => $income_end_time,
'state' => $state,
'myHashRate' => $myHashRate,
));
$this->_rspData($info);
}
}

View File

@ -201,134 +201,6 @@ class HeroController extends BaseAuthedController {
));
}
/*
升级预览
*/
public function upgradeLevelPreview(){
$heroUniId = getReqVal('hero_uniid', 0);
$heroDb = Hero::find($heroUniId);
if (!$heroDb) {
$this->_rspErr(1, 'hero does not exist');
return;
}
$heroMeta = mt\Hero::get($heroDb['hero_id']);
if (!$heroMeta) {
$this->_rspErr(100, 'server internal error');
return;
}
$nextLevelMeta = mt\HeroLevel::getByLevel($heroDb['hero_lv'] + 1);
if (!$nextLevelMeta) {
$this->_rspErr(5, "It's already the highest level");
return;
}
$costItems = array(
array(
'item_id' => V_ITEM_GOLD,
'item_num' => $nextLevelMeta['gold']
),
array(
'item_id' => V_ITEM_HERO_META,
'item_num' => $nextLevelMeta['serum']
)
);
// $metaList = mt\Item::getMetaListByType(mt\Item::FRAGMENT_TYPE);
// foreach ($metaList as $meta){
// if ($meta['relationship'] == $heroDb['hero_id']) {
// array_push($costItems,array(
// 'item_id' => $meta['id'],
// 'item_num' => $nextLevelMeta['piece'],
// ));
// }
// }
$heroDto = Hero::toDto($heroDb);
$newHeroDto = $heroDto;
$newHeroDto['hero_lv'] += 1;
$attrs_new = Hero::nextLvAttr($heroDb);
$newHeroDto['rand_attr'] = $attrs_new;
$this->_rspData(array(
'old_hero' => $heroDto,
'new_hero' => $newHeroDto,
'cost' => $costItems
));
}
/*
英雄升级
*/
public function upgradeLvNew()
{
return
$heroUniId = getReqVal('hero_uniid', 0);
$heroDb = Hero::find($heroUniId);
$oldHero = Hero::toDto($heroDb);
if (!$heroDb) {
$this->_rspErr(100, 'param error or null');
return;
}
$heroMeta = mt\Hero::get($heroDb['hero_id']);
if (!$heroMeta) {
$this->_rspErr(100, 'server internal error');
return;
}
$nextLevelMeta = mt\HeroLevel::getByLevel($heroDb['hero_lv'] + 1);
if (!$nextLevelMeta) {
$this->_rspErr(5, "It's already the highest level");
return;
}
$costItems = array(
array(
'item_id' => V_ITEM_GOLD,
'item_num' => $nextLevelMeta['gold']
),
array(
'item_id' => V_ITEM_HERO_META,
'item_num' => $nextLevelMeta['serum']
),
);
$lackItem = null;
if (!$this->_hasEnoughItems($costItems, $lackItem)) {
$this->_rspErr(3, $this->_getLackItemErrMsg($lackItem));
return;
}
$this->_decItems($costItems);
// Bag::decItem(V_ITEM_HERO_META,$nextLevelMeta['serum']);
{
//埋点
$event = [
'name' => LogService::HERO_LEVEL_UP,
'val' => $nextLevelMeta['gold']
];
LogService::consumeGold($event);
}
$attrs = Hero::LvUpAddAttr($heroDb);
Hero::update($heroUniId, array(
'hero_lv' => $heroDb['hero_lv'] + 1,
'rand_attr' => json_encode($attrs['rand_attr']),
'base_attr' => json_encode($attrs['base_attr']),
//'state' => Hero::GETED_STATE,
));
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();
$propertyChgService->addBagChg();
$this->_rspData(array(
'property_chg' => $propertyChgService->toDto(),
'old_hero' => $oldHero,
'new_hero' => $newHero,
));
}
/*
英雄预设
*/

View File

@ -128,14 +128,6 @@ class UserController extends BaseAuthedController {
'item_id' => V_ITEM_STAR,
'item_num' => 400
));
$itemIds = array(30100,30200,30300,30400,30500,30600,30700,30800,30900,31000,40702,40902,40102);
foreach ($itemIds as $row){
array_push($addItems,
array(
'item_id' => $row,
'item_num' => 1
));
}
}
$awardService = new services\AwardService();

View File

@ -226,32 +226,6 @@ class Hero extends BaseModel {
public static function toDto($row)
{
$attr = emptyReplace(json_decode($row['rand_attr'], true), array());
if (!$attr){
/*
$heroMeta = mt\Hero::get($row['hero_id']);
$baseAttr = mt\Hero::getHeroAttr($heroMeta);
foreach ($baseAttr as $value){
if (in_array($value['attr_id'],array(kHAT_Hp,kHAT_Atk,kHAT_Def))){
array_push($attr,array(
'attr_id' => $value['attr_id'],
'val' => $value['val'] ,
'quality' => rand(2,3),
)
);
}else{
array_push($attr,array(
'attr_id' => $value['attr_id'],
'val' => $value['val'] ,
'quality' => 0,
)
);
}
}*/
$attr = self::getRandAttr($row['hero_id'], 0);
self::update($row['idx'],array(
'rand_attr'=>json_encode($attr)
));
}
// $lockType = 0;
// $unlockTime = 0;
@ -469,39 +443,10 @@ class Hero extends BaseModel {
myself()->_getSelfMysql(),
$heroMeta,
myself()->_getAccountId(),
null,
self::TYPE_FREE);
null
);
}
public static function addHero1($heroMeta)
{
return self::internalAddHero(
myself()->_getSelfMysql(),
$heroMeta,
myself()->_getAccountId(),
null,
self::TYPE_1);
}
public static function addHero2($heroMeta)
{
return self::internalAddHero(
myself()->_getSelfMysql(),
$heroMeta,
myself()->_getAccountId(),
null,
self::TYPE_2);
}
public static function addHero3($heroMeta)
{
return self::internalAddHero(
myself()->_getSelfMysql(),
$heroMeta,
myself()->_getAccountId(),
null,
self::TYPE_3);
}
public static function addHero($heroMeta)
{
@ -509,8 +454,8 @@ class Hero extends BaseModel {
myself()->_getSelfMysql(),
$heroMeta,
myself()->_getAccountId(),
null,
self::TYPE_4);
null
);
}
public static function addNftHero($heroMeta, $tokenId)
@ -519,8 +464,8 @@ class Hero extends BaseModel {
myself()->_getMysql($tokenId),
$heroMeta,
null,
$tokenId,
self::GETED_STATE);
$tokenId
);
}
//添加合成英雄
@ -530,11 +475,11 @@ class Hero extends BaseModel {
$heroMeta,
myself()->_getAccountId(),
null,
self::TYPE_FREE,
$quality );
$quality
);
}
public static function internalAddHero($conn, $heroMeta, $accountId, $tokenId,$type,$quality = 1)
public static function internalAddHero($conn, $heroMeta, $accountId, $tokenId,$quality = 1)
{
$skinItemMeta = \mt\Item::getMetaListByType(\mt\Item::HERO_SKIN_TYPE);
if ($skinItemMeta){
@ -544,15 +489,13 @@ class Hero extends BaseModel {
}
}
}
$state = $type > 0 ? self::GETED_STATE : self::FREE_STATE;
$realHeroMeta = mt\Hero::get($heroMeta['id']);
$randAttr = self::getRandAttr($heroMeta['id'],$type) ;
$randAttr = self::getRandAttr($heroMeta['id']) ;
$fieldsKv = array(
'hero_id' => $heroMeta['id'],
'hero_lv' => 1,
'quality' => $quality,
// 'hero_tili' => FormulaService::Hero_NFT_Maximum_Physical_Strength(1,FormulaService::Hero_Advanced_Lucky_Value(1)),
'state' => $state,
'state' => self::FREE_STATE,
'skill_lv1' => 1,
'skill_lv2' => 1,
'rand_attr' => json_encode($randAttr),
@ -579,99 +522,18 @@ class Hero extends BaseModel {
return true;
}
private static function _getAttrQuality($type){
$quality = 0;
switch ($type){
case self::TYPE_FREE :{
$quality = 1;
}break;
case self::TYPE_1 :{
$paramMeta = mt\Parameter::getVal('small_box_quality',0);
}break;
case self::TYPE_2 :{
$paramMeta = mt\Parameter::getVal('big_box_quality',0);
}break;
case self::TYPE_3 :{
$paramMeta = mt\Parameter::getVal('super_box_quality',0);
}break;
case self::TYPE_4 :{
$paramMeta = mt\Parameter::getVal('buy_hero_quality',0);
}break;
default:{
$quality = 1;
}
}
if (isset($paramMeta)){
$weightArr = explode("|",$paramMeta);
$totalWeight = 0;
foreach ($weightArr as $value){
$weights = explode(":",$value);
$totalWeight += $weights[1];
}
$currWeight = 0;
$rnd = rand() % $totalWeight;
foreach ($weightArr as $value){
$weights = explode(":",$value);
$currWeight += $weights[1];
if ($currWeight > $rnd) {
$quality = $weights[0];
break;
}
}
}
return $quality;
}
private static function getRandAttr($heroId, $type){
private static function getRandAttr($heroId){
$attr = array();
$basicMeta = mt\BattleBasicAttribute::get($heroId);
if ($basicMeta) {
$randMeta = mt\BattleBasicAttribute::get($basicMeta['randomAttribute_Default']);
$randMeta = mt\BattleRandAttribute::getByWeight($basicMeta['randomAttribute_Default']);
if ($randMeta) {
$attr = mt\BattleRandAttribute::getRandAttr($randMeta);
}
}
return $attr;
/*
$heroMeta = mt\Hero::get($heroId);
$baseAttr = mt\Hero::getHeroAttr($heroMeta);
$paramMeta = mt\Parameter::getVal('quality',0);
$attr = array();
if ($paramMeta){
$rate = explode('|',$paramMeta);
foreach ($baseAttr as $value){
if (in_array($value['attr_id'],array(kHAT_Hp,kHAT_Atk,kHAT_Def))){
$quality = self::_getAttrQuality($type);
$minRate = $rate[$quality-1] * 100;
$maxRate = $rate[$quality] * 100 - 1;
if ($quality == 5){
$maxRate = $rate[$quality] * 100;
}
$finalRate = rand($minRate,$maxRate) / 100;
if ( $value['attr_id'] == kHAT_Hp){
$attr_val = round($value['val'] * $finalRate,0);
}else{
$attr_val = round($value['val'] * $finalRate,2);
}
array_push($attr,array(
'attr_id' => $value['attr_id'],
'val' => $attr_val,
'quality' => $quality,
// 'rate' => $finalRate,
)
);
} else {
array_push($attr,array(
'attr_id' => $value['attr_id'],
'val' => $value['val'] ,
'quality' => 0,
)
);
}
}
}
return $attr;*/
}
@ -883,134 +745,4 @@ class Hero extends BaseModel {
return $hero;
}
public static function nextLvAttr($heroDb){ // 165 249 327
$randAttr = emptyReplace(json_decode($heroDb['rand_attr'], true), array());
$heroLevelMeta = \mt\HeroLevel::getByLevel($heroDb['hero_lv']+1);
// $levelAttrMeta= \mt\HeroLevelAttr::find($heroDb['hero_id']);
// $attr= \mt\HeroLevelAttr::addRandAttr($levelAttrMeta,$type);
foreach ($randAttr as &$val){
if (in_array($val['attr_id'],array(
kHAT_Def,
kHAT_Hp,
kHAT_Atk
))){
$temp = $val['val'] * ($heroLevelMeta['promote']+1);
$val['val'] = sprintf("%.2f",substr(sprintf("%.3f", $temp), 0, -1));
}
// if ($val['attr_id'] == kHAT_Def){
// //升级后防御力:上一级防御力*((提升幅度+1^防御力系数)
// $temp = $val['val'] * (pow(($heroLevelMeta['promote']+1),$levelAttrMeta['def_rate']));
//// $temp = $val['val'] * ($heroLevelMeta['promote']+1);
// $val['val'] = sprintf("%.2f",substr(sprintf("%.3f", $temp), 0, -1));
//
// }else if( $val['attr_id'] == kHAT_Hp){
// //升级后生命值:上一级生命值*((提升幅度+1^生命值系数)
// $temp = $val['val'] * (pow(($heroLevelMeta['promote']+1),$levelAttrMeta['hp_rate']));
// $val['val'] = sprintf("%.2f",substr(sprintf("%.3f", $temp), 0, -1));
// }else if( $val['attr_id'] == kHAT_Atk){
// //升级后攻击力:上一级攻击力*((提升幅度+1^攻击力系数)
// $temp = $val['val'] * (pow(($heroLevelMeta['promote']+1),$levelAttrMeta['atk_rate']));
// $val['val'] = sprintf("%.2f",substr(sprintf("%.3f", $temp), 0, -1));
// }
}
return $randAttr;
}
public static function LvUpAddAttr($heroDb){
$heroMeta = mt\Hero::get($heroDb['hero_id']);
$baseAttr = mt\Hero::getHeroAttr($heroMeta);
$attrLv1 = emptyReplace(json_decode($heroDb['base_attr'], true), array());
$randAttr = emptyReplace(json_decode($heroDb['rand_attr'], true), array());
$paramQualityMeta = mt\Parameter::getVal('quality',0);
$heroLevelMeta = \mt\HeroLevel::getByLevel($heroDb['hero_lv']+1);
foreach ($randAttr as &$val){
if (in_array($val['attr_id'],array(
kHAT_Def,
kHAT_Hp,
kHAT_Atk
))){
switch ($val['quality']){
case 1 :{
$paramMeta = mt\Parameter::getVal('d_probability',0);
}break;
case 2 :{
$paramMeta = mt\Parameter::getVal('c_probability',0);
}break;
case 3 :{
$paramMeta = mt\Parameter::getVal('b_probability',0);
}break;
case 4 :{
$paramMeta = mt\Parameter::getVal('a_probability',0);
}break;
default:{
$paramMeta = null;
$temp = $val['val'] * ($heroLevelMeta['promote']+1);
$val['val'] = sprintf("%.2f",substr(sprintf("%.3f", $temp), 0, -1));
}
}
$quality = $val['quality'];
if ($paramMeta){
$weightArr = explode("|",$paramMeta);
$totalWeight = 0;
foreach ($weightArr as $value){
$weights = explode(":",$value);
$totalWeight += $weights[1];
}
$currWeight = 0;
$rnd = rand() % $totalWeight;
foreach ($weightArr as $value){
$weights = explode(":",$value);
$currWeight += $weights[1];
if ($currWeight > $rnd) {
$quality = $weights[0];
break;
}
}
if ($val['quality'] != $quality){
$rate = explode('|',$paramQualityMeta);
$minRate = $rate[$quality-1] * 100;
$maxRate = $rate[$quality] * 100 - 1;
if ($quality == 5){
$maxRate = $rate[$quality] * 100;
}
$finalRate = rand($minRate,$maxRate) / 100;
$tempVal = round(self::_getAttrVal($baseAttr,$val['attr_id']) * $finalRate,2);
$val['quality'] = $quality;
$v = ($tempVal / self::_getAttrVal($attrLv1,$val['attr_id'])) * $val['val'] * (1 + $heroLevelMeta['promote']);
$val['val'] = sprintf("%.2f",substr(sprintf("%.3f", $v), 0, -1));
self::_setAttrVal($attrLv1,$val['attr_id'],array(
'val'=>$tempVal,
'quality'=>$quality,
));
}else{
$temp = $val['val'] * ($heroLevelMeta['promote']+1);
$val['val'] = sprintf("%.2f",substr(sprintf("%.3f", $temp), 0, -1));
}
}
}
}
return array(
'base_attr' => $attrLv1,
'rand_attr' => $randAttr,
);
}
private static function _getAttrVal($baseAttr,$attrId){
$hashAttr = array();
foreach ($baseAttr as $value){
$hashAttr[$value['attr_id']] =$value;
}
return $hashAttr[$attrId]['val'];
}
private static function _setAttrVal(&$baseAttr,$attrId,$attrVal){
foreach ($baseAttr as &$value){
if ($value['attr_id'] == $attrId){
$value['val'] = $attrVal['val'];
$value['quality'] = $attrVal['quality'];
}
}
}
}

View File

@ -11,6 +11,54 @@ class BattleRandAttribute {
return getXVal(self::getMetaList(), $id);
}
public static function getByWeight($invoke){
$metaList = self::getByInvoke($invoke);
$totalWeight = 0;
$randMeta = array();
if ($metaList){
foreach ($metaList as $meta){
$totalWeight += $meta['qualityWeight'];
}
$rnd = rand() % $totalWeight;
$currWeight = 0;
foreach ($metaList as $meta){
$currWeight += $meta['qualityWeight'];
if ($currWeight > $rnd) {
$randMeta = $meta;
break;
}
}
}
return $randMeta;
}
public static function getRandAttr($randMeta){
$attrArray = array();
$strs = explode('|', $randMeta['attributeRange']);
foreach ($strs as $str){
$attrStr = explode(':', $str);
$rnd = rand($attrStr[1]*100000 , $attrStr[2]*100000) / 100000;
$val = $attrStr[1] + ($attrStr[2] - $attrStr[1]) * $rnd;
array_push($attrArray,array(
"attr_id" => $attrStr[0],
"val" => $val,
));
}
return $attrArray;
}
protected static function getByInvoke($invoke){
$metaList = array();
foreach (self::getMetaList() as $meta){
if ($meta['invoke'] == $invoke){
array_push($metaList,$meta);
}
}
return $metaList;
}
protected static function getMetaList()
{
if (!self::$metaList) {

View File

@ -43,8 +43,8 @@ class HashRateService extends BaseService
'modifytime' => myself()->_getNowTime(),
);
}
$currentPeriod= \mt\AchievementsCycle::getPeriod();
if (myself()->_getDaySeconds(getXVal($this->hashRateData, 'modifytime', 0)) <
$currentPeriod= \mt\AchievementsCycle::getCurrentPeriod();
if ($currentPeriod && myself()->_getDaySeconds(getXVal($this->hashRateData, 'modifytime', 0)) <
myself()->_getDaySeconds(strtotime($currentPeriod['obtain_start_time']))) {
$this->hashRateData = array(
'pvpData' => array(),
@ -175,17 +175,19 @@ class HashRateService extends BaseService
if ($taskDto['current'] >= $taskDto['target']) {
$taskDto['current'] = $taskDto['target'];
$taskDto['state'] = self::FINISHED_STATE;
$hashRateDb = HashRate::find($taskMate['id'],$currentPeriod['id']);
if (!$hashRateDb){
$fieldKv = array(
'account_id' => myself()->_getAccountId(),
'task_id' => $taskMate['id'],
'period' => $currentPeriod['id'],
'reward' => $taskMate['Reward_quantity'],
'createtime' => myself()->_getNowTime(),
'modifytime' => myself()->_getNowTime()
);
HashRate::add($fieldKv);
if ($currentPeriod){
$hashRateDb = HashRate::find($taskMate['id'],$currentPeriod['id']);
if (!$hashRateDb){
$fieldKv = array(
'account_id' => myself()->_getAccountId(),
'task_id' => $taskMate['id'],
'period' => $currentPeriod['id'],
'reward' => $taskMate['Reward_quantity'],
'createtime' => myself()->_getNowTime(),
'modifytime' => myself()->_getNowTime()
);
HashRate::add($fieldKv);
}
}
}
return $taskDto;