wangwei01 90f97ad76c 1
2019-04-23 13:49:17 +08:00

117 lines
4.5 KiB
PHP

<?php
namespace classes;
use phpcommon;
class Quest{
protected function getMysql($account_id)
{
$mysql_conf = getMysqlConfig(crc32($account_id));
$conn = new phpcommon\Mysql(array(
'host' => $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.quest.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 ($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);
} 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(71013, 1, 1, $account_id);
}
} else {
if ($quest_num >= $q['value']) {
$quest_num = $q['value'];
$quest_state = 1;
$this->triggerQuest(71013, 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;
}
}
}
}
?>