$mysql_conf['host'], 'port' => $mysql_conf['port'], 'user' => $mysql_conf['user'], 'passwd' => $mysql_conf['passwd'], 'dbname' => DBNAME_PREFIX . $mysql_conf['instance_id'] )); return $conn; } protected function getRedis($shop_uuid) { $redis_conf = getRedisConfig(crc32($shop_uuid)); $r = new phpcommon\Redis(array( 'host' => $redis_conf['host'], 'port' => $redis_conf['port'], 'passwd' => $redis_conf['passwd'] )); return $r; } protected function getBox($box_id) { $box_meta_table = require('../res/box@box.php'); $box_meta = getBoxConfig($box_meta_table, $box_id); $b = array( 'box_id' => $box_meta['box_type'], 'item_id' => $box_meta['item_id'], 'num' => $box_meta['num'], 'weight' => $box_meta['weight'], 'type' => $box_meta['type'], 'time' => $box_meta['time'], 'count' => $box_meta['count'], ); return $b; } protected function getExplode($string) { $delim = "|"; $drop_multiply = explode($delim, $string); $delim1 = ":"; $arr = array(); for ($i = 0; $i < count($drop_multiply); $i++) { $mul = explode($delim1, $drop_multiply[$i]); array_push($arr, $mul); } return $arr; } protected function getEquip($equip_id) { $g_conf_equip_cluster = require('../res/equip@equip.php'); $equip_conf = getEquipConfig($g_conf_equip_cluster, $equip_id); $e = array( 'id' => $equip_conf['id'], 'upgrade_priority' => $equip_conf['upgrade_priority'], 'equip_upgrade' => $equip_conf['equip_upgrade'], 'level_gold_cost' => $equip_conf['level_gold_cost'], 'max_level' => $equip_conf['max_level'], 'equip_upgradematerial' => $equip_conf['equip_upgradematerial'], 'equip_upgradetime' => $equip_conf['equip_upgradetime'], 'diamond_cost' => $equip_conf['diamond_cost'], 'drop_id' => $equip_conf['drop_id'] ); return $e; } protected function getDrop($drop_id) { $drop_meta_table = require('../res/drop@drop.php'); $drop_meta = getDropConfig($drop_meta_table, $drop_id); $d = array( 'drop_id' => $drop_meta['drop_id'], 'item_id' => $drop_meta['item_id'], 'num' => $drop_meta['num'], 'weight' => $drop_meta['weight'], 'type' => $drop_meta['type'] ); return $d; } protected function getParameter($para_id) { $parameter_meta_cluster = require('../res/parameter@parameter.php'); $parameter_meta = getParameterConfig($parameter_meta_cluster, $para_id); $p = array( 'id' => $parameter_meta['id'], 'name' => $parameter_meta['param_name'], 'param_value' => $parameter_meta['param_value'], ); return $p; } protected function getRankReward($rank) { $rank_meta_table = require('../res/rankReward@rankReward.php'); $rank_meta = getRankRewardConfig($rank_meta_table, $rank); $d = array( 'rank' => $rank_meta['rank'], 'parameter' => $rank_meta['parameter'], 'drop' => $rank_meta['drop'], 'ad_drop' => $rank_meta['ad_drop'], 'ad_num' => $rank_meta['ad_num'], 'js_num' => $rank_meta['js_num'], 'js_drop' => $rank_meta['js_drop'], 'zbmode_param' => $rank_meta['zbmode_param'], ); return $d; } public function firstRewardInfo() { $account_id = $_REQUEST['account_id']; //登录校验 $login = loginVerify($account_id, $_REQUEST['session_id']); if (!$login) { phpcommon\sendError(ERR_USER_BASE + 1, 'session无效'); return; } $first_uuid = 'game2004api_first_uuid:' . md5($_REQUEST['account_id']); $r = $this->getRedis($first_uuid); if (!$r) { die(); return; } $rank = $_REQUEST['rank']; $type = 0; $coin = 0; $score = 0; $kills = 0; $normal_coin = 0; $num = 1; if (isset($_REQUEST['type'])) { $type = $_REQUEST['type']; } $p = $this->getParameter(EQUIPREWARD_PARAMETER); $par = $p['param_value']; if ($type == 1) { $ar = $this->getRankReward($rank); $coin = $ar['zbmode_param']; $num = ceil($ar['zbmode_param'] / $par); if (isset($_REQUEST['kills'])) { $score = $_REQUEST['kills'] * 10; } } else if ($type == 0) { if (isset($_REQUEST['coin'])) { $num = ceil($_REQUEST['coin'] / $par); } } //道具物品 $first_list = array(); if (phpcommon\extractChannel($account_id) == 6001 || phpcommon\extractChannel($account_id) == 6000) { array_push($first_list, array( 'item_id' => 18006, 'item_num' => $num, 'time' => 0, )); $first_list = $this->randomBox($first_list, 8); $first_list = $this->randomBox($first_list, 9); } else { $first_list = $this->randomReward($rank, $type); } $first_db = array( 'first_uuid' => $first_uuid, 'first_list' => $first_list, ); $r -> set($first_uuid, json_encode($first_db)); $r -> pexpire($first_uuid, 1000 * 3600 * 2); echo json_encode(array( 'errcode' => 0, 'errmsg'=> '', 'first_uuid' => $first_uuid, 'item_list' => $first_list, 'coin' => $coin, 'score' => $score, )); } public function getFirstReward() { $account_id = $_REQUEST['account_id']; //登录校验 $login = loginVerify($account_id, $_REQUEST['session_id']); if (!$login) { phpcommon\sendError(ERR_USER_BASE + 1, 'session无效'); return; } $type = $_REQUEST['type']; $first_uuid = $_REQUEST['first_uuid']; $item_id = 0; $item_num = 0; $flag = 0; $addreward = new classes\AddReward(); $item_list = array(); $all_item_list = array(); if ($type == 0) { $item_list = $this->fixReward($item_list, 5); } else { $r = $this->getRedis($first_uuid); $user_db_str = $r->get($first_uuid); if (empty($user_db_str)) { phpcommon\sendError(ERR_USER_BASE + 1,'session失效'); return; } $user_db = json_decode($user_db_str, true); if (empty($user_db)) { phpcommon\sendError(ERR_USER_BASE + 1,'session失效'); return; } $item_list = $user_db['first_list']; } foreach($item_list as $it) { $items = $addreward->addReward($it['item_id'], $it['item_num'], $account_id, $it['time'], 0); foreach($items as $j) { array_push($all_item_list, array( 'item_id' => $j['item_id'], 'item_num' => $j['item_num'], 'time' => $j['time'], )); } } $coin_num = $addreward->getCoinNum($account_id); $diamond_num = $addreward->getDiamondNum($account_id); echo json_encode(array( 'errcode' => 0, 'errmsg'=> '', 'coin_nums' => $coin_num, 'diamond_nums' => $diamond_num, 'item_list' => $item_list, 'all_item_list' => $all_item_list )); } protected function fixReward($item_list, $type) { $b1 = $this->getbox($type); if (!$b1) { phpcommon\sendError(ERR_USER_BASE + 3, '没有这个奖励'); die(); } $fixed_id = $this->getExplode($b1['item_id']); $fixed_time = $this->getExplode($b1['time']); $fixed_num = $this->getExplode($b1['num']); $fixed_array = $this->getExplode($b1['weight']); for($i = 0; $i < count($fixed_id); $i++) { $random = Rand(0, 10000); if ($fixed_array[$i][0] >= $random) { array_push($item_list, array( 'item_id' => $fixed_id[$i][0], 'item_num' => $fixed_num[$i][0], 'time' => $fixed_time[$i][0] )); } } return $item_list; } protected function randomBox($item_list, $type) { $b1 = $this->getbox($type); if (!$b1) { phpcommon\sendError(ERR_USER_BASE + 3, '没有这个奖励'); die(); } $fixed_id = $this->getExplode($b1['item_id']); $fixed_time = $this->getExplode($b1['time']); $fixed_num = $this->getExplode($b1['num']); $fixed_array = $this->getExplode($b1['weight']); $sum = 0; for($i = 0; $i < count($fixed_array); $i++) { $sum = $fixed_array[$i][0] + $sum; } $rm = Rand(0, $sum); $key = 0; for($j = 0; $j < count($fixed_array); $j++) { $key = $fixed_array[$j][0] + $key; if ($key >= $rm) { array_push($item_list, array( 'item_id' => $fixed_id[$j][0], 'item_num' => $fixed_num[$j][0], 'time' => $fixed_time[$j][0] )); if ($type == 8) { array_push($item_list, array( 'item_id' => $fixed_id[$j][0] + 2000, 'item_num' => $fixed_num[$j][0], 'time' => $fixed_time[$j][0] )); } break; } } return $item_list; } protected function randomReward($rank,$type) { //随机奖励 $r = $this->getRankReward($rank); $b = $this->getDrop($r['ad_drop']); $count = $r['ad_num']; if ($type == 1) { $b = $this->getDrop($r['js_drop']); $count = $r['js_num']; } $item_list = array(); $item_id_array = $this->getExplode($b['item_id']); $item_num_array = $this->getExplode($b['num']); $weight_array = $this->getExplode($b['weight']); $reward_array = array(); for ($c = 0; $c < $count; $c++) { $weight_sum = 0; $keys = 0; for ($ii = 0; $ii < count($weight_array); $ii++) { $flag = $this->removal($reward_array, $item_id_array[$ii][0]); if ($flag == 1) { continue; } $weight_sum += $weight_array[$ii][0]; } $random = Rand(0, $weight_sum); $weight = 0; for ($ii = 0; $ii < count($weight_array); $ii++) { $flag = $this->removal($reward_array, $item_id_array[$ii][0]); if ($flag == 1) { continue; } $weight += $weight_array[$ii][0]; if ($weight >= $random) { $keys = $ii; break; } } $item_id = $item_id_array[$keys][0]; $item_num = $item_num_array[$keys][0]; $time = 0; array_push($reward_array, array( 'id' => $item_id )); array_push($item_list, array( 'item_id' => $item_id, 'item_num' => $item_num, 'time' => $time )); } return $item_list; } protected function removal($reward, $id) { $flag = 0; foreach ($reward as $r) { if ($id == $r['id']) { $flag = 1; break; } } return $flag; } public function getFuckBoxReward() { $account_id = $_REQUEST['account_id']; //登录校验 $login = loginVerify($account_id, $_REQUEST['session_id']); if (!$login) { phpcommon\sendError(ERR_USER_BASE + 1, 'session无效'); return; } $id = 10; if (isset($_REQUEST['id'])) { $id = $_REQUEST['id']; } $item_list = array(); $all_item_list = array(); $item_list = $this->randomBoxNew($id); $addreward = new classes\AddReward(); foreach($item_list as $it) { $items = $addreward->addReward($it['item_id'], $it['item_num'], $account_id, $it['time'], 0); foreach($items as $j) { array_push($all_item_list, array( 'item_id' => $j['item_id'], 'item_num' => $j['item_num'], 'time' => $j['time'], )); } } $coin_num = $addreward->getCoinNum($account_id); $diamond_num = $addreward->getDiamondNum($account_id); echo json_encode(array( 'errcode' => 0, 'errmsg'=> '', 'coin_nums' => $coin_num, 'diamond_nums' => $diamond_num, 'item_list' => $item_list, 'all_item_list' => $all_item_list )); } protected function randomBoxNew($type) { //随机奖励 $b = $this->getBox($type); $count = $b['count']; $item_list = array(); $item_id_array = $this->getExplode($b['item_id']); $item_num_array = $this->getExplode($b['num']); $item_time_array = $this->getExplode($b['time']); $weight_array = $this->getExplode($b['weight']); $reward_array = array(); for ($c = 0; $c < $count; $c++) { $weight_sum = 0; $keys = 0; for ($ii = 0; $ii < count($weight_array); $ii++) { $flag = $this->removal($reward_array, $item_id_array[$ii][0]); if ($flag == 1) { continue; } $weight_sum += $weight_array[$ii][0]; } $random = Rand(0, $weight_sum); $weight = 0; for ($ii = 0; $ii < count($weight_array); $ii++) { $flag = $this->removal($reward_array, $item_id_array[$ii][0]); if ($flag == 1) { continue; } $weight += $weight_array[$ii][0]; if ($weight >= $random) { $keys = $ii; break; } } $item_id = $item_id_array[$keys][0]; $item_num = $item_num_array[$keys][0]; $time = $item_time_array[$keys][0]; array_push($reward_array, array( 'id' => $item_id )); array_push($item_list, array( 'item_id' => $item_id, 'item_num' => $item_num, 'time' => $time )); } return $item_list; } public function getDiamond() { $account_id = $_REQUEST['account_id']; //登录校验 $login = loginVerify($account_id, $_REQUEST['session_id']); if (!$login) { phpcommon\sendError(ERR_USER_BASE + 1, 'session无效'); return; } $addreward = new classes\AddReward(); $p = $this->getParameter(CLAN_VIDEO_DIAMOND); $par = $p['param_value']; $items = $addreward->addReward(10003, $par, $account_id, 0, 0); $diamond_num = $addreward->getDiamondNum($account_id); echo json_encode(array( 'errcode' => 0, 'errmsg'=> '', 'diamond_nums' => $diamond_num, )); } public function updateDiamond() { $account_id = $_REQUEST['account_id']; //登录校验 $login = loginVerify($account_id, $_REQUEST['session_id']); if (!$login) { phpcommon\sendError(ERR_USER_BASE + 1, 'session无效'); return; } $conn = $this->getMysql($account_id); if (!$conn) { phpcommon\sendError(ERR_USER_BASE + 2, '没有这个玩家'); die(); } $rowUser = $conn->execQueryOne('SELECT diamond_num FROM user WHERE accountid=:accountid;', array( ':accountid' => $account_id, )); if (!$rowUser) { phpcommon\sendError(ERR_USER_BASE + 2, '没有这个玩家'); return; } $p = $this->getParameter(CLAN_DIAMOND); $par = $p['param_value']; if ($rowUser['diamond_num'] < $par) { $par = 0; } $addreward = new classes\AddReward(); $items = $addreward->addReward(10003, -$par, $account_id, 0, 0); $diamond_num = $addreward->getDiamondNum($account_id); echo json_encode(array( 'errcode' => 0, 'errmsg'=> '', 'diamond_nums' => $diamond_num, )); } }