Skip to content

Commit

Permalink
Merge pull request #516 from hanshino/fix/world_boss
Browse files Browse the repository at this point in the history
Fix character skill damage and attack count display issues
  • Loading branch information
hanshino authored Sep 7, 2024
2 parents c184172 + 7e46c02 commit 82dd346
Show file tree
Hide file tree
Showing 6 changed files with 491 additions and 426 deletions.
2 changes: 1 addition & 1 deletion app/config/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"傷害會隨著等級的提升",
"經驗值是透過傷害比例計算出來的",
"可以使用 #冒險小卡 查看自己的進度",
"每一次攻擊都會依照攻擊型態來消耗 cost",
"每一次攻擊都會依照技能來消耗 cost",
"每一次攻擊都會間隔 5 秒"
]
},
Expand Down
24 changes: 12 additions & 12 deletions app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@
"migrate": "knex migrate:latest"
},
"dependencies": {
"@sentry/node": "^8.7.0",
"ajv": "^8.16.0",
"@sentry/node": "^8.28.0",
"ajv": "^8.17.1",
"ajv-formats": "^3.0.1",
"axios": "1.7.2",
"axios": "1.7.7",
"bottender": "1.5.5",
"brotli": "^1.3.3",
"cheerio": "^1.0.0-rc.12",
"config": "^3.3.11",
"cheerio": "^1.0.0",
"config": "^3.3.12",
"cron": "^3.1.7",
"date-format": "^4.0.14",
"express": "^4.19.2",
"express-rate-limit": "^7.3.0",
"express-rate-limit": "^7.4.0",
"human-number": "^2.0.4",
"i18n": "^0.15.1",
"imgur": "^2.4.2",
Expand All @@ -34,8 +34,8 @@
"md5": "^2.3.0",
"minimist": "^1.2.8",
"moment": "^2.30.1",
"mysql2": "^3.10.0",
"redis": "^4.6.14",
"mysql2": "^3.11.0",
"redis": "^4.7.0",
"socket.io": "^4.7.5",
"sqlite3": "^5.1.7",
"table": "^6.8.2",
Expand All @@ -45,12 +45,12 @@
"@types/express": "^4.17.21",
"cors": "^2.8.5",
"dotenv": "^16.4.5",
"eslint": "^9.4.0",
"eslint": "^9.10.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.1.3",
"eslint-plugin-prettier": "^5.2.1",
"jest": "^29.7.0",
"nodemon": "^3.1.3",
"prettier": "^3.3.1"
"nodemon": "^3.1.4",
"prettier": "^3.3.3"
},
"packageManager": "[email protected]+sha1.4ba7fc5c6e704fce2066ecbfb0b0d8976fe62447"
}
19 changes: 10 additions & 9 deletions app/src/controller/application/WorldBossController.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const { get, sample, sortBy } = require("lodash");
const humanNumber = require("human-number");
const { format } = require("util");
const { table, getBorderCharacters } = require("table");
const { parse } = require("path");

