Skip to content

Commit

Permalink
Add Europe gacha feature
Browse files Browse the repository at this point in the history
  • Loading branch information
hanshino committed Dec 16, 2023
1 parent 3494e50 commit 5483425
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 9 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
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

0 comments on commit 5483425

Please sign in to comment.