Skip to content

Commit

Permalink
Merge pull request #452 from hanshino:feature/europe-gacha
Browse files Browse the repository at this point in the history
Update dependencies and add Europe gacha feature
  • Loading branch information
hanshino authored Dec 16, 2023
2 parents c1ca6d0 + 5483425 commit d12e1cd
Show file tree
Hide file tree
Showing 6 changed files with 154 additions and 117 deletions.
1 change: 1 addition & 0 deletions app/config/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@
"user_cooldown": 1,
"pick_up_cost": 1500,
"ensure_cost": 3000,
"europe_cost": 10000,
"silver_repeat_reward": 1,
"gold_repeat_reward": 10,
"rainbow_repeat_reward": 50
Expand Down
6 changes: 4 additions & 2 deletions app/locales/zh_tw.json
Original file line number Diff line number Diff line change
Expand Up @@ -233,11 +233,13 @@
}
},
"gacha": {
"not_enough_stone": "女神石不足,無法進行保證抽",
"not_enough_stone": "女神石不足,無法花錢進行特別抽取",
"pick_up_cost_note": "消耗抽扣除女神石",
"ensure_cost_note": "保證抽扣除女神石",
"europe_cost_note": "歐洲抽扣除女神石",
"repeat_reward_note": "重複角色女神石",
"new_character_note": "獲得新角色"
"new_character_note": "獲得新角色",
"cross_year_only": "現在並非活動期間"
}
},
"advancement": {
Expand Down
20 changes: 10 additions & 10 deletions app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,30 @@
"knex": "knex"
},
"dependencies": {
"@sentry/node": "^7.80.0",
"@sentry/node": "^7.88.0",
"ajv": "^8.12.0",
"ajv-formats": "^2.1.1",
"axios": "1.6.1",
"axios": "1.6.2",
"bottender": "1.5.5",
"brotli": "^1.3.3",
"cheerio": "^1.0.0-rc.12",
"config": "^3.3.9",
"cron": "^3.1.6",
"date-format": "^4.0.14",
"express": "^4.18.2",
"express-rate-limit": "^7.1.4",
"express-rate-limit": "^7.1.5",
"human-number": "^2.0.4",
"i18n": "^0.15.1",
"imgur": "^2.3.0",
"knex": "^3.0.1",
"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.29.4",
"mysql2": "^3.6.3",
"redis": "^4.6.10",
"mysql2": "^3.6.5",
"redis": "^4.6.11",
"socket.io": "^4.7.2",
"sqlite3": "^5.1.6",
"table": "^6.8.1",
Expand All @@ -45,11 +45,11 @@
"devDependencies": {
"@types/express": "^4.17.21",
"cors": "^2.8.5",
"eslint": "^8.53.0",
"eslint-config-prettier": "^9.0.0",
"eslint": "^8.56.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.0.1",
"jest": "^29.7.0",
"nodemon": "^3.0.1",
"prettier": "^3.0.3"
"nodemon": "^3.0.2",
"prettier": "^3.1.1"
}
}
3 changes: 3 additions & 0 deletions app/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ async function OrderBased(context, { next }) {
text(/^[/#.]消耗抽(\*(?<times>\d+))?(\s*(?<tag>[\s\S]+))?$/, (context, props) =>
gacha.play(context, { ...props, pickup: true })
),
text(/^[/#.]歐洲抽(\*(?<times>\d+))?(\s*(?<tag>[\s\S]+))?$/, (context, props) =>
gacha.play(context, { ...props, europe: true })
),
text(/^[/#.]保證抽(\*(?<times>\d+))?(\s*(?<tag>[\s\S]+))?$/, (context, props) =>
withProps(gacha.play, { ...props, ensure: true })
),
Expand Down
45 changes: 38 additions & 7 deletions app/src/controller/princess/gacha.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,18 @@ async function showGachaBag(context) {
* @param {Boolean} param1.pickup
* @param {Boolean} param1.ensure
*/
async function gacha(context, { match, pickup, ensure = false }) {
async function gacha(context, { match, pickup, ensure = false, europe = false }) {
let { tag, times = 10 } = match.groups;
const { userId, type, groupId } = context.event.source;
const now = moment();
const month = now.month() + 1;
const date = now.date();
const isCrossYear = (month === 12 && date === 31) || (month === 1 && date === 1);

// 只有 12/31~1/1 這兩天才會開放歐洲轉蛋池
if (europe && !isCrossYear) {
return context.replyText(i18n.__("message.gacha.cross_year_only"));
}

if (type === "group" && context.state.guildConfig.Gacha === "N") {
DefaultLogger.info(`${userId} 在群組 ${groupId} 嘗試進行轉蛋,但該群組已關閉轉蛋功能`);
Expand Down Expand Up @@ -236,12 +245,15 @@ async function gacha(context, { match, pickup, ensure = false }) {
const userOwnStone = parseInt(await GachaModel.getUserGodStoneCount(userId));
const pickupCost = config.get("gacha.pick_up_cost");
const ensureCost = config.get("gacha.ensure_cost");
const europeCost = config.get("gacha.europe_cost");

// 檢查是否有足夠的女神石
if (pickup && userOwnStone < pickupCost) {
return context.replyText(i18n.__("message.gacha.not_enough_stone"));
} else if (ensure && userOwnStone < ensureCost) {
return context.replyText(i18n.__("message.gacha.not_enough_stone"));
} else if (europe && userOwnStone < europeCost) {
return context.replyText(i18n.__("message.gacha.not_enough_stone"));
}

const queries = [];
Expand All @@ -252,14 +264,33 @@ async function gacha(context, { match, pickup, ensure = false }) {
newCharacters: [],
repeatReward: 0,
};
const dailyPool = pickup ? makePickup(filteredPool, 200) : filteredPool;
// const dailyPool = pickup ? makePickup(filteredPool, 200) : filteredPool;
const dailyPool = (() => {
if (pickup) {
return makePickup(filteredPool, 200);
} else if (ensure) {
return filteredPool;
} else if (europe) {
return filteredPool.filter(data => data.star == "3");
}
return filteredPool;
})();

// 進行特殊費用扣除
if (pickup || ensure) {
const cost = pickup ? pickupCost : ensureCost;
const note = pickup
? i18n.__("message.gacha.pick_up_cost_note")
: i18n.__("message.gacha.ensure_cost_note");
if (pickup || ensure || europe) {
let cost = 0;
let note = "";
if (pickup) {
cost = pickupCost;
note = i18n.__("message.gacha.pick_up_cost_note");
} else if (ensure) {
cost = ensureCost;
note = i18n.__("message.gacha.ensure_cost_note");
} else if (europe) {
cost = europeCost;
note = i18n.__("message.gacha.europe_cost_note");
}

queries.push(
inventory.knex.insert({
userId,
Expand Down
Loading

0 comments on commit d12e1cd

Please sign in to comment.