exports.router = [
text("#冒險小卡", myStatus),
Expand Down Expand Up @@ -225,9 +226,9 @@ async function myStatus(context) {
const character = makeCharacter(job_key, { level });

// 取得今日已經攻擊的次數
const [todayAttackCount, sumLogs, { max: maxDamage = 0 }, { count: attendTimes = 0 }] =
const [{ totalCost = 0 }, sumLogs, { max: maxDamage = 0 }, { count: attendTimes = 0 }] =
await Promise.all([
worldBossEventLogService.getTodayAttackCount(id),
worldBossEventLogService.getTodayCost(id),
worldBossLogModel.getBossLogs(id, { limit: 2 }),
worldBossLogModel.getUserMaxDamage(id),
worldBossLogModel.getUserAttendance(id),
Expand All @@ -239,7 +240,7 @@ async function myStatus(context) {
name: displayName,
image: pictureUrl,
exp,
attackCount: todayAttackCount,
totalCost,
jobName: job_name,
jobAdvancement: job_class_advancement,
};
Expand Down Expand Up @@ -387,7 +388,7 @@ async function bossEvent(context) {

// 取得攻擊面板
const attackBubble = worldBossTemplate.generateAttackBubble({
eventId
eventId,
});

const contents = [ruleBubble, attackBubble, mainBubble, infoBubble, rankBubble];
Expand Down Expand Up @@ -635,19 +636,19 @@ async function isUserCanAttack(userId) {
}

// 取得今日紀錄
let todayLogs = await worldBossEventLogService.getTodayLogs(userId);
const result = await worldBossEventLogService.getTodayCost(userId);
const totalCost = parseInt(get(result, "totalCost", 0));
// 如果完全沒有紀錄,代表可以攻擊
if (todayLogs.length === 0) {
if (totalCost === 0) {
await redis.set(key, 1, {
EX: cooldownSeconds * 1,
NX: true,
});
return true;
}

let currentCost = todayLogs.reduce((acc, log) => acc + get(log, "cost", 0), 0);
let canAttack = currentCost < config.get("worldboss.daily_limit");
console.log(`${userId} can attack ${canAttack}, currentCost ${currentCost}`);
let canAttack = totalCost < config.get("worldboss.daily_limit");
console.log(`${userId} can attack ${canAttack}, currentCost ${totalCost}`);

// 不管是否可以攻擊,都要更新 redis 的資料
await redis.set(key, 1, {
Expand Down
8 changes: 4 additions & 4 deletions app/src/model/application/RPGCharacter.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ class Swordman extends Adventurer {
constructor({ level }) {
super({ level });
this.key = "swordman";
this.power = 1.5;
this.power = 1.8;
}

get skillOne() {
Expand Down Expand Up @@ -209,8 +209,8 @@ class Mage extends Adventurer {
name: "元素之力",
description: "敵に1.1倍のダメージを与える。クリティカル時は2倍",
cost: 8,
rate: 1.1,
criticalRate: 10,
rate: 0.8,
criticalRate: 20,
criticalConfig: [makeCriticalConfig(1.5, 2, 90), makeCriticalConfig(2, 3, 10)],
};
}
Expand Down Expand Up @@ -243,7 +243,7 @@ class Thief extends Adventurer {
description: "敵に1.2倍のダメージを与える",
cost: 12,
rate: 1.2,
criticalRate: 30,
criticalRate: 40,
criticalConfig: [
makeCriticalConfig(1.5, 2, 70),
makeCriticalConfig(2, 3, 20),
Expand Down
22 changes: 15 additions & 7 deletions app/src/templates/application/WorldBoss.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const makeAttackPayload = (worldBossEventId, jobKey, skill) => ({
attackType: [jobKey, skill].join("|"),
});

exports.generateAttackBubble = ({eventId}) => ({
exports.generateAttackBubble = ({ eventId }) => ({
type: "bubble",
body: {
type: "box",
Expand Down Expand Up @@ -127,7 +127,11 @@ exports.generateAttackBubble = ({eventId}) => ({
action: {
type: "postback",
data: JSON.stringify(
makeAttackPayload(eventId, RPGCharacter.Mage.key, RPGCharacter.enumSkills.SKILL_ONE)
makeAttackPayload(
eventId,
RPGCharacter.Mage.key,
RPGCharacter.enumSkills.SKILL_ONE
)
),
},
},
Expand Down Expand Up @@ -164,7 +168,11 @@ exports.generateAttackBubble = ({eventId}) => ({
action: {
type: "postback",
data: JSON.stringify(
makeAttackPayload(eventId, RPGCharacter.Thief.key, RPGCharacter.enumSkills.SKILL_ONE)
makeAttackPayload(
eventId,
RPGCharacter.Thief.key,
RPGCharacter.enumSkills.SKILL_ONE
)
),
},
},
Expand Down Expand Up @@ -710,15 +718,15 @@ exports.generateOshirase = () => ({
* @param {String} param0.level 冒險者等級
* @param {String} param0.exp 冒險者經驗值
* @param {String} param0.expPercentage 冒險者經驗值 % 數值
* @param {Number} param0.attackCount 攻擊次數
* @param {Number} param0.totalCost cost 總量
*/
exports.generateAdventureCard = ({
name,
image,
level,
exp,
expPercentage,
attackCount,
totalCost,
jobName,
jobAdvancement = 0,
}) => ({
Expand Down Expand Up @@ -824,11 +832,11 @@ exports.generateAdventureCard = ({
contents: [
{
type: "span",
text: "刀數:",
text: "cost:",
},
{
type: "span",
text: `${attackCount}/${config.get("worldboss.daily_limit")}`,
text: `${totalCost}/${config.get("worldboss.daily_limit")}`,
},
],
},
Expand Down
Loading

0 comments on commit 82dd346

Please sign in to comment.