649 lines
23 KiB
PHP
649 lines
23 KiB
PHP
<?php
|
|
|
|
require_once('models/Chip.php');
|
|
require_once('models/Hero.php');
|
|
require_once('models/Gun.php');
|
|
require_once('mt/ChipAttr.php');
|
|
require_once('mt/AttrHelper.php');
|
|
require_once('services/FormulaService.php');
|
|
|
|
use models\Chip;
|
|
use models\Hero;
|
|
use models\Gun;
|
|
use services\NftService;
|
|
use phpcommon\SqlHelper;
|
|
|
|
class ChipController extends BaseAuthedController
|
|
{
|
|
public function chipList()
|
|
{
|
|
$type = getReqVal('type','');
|
|
if (! $type){
|
|
$this->_rspErr(1,'Please enter instructions');
|
|
return ;
|
|
}
|
|
$chipList = Chip::all($type);
|
|
$chipDtoList = array();
|
|
foreach ($chipList as $item) {
|
|
array_push($chipDtoList, Chip::toDto($item));
|
|
}
|
|
$this->_rspData(array(
|
|
'data' => $chipDtoList,
|
|
));
|
|
}
|
|
|
|
public function chipOrder(){
|
|
$type = getReqVal('type','');
|
|
if (! $type){
|
|
$this->_rspErr(1,'Please enter instructions');
|
|
return ;
|
|
}
|
|
$order = getReqVal('order','asc');
|
|
$chipList = Chip::all($type);
|
|
$chipDtoList = array();
|
|
foreach ($chipList as $item) {
|
|
array_push($chipDtoList, Chip::toDto($item));
|
|
}
|
|
$data = $this->_orderByChip($chipDtoList,$order);
|
|
$this->_rspData(array(
|
|
'data' => $data,
|
|
));
|
|
}
|
|
|
|
public function beforeInlay(){
|
|
$type = getReqVal('type','');
|
|
if (! $type){
|
|
$this->_rspErr(1,'Please enter instructions');
|
|
return ;
|
|
}
|
|
$chipList = Chip::all($type);
|
|
$chipDtoList = array();
|
|
foreach ($chipList as $item) {
|
|
if ($item['supper_state']==0 && $item['inlay_state']==0){
|
|
array_push($chipDtoList, Chip::toDto($item));
|
|
}
|
|
}
|
|
$this->_rspData(array(
|
|
'data' => $chipDtoList,
|
|
));
|
|
}
|
|
|
|
public function inlayChip(){
|
|
$type = trim(getReqVal('type', 0));
|
|
$unique_id = trim(getReqVal('unique_id', 0));
|
|
$token_id = trim(getReqVal('token_id', 0));
|
|
if (!$type || ! $token_id || ! $unique_id) {
|
|
$this->_rspErr(1, 'Please enter instructions');
|
|
return;
|
|
}
|
|
if ($type == 1){
|
|
$this->_doInlayHero($unique_id,$token_id);
|
|
$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);
|
|
$gun = $this->_inLayNewAttrGun($unique_id);
|
|
$chip_core = $this->_chipCore($unique_id,$type);
|
|
$gun['chip_core'] = $chip_core;
|
|
$this->_rspData(['data'=>$gun]);
|
|
}
|
|
|
|
}
|
|
|
|
public function demountChip(){
|
|
$type = trim(getReqVal('type', 0));
|
|
$unique_id = trim(getReqVal('unique_id', 0));
|
|
$token_id = trim(getReqVal('token_id', 0));
|
|
if (!$type || ! $token_id || ! $unique_id) {
|
|
$this->_rspErr(1, 'Please enter instructions');
|
|
return;
|
|
}
|
|
if ($type == 1){
|
|
$this->_doDemount($unique_id,$token_id);
|
|
$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);
|
|
$gun = $this->_inLayNewAttrGun($unique_id);
|
|
$chip_core = $this->_chipCore($unique_id,$type);
|
|
$gun['chip_core'] = $chip_core;
|
|
$this->_rspData(['data'=>$gun]);
|
|
}
|
|
|
|
}
|
|
|
|
public function replaceChip(){
|
|
$type = trim(getReqVal('type', 0));
|
|
$unique_id = trim(getReqVal('unique_id', 0));
|
|
$token_id_new = trim(getReqVal('token_id_new', 0));
|
|
$token_id_old = trim(getReqVal('token_id_old', 0));
|
|
if (! $token_id_new ||! $token_id_old || ! $unique_id || !$type) {
|
|
$this->_rspErr(1, 'Please enter instructions');
|
|
return;
|
|
}
|
|
if ($type == 1){
|
|
$this->_doDemount($unique_id,$token_id_old);
|
|
$this->_doInlayHero($unique_id,$token_id_new);
|
|
$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);
|
|
$gun = $this->_inLayNewAttrGun($unique_id);
|
|
$chip_core = $this->_chipCore($unique_id,$type);
|
|
$gun['chip_core'] = $chip_core;
|
|
$this->_rspData(['data'=>$gun]);
|
|
}
|
|
|
|
}
|
|
|
|
public function aKeyInlayChip(){
|
|
$type = trim(getReqVal('type', 0));
|
|
$unique_id = trim(getReqVal('unique_id', 0));
|
|
if ( ! $type || ! $unique_id) {
|
|
$this->_rspErr(1, 'Please enter instructions');
|
|
return;
|
|
}
|
|
if ($type == 1){
|
|
$hero_or_gun = Hero::find($unique_id);
|
|
}else{
|
|
$hero_or_gun = Gun::find($unique_id);
|
|
}
|
|
|
|
if (! $hero_or_gun){
|
|
$this->_rspErr(1, 'Not enough hero or gun');
|
|
return;
|
|
}
|
|
$limit = 0;
|
|
if (! $hero_or_gun['chip_ids'] ){
|
|
$limit = 4;
|
|
}
|
|
if ($hero_or_gun['chip_ids'] && !strpos($hero_or_gun['chip_ids'], '|')){
|
|
$limit = 3;
|
|
}
|
|
if ($hero_or_gun['chip_ids'] && strpos($hero_or_gun['chip_ids'], '|')){
|
|
$chipIdsArr = explode('|',$hero_or_gun['chip_ids']);
|
|
$limit = 4-count($chipIdsArr);
|
|
}
|
|
|
|
$chipList = Chip::all($type);
|
|
if (! $chipList){
|
|
$this->_rspErr(1, 'Not enough chip');
|
|
return;
|
|
}
|
|
$usable = array();
|
|
foreach ($chipList as $item) {
|
|
if ($item['supper_state']==0 && $item['inlay_state']==0){
|
|
array_push($usable, $item);
|
|
}
|
|
}
|
|
|
|
$res = $this->_getHignGradeLimit($usable,$limit);
|
|
if (! $res){
|
|
$this->_rspErr(1, 'The chip slot is full');
|
|
return;
|
|
}
|
|
if ($type == 1){
|
|
foreach ($res as $val){
|
|
$this->_doInlayHero($unique_id,$val['token_id']);
|
|
}
|
|
$hero_new = $this->_inLayNewAttr($unique_id);
|
|
$chip_core = $this->_chipCore($unique_id,$type);
|
|
$hero_new['chip_core'] = $chip_core;
|
|
$this->_rspData(['data'=>$hero_new]);
|
|
}else{
|
|
foreach ($res as $val){
|
|
$this->_doInlayGun($unique_id,$val['token_id']);
|
|
}
|
|
$gun_new = $this->_inLayNewAttrGun($unique_id);
|
|
$chip_core = $this->_chipCore($unique_id,$type);
|
|
$gun_new['chip_core'] = $chip_core;
|
|
$this->_rspData(['data'=>$gun_new]);
|
|
}
|
|
}
|
|
|
|
public function beforeSynthetic(){
|
|
$token_id = trim(getReqVal('token_id', 0));
|
|
if (! $token_id) {
|
|
$this->_rspErr(1, 'Please enter instructions');
|
|
return;
|
|
}
|
|
$chip = Chip::getChipByTokenId($token_id);
|
|
if ($chip['supper_state'] == 1 || $chip['inlay_state'] == 1 || $chip['state'] == -1){
|
|
$this->_rspErr(1, "The chip can't synthetic");
|
|
return;
|
|
}
|
|
if ($chip['chip_grade'] == 15){
|
|
$this->_rspErr(1, "Chip Lv upper limit");
|
|
return;
|
|
}
|
|
$chip = Chip::toDto($chip);
|
|
foreach ($chip['rand_attr'] as $k=>$val){
|
|
$attr = \mt\ChipAttr::getAttrById($val['attr_id'],$val['chip_type']);
|
|
$chip['rand_attr_after'][$k] =[
|
|
'attr_id'=>$val['attr_id'],
|
|
'type'=>$val['type'],
|
|
'val'=>$attr['lv'.($chip['chip_grade']+1)]*$val['attr_pool_num'],
|
|
'chip_type'=>$val['chip_type']
|
|
];
|
|
}
|
|
$chip['upgrade_cost']=\services\FormulaService::getChipUpgradeCost($chip['chip_grade']+1);
|
|
$this->_rspData(['data'=>$chip]);
|
|
}
|
|
|
|
public function selectChip(){
|
|
$token_id = trim(getReqVal('token_id', 0));
|
|
$token_ids = explode(' ',$token_id);
|
|
if (count($token_ids)<0){
|
|
$this->_rspErr(1, 'Please enter instructions');
|
|
return;
|
|
}
|
|
|
|
|
|
$chip_main = Chip::getChipByTokenId($token_ids[0]);
|
|
$chip_param = Chip::getChipByTokenId($token_ids[1]);
|
|
if ($chip_param['supper_state'] == 1 || $chip_param['inlay_state'] == 1 || $chip_param['state'] == -1){
|
|
$this->_rspErr(1, "The chip can't select");
|
|
return;
|
|
}
|
|
if ($chip_param['chip_grade']>$chip_main['chip_grade']){
|
|
$this->_rspErr(1, "The selected material is too high grade");
|
|
return;
|
|
}
|
|
if ($chip_param['state']){
|
|
Chip::update($token_ids[1],['state'=>0]);
|
|
$cost = 0;
|
|
}else{
|
|
Chip::update($token_ids[1],['state'=>1]);
|
|
$cost = \services\FormulaService::getChipCumulativeCost($chip_param['chip_grade']);
|
|
}
|
|
$this->_rspData(['data'=>$cost]);
|
|
}
|
|
|
|
public function syntheticChip(){
|
|
$token_id_main = trim(getReqVal('token_id_main', 0));
|
|
$token_id_param = explode(' ',getReqVal('token_id_param', 0));
|
|
if (! $token_id_main || count($token_id_param)<=0 ) {
|
|
$this->_rspErr(1, 'Please enter instructions');
|
|
return;
|
|
}
|
|
$chip_main = Chip::getChipByTokenId($token_id_main);
|
|
$upgrade_cost = \services\FormulaService::getChipUpgradeCost($chip_main['chip_grade']+1);
|
|
if ($upgrade_cost==0){
|
|
$this->_rspErr(1, 'Error in calculation formula');
|
|
return;
|
|
}
|
|
$cumulative_cost = 0;
|
|
foreach ($token_id_param as $val){
|
|
$chip_param = Chip::getChipByTokenId($val);
|
|
$cumulative_cost += \services\FormulaService::getChipCumulativeCost($chip_param['chip_grade']);
|
|
Chip::deleteChip(['token_id'=>$val]);
|
|
}
|
|
$num = round(round(($cumulative_cost/$upgrade_cost),5)*10000);
|
|
if ($num<rand(1,10000)){
|
|
//合成失败
|
|
$this->_rspErr(1, 'The chip Upgrade failed');
|
|
return;
|
|
}else{
|
|
//合成成功
|
|
$this->_upgraded($chip_main);
|
|
$chip_new = Chip::toDto(Chip::getChipByTokenId($token_id_main));
|
|
$chip_new['strength_temporary'] = \services\FormulaService::getChipPhysicalStrengthValue($chip_new['chip_grade'],$chip_new['lucky_temporary']);
|
|
$this->_rspData(['data'=>$chip_new]);
|
|
}
|
|
}
|
|
|
|
public function isNeedLucky(){
|
|
$token_id = trim(getReqVal('token_id', 0));
|
|
if (! $token_id) {
|
|
$this->_rspErr(1, 'Please enter instructions');
|
|
return;
|
|
}
|
|
$chip = Chip::getChipByTokenId($token_id);
|
|
$fieldsKv = [
|
|
'lucky_final'=>$chip['lucky_temporary'],
|
|
'lucky_temporary'=>0,
|
|
'strength' => \services\FormulaService::getChipPhysicalStrengthValue($chip['chip_grade'],$chip['lucky_temporary'])
|
|
];
|
|
Chip::update($chip['token_id'],$fieldsKv);
|
|
$this->_rspOk();
|
|
}
|
|
|
|
public function isNotNeedLucky(){
|
|
$token_id = trim(getReqVal('token_id', 0));
|
|
if (! $token_id) {
|
|
$this->_rspErr(1, 'Please enter instructions');
|
|
return;
|
|
}
|
|
$chip = Chip::getChipByTokenId($token_id);
|
|
$fieldsKv = [
|
|
'lucky_temporary'=>0,
|
|
];
|
|
Chip::update($chip['token_id'],$fieldsKv);
|
|
$this->_rspOk();
|
|
}
|
|
|
|
public function waitingLucky(){
|
|
$token_id = trim(getReqVal('token_id', 0));
|
|
if (! $token_id) {
|
|
$this->_rspErr(1, 'Please enter instructions');
|
|
return;
|
|
}
|
|
$chip = Chip::getChipByTokenId($token_id);
|
|
$fieldsKv = [
|
|
'supper_state'=>1,
|
|
];
|
|
Chip::update($chip['token_id'],$fieldsKv);
|
|
$this->_rspOk();
|
|
}
|
|
|
|
public function aKeySynthetic(){
|
|
$token_id = trim(getReqVal('token_id', 0));
|
|
if (! $token_id) {
|
|
$this->_rspErr(1, 'Please enter instructions');
|
|
return;
|
|
}
|
|
$chip = Chip::getChipByTokenId($token_id);
|
|
$upgrade_cost =\services\FormulaService::getChipUpgradeCost($chip['chip_grade']+1); //芯片升星价值
|
|
|
|
$chipList = Chip::all($chip['chip_type']);
|
|
$chipDtoList = array();
|
|
foreach ($chipList as $item) {
|
|
if ($item['supper_state']==0 && $item['inlay_state']==0 && $item['state']==0 && $item['token_id'] != $token_id && $item['chip_grade'] <= $chip['chip_grade']){
|
|
array_push($chipDtoList, $item);
|
|
}
|
|
};
|
|
$data = $this->_orderByChip($chipDtoList,'asc');
|
|
$chip_param = [];
|
|
$chip_param_out = [];
|
|
if (count($data) > 20) {
|
|
$cost = 0;
|
|
for ($i=0;$i<count($data);$i++){
|
|
$data[$i]['cost'] = \services\FormulaService::getChipCumulativeCost($data[$i]['chip_grade']);
|
|
if ($i<20){
|
|
$cost += $data[$i]['cost'];
|
|
array_push($chip_param,$data[$i]);
|
|
}else{
|
|
array_push($chip_param_out,$data[$i]);
|
|
}
|
|
}
|
|
if ($cost>$upgrade_cost){
|
|
$diff_cost = $cost - $upgrade_cost;
|
|
foreach ($chip_param as $k=>$value){
|
|
if ($diff_cost>$value['cost']){
|
|
$diff_cost -= $value['cost'];
|
|
unset($chip_param[$k]);
|
|
}
|
|
}
|
|
}else{
|
|
$chip_param = $this->_bestFun($upgrade_cost,$chip_param,$chip_param_out);
|
|
}
|
|
|
|
}else{
|
|
$cost = 0;
|
|
foreach ($data as $k=>$val){
|
|
$data[$k]['cost'] = \services\FormulaService::getChipCumulativeCost($data[$k]['chip_grade']);
|
|
$cost += $data[$k]['cost'];
|
|
}
|
|
if ($cost > $upgrade_cost){
|
|
$diff_cost = $cost - $upgrade_cost;
|
|
foreach ($data as $k=>$value){
|
|
if ($diff_cost>$value['cost']){
|
|
$diff_cost -= $value['cost'];
|
|
unset($data[$k]);
|
|
}
|
|
}
|
|
}
|
|
$chip_param = $data;
|
|
}
|
|
$cumulative_cost = 0;
|
|
$token_id_arr = [];
|
|
foreach ($chip_param as $value){
|
|
$cumulative_cost += $value['cost'];
|
|
array_push($token_id_arr,$value['token_id']);
|
|
}
|
|
$this->_rspData(['data'=>['cost'=>$cumulative_cost,'token_ids'=>implode(' ',$token_id_arr)]]);
|
|
}
|
|
|
|
|
|
private function _doInlayHero($hero_id,$token_id){
|
|
$chip = Chip::getChipByTokenId($token_id);
|
|
$hero = Hero::find($hero_id);
|
|
if (! $chip || ! $hero){
|
|
$this->_rspErr(1, 'Not enough chip or hero');
|
|
return;
|
|
}
|
|
if (! $hero['chip_ids']){
|
|
$fieldsKv = ['chip_ids'=>$chip['idx']];
|
|
}
|
|
if ($hero['chip_ids'] && !strpos($hero['chip_ids'], '|')){
|
|
$chipIdsArr = [$hero['chip_ids']];
|
|
array_push($chipIdsArr,$chip['idx']);
|
|
$fieldsKv = ['chip_ids'=>implode('|',$chipIdsArr)];
|
|
}
|
|
if ($hero['chip_ids'] && strpos($hero['chip_ids'], '|')){
|
|
$chipIdsArr = explode('|',$hero['chip_ids']);
|
|
array_push($chipIdsArr,$chip['idx']);
|
|
$fieldsKv = ['chip_ids'=>implode('|',$chipIdsArr)];
|
|
}
|
|
Hero::update($hero_id,$fieldsKv);
|
|
Chip::updateChipInlayState($token_id,1);
|
|
}
|
|
|
|
private function _doInlayGun($gun_id,$token_id){
|
|
$chip = Chip::getChipByTokenId($token_id);
|
|
$gun = Gun::find($gun_id);
|
|
if (! $chip || ! $gun){
|
|
$this->_rspErr(1, 'Not enough chip or gun');
|
|
return;
|
|
}
|
|
if (! $gun['chip_ids']){
|
|
$fieldsKv = ['chip_ids'=>$chip['idx']];
|
|
}
|
|
if ($gun['chip_ids'] && !strpos($gun['chip_ids'], '|')){
|
|
$chipIdsArr = [$gun['chip_ids']];
|
|
array_push($chipIdsArr,$chip['idx']);
|
|
$fieldsKv = ['chip_ids'=>implode('|',$chipIdsArr)];
|
|
}
|
|
if ($gun['chip_ids'] && strpos($gun['chip_ids'], '|')){
|
|
$chipIdsArr = explode('|',$gun['chip_ids']);
|
|
array_push($chipIdsArr,$chip['idx']);
|
|
$fieldsKv = ['chip_ids'=>implode('|',$chipIdsArr)];
|
|
}
|
|
Gun::update($gun_id,$fieldsKv);
|
|
Chip::updateChipInlayState($token_id,1);
|
|
}
|
|
|
|
private function _doDemount($unique_id,$token_id){
|
|
$chip = Chip::getChipByTokenId($token_id);
|
|
$hero = Hero::find($unique_id);
|
|
if (! $chip || ! $hero){
|
|
$this->_rspErr(1, 'Not enough chip or hero');
|
|
return;
|
|
}
|
|
$chipIdsArr = explode('|',$hero['chip_ids']);
|
|
$k = array_search($chip['idx'],$chipIdsArr);
|
|
unset($chipIdsArr[$k]);
|
|
$fieldsKv = ['chip_ids'=>implode('|',$chipIdsArr)];
|
|
Hero::update($unique_id,$fieldsKv);
|
|
Chip::updateChipInlayState($token_id,0);
|
|
}
|
|
|
|
private function _doDemountGun($unique_id,$token_id){
|
|
$chip = Chip::getChipByTokenId($token_id);
|
|
$gun = Gun::find($unique_id);
|
|
if (! $chip || ! $gun){
|
|
$this->_rspErr(1, 'Not enough chip or gun');
|
|
return;
|
|
}
|
|
$chipIdsArr = explode('|',$gun['chip_ids']);
|
|
$k = array_search($chip['idx'],$chipIdsArr);
|
|
unset($chipIdsArr[$k]);
|
|
$fieldsKv = ['chip_ids'=>implode('|',$chipIdsArr)];
|
|
Gun::update($unique_id,$fieldsKv);
|
|
Chip::updateChipInlayState($token_id,0);
|
|
}
|
|
|
|
private function _inLayNewAttr($hero_id){
|
|
$hero = Hero::find($hero_id);
|
|
$chipAttr = [];
|
|
if (! $hero['chip_ids'] ){
|
|
return $hero;
|
|
}
|
|
if ($hero['chip_ids'] && !strpos($hero['chip_ids'], '|')){
|
|
$chip =Chip::toDto(Chip::getChipByIdx($hero['chip_ids']));
|
|
foreach ($chip['rand_attr'] as $val){
|
|
array_push($chipAttr,$val);
|
|
}
|
|
}
|
|
if ($hero['chip_ids'] && strpos($hero['chip_ids'], '|')){
|
|
$chipIdsArr = explode('|',$hero['chip_ids']);
|
|
foreach ($chipIdsArr as $val){
|
|
$chip = Chip::toDto(Chip::getChipByIdx($val));
|
|
foreach ($chip['rand_attr'] as $v){
|
|
array_push($chipAttr,$v);
|
|
}
|
|
}
|
|
}
|
|
$hero_attr = emptyReplace(json_decode($hero['rand_attr'], true), array());
|
|
\mt\AttrHelper::mergeAttr($hero_attr,$chipAttr);
|
|
$hero['rand_attr'] = $hero_attr;
|
|
return $hero;
|
|
}
|
|
|
|
private function _inLayNewAttrGun($gun_id){
|
|
$gun = Gun::find($gun_id);
|
|
$chipAttr = [];
|
|
if (! $gun['chip_ids'] ){
|
|
return $gun;
|
|
}
|
|
if ($gun['chip_ids'] && !strpos($gun['chip_ids'], '|')){
|
|
$chip =Chip::toDto(Chip::getChipByIdx($gun['chip_ids']));
|
|
foreach ($chip['rand_attr'] as $val){
|
|
array_push($chipAttr,$val);
|
|
}
|
|
}
|
|
if ($gun['chip_ids'] && strpos($gun['chip_ids'], '|')){
|
|
$chipIdsArr = explode('|',$gun['chip_ids']);
|
|
foreach ($chipIdsArr as $val){
|
|
$chip = Chip::toDto(Chip::getChipByIdx($val));
|
|
foreach ($chip['rand_attr'] as $v){
|
|
array_push($chipAttr,$v);
|
|
}
|
|
}
|
|
}
|
|
$gun_attr = emptyReplace(json_decode($gun['rand_attr'], true), array());
|
|
\mt\AttrHelper::mergeAttr($gun_attr,$chipAttr);
|
|
$gun['rand_attr'] = $gun_attr;
|
|
return $gun;
|
|
}
|
|
|
|
private function _chipCore($unique_id,$type){
|
|
$chipCore = [];
|
|
if ($type==1){
|
|
$hero = Hero::find($unique_id);
|
|
}else{
|
|
$hero = Gun::find($unique_id);
|
|
}
|
|
|
|
if ($hero['chip_ids'] && strpos($hero['chip_ids'], '|')){
|
|
$chipIdsArr = explode('|',$hero['chip_ids']);
|
|
if (count($chipIdsArr) == 4){
|
|
$min = 15;
|
|
foreach ($chipIdsArr as $val){
|
|
$chip = Chip::getChipByIdx($val);
|
|
if ($chip['chip_grade']<$min){
|
|
$min = $chip['chip_grade'];
|
|
}
|
|
}
|
|
$chipCoreList = getMetaTable('chipCore@chipCore.php');
|
|
foreach ($chipCoreList as $val){
|
|
if ($val['chip_core_type']==$type && $val['chip_core_lv']<=$min){
|
|
array_push($chipCore,$val);
|
|
}
|
|
}
|
|
return $chipCore;
|
|
}else{
|
|
return [];
|
|
}
|
|
}else{
|
|
return [];
|
|
}
|
|
}
|
|
|
|
private function _getHignGradeLimit($data,$limit){
|
|
$len = count($data);
|
|
if ($len<=1 || $len<=$limit){
|
|
return $data;
|
|
}
|
|
for ($i = 0; $i < $len - 1; $i++) {
|
|
for ($j = $i + 1; $j < $len; $j++) {
|
|
if ($data[$i]['chip_grade'] < $data[$j]['chip_grade']) {
|
|
$tmp = $data[$i];
|
|
$data[$i] = $data[$j];
|
|
$data[$j] = $tmp;
|
|
}
|
|
}
|
|
}
|
|
return array_slice($data,0,$limit);
|
|
}
|
|
|
|
private function _orderByChip($data,$order){
|
|
$len = count($data);
|
|
if ($len<=1){
|
|
return $data;
|
|
}
|
|
if ($order == 'desc'){
|
|
for ($i = 0; $i < $len - 1; $i++) {
|
|
for ($j = $i + 1; $j < $len; $j++) {
|
|
if ($data[$i]['chip_grade'] < $data[$j]['chip_grade']) {
|
|
$tmp = $data[$i];
|
|
$data[$i] = $data[$j];
|
|
$data[$j] = $tmp;
|
|
}
|
|
}
|
|
}
|
|
}else{
|
|
for ($i = 0; $i < $len - 1; $i++) {
|
|
for ($j = $i + 1; $j < $len; $j++) {
|
|
if ($data[$i]['chip_grade'] > $data[$j]['chip_grade']) {
|
|
$tmp = $data[$i];
|
|
$data[$i] = $data[$j];
|
|
$data[$j] = $tmp;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return $data;
|
|
}
|
|
|
|
private function _upgraded($chip){
|
|
$new_grade = $chip['chip_grade']+1;
|
|
if ($new_grade == 3 || $new_grade == 5){
|
|
Chip::updateRandAttr($chip);
|
|
}
|
|
$lucky = ltrim(\services\FormulaService::getChipLuckyValue($new_grade),'-') ;
|
|
Chip::update($chip['token_id'],['lucky_temporary'=>$lucky, 'chip_grade'=>$new_grade]);
|
|
}
|
|
|
|
private function _bestFun($upgrade_cost,$chip_param,$chip_param_out){
|
|
$cost = 0;
|
|
foreach ($chip_param as $v){
|
|
$cost += $v['cost'];
|
|
};
|
|
if ($cost>$upgrade_cost){
|
|
return $chip_param;
|
|
}else{
|
|
array_shift($chip_param);
|
|
array_push($chip_param,array_shift($chip_param_out));
|
|
return $this->_bestFun($upgrade_cost,$chip_param,$chip_param_out);
|
|
}
|
|
}
|
|
|
|
} |