完成Gun重构
This commit is contained in:
parent
e327bc9687
commit
88a2a920d4
16
doc/Gun.py
16
doc/Gun.py
@ -24,6 +24,8 @@ class Gun(object):
|
||||
'url': 'webapp/index.php?c=Gun&a=skillLvUp',
|
||||
'params': [
|
||||
_common.ReqHead(),
|
||||
['skill_id', 0, '天赋id'],
|
||||
['skill_type_id', 0, '枪支类型'],
|
||||
],
|
||||
'response': [
|
||||
_common.RspHead(),
|
||||
@ -31,7 +33,7 @@ class Gun(object):
|
||||
]
|
||||
},
|
||||
{
|
||||
'desc': 'getGunAndSkinInfo',
|
||||
'desc': '获取枪支和皮肤信息getGunAndSkinInfo',
|
||||
'group': 'Gun',
|
||||
'url': 'webapp/index.php?c=Gun&a=getGunAndSkinInfo',
|
||||
'params': [
|
||||
@ -39,28 +41,36 @@ class Gun(object):
|
||||
],
|
||||
'response': [
|
||||
_common.RspHead(),
|
||||
['!data', _common.GunSkinInfo(), '枪支皮肤信息']
|
||||
]
|
||||
},
|
||||
{
|
||||
'desc': 'equipGunSkin',
|
||||
'desc': '装备枪支皮肤equipGunSkin',
|
||||
'group': 'Gun',
|
||||
'url': 'webapp/index.php?c=Gun&a=equipGunSkin',
|
||||
'params': [
|
||||
_common.ReqHead(),
|
||||
['gun_id', 0, '枪支id'],
|
||||
['skin_id', 0, '皮肤id'],
|
||||
],
|
||||
'response': [
|
||||
_common.RspHead(),
|
||||
['data', _common.GunSkinInfo(), '枪支皮肤信息']
|
||||
]
|
||||
},
|
||||
{
|
||||
'desc': 'buyGunSkin',
|
||||
'desc': '购买枪支皮肤buyGunSkin',
|
||||
'group': 'Gun',
|
||||
'url': 'webapp/index.php?c=Gun&a=buyGunSkin',
|
||||
'params': [
|
||||
_common.ReqHead(),
|
||||
['gun_id', 0, '枪支id'],
|
||||
['skin_id', 0, '皮肤id'],
|
||||
['goodsID', 0, '商品id'],
|
||||
],
|
||||
'response': [
|
||||
_common.RspHead(),
|
||||
['data', _common.GunSkinInfo(), '枪支皮肤信息']
|
||||
]
|
||||
},
|
||||
]
|
||||
|
@ -24,3 +24,11 @@ class GunInfo(object):
|
||||
['skill_id', 0, '技能id'],
|
||||
['skill_lv', 0, '技能等级'],
|
||||
]
|
||||
|
||||
class GunSkinInfo(object):
|
||||
|
||||
def __init__(self):
|
||||
self.fields = [
|
||||
['gun_id', 0, '枪支id'],
|
||||
['skin_id', 0, '皮肤id'],
|
||||
]
|
||||
|
2
third_party/phpcommon
vendored
2
third_party/phpcommon
vendored
@ -1 +1 @@
|
||||
Subproject commit c07d074acbdc49eab57e0eb1f7ae6afa3f1c9ab9
|
||||
Subproject commit c4a249c3d58d01d103351af2ab22c6dd67d15de9
|
@ -93,6 +93,10 @@ define('OFFLINE_TIME_LIMIT', 180); //基础时间上限
|
||||
define('OFFLINE_TIME_UNIT', 181); //金币每次增长的时间
|
||||
define('OFFLINE_REWARD_NUMBER', 182); //单位时间金币增长数量
|
||||
|
||||
define('V_ITEM_GOLD', 10001); //金币
|
||||
define('V_ITEM_DIAMOND', 10003); //钻石
|
||||
define('V_ITEM_LOTTERY', 10007); //点券
|
||||
|
||||
function getConfigBaseDir()
|
||||
{
|
||||
return '../res/';
|
||||
|
@ -44,7 +44,6 @@ class BaseAuthedController extends BaseController {
|
||||
return $registertime;
|
||||
}
|
||||
|
||||
|
||||
protected function getMysql($data)
|
||||
{
|
||||
$mysql_conf = getMysqlConfig(crc32($data));
|
||||
@ -79,22 +78,6 @@ class BaseAuthedController extends BaseController {
|
||||
return $r;
|
||||
}
|
||||
|
||||
protected function rspErr($errno, $errmsg)
|
||||
{
|
||||
echo json_encode(array(
|
||||
'errno' => $errno,
|
||||
'errmsg' => $errmsg
|
||||
));
|
||||
}
|
||||
|
||||
protected function rspOk()
|
||||
{
|
||||
echo json_encode(array(
|
||||
'errno' => 0,
|
||||
'errmsg' => ''
|
||||
));
|
||||
}
|
||||
|
||||
protected function isValidSex($sex)
|
||||
{
|
||||
return in_array($sex, array(0, 1, 2));
|
||||
@ -117,6 +100,7 @@ class BaseAuthedController extends BaseController {
|
||||
}
|
||||
return $row;
|
||||
}
|
||||
|
||||
protected function sendDataToClient($_code,$_msg,$_data)
|
||||
{
|
||||
echo json_encode(array(
|
||||
@ -125,6 +109,7 @@ class BaseAuthedController extends BaseController {
|
||||
'data' => $_data,
|
||||
));
|
||||
}
|
||||
|
||||
protected function getItem($itemId)
|
||||
{
|
||||
$row = phpcommon\SqlHelper::selectOne
|
||||
@ -146,6 +131,44 @@ class BaseAuthedController extends BaseController {
|
||||
'item_num' => $row['num']
|
||||
);
|
||||
}
|
||||
|
||||
protected function getItemCount($itemId, $userInfo)
|
||||
{
|
||||
switch ($itemId) {
|
||||
case V_ITEM_GOLD:
|
||||
{
|
||||
return $userInfo['coin_num'];
|
||||
}
|
||||
break;
|
||||
case V_ITEM_DIAMOND:
|
||||
{
|
||||
return $userInfo['diamond_num'];
|
||||
}
|
||||
break;
|
||||
case V_ITEM_LOTTERY:
|
||||
{
|
||||
return $userInfo['rmb_num'];
|
||||
}
|
||||
break;
|
||||
default:
|
||||
{
|
||||
$row = phpcommon\SqlHelper::selectOne
|
||||
($this->getSelfMysql(),
|
||||
'bag',
|
||||
array(
|
||||
'id',
|
||||
'num'
|
||||
),
|
||||
array(
|
||||
'id' => $itemId,
|
||||
'accountid' => $this->getAccountId()
|
||||
));
|
||||
return $row ? $row['num'] : 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
protected function isVirtualItem($itemId)
|
||||
{
|
||||
$isVirtualItem = false;
|
||||
@ -348,5 +371,46 @@ class BaseAuthedController extends BaseController {
|
||||
}
|
||||
return $code;
|
||||
}
|
||||
|
||||
|
||||
protected function getTalentLv($skillId, $skillTypeId)
|
||||
{
|
||||
$row = phpcommon\SqlHelper::selectOne
|
||||
(
|
||||
$this->getSelfMysql(),
|
||||
'gun_intensify',
|
||||
array(
|
||||
'gun_type_id',
|
||||
'skill_id',
|
||||
'skill_lv'
|
||||
),
|
||||
array(
|
||||
'accountid' => $this->getAccountId(),
|
||||
'skill_id' => $skillId,
|
||||
'gun_type_id' => $skillTypeId
|
||||
)
|
||||
);
|
||||
return $row ? $row['skill_iv'] : 0;
|
||||
}
|
||||
|
||||
protected function hasEnoughItemsEx($items, &$lackItem)
|
||||
{
|
||||
$userInfo = $this->getUserInfo(array(
|
||||
'coin_num',
|
||||
'diamond_num',
|
||||
'rmb_num'
|
||||
));
|
||||
foreach ($items as $item) {
|
||||
$inventory = $this->getItemCount($item['item_id'], $userInfo);
|
||||
if ($inventory < $item['item_num']) {
|
||||
$lackItem = array(
|
||||
'item_id' => $item['item_id'],
|
||||
'item_num' => $item['item_num'],
|
||||
'inventory' => $inventory
|
||||
);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
<?php
|
||||
|
||||
require_once('mt/NewShop.php');
|
||||
require_once('mt/GunTalentLv.php');
|
||||
require_once('mt/GunTalent.php');
|
||||
|
||||
class GunController extends BaseAuthedController {
|
||||
|
||||
@ -8,333 +10,283 @@ class GunController extends BaseAuthedController {
|
||||
{
|
||||
$data = array();
|
||||
phpcommon\SqlHelper::select
|
||||
(
|
||||
$this->getSelfMysql(),
|
||||
'gun_intensify',
|
||||
array(
|
||||
'gun_type_id',
|
||||
'skill_id',
|
||||
'skill_lv'
|
||||
),
|
||||
array(
|
||||
'accountid' => $this->getAccountId()
|
||||
),
|
||||
function ($row) use(&$data) {
|
||||
array_push($data, array(
|
||||
'gun_type_id' => $row['gun_type_id'],
|
||||
'skill_id' => $row['skill_id'],
|
||||
'skill_lv' => $row['skill_lv'],
|
||||
));
|
||||
}
|
||||
($this->getSelfMysql(),
|
||||
'gun_intensify',
|
||||
array(
|
||||
'gun_type_id',
|
||||
'skill_id',
|
||||
'skill_lv'
|
||||
),
|
||||
array(
|
||||
'accountid' => $this->getAccountId()
|
||||
),
|
||||
function ($row) use(&$data) {
|
||||
array_push($data, array(
|
||||
'gun_type_id' => $row['gun_type_id'],
|
||||
'skill_id' => $row['skill_id'],
|
||||
'skill_lv' => $row['skill_lv'],
|
||||
));
|
||||
}
|
||||
);
|
||||
$this->rspData($data);
|
||||
}
|
||||
|
||||
public function skillLvUp()
|
||||
{
|
||||
$code = 100;
|
||||
$skillLv = 1;
|
||||
$skillLvData = 0;
|
||||
$account_id = $_REQUEST['account_id'];
|
||||
//$skil
|
||||
$skill_id = $_REQUEST['skill_id'];
|
||||
$skill_type_id = $_REQUEST['skill_type_id'];
|
||||
$gunSkillCfg = require('../res/guntalentlv@guntalentlv.php');
|
||||
$skillCfg = null;
|
||||
if($gunSkillCfg[$skill_id])
|
||||
{
|
||||
$skillCfg = $gunSkillCfg[$skill_id];
|
||||
$conn = $this->getMysql($account_id);
|
||||
$sqlStr3 = "SELECT skill_lv FROM gun_intensify WHERE accountid=:accountid AND gun_type_id=:gun_type_id AND skill_id=:skill_id";
|
||||
$row = $conn->execQuery($sqlStr3,array(':accountid' => $account_id,':gun_type_id' => $skill_type_id,':skill_id' => $skill_id));
|
||||
|
||||
if($row)
|
||||
{
|
||||
$skillLvData = 1;
|
||||
$skillLv = $row[0]["skill_lv"];
|
||||
//error_log("查询到gunSkill=====".json_encode($row));
|
||||
}
|
||||
else
|
||||
{
|
||||
//error_log("未查询到gunSkill=====");
|
||||
}
|
||||
$talentId = $_REQUEST['skill_id'];
|
||||
$gunTypeId = $_REQUEST['skill_type_id'];
|
||||
$talentLvMeta = mt\GunTalentLv::get($talentId);
|
||||
if (!$talentLvMeta) {
|
||||
$this->rspErr(99, "技能不存在");
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
$code = 99;//技能不存在
|
||||
$gunTalentMeta = mt\GunTalentLv::get($gunTypeId);
|
||||
if (!$gunTalentMeta) {
|
||||
$this->rspErr(1, "参数错误");
|
||||
return;
|
||||
}
|
||||
$itemArr = array();
|
||||
$resultData = null;
|
||||
$lvUpNeedItemArr = array();
|
||||
if($skillCfg)
|
||||
{
|
||||
$needItemStr = $skillCfg["cost"];
|
||||
$needItemArr = explode("|",$needItemStr);
|
||||
$needItemLen = count($needItemArr);
|
||||
for($i = 0;$i < $needItemLen ;$i++)
|
||||
{
|
||||
$tmpStr = $needItemArr[$i];
|
||||
$tmpStrArr = explode(":",$tmpStr);
|
||||
$itemData = array("itemID"=>$tmpStrArr[0],"itemNum"=>$tmpStrArr[1]);
|
||||
array_push($lvUpNeedItemArr,$itemData);
|
||||
}
|
||||
//获得Money和钻石
|
||||
$money = 0;
|
||||
$diamond = 0;
|
||||
$conn = $this->getMysql($account_id);
|
||||
$sqlStr3 = "SELECT coin_num,diamond_num FROM user WHERE accountid=:accountid; ";
|
||||
$row = $conn->execQuery($sqlStr3,array(':accountid' => $account_id));
|
||||
|
||||
if($row)
|
||||
{
|
||||
$money = $row[0]["coin_num"];
|
||||
$diamond = $row[0]["diamond_num"];
|
||||
$leftMoney = $money;
|
||||
$leftDiamond = $diamond;
|
||||
}
|
||||
else
|
||||
{
|
||||
$code = 90;
|
||||
}
|
||||
//获得背包所有道具
|
||||
if($code == 100)
|
||||
{
|
||||
$conn = $this->getMysql($account_id);
|
||||
$sqlStr3 = "SELECT * FROM bag WHERE accountid=:accountid; ";
|
||||
$row = $conn->execQuery($sqlStr3,array(':accountid' => $account_id));
|
||||
|
||||
if($row) {//判断道具是否足够
|
||||
$needItemArrLen = count($lvUpNeedItemArr);
|
||||
$enoughN = 0;
|
||||
$allItemLen = count($row);
|
||||
for($i = 0; $i < $needItemArrLen; $i++)
|
||||
{
|
||||
$tempNeedItemID = $lvUpNeedItemArr[$i]["itemID"];
|
||||
$tempNeedItemNum = $lvUpNeedItemArr[$i]["itemNum"];
|
||||
error_log("技能升级01======".$tempNeedItemID."==".$tempNeedItemNum);
|
||||
if($tempNeedItemID == "10001")
|
||||
{
|
||||
$code = 97;//金币不足
|
||||
if($tempNeedItemNum <= $money)
|
||||
{
|
||||
$code = 100;
|
||||
$leftMoney = $money -$tempNeedItemNum;
|
||||
}
|
||||
}
|
||||
else if($tempNeedItemID == "10003")
|
||||
{
|
||||
$code = 96;//钻石不足
|
||||
if($tempNeedItemNum <= $diamond)
|
||||
{
|
||||
$code = 100;
|
||||
$leftDiamond = $diamond - $tempNeedItemNum;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$code = 95;//道具不足
|
||||
for($j = 0; $j < $allItemLen; $j++)
|
||||
{
|
||||
$bagItemID = $row[$j]["id"];
|
||||
$bagItemNum = $row[$j]["num"];
|
||||
if($tempNeedItemID == $bagItemID)
|
||||
{
|
||||
// error_log("技能升级======".$bagItemID."==".$bagItemNum);
|
||||
if($tempNeedItemNum <= $bagItemNum)
|
||||
{
|
||||
$code = 100;
|
||||
$deleteItem = array("item_id"=>$bagItemID,"item_num"=>$tempNeedItemNum);
|
||||
array_push($itemArr,$deleteItem);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (SERVER_ENV != _ONLINE) {
|
||||
$code = 100;
|
||||
}
|
||||
}
|
||||
if($code != 100)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$code = 90;
|
||||
}
|
||||
}
|
||||
if($code == 100)
|
||||
{
|
||||
if($skillCfg["nextid"] > 0)
|
||||
{
|
||||
$skillLv ++;
|
||||
}
|
||||
else
|
||||
{
|
||||
$code = 98;//已经升到最大级
|
||||
}
|
||||
}
|
||||
if($code == 100)
|
||||
{
|
||||
$this->decItem($itemArr);
|
||||
$this->updateCurrency($leftMoney,$leftDiamond);
|
||||
$tempItemData = array("skill_type_id"=>$skill_type_id,"skill_id"=>$skill_id,"skill_lv"=>$skillLv);
|
||||
$this->updateGunSkillIntensify($tempItemData);
|
||||
$resultData = array("skill_type_id"=>$skill_type_id,"skill_id"=>$skill_id,"skill_lv"=>$skillLv);
|
||||
}
|
||||
//error_log("GunTest3======".$skill_id."==".$skill_type_id);
|
||||
if (!mt\GunTalentLv::isValidTalent($gunTypeId, $talentId)) {
|
||||
$this->rspErr(1, "参数错误");
|
||||
return;
|
||||
}
|
||||
$this->sendDataToClient($code,"gunSkillLvUp",$resultData);
|
||||
//$conn = $this->getMysql($account_id);
|
||||
}
|
||||
private function updateCurrency($_money,$_diamond)
|
||||
{
|
||||
$account_id = $_REQUEST['account_id'];
|
||||
$conn = $this->getMysql($account_id);
|
||||
|
||||
$sqlStr2 = "Update user set coin_num =:coin_num,diamond_num =:diamond_num WHERE accountid=:accountid ";
|
||||
$row = $conn->execQuery($sqlStr2,array(':accountid' => $account_id,':coin_num' => $_money,':diamond_num' => $_diamond));
|
||||
|
||||
}
|
||||
private function updateGunSkillIntensify($item)
|
||||
{
|
||||
phpcommon\SqlHelper::insertOrUpdate
|
||||
($this->getSelfMysql(),
|
||||
'gun_intensify',
|
||||
array(
|
||||
'accountid' => $this->getAccountId(),
|
||||
'gun_type_id' => $item['skill_type_id'],
|
||||
'skill_id' => $item['skill_id']
|
||||
),
|
||||
array(
|
||||
'accountid' => $this->getAccountId(),
|
||||
'gun_type_id' => $item['skill_type_id'],
|
||||
'skill_id' => $item['skill_id'],
|
||||
'skill_lv' =>$item['skill_lv'],
|
||||
'createtime' => $this->getNowTime(),
|
||||
'modifytime' => $this->getNowTime()
|
||||
),
|
||||
array(
|
||||
'skill_lv' => $item['skill_lv'],
|
||||
'modifytime' => $this->getNowTime()
|
||||
)
|
||||
$talentLv = $this->getTalentLv($talentId, $gunTypeId);
|
||||
if (mt\GunTalentLv::isFullLv($talentLvMeta, $talentLv)) {
|
||||
$this->rspErr(98, "已满级");
|
||||
return;
|
||||
}
|
||||
$nextLvMeta = mt\GunTalentLv::getByLv($meta, $talentLv + 1);
|
||||
if (!$nextLvMeta) {
|
||||
$this->rspErr(2, "配置表错误");
|
||||
return;
|
||||
}
|
||||
$costList = mt\GunTalentLv::getCostList($nextLvMeta);
|
||||
$lackItem = array();
|
||||
if (!$this->hasEnoughItemsEx($costItem, $lackItem)) {
|
||||
switch ($lackItem['item_id']) {
|
||||
case V_ITEM_GOLD:
|
||||
{
|
||||
$this->rspErr(97, "金币不足");
|
||||
}
|
||||
break;
|
||||
case V_ITEM_DIAMOND:
|
||||
{
|
||||
$this->rspErr(96, "钻石不足");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
{
|
||||
$this->rspErr(95, "道具不足");
|
||||
}
|
||||
break;
|
||||
}
|
||||
return;
|
||||
}
|
||||
++$talentLv;
|
||||
phpcommon\SqlHelper::upsert
|
||||
($this->getSelfMysql(),
|
||||
'gun_intensify',
|
||||
array(
|
||||
'accountid' => $this->getAccountId(),
|
||||
'gun_type_id' => $gunTypeId,
|
||||
'skill_id' => $talentId
|
||||
),
|
||||
array(
|
||||
'skill_lv' => $talentLv,
|
||||
'modifytime' => $this->getNowTime()
|
||||
),
|
||||
array(
|
||||
'accountid' => $this->getAccountId(),
|
||||
'gun_type_id' => $gunTypeId,
|
||||
'skill_id' => $talentId,
|
||||
'skill_lv' => $talentLv,
|
||||
'createtime' => $this->getNowTime(),
|
||||
'modifytime' => $this->getNowTime()
|
||||
)
|
||||
);
|
||||
$this->rspRawData(array(
|
||||
'errcode' => 100,
|
||||
'errmsg' => '',
|
||||
'data' => array(
|
||||
'gun_type_id' => $gunTypeId,
|
||||
'skill_id' => $talentId,
|
||||
'skill_lv' => $talentLv,
|
||||
)
|
||||
));
|
||||
}
|
||||
|
||||
public function getGunAndSkinInfo()
|
||||
{
|
||||
$account_id = $_REQUEST['account_id'];
|
||||
$conn = $this->getMysql($account_id);
|
||||
$sqlStr2 = "SELECT gun_id,skin_id FROM gun WHERE accountid=:accountid; ";
|
||||
$row = $conn->execQuery($sqlStr2,array(':accountid' => $account_id));
|
||||
$resultData = array();
|
||||
|
||||
array_push($resultData,$row);
|
||||
//获得已经购买的皮肤列表
|
||||
$sqlStr3 = "SELECT gun_id,skin_id FROM gun_skin WHERE accountid=:accountid; ";
|
||||
$row = $conn->execQuery($sqlStr3,array(':accountid' => $account_id));
|
||||
array_push($resultData,$row);
|
||||
$this->sendDataToClient(100,"getGunAndSkinInfo",$resultData);
|
||||
$data = array();
|
||||
phpcommon\SqlHelper::select
|
||||
($this->getSelfMysql(),
|
||||
'gun',
|
||||
array(
|
||||
'gun_id',
|
||||
'skin_id'
|
||||
),
|
||||
array(
|
||||
'accountid' => $this->getAccountId()
|
||||
),
|
||||
function ($row) use(&$data) {
|
||||
array_push($data, array(
|
||||
'gun_id' => $row['gun_id'],
|
||||
'skin_lv' => $row['skin_id'],
|
||||
));
|
||||
}
|
||||
);
|
||||
phpcommon\SqlHelper::select
|
||||
($this->getSelfMysql(),
|
||||
'gun_skin',
|
||||
array(
|
||||
'gun_id',
|
||||
'skin_id'
|
||||
),
|
||||
array(
|
||||
'accountid' => $this->getAccountId()
|
||||
),
|
||||
function ($row) use(&$data) {
|
||||
array_push($data, array(
|
||||
'gun_id' => $row['gun_id'],
|
||||
'skin_lv' => $row['skin_id'],
|
||||
));
|
||||
}
|
||||
);
|
||||
$this->rspRawData(array(
|
||||
'errcode' => 100,
|
||||
'errmsg' => '',
|
||||
'data' => $data
|
||||
));
|
||||
}
|
||||
|
||||
public function equipGunSkin()
|
||||
{
|
||||
$account_id = $_REQUEST['account_id'];
|
||||
$gunID = $_REQUEST['gun_id'];
|
||||
$skinID = $_REQUEST['skin_id'];
|
||||
$gunId = $_REQUEST['gun_id'];
|
||||
$skinId = $_REQUEST['skin_id'];
|
||||
|
||||
phpcommon\SqlHelper::insertOrUpdate
|
||||
($this->getSelfMysql(),
|
||||
'gun',
|
||||
array(
|
||||
'accountid' => $this->getAccountId(),
|
||||
'gun_id' => $gunID
|
||||
),
|
||||
array(
|
||||
'accountid' => $this->getAccountId(),
|
||||
'gun_id' => $gunID,
|
||||
'skin_id' =>$skinID,
|
||||
'trytime' =>0,
|
||||
'createtime' => $this->getNowTime(),
|
||||
'modifytime' => $this->getNowTime()
|
||||
),
|
||||
array(
|
||||
'skin_id' =>$skinID,
|
||||
'modifytime' => $this->getNowTime()
|
||||
phpcommon\SqlHelper::upsert
|
||||
($this->getSelfMysql(),
|
||||
'gun',
|
||||
array(
|
||||
'accountid' => $this->getAccountId(),
|
||||
'gun_id' => $gunId
|
||||
),
|
||||
array(
|
||||
),
|
||||
array(
|
||||
'accountid' => $this->getAccountId(),
|
||||
'gun_id' => $gunId,
|
||||
'skin_id' => $skinId,
|
||||
'trytime' => 0,
|
||||
'createtime' => $this->getNowTime(),
|
||||
'modifytime' => $this->getNowTime()
|
||||
)
|
||||
);
|
||||
$this->rspRawData(array(
|
||||
'errcode' => 100,
|
||||
'errmsg' => '',
|
||||
'data' => array(
|
||||
'gun_id' => $gunId,
|
||||
'skin_id' => $skinId
|
||||
)
|
||||
);
|
||||
$resultData = array("gun_id"=>$gunID,"skin_id"=>$skinID);
|
||||
$this->sendDataToClient(100,"changeGunSkin",$resultData);
|
||||
));
|
||||
}
|
||||
|
||||
public function buyGunSkin()
|
||||
{
|
||||
$account_id = $_REQUEST['account_id'];
|
||||
$gunID = $_REQUEST['gun_id'];
|
||||
$skinID = $_REQUEST['skin_id'];
|
||||
$goodsID = $_REQUEST['goodsID'];
|
||||
$gunId = $_REQUEST['gun_id'];
|
||||
$skinId = $_REQUEST['skin_id'];
|
||||
$goodsId = $_REQUEST['goodsID'];
|
||||
|
||||
//error_log("购买皮肤======".$goodsID);
|
||||
$shopMeta = mt\NewShop::getShopItemByID($goodsID);
|
||||
$code = 100;
|
||||
$skinData = null;
|
||||
if($shopMeta)
|
||||
{
|
||||
$priceNum = $shopMeta["priceNum"];
|
||||
$priceID = $shopMeta["priceID"];
|
||||
$code = $this->checkPriceEnough($priceNum,$priceID);
|
||||
$shopMeta = mt\NewShop::getShopItemById(3);
|
||||
if (!$shopMeta) {
|
||||
$this->rspErr(1, "参数错误");
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
$code = 99;
|
||||
$goodsInfo = mt\NewShop::getGoodsInfo($shopMeta, $goodsId);
|
||||
if (!$goodsInfo) {
|
||||
$this->rspErr(1, "参数错误");
|
||||
return;
|
||||
}
|
||||
$costList = array(
|
||||
array(
|
||||
'item_id' => $goodsInfo['costItemId'],
|
||||
'item_num' => $goodsInfo['costItemNum'],
|
||||
)
|
||||
);
|
||||
$lackItem = array();
|
||||
if (!$this->hasEnoughItemsEx($costItem, $lackItem)) {
|
||||
switch ($lackItem['item_id']) {
|
||||
case V_ITEM_GOLD:
|
||||
{
|
||||
$this->rspErr(88, "金币不足");
|
||||
}
|
||||
break;
|
||||
case V_ITEM_DIAMOND:
|
||||
{
|
||||
$this->rspErr(87, "钻石不足");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
{
|
||||
$this->rspErr(86, "道具不足");
|
||||
}
|
||||
break;
|
||||
}
|
||||
return;
|
||||
}
|
||||
{
|
||||
phpcommon\SqlHelper::upsert
|
||||
($this->getSelfMysql(),
|
||||
'gun_skin',
|
||||
array(
|
||||
'accountid' => $this->getAccountId(),
|
||||
'gun_id' => $gunId,
|
||||
'skin_id' => $skinId
|
||||
),
|
||||
array(
|
||||
'trytime' => 0,
|
||||
'modifytime' => $this->getNowTime()
|
||||
),
|
||||
array(
|
||||
'accountid' => $this->getAccountId(),
|
||||
'gun_id' => $gunId,
|
||||
'skin_id' => $skinId,
|
||||
'trytime' => 0,
|
||||
'createtime' => $this->getNowTime(),
|
||||
'modifytime' => $this->getNowTime()
|
||||
)
|
||||
);
|
||||
|
||||
if($code == 100)
|
||||
{
|
||||
phpcommon\SqlHelper::insertOrUpdate
|
||||
($this->getSelfMysql(),
|
||||
'gun_skin',
|
||||
array(
|
||||
'accountid' => $this->getAccountId(),
|
||||
'gun_id' => $gunID,
|
||||
'skin_id' => $skinID
|
||||
),
|
||||
array(
|
||||
'accountid' => $this->getAccountId(),
|
||||
'gun_id' => $gunID,
|
||||
'skin_id' =>$skinID,
|
||||
'trytime' =>0,
|
||||
'createtime' => $this->getNowTime(),
|
||||
'modifytime' => $this->getNowTime()
|
||||
),
|
||||
array(
|
||||
'trytime' => 0,
|
||||
'modifytime' => $this->getNowTime()
|
||||
)
|
||||
);
|
||||
|
||||
phpcommon\SqlHelper::insertOrUpdate
|
||||
($this->getSelfMysql(),
|
||||
'gun',
|
||||
array(
|
||||
'accountid' => $this->getAccountId(),
|
||||
'gun_id' => $gunID
|
||||
),
|
||||
array(
|
||||
'accountid' => $this->getAccountId(),
|
||||
'gun_id' => $gunID,
|
||||
'skin_id' =>$skinID,
|
||||
'trytime' =>0,
|
||||
'createtime' => $this->getNowTime(),
|
||||
'modifytime' => $this->getNowTime()
|
||||
),
|
||||
array(
|
||||
'skin_id' =>$skinID,
|
||||
'modifytime' => $this->getNowTime()
|
||||
)
|
||||
);
|
||||
phpcommon\SqlHelper::upsert
|
||||
($this->getSelfMysql(),
|
||||
'gun',
|
||||
array(
|
||||
'accountid' => $this->getAccountId(),
|
||||
'gun_id' => $gunId
|
||||
),
|
||||
array(
|
||||
'skin_id' => $skinId,
|
||||
'modifytime' => $this->getNowTime()
|
||||
),
|
||||
array(
|
||||
'accountid' => $this->getAccountId(),
|
||||
'gun_id' => $gunId,
|
||||
'skin_id' => $skinId,
|
||||
'trytime' => 0,
|
||||
'createtime' => $this->getNowTime(),
|
||||
'modifytime' => $this->getNowTime()
|
||||
)
|
||||
);
|
||||
}
|
||||
$resultData = array("gun_id"=>$gunID,"skin_id"=>$skinID);
|
||||
$this->sendDataToClient($code,"buyGunSkin",$resultData);
|
||||
|
||||
$this->rspRawData(array(
|
||||
'errcode' => 100,
|
||||
'errmsg' => '',
|
||||
'data' => array(
|
||||
'gun_id' => $gunId,
|
||||
'skin_id' => $skinid
|
||||
)
|
||||
));
|
||||
}
|
||||
|
||||
}
|
||||
|
30
webapp/mt/GunTalent.php
Normal file
30
webapp/mt/GunTalent.php
Normal file
@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace mt;
|
||||
|
||||
use phpcommon;
|
||||
|
||||
class GunTalent {
|
||||
|
||||
public static function get($id)
|
||||
{
|
||||
return self::getMetaList()[$id];
|
||||
}
|
||||
|
||||
public static function isValidTalent($meta, $talentId)
|
||||
{
|
||||
$strArr = explode("|", $meta["list"]);
|
||||
return in_array($talentId, $strArr);
|
||||
}
|
||||
|
||||
protected static function getMetaList()
|
||||
{
|
||||
if (!self::$metaList) {
|
||||
self::$metaList = getMetaTable('guntalent@guntalent.php');
|
||||
}
|
||||
return self::$metaList;
|
||||
}
|
||||
|
||||
protected static $metaList;
|
||||
|
||||
}
|
68
webapp/mt/GunTalentLv.php
Normal file
68
webapp/mt/GunTalentLv.php
Normal file
@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
namespace mt;
|
||||
|
||||
use phpcommon;
|
||||
|
||||
class GunTalentLv {
|
||||
|
||||
public static function get($id)
|
||||
{
|
||||
return self::getMetaList()[$id];
|
||||
}
|
||||
|
||||
public static function getCostList($meta)
|
||||
{
|
||||
$costList = array();
|
||||
$strArr = explode("|", $meta["cost"]);
|
||||
foreach ($strArr as $str) {
|
||||
$strArr2 = explode(":", $str);
|
||||
array_push(
|
||||
$costList,
|
||||
array(
|
||||
'item_id' => (int)$strArr2[0],
|
||||
'item_num' => (int)$strArr2[1],
|
||||
)
|
||||
);
|
||||
}
|
||||
return $costList;
|
||||
}
|
||||
|
||||
public static function isFullLv($meta, $talentLv)
|
||||
{
|
||||
$fullLvMeta = self::getFullLvMeta($meta);
|
||||
return $fullLvMeta && $talentLv >= $fullLvMeta['lv'];
|
||||
}
|
||||
|
||||
public static function getFullLvMeta($meta)
|
||||
{
|
||||
$currMeta = $meta;
|
||||
while ($currMeta['nextid'] > 0) {
|
||||
$currMeta = self::get($currMeta['nextid']);
|
||||
}
|
||||
return $currMeta;
|
||||
}
|
||||
|
||||
public static function getByLv($meta, $talentLv)
|
||||
{
|
||||
$currMeta = $meta;
|
||||
while ($currMeta) {
|
||||
if ($currMeta['lv'] == $talentLv) {
|
||||
return $currMeta;
|
||||
}
|
||||
$currMeta = self::get($currMeta['nextid']);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected static function getMetaList()
|
||||
{
|
||||
if (!self::$metaList) {
|
||||
self::$metaList = getMetaTable('guntalentlv@guntalentlv.php');
|
||||
}
|
||||
return self::$metaList;
|
||||
}
|
||||
|
||||
protected static $metaList;
|
||||
|
||||
}
|
@ -118,6 +118,56 @@ class NewShop {
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static function getGoodsInfo($meta, $goodsId)
|
||||
{
|
||||
$goodsStrArr = explode("|", $meta['goods']);
|
||||
$priceStrArr = explode("|", $meta['price']);
|
||||
if (count($goodsStrArr) != count($priceStrArr)) {
|
||||
return null;
|
||||
}
|
||||
$idx = -1;
|
||||
{
|
||||
$i = 0;
|
||||
array_filter($goodsStrArr, function($str) use(&$i, &$idx, $goodsId) {
|
||||
if ($idx != -1) {
|
||||
$strArr = explode(":", $str);
|
||||
if (count($strArr) >= 2) {
|
||||
if ($strArr[0] == $goodsId) {
|
||||
$idx = $i;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
++$i;
|
||||
return false;
|
||||
});
|
||||
}
|
||||
if ($idx <= 0) {
|
||||
return null;
|
||||
}
|
||||
$info = array(
|
||||
'goodsId' => 0,
|
||||
'goodsNum' => 0,
|
||||
'costItemId' => 0,
|
||||
'costItemNum' => 0
|
||||
);
|
||||
{
|
||||
$strArr = explode(":", $goodsStrArr[$idx]);
|
||||
$info['goodsId'] = $strArr[0];
|
||||
$info['goodsNum'] = $strArr[1];
|
||||
}
|
||||
{
|
||||
$strArr = explode(":", $priceStrArr[$idx]);
|
||||
if (count($strArr) < 2) {
|
||||
return null;
|
||||
}
|
||||
$info['costItemId'] = $strArr[0];
|
||||
$info['costItemNum'] = $strArr[1];
|
||||
}
|
||||
return $info;
|
||||
}
|
||||
|
||||
protected static $itemArr;
|
||||
protected static $meta;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user