game2005api/webapp/controller/EquipController.class.php
aozhiwei 44ccdc20a0 1
2021-11-26 19:54:59 +08:00

628 lines
25 KiB
PHP

<?php
require 'classes/Quest.php';
require 'classes/AddReward.php';
require_once('mt/Equip.php');
require_once('mt/Item.php');
class EquipController extends BaseAuthedController {
public function equipInfo()
{
$account_id = $_REQUEST['account_id'];
$conn = $this->_getMysql($account_id);
$equip_list = array();
$rows = $conn->execQuery('SELECT * FROM equip WHERE account_id=:account_id;',
array(
'account_id' => $account_id,
));
$addreward = new classes\AddReward();
if (!$rows) {
//新玩家装备数据
//$id = $addreward->getRealIndexid(12151, $account_id);
// $id = 23001;
// $ret = $conn->execScript('INSERT INTO equip(account_id, id, lv, active_time, sub_time, create_time, modify_time, using_id, exp) ' .
// ' VALUES(:account_id, :id, 0, :active_time, :sub_time, :create_time, :modify_time, :using_id, 0) ' .
// ' ON DUPLICATE KEY UPDATE account_id=:account_id, id=:id, lv=0, active_time=:active_time, sub_time=:sub_time, modify_time=:modify_time, using_id=:using_id, exp=0;',
// array(
// ':account_id' => $account_id,
// ':id' => $id,
// ':active_time' => 0,
// ':create_time' => phpcommon\getNowTime(),
// ':modify_time' => phpcommon\getNowTime(),
// ':sub_time' => 0,
// ':using_id' => $id,
// ));
// if(!$ret){
// die();
// return;
// }
array_push($equip_list, array(
'id' => 0,
'lv' => 0,
'active_time' => 0,
'using_id' => 0,
'exp' => 0,
'time_flag' => 0,
));
} else {
foreach ($rows as $row) {
$time_flag = 0;
//$id = $addreward->getRealIndexid($row['id'], $account_id);
$id = $row['id'];
$time = $row['active_time'] + $row['sub_time'];
if (phpcommon\getNowTime() >= $time && $row['sub_time'] != 0) {
$ret1 = $conn->execScript('UPDATE equip SET active_time=0, sub_time=0, modify_time=:modify_time ' .
' WHERE account_id=:account_id AND id=:id;',
array(
':account_id' => $account_id,
':modify_time' => phpcommon\getNowTime(),
':id' => $row['id'],
));
if (!$ret1) {
die();
return;
}
$time = 0;
$time_flag = 1;
}
array_push($equip_list, array(
'id' => $id,
'lv' => $row['lv'],
'active_time' => $time,
'using_id' => $row['using_id'],
'exp' => $row['exp'],
'time_flag' => $time_flag
));
}
//}
}
echo json_encode(array(
'errcode' => 0,
'errmsg' => '',
'equip_list' => $equip_list,
));
}
public function speedUpTime()
{
$account_id = $_REQUEST['account_id'];
$conn = $this->_getMysql($account_id);
$id = 0;
if (isset($_REQUEST['id'])) {
$id = $_REQUEST['id'];
}
$type = $_REQUEST['type'];
$row = $conn->execQueryOne('SELECT * FROM equip WHERE account_id=:account_id AND id=:id;',
array(
':account_id' => $account_id,
':id' => $id
));
if (!$row) {
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家');
return;
}
$e = mt\Equip::getOldEquip($id);
if (!$e) {
phpcommon\sendError(ERR_USER_BASE + 2, '没有这个装备');
return;
}
$view_list = $this->_getExplode($e['reduce_time']);
$reduce_time = $view_list[$row['lv'] - 1][0];
$flag = 0;
//error_log($e['reduce_time']);
$sub_time = $row['sub_time'] - floor($row['sub_time'] * $reduce_time * 0.01);
if ($type == 1) {
$rowUser = $conn->execQueryOne('SELECT rmb_num FROM user WHERE account_id=:account_id;',
array(
':account_id' => $account_id
));
if (!$rowUser) {
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家');
return;
}
$diamond_arr = $this->_getExplode($e['diamond_cost']);
$diamond_cost = $diamond_arr[$row['lv'] - 1][0];
if ($rowUser['rmb_num'] < $diamond_cost) {
phpcommon\sendError(ERR_USER_BASE + 3, '钻石不足');
return;
}
$diamond_list = $this->_getExplode($e['diamond_time']);
$diamond_time = $diamond_list[$row['lv'] - 1][0];
$sub_time = $row['sub_time'] - floor($row['sub_time'] * $diamond_time * 0.01);
$retUser = $conn->execScript('UPDATE user SET rmb_num=:rmb_num, modify_time=:modify_time ' .
' WHERE account_id=:account_id;',
array(
':account_id' => $account_id,
':rmb_num' => $rowUser['rmb_num'] - $diamond_cost,
':modify_time' => phpcommon\getNowTime()
));
if (!$retUser) {
die();
return;
}
}
$active_time = $row['active_time'];
if ($active_time + $sub_time <= phpcommon\getNowTime() ||
$active_time + $row['sub_time'] <= phpcommon\getNowTime() + 30) {
$active_time = 0;
$sub_time = 0;
$flag = 1;
}
$retEquip = $conn->execScript('UPDATE equip SET active_time=:active_time, sub_time=:sub_time, modify_time=:modify_time ' .
' WHERE account_id=:account_id AND id=:id;',
array(
':account_id' => $account_id,
':active_time' => $active_time,
':sub_time' => $sub_time,
':modify_time' => phpcommon\getNowTime(),
':id' => $id,
));
if (!$retEquip) {
die();
return;
}
$addreward = new classes\AddReward();
$num = $addreward->getRmbNum($account_id);
echo json_encode(array(
'errcode' => 0,
'errmsg' => '',
'rmb_nums' => $num,
'flag' => $flag,
'id' => $row['id'],
'lv' => $row['lv'],
));
}
public function exchangeNewEquip()
{
$account_id = $_REQUEST['account_id'];
$equip_id = $_REQUEST['id'];
$conn = $this->_getMysql($account_id);
$row = $conn->execQueryOne('SELECT * FROM equip WHERE account_id=:account_id AND id=:id;',
array(
':account_id' => $account_id,
':id' => $equip_id
));
$lv = 0;
if (!$row) {
phpcommon\sendError(ERR_USER_BASE + 3, '武器未获得');
return;
} else {
$lv = $row['lv'];
}
$ret = $conn->execScript('UPDATE equip SET using_id=:using_id, modify_time=:modify_time ' .
' WHERE account_id=:account_id;',
array(
':account_id' => $account_id,
':using_id' => $equip_id,
':modify_time' => phpcommon\getNowTime(),
));
if (!$ret) {
die();
return;
}
echo json_encode(array(
'errcode' => 0,
'errmsg' => '',
'using_id' => $equip_id,
'lv' => $lv,
'active_time' => $row['active_time'] + $row['sub_time'],
));
}
public function shengjiEquip()
{
$account_id = $_REQUEST['account_id'];
$equip_id = $_REQUEST['id'];
$conn = $this->_getMysql($account_id);
$e = mt\Equip::getOldEquip($equip_id);
if (!$e) {
phpcommon\sendError(ERR_USER_BASE + 2, '没有这个装备');
return;
}
$upgrade_gold = $e['upgrade_gold'];
$drop_multiply = explode('&', $upgrade_gold);
$arr = array();
for ($i = 0; $i < count($drop_multiply); $i++) {
$mul = explode('|', $drop_multiply[$i]);
array_push($arr, $mul);
}
$row = $conn->execQueryOne('SELECT id, lv, exp FROM equip WHERE account_id=:account_id AND id=:id;',
array(
':account_id' => $account_id,
':id' => $equip_id
));
$item_id_arr = array();
$item_num_arr = array();
$exp = 0;
$lv = 0;
if (!$row) {
phpcommon\sendError(ERR_USER_BASE + 3, '武器未获得');
return;
} else {
$lv = $row['lv'];
$exp = $row['exp'];
}
if ($lv >= $e['max_level']) {
phpcommon\sendError(ERR_USER_BASE + 5, '达到最大等级');
return;
}
$arr2 = array();
$str = $arr[$lv][0];
$estr = explode(';', $str);
$val = $estr[1];
if ($lv > 0) {
$str1 = $arr[$lv - 1][0];
$estr1 = explode(';', $str1);
$val = $estr[1] - $estr1[1];
}
if ($val <= $exp) {
phpcommon\sendError(ERR_USER_BASE + 4, '当前等级经验已满');
return;
}
for ($a1 = 0; $a1 < count($arr[$lv]); $a1++) {
$mul2 = explode(';', $arr[$lv][$a1]);
array_push($arr2, $mul2);
}
$arr3 = array();
for ($ii = 0; $ii < count($arr2); $ii++) {
for ($a2 = 0; $a2 < count($arr2[$ii]); $a2++) {
$mul3 = explode(':', $arr2[$ii][$a2]);
if (count($mul3) > 1) {
array_push($arr3, $mul3);
}
}
}
$addreward = new classes\AddReward();
foreach ($arr3 as $ar) {
$it = mt\Item::getOldItem($ar[0]);
if (!$it) {
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个道具');
return;
}
$rowuser = $conn->execQueryOne('SELECT coin_num, rmb_num FROM user WHERE account_id=:account_id;',
array(
':account_id' => $account_id,
));
if (!$rowuser) {
phpcommon\sendError(ERR_USER_BASE + 2, '没有这个玩家');
return;
}
$val = $addreward->getVipVal($account_id, 3);
$ar[1] = floor($ar[1] - $ar[1] * $val / 100);
if ($it['type'] == 1) {
if ($ar[1] > $rowuser['coin_num']) {
phpcommon\sendError(ERR_USER_BASE + 3, '金币不足');
return;
}
} else if ($it['type'] == 3) {
if ($ar[1] > $row['rmb_num']) {
phpcommon\sendError(ERR_USER_BASE + 4, '钻石不足');
return;
}
} else if ($it['type'] == 11) {
$rowbag = $conn->execQueryOne('SELECT num FROM bag WHERE account_id=:account_id AND id=:id;',
array(
':account_id' => $account_id,
'id' => $ar[0]
));
if ($ar[1] > $rowbag['num']) {
phpcommon\sendError(ERR_USER_BASE + 5, '道具不足');
return;
}
}
}
foreach ($arr3 as $ar1) {
$val = $addreward->getVipVal($account_id, 3);
$ar1[1] = floor($ar1[1] - $ar1[1] * $val / 100);
$this->subCoin($ar1[0], $ar1[1], $account_id);
}
$ret = $conn->execScript('UPDATE equip SET exp=:exp, modify_time=:modify_time ' .
' WHERE account_id=:account_id AND id=:id;',
array(
':account_id' => $account_id,
':id' => $equip_id,
':modify_time' => phpcommon\getNowTime(),
':exp' => $exp + 1,
));
if (!$ret) {
die();
return;
}
$addreward = new classes\AddReward();
$coin_num = $addreward->getCoinNum($account_id);
$num = $addreward->getRmbNum($account_id);
echo json_encode(array(
'errcode' => 0,
'errmsg' => '',
'exp' => $exp + 1,
'coin_nums' => $coin_num,
'rmb_nums' => $num,
'lv' => $lv,
));
}
protected function subCoin($item_id, $item_num, $account_id)
{
$conn = $this->_getMysql($account_id);
$row = $conn->execQueryOne('SELECT coin_num, rmb_num FROM user WHERE account_id=:account_id;',
array(
':account_id' => $account_id,
));
if (!$row) {
phpcommon\sendError(ERR_USER_BASE + 2, '没有这个玩家');
die();
return;
}
$it = mt\Item::getOldItem($item_id);
if (!$it) {
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个道具');
die();
return;
}
if ($item_id != 0){
if ($it['type'] == 1) {
$ret = $conn->execScript('UPDATE user SET coin_num=:coin_num, modify_time=:modify_time ' .
' WHERE account_id=:account_id;',
array(
':account_id' => $account_id,
':modify_time' => phpcommon\getNowTime(),
':coin_num' => $row['coin_num'] - $item_num,
));
if (!$ret) {
die();
return;
}
} else if ($it['type'] == 3) {
$ret = $conn->execScript('UPDATE user SET rmb_num=:rmb_num, modify_time=:modify_time ' .
' WHERE account_id=:account_id;',
array(
':account_id' => $account_id,
':modify_time' => phpcommon\getNowTime(),
':rmb_num' => $row['rmb_num'] - $item_num,
));
if (!$ret) {
die();
return;
}
} else if ($it['type'] == 11) {
$rowbag = $conn->execQueryOne('SELECT num FROM bag WHERE account_id=:account_id AND id=:id;',
array(
':account_id' => $account_id,
'id' => $item_id
));
$ret = $conn->execScript('UPDATE bag SET num=:num, modify_time=:modify_time ' .
' WHERE account_id=:account_id AND id=:id;',
array(
':account_id' => $account_id,
':modify_time' => phpcommon\getNowTime(),
':num' => $rowbag['num'] - $item_num,
':id' => $item_id
));
if (!$ret) {
die();
return;
}
}
}
}
public function jinjieEquip()
{
$account_id = $_REQUEST['account_id'];
$equip_id = $_REQUEST['id'];
$conn = $this->_getMysql($account_id);
$row = $conn->execQueryOne('SELECT id, using_id, lv, exp FROM equip WHERE account_id=:account_id AND id=:id;',
array(
':account_id' => $account_id,
':id' => $equip_id
));
if (!$row) {
phpcommon\sendError(ERR_USER_BASE + 3, '武器未获得');
return;
}
$lv = $row['lv'];
$e = mt\Equip::getOldEquip($equip_id);
if (!$e) {
phpcommon\sendError(ERR_USER_BASE + 2, '没有这个装备');
return;
}
$upgrade_gold = $e['upgrade_gold'];
$drop_multiply = explode('&', $upgrade_gold);
$arr = array();
for ($i = 0; $i < count($drop_multiply); $i++) {
$mul = explode('|', $drop_multiply[$i]);
array_push($arr, $mul);
}
$arr2 = array();
$flag = 0;
$valexp = 0;
if ($lv == 0) {
$str = $arr[$lv][0];
$estr = explode(';', $str);
$valexp = $estr[1];
} else {
$str1 = $arr[$lv][0];
$estr1 = explode(';', $str1);
$str = $arr[$lv - 1][0];
$estr = explode(';', $str);
$valexp = $estr1[1] - $estr[1];
}
if ($valexp > $row['exp']) {
phpcommon\sendError(ERR_USER_BASE + 4, '未达到进阶需求');
return;
}
if ($lv >= $e['max_level']) {
phpcommon\sendError(ERR_USER_BASE + 5, '达到最大等级');
return;
}
$arr1 = explode('|', $e['promote_material']);
$arr_key = $arr1[$lv];
$arr2 = explode(';', $arr_key);
$arr3 = array();
for ($i = 0; $i < count($arr2); $i++) {
$mul = explode(':', $arr2[$i]);
array_push($arr3, $mul);
}
foreach ($arr3 as $a) {
$this->checkcoin($a[0], $a[1], $account_id);
}
foreach ($arr3 as $a) {
$this->subCoin($a[0], $a[1], $account_id);
}
$active_time = phpcommon\getNowTime();
$sub_list = $this->_getExplode($e['equip_upgradetime']);
$sub_time = $sub_list[$lv][0];
if ($sub_time == 0) {
$active_time = 0;
$flag = 1;
}
$ret = $conn->execScript('UPDATE equip SET exp=:exp, lv=:lv, modify_time=:modify_time, active_time=:active_time, sub_time=:sub_time ' .
' WHERE account_id=:account_id AND id=:id;',
array(
':account_id' => $account_id,
':id' => $equip_id,
':modify_time' => phpcommon\getNowTime(),
':exp' => 0,
':lv' => $lv + 1,
':active_time' => $active_time,
':sub_time' => $sub_time
));
if (!$ret) {
die();
return;
}
$addreward = new classes\AddReward();
$coin_num = $addreward->getCoinNum($account_id);
$num = $addreward->getRmbNum($account_id);
echo json_encode(array(
'errcode' => 0,
'errmsg' => '',
'exp' => 0,
'lv' => $lv + 1,
'coin_nums' => $coin_num,
'rmb_nums' => $num,
'flag' => $flag,
'id' => $equip_id,
));
}
protected function checkcoin($id, $num, $account_id)
{
$conn = $this->_getMysql($account_id);
$row = $conn->execQueryOne('SELECT coin_num, rmb_num FROM user WHERE account_id=:account_id;',
array(
':account_id' => $account_id,
));
if (!$row) {
phpcommon\sendError(ERR_USER_BASE + 2, '没有这个玩家');
die();
return;
}
$it = mt\Item::getOldItem($id);
if (!$it) {
phpcommon\sendError(ERR_USER_BASE + 1, '没有这个道具');
die();
return;
}
if ($id != 0){
if ($it['type'] == 1) {
if ($row['coin_num'] < $num) {
phpcommon\sendError(ERR_USER_BASE + 3, '金币不足');
die();
return;
}
} else if ($it['type'] == 3) {
if ($row['rmb_num'] < $num) {
phpcommon\sendError(ERR_USER_BASE + 4, '点券不足');
die();
return;
}
} else if ($it['type'] == 11 ||
$it['type'] == 19) {
$rowbag = $conn->execQueryOne('SELECT num FROM bag WHERE account_id=:account_id AND id=:id;',
array(
':account_id' => $account_id,
'id' => $id
));
if ($rowbag['num'] < $num) {
phpcommon\sendError(ERR_USER_BASE + 5, '材料不足');
die();
return;
}
}
}
}
public function unlockEquip()
{
$account_id = $_REQUEST['account_id'];
$conn = $this->_getMysql($account_id);
$id = $_REQUEST['id'];
$row = $conn->execQueryOne('SELECT num FROM bag WHERE account_id=:account_id AND id=:id;',
array(
':account_id' => $account_id,
':id' => $id
));
$item = mt\Item::getOldItem($id);
if (!$item || empty($item['synthesis'])) {
phpcommon\sendError(ERR_USER_BASE + 2,'没有这个道具');
return;
}
if (!$row || $row['num'] < $item['cost']) {
phpcommon\sendError(ERR_USER_BASE + 3,'碎片数量不足');
return;
}
$ret = $conn->execScript('UPDATE bag SET num=:num, modify_time=:modify_time ' .
' WHERE account_id=:account_id AND id=:id;',
array(
':account_id' => $account_id,
':id' => $id,
':num' => $row['num'] - $item['cost'],
':modify_time' => phpcommon\getNowTime()
));
if (!$ret) {
die();
return;
}
$item_list = array();
array_push($item_list, array(
'item_id' => $item['synthesis'],
'item_num' => 1,
'time' => 0,
));
$addreward = new classes\AddReward();
$all_item_list = $addreward->addReward($item['synthesis'], 1, $account_id, 0, 0);
echo json_encode(array(
'errcode' => 0,
'errmsg'=> '',
'num' => $row['num'] - $item['cost'],
'item_list' => $item_list,
'all_item_list' => $all_item_list,
));
}
}