Skip to content

Commit

Permalink
Merge pull request #463 from hanshino/feature/job
Browse files Browse the repository at this point in the history
新增小遊戲轉職系統
  • Loading branch information
hanshino authored Feb 5, 2024
2 parents 0dfa165 + 83ac8a3 commit 2bb8fd2
Show file tree
Hide file tree
Showing 16 changed files with 1,508 additions and 320 deletions.
1 change: 1 addition & 0 deletions app/config/default.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"defaultUserIcon": "https://i.imgur.com/SGDoCtd.png",
"app": {
"funds": {
"server": 3000,
Expand Down
3 changes: 3 additions & 0 deletions app/knexfile.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
// Update with your config settings.
require("dotenv").config({
path: "../.env",
});

module.exports = {
development: {
Expand Down
11 changes: 11 additions & 0 deletions app/locales/zh_tw.json
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,17 @@
"repeat_reward_note": "重複角色女神石",
"new_character_note": "獲得新角色",
"cross_year_only": "現在並非活動期間"
},
"rpg": {
"change_job": "請選擇職業",
"change_job_already": "你已經通過轉職任務,無法再次轉職",
"swordman_job_mission_already_started": "你已經開始進行劍士的轉職任務了,時間還剩下 {{ time }} 秒",
"mage_job_mission_already_started": "你已經開始進行法師的轉職任務了,時間還剩下 {{ time }} 秒",
"thief_job_mission_already_started": "你已經開始進行盜賊的轉職任務了,時間還剩下 {{ time }} 秒",
"swordman_start_job_mission": "已開始進行劍士的轉職任務,限時 10 分鐘",
"mage_start_job_mission": "已開始進行法師的轉職任務,限時 10 分鐘",
"mage_start_job_mission_help": "那麼就先從火元素開始詠唱吧~",
"thief_start_job_mission": "已開始進行盜賊的轉職任務,限時 10 分鐘,請摸走三個有價值的錢包"
}
},
"advancement": {
Expand Down
52 changes: 52 additions & 0 deletions app/migrations/20240120181544_create_minigame_job_table.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
exports.up = async function (knex) {
await knex.schema.createTable("minigame_job", table => {
table.increments("id").primary();
table.string("key").notNullable().unique();
table.string("name").notNullable();
table.string("description").notNullable().comment("職業描述");
table.integer("class_advancement").notNullable().comment("轉職位階");

table.timestamps(true, true);
});

return knex
.insert([
{
key: "adventurer",
name: "冒險者",
description: "冒險者",
class_advancement: 0,
},
{
key: "swordman",
name: "劍士",
description: "劍士是近戰專家,以高生命值和防禦力為優勢,擅長在前線與敵人近距離交戰。",
class_advancement: 1,
},
{
key: "thief",
name: "盜賊",
description: "盜賊以靈活性和隱密行動為優勢,能夠在戰場上迅速移動,進行偷襲和情報收集。",
class_advancement: 1,
},
{
key: "mage",
name: "法師",
description: "法師是遠距離攻擊者,以元素和魔法為主,雖然生命值較低,但擁有強大的法術威力。",
class_advancement: 1,
},
])
.into("minigame_job");
};

/**
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
exports.down = function (knex) {
return knex.schema.dropTable("minigame_job");
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
exports.up = function (knex) {
return knex.schema.table("minigame_level", table => {
table.integer("job_id").notNullable().comment("職業ID").after("exp").defaultTo(1);
});
};

/**
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
exports.down = function (knex) {
return knex.schema.table("minigame_level", table => {
table.dropColumn("job_id");
});
};
27 changes: 13 additions & 14 deletions app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,48 +9,47 @@
"worker": "node tasks.js",
"debug": "DEBUG=bottender:action node server.js",
"test": "jest",
"migrate": "knex migrate:latest",
"knex": "knex"
"migrate": "knex migrate:latest"
},
"dependencies": {
"@sentry/node": "^7.91.0",
"@sentry/node": "^7.99.0",
"ajv": "^8.12.0",
"ajv-formats": "^2.1.1",
"axios": "1.6.3",
"axios": "1.6.7",
"bottender": "1.5.5",
"brotli": "^1.3.3",
"cheerio": "^1.0.0-rc.12",
"config": "^3.3.9",
"config": "^3.3.11",
"cron": "^3.1.6",
"date-format": "^4.0.14",
"express": "^4.18.2",
"express-rate-limit": "^7.1.5",
"human-number": "^2.0.4",
"i18n": "^0.15.1",
"imgur": "^2.3.0",
"imgur": "^2.4.2",
"knex": "^3.1.0",
"lodash": "^4.17.21",
"log4js": "^6.9.1",
"math-random": "^2.0.1",
"md5": "^2.3.0",
"minimist": "^1.2.8",
"moment": "^2.30.1",
"mysql2": "^3.6.5",
"redis": "^4.6.12",
"socket.io": "^4.7.2",
"sqlite3": "^5.1.6",
"mysql2": "^3.9.1",
"redis": "^4.6.13",
"socket.io": "^4.7.4",
"sqlite3": "^5.1.7",
"table": "^6.8.1",
"uuid-random": "^1.3.2"
},
"devDependencies": {
"@types/express": "^4.17.21",
"cors": "^2.8.5",
"dotenv": "^16.3.1",
"dotenv": "^16.4.1",
"eslint": "^8.56.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.1.2",
"eslint-plugin-prettier": "^5.1.3",
"jest": "^29.7.0",
"nodemon": "^3.0.2",
"prettier": "^3.1.1"
"nodemon": "^3.0.3",
"prettier": "^3.2.5"
}
}
30 changes: 28 additions & 2 deletions app/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const BullshitController = require("./controller/application/BullshitController"
const SubscribeController = require("./controller/application/SubscribeController");
const ScratchCardController = require("./controller/application/ScratchCardController");
const NumberController = require("./controller/application/NumberController");
const JobController = require("./controller/application/JobController");
const { transfer } = require("./middleware/dcWebhook");
const redis = require("./util/redis");
const traffic = require("./util/traffic");
Expand Down Expand Up @@ -99,6 +100,30 @@ async function HandlePostback(context, { next }) {
withProps(ScratchCardController.exchange, { payload })
),
route(() => action === "sicBoGuess", withProps(NumberController.postbackDecide, { payload })),
route(
() => action === "startSwordmanChangeJobMission",
withProps(JobController.startSwordmanJobMission, { payload })
),
route(
() => action === "swordmanChangeJobMission",
withProps(JobController.swordmanAttackTarget, { payload })
),
route(
() => action === "startMageChangeJobMission",
withProps(JobController.startMageChangeJobMission, { payload })
),
route(
() => action === "mageChangeJobMission",
withProps(JobController.mageUseElement, { payload })
),
route(
() => action === "startThiefChangeJobMission",
withProps(JobController.startThiefChangeJobMission, { payload })
),
route(
() => action === "thiefChangeJobMission",
withProps(JobController.thiefSteal, { payload })
),
route("*", next),
]);
} catch (e) {
Expand All @@ -109,10 +134,10 @@ async function HandlePostback(context, { next }) {

/**
* 基於功能指令優先辨識
* @param {Context}
* @param {import("bottender").LineContext} context
*/
async function OrderBased(context, { next }) {
const { userId } = context.event.source;
const { userId, type } = context.event.source;
const isAdmin = userId && (await AdminModel.isAdminFromCache(userId));

return router([
Expand All @@ -137,6 +162,7 @@ async function OrderBased(context, { next }) {
...SubscribeController.router,
...ScratchCardController.router,
...NumberController.router,
...(type === "user" ? JobController.router : []),
text(/^[/#.](使|help)$/, welcome),
text(/^[/#.](\*(?<times>\d+))?(\s*(?<tag>[\s\S]+))?$/, gacha.play),
text(/^[/#.](\*(?<times>\d+))?(\s*(?<tag>[\s\S]+))?$/, (context, props) =>
Expand Down
Loading

0 comments on commit 2bb8fd2

Please sign in to comment.