diff --git a/server/game2006service/constant.js b/server/game2006service/constant.js index e69de29b..d6d9e9f5 100644 --- a/server/game2006service/constant.js +++ b/server/game2006service/constant.js @@ -0,0 +1 @@ +exports.TIME_ZONE = 0; diff --git a/server/game2006service/tasks/factory.js b/server/game2006service/tasks/factory.js index adf60be2..65dc0b4b 100644 --- a/server/game2006service/tasks/factory.js +++ b/server/game2006service/tasks/factory.js @@ -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; diff --git a/server/game2006service/tasks/fragment.js b/server/game2006service/tasks/fragment.js new file mode 100644 index 00000000..b21865f9 --- /dev/null +++ b/server/game2006service/tasks/fragment.js @@ -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; diff --git a/sql/gamedb.sql b/sql/gamedb.sql index 52fe301a..ebb1cbae 100644 --- a/sql/gamedb.sql +++ b/sql/gamedb.sql @@ -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 */; diff --git a/third_party/j7 b/third_party/j7 index 60793c7b..6a6a58c9 160000 --- a/third_party/j7 +++ b/third_party/j7 @@ -1 +1 @@ -Subproject commit 60793c7b53c719d4b50482a88d25b2b18aa51069 +Subproject commit 6a6a58c94497cc008ca467942f99576e1385d9ad diff --git a/webapp/models/Gun.php b/webapp/models/Gun.php index e2013850..218197f3 100644 --- a/webapp/models/Gun.php +++ b/webapp/models/Gun.php @@ -485,4 +485,9 @@ class Gun extends BaseModel { return $newAttrPro; } + public static function calcPveGainGold($gunDto, $count) + { + return 0; + } + }