516 lines
19 KiB
PHP
516 lines
19 KiB
PHP
<?php
|
|
|
|
require 'classes/Quest.php';
|
|
require 'classes/AddReward.php';
|
|
require_once 'metatable/drop.php';
|
|
|
|
require_once('mt/Parameter.php');
|
|
require_once('mt/Item.php');
|
|
|
|
class BagController extends BaseAuthedController {
|
|
|
|
private $bagTableCache = null;
|
|
protected function getBag($bag_id)
|
|
{
|
|
if ($this->bagTableCache == null) {
|
|
$this->bagTableCache = require('../res/bag@bag.php');
|
|
}
|
|
$bag_conf = getBagConfig($this->bagTableCache, $bag_id);
|
|
$b = array(
|
|
'id' => $bag_conf['id'],
|
|
'name' => $bag_conf['name'],
|
|
'fuction' => $bag_conf['fuction'],
|
|
);
|
|
return $b;
|
|
}
|
|
|
|
public function getBagInfo()
|
|
{
|
|
$account_id = $_REQUEST['account_id'];
|
|
$conn = $this->_getMysql($account_id);
|
|
$bag_list = array();
|
|
$rows = $conn->execQuery('SELECT * FROM bag WHERE accountid=:account_id;',
|
|
array(
|
|
':account_id' => $account_id
|
|
));
|
|
if ($rows) {
|
|
foreach ($rows as $row){
|
|
$active_time = 0;
|
|
$color_id = 0;
|
|
$status = $row['status'];
|
|
if (phpcommon\getNowTime() >= $row['active_time'] && $row['active_time'] != 0) {
|
|
$ret = $conn->execScript('UPDATE bag SET active_time=0, color_id=0, status=2, modify_time=:modify_time ' .
|
|
' WHERE accountid=:account_id AND id=:id;',
|
|
array(
|
|
':account_id' => $account_id,
|
|
':id' => $row['id'],
|
|
':modify_time' => phpcommon\getNowTime()
|
|
));
|
|
if (!$ret) {
|
|
die();
|
|
return;
|
|
}
|
|
$active_time = 0;
|
|
$color_id = 0;
|
|
$status = 2;
|
|
} else {
|
|
if ($row['active_time'] != 0) {
|
|
$active_time = $row['active_time'];
|
|
}
|
|
$color_id = $row['color_id'];
|
|
$status = $row['status'];
|
|
}
|
|
array_push($bag_list, array(
|
|
'id' => $row['id'],
|
|
'active_time' => $active_time,
|
|
'status' => $status,
|
|
'color_id' => $color_id,
|
|
'num' => $row['num'],
|
|
));
|
|
}
|
|
}
|
|
echo json_encode(array(
|
|
'errcode' => 0,
|
|
'errmsg' => '',
|
|
'bag_list' => $bag_list
|
|
));
|
|
}
|
|
|
|
public function exchangeBagItem() {
|
|
$account_id = $_REQUEST['account_id'];
|
|
$item_id = $_REQUEST['item_id'];
|
|
$color_id = $_REQUEST['color_id'];
|
|
$conn = $this->_getMysql($account_id);
|
|
$b = $this->getBag($item_id);
|
|
$bag_meta_table = require('../res/bag@bag.php');
|
|
//正在装备的道具
|
|
if ($b['fuction'] != 5 && $b['fuction'] != 6) {
|
|
foreach ($bag_meta_table as $bag_info) {
|
|
$id = $bag_info['id'];
|
|
$bag = $this->getBag($id);
|
|
if ($bag['fuction'] != $b['fuction']) {
|
|
continue;
|
|
}
|
|
$row = $conn->execQueryOne('SELECT status, active_time FROM bag WHERE accountid=:accountid AND id=:id;',
|
|
array(
|
|
':accountid' => $account_id,
|
|
':id' => $id,
|
|
));
|
|
if ($row['status'] != 0 || !$row) {
|
|
continue;
|
|
}
|
|
$status = 2;
|
|
if ($row['active_time'] == 0) {
|
|
$status = 1;
|
|
}
|
|
$using_ret = $conn->execScript('UPDATE bag SET status=:status, color_id=0, modify_time=:modify_time ' .
|
|
' WHERE accountid = :account_id AND id = :id;',
|
|
array(
|
|
':account_id' => $account_id,
|
|
':id' => $id,
|
|
':status' => $status,
|
|
':modify_time' => phpcommon\getNowTime()
|
|
));
|
|
if(!$using_ret){
|
|
die();
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
//要装备的道具
|
|
$row = $conn->execQueryOne('SELECT status FROM bag WHERE accountid=:accountid AND id=:id;',
|
|
array(
|
|
':accountid' => $account_id,
|
|
':id' => $item_id,
|
|
));
|
|
if (!$row) {
|
|
phpcommon\sendError(ERR_USER_BASE + 2, '没有这个道具');
|
|
return;
|
|
}
|
|
|
|
$exchange_ret = $conn->execScript('UPDATE bag SET status=0, color_id=:color_id, modify_time=:modify_time ' .
|
|
' WHERE accountid = :account_id AND id = :id;',
|
|
array(
|
|
':account_id' => $account_id,
|
|
':id' => $item_id,
|
|
':color_id' => $color_id,
|
|
':modify_time' => phpcommon\getNowTime()
|
|
));
|
|
if(!$exchange_ret){
|
|
die();
|
|
return;
|
|
}
|
|
|
|
echo json_encode(array(
|
|
'errcode' => 0,
|
|
'errmsg' => '',
|
|
'item_id' => $item_id,
|
|
'color_id' => $color_id
|
|
));
|
|
}
|
|
|
|
public function downItem()
|
|
{
|
|
$account_id = $_REQUEST['account_id'];
|
|
$item_id = $_REQUEST['item_id'];
|
|
$conn = $this->_getMysql($account_id);
|
|
$b = $this->getBag($item_id);
|
|
|
|
$row = $conn->execQueryOne('SELECT status,active_time FROM bag WHERE accountid=:accountid AND id=:id;',
|
|
array(
|
|
':accountid' => $account_id,
|
|
':id' => $item_id,
|
|
));
|
|
if (!$row) {
|
|
phpcommon\sendError(ERR_USER_BASE + 2, '没有这个道具');
|
|
return;
|
|
}
|
|
$status = 2;
|
|
if ($row['active_time'] == 0) {
|
|
$status = 1;
|
|
}
|
|
$exchange_ret = $conn->execScript('UPDATE bag SET status=:status, color_id=0, modify_time=:modify_time ' .
|
|
' WHERE accountid = :account_id AND id = :id;',
|
|
array(
|
|
':account_id' => $account_id,
|
|
':id' => $item_id,
|
|
':status' => $status,
|
|
':modify_time' => phpcommon\getNowTime()
|
|
));
|
|
if(!$exchange_ret){
|
|
die();
|
|
return;
|
|
}
|
|
|
|
echo json_encode(array(
|
|
'errcode' => 0,
|
|
'errmsg' => '',
|
|
'item_id' => $item_id,
|
|
'color_id' => 0
|
|
));
|
|
}
|
|
|
|
public function downItemColor()
|
|
{
|
|
$account_id = $_REQUEST['account_id'];
|
|
$item_id = $_REQUEST['item_id'];
|
|
$conn = $this->_getMysql($account_id);
|
|
$exchange_ret = $conn->execScript('UPDATE bag SET color_id=0, modify_time=:modify_time ' .
|
|
' WHERE accountid = :account_id AND id = :id;',
|
|
array(
|
|
':account_id' => $account_id,
|
|
':id' => $item_id,
|
|
':modify_time' => phpcommon\getNowTime()
|
|
));
|
|
if(!$exchange_ret){
|
|
die();
|
|
return;
|
|
}
|
|
|
|
echo json_encode(array(
|
|
'errcode' => 0,
|
|
'errmsg' => '',
|
|
'item_id' => $item_id,
|
|
'color_id' => 0
|
|
));
|
|
}
|
|
|
|
public function tryItem()
|
|
{
|
|
$account_id = $_REQUEST['account_id'];
|
|
$item_id = $_REQUEST['item_id'];
|
|
$conn = $this->_getMysql($account_id);
|
|
$addreward = new classes\AddReward();
|
|
$ptime = mt\Parameter::getOldParam(RECOMMEND_TIME);
|
|
$addreward->addReward($item_id, 1, $account_id, $ptime['param_value'], 0);
|
|
echo json_encode(array(
|
|
'errcode' => 0,
|
|
'errmsg' => '',
|
|
'item_id' => $item_id,
|
|
'color_id' => 0
|
|
));
|
|
}
|
|
|
|
public function freeGetItem()
|
|
{
|
|
$account_id = $_REQUEST['account_id'];
|
|
$arr = $_REQUEST['arr'];
|
|
$delim = ',';
|
|
$item_multiply = explode($delim, $arr);
|
|
$all_item_list = array();
|
|
$item_list = array();
|
|
$addreward = new classes\AddReward();
|
|
$random = Rand(0, 10000);
|
|
$time = 1;
|
|
$p = mt\Parameter::getOldParam(RECOMMEND_FOREVER_WEIGHT);
|
|
$ptime = mt\Parameter::getOldParam(RECOMMEND_TIME);
|
|
if ($random < $p['param_value']) {
|
|
$time = 0;
|
|
} else {
|
|
$time = $ptime['param_value'];
|
|
}
|
|
foreach ($item_multiply as $i) {
|
|
array_push($item_list, array(
|
|
'item_id' => $i,
|
|
'item_num' => 1,
|
|
'time' => 1,
|
|
));
|
|
$items = $addreward->addReward($i, 1, $account_id, $time, 1);
|
|
foreach($items as $it) {
|
|
array_push($all_item_list, array(
|
|
'item_id' => $it['item_id'],
|
|
'item_num' => $it['item_num'],
|
|
'time' => $it['time'],
|
|
));
|
|
}
|
|
}
|
|
$num = $addreward->getDiamondNum($account_id);
|
|
echo json_encode(array(
|
|
'errcode' => 0,
|
|
'errmsg' => '',
|
|
'item_list' => $item_list,
|
|
'diamond_nums' => $num,
|
|
'all_item_list' => $all_item_list
|
|
));
|
|
}
|
|
|
|
public function updateWeizhuang()
|
|
{
|
|
$account_id = $_REQUEST['account_id'];
|
|
$conn = $this->_getMysql($account_id);
|
|
$arr = json_decode($_REQUEST['arr'], true);
|
|
foreach ($arr as $a) {
|
|
$row = $conn->execQueryOne('SELECT status FROM bag WHERE accountid=:account_id AND id=:id;',
|
|
array(
|
|
':account_id' => $account_id,
|
|
':id' => $a['id']
|
|
));
|
|
if (!$row) {
|
|
continue;
|
|
}
|
|
$status = $row['status'];
|
|
if ($a['count'] == 0) {
|
|
$status = 2;
|
|
}
|
|
$ret = $conn->execScript('UPDATE bag SET status=:status, num=:num, modify_time=:modify_time ' .
|
|
' WHERE accountid = :account_id AND id = :id;',
|
|
array(
|
|
':account_id' => $account_id,
|
|
':id' => $a['id'],
|
|
':status' => $status,
|
|
':num' => $a['count'],
|
|
':modify_time' => phpcommon\getNowTime()
|
|
));
|
|
if(!$ret){
|
|
die();
|
|
return;
|
|
}
|
|
}
|
|
echo json_encode(array(
|
|
'errcode' => 0,
|
|
'errmsg' => '',
|
|
));
|
|
}
|
|
|
|
public function deleteItem()
|
|
{
|
|
$account_id = $_REQUEST['account_id'];
|
|
$conn = $this->_getMysql($account_id);
|
|
$id = $_REQUEST['id'];
|
|
$row = $conn->execQueryOne('SELECT num, status FROM bag WHERE accountid=:account_id AND id=:id;',
|
|
array(
|
|
':account_id' => $account_id,
|
|
':id' => $id
|
|
));
|
|
if (!$row || $row['num'] - 1 < 0) {
|
|
phpcommon\sendError(ERR_USER_BASE + 2, '道具不足');
|
|
return;
|
|
}
|
|
$status = $row['status'];
|
|
if ($row['num'] - 1 <= 0) {
|
|
$status = 2;
|
|
}
|
|
$ret = $conn->execScript('UPDATE bag SET status=:status, num=:num, modify_time=:modify_time ' .
|
|
' WHERE accountid = :account_id AND id = :id;',
|
|
array(
|
|
':account_id' => $account_id,
|
|
':id' => $id,
|
|
':status' => $status,
|
|
':num' => $row['num'] - 1,
|
|
':modify_time' => phpcommon\getNowTime()
|
|
));
|
|
if(!$ret){
|
|
die();
|
|
return;
|
|
}
|
|
|
|
echo json_encode(array(
|
|
'errcode' => 0,
|
|
'errmsg' => '',
|
|
'id' => $id,
|
|
'num' => $row['num'] - 1
|
|
));
|
|
}
|
|
|
|
public function addItemToDB()
|
|
{
|
|
// $itemArr = [10101,10102,10103,10104,10105,10106,10200,10201,
|
|
// 10202,10203,10204,10205,10206,10207,10208,12100,12102,12103,12104,
|
|
// 12105,12106,12107,12119,12120,12121];
|
|
$itemIDArr = array(10101,10102,10103,10104,10105,10106,10200,10201,10202,10203,10204,10205,10206,10207,10208,12100,12102,12103,12104,
|
|
12105,12106,12107,12119,12120,12121,1006,1005,1004,1003,1002,1001,17004);
|
|
$len = count($itemIDArr);
|
|
$itemArr = array();
|
|
for($i = 0; $i< $len; $i++)
|
|
{
|
|
$itemN = rand(2,6);
|
|
if($itemIDArr[$i] == "17004")
|
|
{
|
|
$itemN = 30;
|
|
}
|
|
$itemData = array("item_id"=>$itemIDArr[$i],"item_num"=>$itemN);
|
|
array_push($itemArr,$itemData);
|
|
error_log("itemTest=01====".$itemIDArr[$i]."==".$itemN);
|
|
}
|
|
$this->_addItem($itemArr);
|
|
$this->sendDataToClient(1,"test03",null);
|
|
}
|
|
public function saleItem()
|
|
{
|
|
$newItemCfg = require('../res/newitem@newitem.php');
|
|
$itemArr = array();
|
|
$itemID = $_REQUEST['itemID'];
|
|
$itemNum = $_REQUEST['itemNum'];
|
|
$itemCfg = $newItemCfg[$itemID];
|
|
$singlePrice = $itemCfg["sell_price"];
|
|
//error_log("NewItemCfg=03=====".$itemID."===".$itemNum."==".$singlePrice);
|
|
|
|
$deleteItem = array("item_id"=>$itemID,"item_num"=>$itemNum);
|
|
array_push($itemArr,$deleteItem);
|
|
$code = $this->_deleteItem($deleteItem);
|
|
//error_log("准备删除道具======".$code);
|
|
if($code == 100)
|
|
{
|
|
$this->_decItem($itemArr);
|
|
$this->_addGold($singlePrice*$itemNum);
|
|
|
|
}
|
|
$resultArr = array('saleMoney'=>$singlePrice*$itemNum,'itemID'=>$itemID,'itemNum'=>$itemNum);
|
|
$this->sendDataToClient($code,"ok",$resultArr);
|
|
}
|
|
public function useItem()
|
|
{
|
|
$newItemCfg = require('../res/newitem@newitem.php');
|
|
$itemID = $_REQUEST['itemID'];
|
|
$itemNum = $_REQUEST['itemNum'];
|
|
$itemCfg = $newItemCfg[$itemID];
|
|
$dropID = $itemCfg["drop"];
|
|
//error_log("掉落道具======".$dropID);
|
|
$item_list = array();
|
|
$itemArr = array();
|
|
$deleteItem = array("item_id"=>$itemID,"item_num"=>$itemNum);
|
|
array_push($itemArr,$deleteItem);
|
|
$code = $this->_deleteItem($deleteItem);
|
|
if($code == 100)
|
|
{
|
|
$this->_decItem($itemArr);
|
|
//合并打开礼包的获得的道具开始--
|
|
if($dropID >0)
|
|
{
|
|
for($i = 0 ; $i < $itemNum; $i++)
|
|
{
|
|
$dropItemArr = metatable\getDropListById($dropID);
|
|
$dropItemLen = count($dropItemArr);
|
|
for($j = 0; $j < $dropItemLen ; $j++)
|
|
{
|
|
$itemID = $dropItemArr[$j]["item_id"];
|
|
$itemListLen = count($item_list);
|
|
$isUpdate = 0;
|
|
for($k = 0; $k < $itemListLen; $k++)
|
|
{
|
|
if($item_list[$k]["item_id"] == $itemID)
|
|
{
|
|
$item_list[$k]["item_num"] += $dropItemArr[$j]["item_num"];
|
|
$isUpdate = 1;
|
|
break;
|
|
}
|
|
}
|
|
if($isUpdate == 0)
|
|
{
|
|
array_push($item_list,$dropItemArr[$j]);
|
|
}
|
|
}
|
|
}
|
|
//合并打开礼包的获得的道具结束--
|
|
$resultDropItemLen = count($item_list);
|
|
if($resultDropItemLen >0)
|
|
{
|
|
$this->_addItem($item_list);
|
|
}
|
|
|
|
}
|
|
}
|
|
// error_log("dropInfo=======".json_encode($item_list));
|
|
// error_log("使用道具=====".json_encode($itemCfg));
|
|
$resultArr = array('itemID'=>$itemID,'itemNum'=>$itemNum,"dropItem"=>$item_list);
|
|
$this->sendDataToClient($code,"ok",$resultArr);
|
|
}
|
|
public function updateBag()
|
|
{
|
|
$this->getAllItem();
|
|
}
|
|
public function getAllItem()
|
|
{
|
|
$account_id = $_REQUEST['account_id'];
|
|
$conn = $this->_getMysql($account_id);
|
|
$sqlStr = "SELECT * FROM bag WHERE accountid=:accountid; ";
|
|
$row = $conn->execQuery($sqlStr,array(':accountid' => $account_id));
|
|
if($row) {
|
|
|
|
}
|
|
$this->sendDataToClient(0,"test03",$row);
|
|
}
|
|
public function getAllYokeItem()
|
|
{
|
|
$account_id = $_REQUEST['account_id'];
|
|
$conn = $this->_getMysql($account_id);
|
|
$sqlStr = "SELECT * FROM bag WHERE accountid=:accountid; ";
|
|
$row = $conn->execQuery($sqlStr,array(':accountid' => $account_id));
|
|
$allYokeItem = array();
|
|
$newItemCfg = require('../res/newitem@newitem.php');
|
|
if($row) {
|
|
$len = count($row);
|
|
for($i = 0; $i < $len ; $i++)
|
|
{
|
|
$itemID = $row[$i]["id"];
|
|
$itemNum = $row[$i]["num"];
|
|
//error_log("Item=====".json_encode($row[$i]));
|
|
if(isset($newItemCfg[$itemID]))
|
|
{
|
|
$itemCfg = $newItemCfg[$itemID];
|
|
if($itemCfg)
|
|
{
|
|
if($itemCfg["type"] == 10)
|
|
{
|
|
$itemData = array("item_id"=>$itemID,"item_num"=>$itemNum);
|
|
array_push($allYokeItem,$itemData);
|
|
}
|
|
|
|
}
|
|
else
|
|
{
|
|
error_log("未定义======".$itemID."==".$len."==".$i);
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
else{
|
|
error_log("GetYokeItem=======");
|
|
}
|
|
$this->sendDataToClient(100,"allYokeItem",$allYokeItem);
|
|
}
|
|
|
|
}
|