wangwei01 3711686abf 1
2019-07-11 14:20:06 +08:00

138 lines
5.9 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' => 'gamedb2002_' . $mysql_conf['instance_id']
));
return $conn;
}
protected function getQuest($quest_id)
{
$g_conf_quest_cluster = require('../res/task@task.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'],
);
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, modify_time=:modify_time ' .
' 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,
':modify_time' => time()
));
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, create_time, modify_time) ' .
' VALUES(:accountid, :quest_id, :quest_num, :quest_type, :quest_state, :create_time, :modify_time) ' .
' ON DUPLICATE KEY UPDATE accountid=:accountid, quest_id=:quest_id, quest_num=:quest_num, quest_type=:quest_type, quest_state=:quest_state, modify_time=:modify_time;',
array(
':accountid' => $account_id,
':quest_id' => $quest_id,
':quest_num' => $quest_num,
':quest_type' => $quest_type,
':quest_state'=> $quest_state,
':create_time' => time(),
':modify_time' => time()
));
if (!$ret) {
die();
return;
}
}
}
}
?>