From a4ce44cd28104fee3184fd21213557f4d2ed2c1b Mon Sep 17 00:00:00 2001 From: wangwei01 Date: Tue, 23 Apr 2019 16:18:47 +0800 Subject: [PATCH] 1 --- webapp/classes/Quest.php | 53 +++++++------- webapp/controller/EquipController.class.php | 8 +-- webapp/controller/QuestController.class.php | 80 ++++++++++++++++++--- webapp/controller/RoleController.class.php | 52 ++++++++++++++ 4 files changed, 154 insertions(+), 39 deletions(-) diff --git a/webapp/classes/Quest.php b/webapp/classes/Quest.php index c1b55ad..56e1917 100644 --- a/webapp/classes/Quest.php +++ b/webapp/classes/Quest.php @@ -53,34 +53,35 @@ class Quest{ ':quest_type' => $quest_type, )); if ($row) { - if ($q['condition'] == 7 && $quest_type == 1) { - if($quest_num <= $q['value']) { - $quest_state = 1; - $this->triggerQuest(71013, 1, 1, $account_id); - } - } - else { - if ($row['quest_num'] + $quest_num >= $q['value']) { - $quest_num = $q['value']; - $quest_state = 1; - $this->triggerQuest(71013, 1, 1, $account_id); + if ($row['quest_state'] == 0) { + if ($q['condition'] == 7 && $quest_type == 1) { + if($quest_num <= $q['value']) { + $quest_state = 1; + $this->triggerQuest(71013, 1, 1, $account_id); + } } else { - $quest_num = $row['quest_num'] + $quest_num; - $quest_state = 0; + if ($row['quest_num'] + $quest_num >= $q['value']) { + $quest_num = $q['value']; + $quest_state = 1; + $this->triggerQuest(71013, 1, 1, $account_id); + } else { + $quest_num = $row['quest_num'] + $quest_num; + $quest_state = 0; + } + } + $ret = $conn->execScript('UPDATE quest SET quest_num=:quest_num, quest_state=:quest_state ' . + ' WHERE accountid=:accountid AND quest_id =:quest_id AND quest_type=:quest_type;', + array( + ':accountid' => $account_id, + ':quest_id' => $quest_id, + ':quest_type' => $quest_type, + ':quest_num' => $quest_num, + ':quest_state' => $quest_state + )); + if (!$ret) { + die(); + return; } - } - $ret = $conn->execScript('UPDATE quest SET quest_num=:quest_num, quest_state=:quest_state ' . - ' WHERE accountid=:accountid AND quest_id =:quest_id AND quest_type=:quest_type;', - array( - ':accountid' => $account_id, - ':quest_id' => $quest_id, - ':quest_type' => $quest_type, - ':quest_num' => $quest_num, - ':quest_state' => $quest_state - )); - if (!$ret) { - die(); - return; } } else { diff --git a/webapp/controller/EquipController.class.php b/webapp/controller/EquipController.class.php index 02d7e07..1e8e394 100644 --- a/webapp/controller/EquipController.class.php +++ b/webapp/controller/EquipController.class.php @@ -105,6 +105,10 @@ class EquipController{ $equip_id = $_REQUEST['equip_id']; $coin_num = $_REQUEST['coin_num']; $equip_level = $_REQUEST['equip_level']; + if ($equip_level >= 10) { + phpcommon\sendError(ERR_USER_BASE + 4, '装备已到满级'); + return; + } $e = $this->getEquip($equip_id * 10 + $equip_level); if (!$e) { phpcommon\sendError(ERR_USER_BASE + 2, '没有这个装备'); @@ -114,10 +118,6 @@ class EquipController{ phpcommon\sendError(ERR_USER_BASE + 3, '金币不足'); return; } - if ($e['equip_level'] >= 10) { - phpcommon\sendError(ERR_USER_BASE + 4, '装备已到满级'); - return; - } $row = $conn->execQueryOne('SELECT * FROM equip WHERE accountid=:account_id AND equip_id=:equip_id;', array( ':account_id' => $account_id, diff --git a/webapp/controller/QuestController.class.php b/webapp/controller/QuestController.class.php index 82257cb..7d2d718 100644 --- a/webapp/controller/QuestController.class.php +++ b/webapp/controller/QuestController.class.php @@ -45,6 +45,33 @@ class QuestController{ return $t; } + 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 getDrop($drop_id) + { + $g_conf_drop_cluster = require('../config/game2001api.drop.cluster.php'); + $drop_conf = getDropConfig($g_conf_drop_cluster, $drop_id); + $d = array( + 'drop_id' => $drop_conf['drop_id'], + 'item_id' => $drop_conf['item_id'], + 'num' => $drop_conf['num'], + 'weight' => $drop_conf['weight'], + 'type' => $drop_conf['type'] + ); + return $d; + } + protected function insertActive($account_id) { $conn = $this->getMysql($account_id); @@ -260,11 +287,6 @@ class QuestController{ phpcommon\sendError(ERR_USER_BASE + 1, '没有这个玩家'); return; } - $q = $this->getQuest($quest_id); - if (!$q) { - phpcommon\sendError(ERR_USER_BASE + 2, '没有这个任务'); - return; - } $row = $conn->execQueryOne('SELECT * FROM quest WHERE accountid=:accountid AND quest_id=:quest_id AND quest_type=:quest_type;', array( ':accountid' => $account_id, @@ -288,11 +310,51 @@ class QuestController{ die(); return; } - if ($q['condition'] == 13) { - $this->triggerQuest($quest_id, $quest_type, 1, $account_id); - } - //发奖励 + //发奖励 + $reward = $q['gold']; + if ($quest_type == 0) { + $t = $this->getTaskReward($quest_id); + if (!$t) { + phpcommon\sendError(ERR_USER_BASE + 2, '没有这个任务'); + return; + } + $d = $this->getDrop($t['reward']); + if (!$d) { + phpcommon\sendError(ERR_USER_BASE + 3, '没有这个奖励'); + return; + } + $weight_sum = 0; + $weight_array = $this->getExplode($d['weight']); + for ($i = 0; $i < count($weight_array); $i++) { + $weight_sum += $weight_array[$i][0]; + } + $random = Rand(0, $weight_sum); + $weight = 0; + for ($i = 0; $i < count($weight_array); $i++) { + $weight += $weight_array[$i][0]; + if ($weight > $random) { + $key = $i; + break; + } + } + $item_id_array = $this->getExplode($d['item_id']); + $num_array = $this->getExplode($d['num']); + $item_id = $item_id_array[$key][0]; + $item_num = $num_array[$key][0] * $mul; + array_push($item_list, array( + 'item_id' => $item_id, + 'item_num' => $item_num, + )); + } else { + $q = $this->getQuest($quest_id); + if (!$q) { + phpcommon\sendError(ERR_USER_BASE + 2, '没有这个任务'); + return; + } + $reward = $q['gold']; + error_log($reward); + } if ($row['quest_type'] == 1) { $active = $conn->execQueryOne('SELECT active_num, active_sum FROM active WHERE accountid=:accountid;', array( diff --git a/webapp/controller/RoleController.class.php b/webapp/controller/RoleController.class.php index 3318f5b..cda349b 100644 --- a/webapp/controller/RoleController.class.php +++ b/webapp/controller/RoleController.class.php @@ -1,5 +1,7 @@ getMysql($account_id); $kill_his = $kills; $harm_his = $harm; @@ -142,6 +150,37 @@ class RoleController{ die(); return; } + //刷新任务 + $quest = new classes\Quest(); + $quest->triggerQuest(71003, 1, 1, $account_id); + $quest->triggerQuest(71008, 1, $alive_time, $account_id); + $quest->triggerQuest(71009, 1, $harm, $account_id); + $quest->triggerQuest(71010, 1, $kills, $account_id); + $quest->triggerQuest(71011, 1, 1, $account_id); + $quest->triggerQuest(71012, 1, $rescue_member, $account_id); + $quest->triggerQuest(72003, 1, 1, $account_id); + $quest->triggerQuest(72009, 1, $alive_time, $account_id); + $quest->triggerQuest(72010, 1, $harm, $account_id); + $quest->triggerQuest(72011, 1, $kills, $account_id); + $quest->triggerQuest(72016, 1, 1, $account_id); + $quest->triggerQuest(72017, 1, $rescue_member, $account_id); + $quest->triggerQuest(72012, 1, $snipe_kill, $account_id); + $quest->triggerQuest(72013, 1, $rifle_kill, $account_id); + $quest->triggerQuest(72014, 1, $pistol_kill, $account_id); + $quest->triggerQuest(72015, 1, $submachine_kill, $account_id); + if ($team_status != 0 && $rank <= 5) { + $quest->triggerQuest(71007, 1, 1, $account_id); + } + if ($team_status == 1 && $rank == 1) { + $quest->triggerQuest(72007, 1, 1, $account_id); + } + if ($team_status == 2) { + $quest->triggerQuest(71006, 1, 1, $account_id); + $quest->triggerQuest(72006, 1, 1, $account_id); + if ($rank == 1) { + $quest->triggerQuest(72008, 1, 1, $account_id); + } + } } public function HistoryRecord() @@ -181,6 +220,19 @@ class RoleController{ )); } + public function shareGame() + { + $account_id = $_REQUEST['account_id']; + $conn = $this->getMysql($account_id); + if (!$conn) { + phpcommon\sendError(ERR_BASE_USER + 1, '没有这个玩家'); + return; + } + $quest = new classes\Quest(); + $quest->triggerQuest(71002, 1, 1, $account_id); + $quest->triggerQuest(72002, 1, 1, $account_id); + } + }