$mysql_conf['host'], 'port' => $mysql_conf['port'], 'user' => $mysql_conf['user'], 'passwd' => $mysql_conf['passwd'], 'dbname' => 'gamedb2001_' . $mysql_conf['instance_id'] )); return $conn; } protected function getQuest($quest_id) { $g_conf_quest_cluster = require('../config/game2001api.task.cluster.php'); $quest_conf = getQuestConfig($g_conf_quest_cluster, $quest_id); $q = array( 'id' => $quest_conf['id'], 'type' => $quest_conf['type'], 'condition' => $quest_conf['condition'], 'value' => $quest_conf['value'], 'active_value' => $quest_conf['active_value'], 'gold' => $quest_conf['gold'], ); return $q; } public function triggerQuest($quest_id, $quest_type, $quest_num, $account_id) { $conn = $this->getMysql($account_id); if (!$conn) { 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, ':quest_id' => $quest_id, ':quest_type' => $quest_type, )); if ($row) { if ($row['quest_state'] == 0) { if ($q['condition'] == 7 && $quest_type == 1) { if($quest_num <= $q['value']) { $quest_state = 1; $this->triggerQuest(QUEST_DAY_COMPLETE, 1, 1, $account_id); } } else if ($q['condition'] == 13 && $quest_type == 1){ if ($row['quest_num'] + $quest_num >= $q['value']) { $quest_num = $q['value']; $quest_state = 1; } else { $quest_num = $row['quest_num'] + $quest_num; $quest_state = 0; } } else { if ($row['quest_num'] + $quest_num >= $q['value']) { $quest_num = $q['value']; $quest_state = 1; if ($quest_type == 1) { $this->triggerQuest(QUEST_DAY_COMPLETE, 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; } } } else { $quest_state = 0; if ($q['condition'] == 7 && $quest_type == 1) { if($quest_num <= $q['value']) { $quest_state = 1; $this->triggerQuest(QUEST_DAY_COMPLETE, 1, 1, $account_id); } } else if ($q['condition'] == 13 && $quest_type == 1){ if ($row['quest_num'] >= $q['value']) { $quest_num = $q['value']; $quest_state = 1; } } else { if ($quest_num >= $q['value']) { $quest_num = $q['value']; $quest_state = 1; if ($quest_type == 1) { $this->triggerQuest(QUEST_DAY_COMPLETE, 1, 1, $account_id); } } } $ret = $conn->execScript('INSERT INTO quest(accountid, quest_id, quest_num, quest_type, quest_state) ' . ' VALUES(:accountid, :quest_id, :quest_num, :quest_type, :quest_state);', array( ':accountid' => $account_id, ':quest_id' => $quest_id, ':quest_num' => $quest_num, ':quest_type' => $quest_type, ':quest_state'=> $quest_state )); if (!$ret) { die(); return; } } } } ?>