Merge branch 'hjb' of git.kingsome.cn:server/game2006api into hjb

This commit is contained in:
hujiabin 2022-09-21 16:45:37 +08:00
commit b06c64fef5
6 changed files with 119 additions and 4 deletions

View File

@ -0,0 +1 @@
exports.TIME_ZONE = 0;

View File

@ -1,5 +1,12 @@
function init() {
const tasks = {};
function add(name) {
tasks[name] = require(`./${name}`);
tasks[name].init();
}
function init() {
add('fragment');
}
exports.init = init;

View File

@ -0,0 +1,100 @@
const app = require('j7/app');
const utils = require('j7/utils');
const constant = require('../constant');
const YESTERDAY_HERO_NUM = 1000;
const YESTERDAY_GUN_NUM = 1000;
class Fragment {
async start() {
while (true) {
await this.alloc(utils.getUtcTime());
const nowTime = utils.getUtcTime();
const daySeconds = utils.getDaySeconds(nowTime, constant.TIME_ZONE);
const hourSeconds = utils.getHourSeconds(nowTime, constant.TIME_ZONE);
const sleepTime = 3600 + 10;
await utils.sleep(sleepTime * 1000);
}
}
async alloc(nowTime) {
try {
const daySeconds = utils.getDaySeconds(nowTime, constant.TIME_ZONE);
const hourSeconds = utils.getHourSeconds(nowTime, constant.TIME_ZONE);
const {err, conn} = await app.getDbConn("GameDb1");
if (!err && conn) {
const isAlloced = await this.isAlloced(conn, daySeconds, nowTime, hourSeconds);
if (!isAlloced) {
const allocedFragments = await this.fetchAllocedFragments(conn, daySeconds, nowTime);
await this.realloc(conn, daySeconds, nowTime, allowedVersions);
}
}
} catch (err) {
console.log(err);
}
}
async isAlloced(conn, daySeconds, nowTime, hourSeconds) {
const {err, row} = await conn.execQueryOne(
'SELECT * FROM t_fragment_pool WHERE alloc_time = ?',
[
daySeconds + hourSeconds
]
);
if (err) {
throw err;
return true;
}
return row ? true : false;
}
async fetchAllocedFragments(conn, daySeconds, nowTime) {
const {err, rows} = await conn.execQuery(
'SELECT * FROM t_fragment_pool WHERE alloc_time >= ? AND alloc_time <= ?',
[
daySeconds,
nowTime
]
);
if (err) {
throw err;
return;
}
const allocedFragments = new Map();
allocedFragments.set(0, new Map());
allocedFragments.set(1, new Map());
rows.forEach(
(element) => {
if (element['type'] == 0 ||
element['type'] == 1) {
const data = allocedFragments.get(element['type']);
if (data) {
const num = Math.max(0, element['alloc_num'] - element['fragment_num']);
if (!data.has(element['fragment_id'])) {
data.set(element['fragment_id'], {
'fragment_id' : element['fragment_id'],
'num' : num
});
} else {
data.get(element['fragment_id'])['num'] += num
}
}
}
}
);
return allocedFragments;
}
async realloc(conn, daySeconds, nowTime, hourSeconds, allocedFragments) {
}
}
function init() {
(new Fragment()).start();
}
exports.init = init;

View File

@ -610,13 +610,15 @@ DROP TABLE IF EXISTS `t_fragment_pool`;
CREATE TABLE `t_fragment_pool` (
`idx` bigint NOT NULL AUTO_INCREMENT COMMENT '自增id',
`fragment_id` int(11) NOT NULL DEFAULT '0' COMMENT '碎片id',
`type` int(11) NOT NULL DEFAULT '0' COMMENT '0:pvp 1:pve',
`fragment_type` int(11) NOT NULL DEFAULT '0' COMMENT '碎片类型 0:英雄 1:武器',
`fragment_num` int(11) NOT NULL DEFAULT '0' COMMENT '碎片数量',
`fragment_num` int(11) NOT NULL DEFAULT '0' COMMENT '剩余碎片数量',
`alloc_num` int(11) NOT NULL DEFAULT '0' COMMENT '分配的碎片数量',
`alloc_time` int(11) NOT NULL DEFAULT '0' COMMENT '分配时间',
`createtime` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间',
`modifytime` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间',
PRIMARY KEY (`idx`),
KEY `alloc_time_fragment_type` (`alloc_time`, `fragment_type`)
KEY `alloc_time_type_fragment_type` (`alloc_time`, `type`, `fragment_type`)
) ENGINE=InnoDB AUTO_INCREMENT=10000 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
/*!40101 SET character_set_client = @saved_cs_client */;

2
third_party/j7 vendored

@ -1 +1 @@
Subproject commit 60793c7b53c719d4b50482a88d25b2b18aa51069
Subproject commit 6a6a58c94497cc008ca467942f99576e1385d9ad

View File

@ -485,4 +485,9 @@ class Gun extends BaseModel {
return $newAttrPro;
}
public static function calcPveGainGold($gunDto, $count)
{
return 0;
}
}