feat: view stats + player attack logic
This commit is contained in:
parent
076b9f1a38
commit
c16bf27cec
88
index.js
88
index.js
|
@ -401,10 +401,20 @@ If you want to choose an opponent yourself, simply use \`/chooseopponent\` to ge
|
||||||
await ctx.next();
|
await ctx.next();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function playerLoss(ctx) {}
|
||||||
|
|
||||||
|
async function playerWin(ctx) {}
|
||||||
|
|
||||||
app.action("continue", checkButton, async (ctx) => {
|
app.action("continue", checkButton, async (ctx) => {
|
||||||
const user = await initializeUser(ctx.context.userId);
|
const user = await initializeUser(ctx.context.userId);
|
||||||
const slackUser = (await ctx.client.users.info({ user: ctx.context.userId })).user.profile;
|
const slackUser = (await ctx.client.users.info({ user: ctx.context.userId })).user.profile;
|
||||||
|
|
||||||
|
if (user.playerhealth <= 0) {
|
||||||
|
return playerLoss(ctx)
|
||||||
|
} else if (user.opponenthealth <= 0) {
|
||||||
|
return playerWin(ctx)
|
||||||
|
}
|
||||||
|
|
||||||
ctx.respond({
|
ctx.respond({
|
||||||
replace_original: true,
|
replace_original: true,
|
||||||
text: "",
|
text: "",
|
||||||
|
@ -414,16 +424,16 @@ app.action("continue", checkButton, async (ctx) => {
|
||||||
"fields": [
|
"fields": [
|
||||||
{
|
{
|
||||||
"type": "mrkdwn",
|
"type": "mrkdwn",
|
||||||
"text": `${slackUser.display_name_normalized}:\n\n*Health:* 20\n*Min Damage:* 1\n*Max Damage:* 9`
|
"text": `${slackUser.display_name_normalized}:\n\n*Health:* ${user.playerhealth}\n*Min Damage:* ${user.playermin}\n*Max Damage:* ${user.playermax}`
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "mrkdwn",
|
"type": "mrkdwn",
|
||||||
"text": `${AllOpponents.find(x=> x.rawId == user.currentopponent).name}:\n\n*Health:* 25\n*Min Damage:* 2\n*Max Damage:* 5`
|
"text": `${AllOpponents.find(x=> x.rawId == user.currentopponent).name}:\n\n*Health:* ${user.opponenthealth}\n*Min Damage:* ${user.opponentmin}\n*Max Damage:* ${user.opponentmax}`
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"accessory": {
|
"accessory": {
|
||||||
"type": "image",
|
"type": "image",
|
||||||
"image_url": "https://media.discordapp.net/attachments/1108683335347212389/1118119440702242816/BM_-_Rap_Star_1.png?ex=6674a820&is=667356a0&hm=520cf408d3cadad838b0d2350fb212470949257cbd2768bfea64523feb33b494&",
|
"image_url": AllOpponents.find(x=> x.rawId == user.currentopponent).image,
|
||||||
"alt_text": AllOpponents.find(x=> x.rawId == user.currentopponent).name
|
"alt_text": AllOpponents.find(x=> x.rawId == user.currentopponent).name
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -432,7 +442,7 @@ app.action("continue", checkButton, async (ctx) => {
|
||||||
"elements": [
|
"elements": [
|
||||||
{
|
{
|
||||||
"type": "mrkdwn",
|
"type": "mrkdwn",
|
||||||
"text": `*${slackUser.display_name_normalized}* vs *${AllOpponents.find(x=> x.rawId == user.currentopponent).name}*`
|
"text": `*${slackUser.display_name_normalized}* vs *${AllOpponents.find(x=> x.rawId == user.currentopponent).name}* | Your Turn`
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
@ -478,7 +488,7 @@ app.action("continue", checkButton, async (ctx) => {
|
||||||
},
|
},
|
||||||
"style": "danger",
|
"style": "danger",
|
||||||
"value": ctx.context.userId,
|
"value": ctx.context.userId,
|
||||||
"action_id": "actionId-4"
|
"action_id": "forfeit"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -486,6 +496,74 @@ app.action("continue", checkButton, async (ctx) => {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
app.action('forfeit', checkButton, async (ctx) => {
|
||||||
|
ctx.respond({
|
||||||
|
replace_original: false,
|
||||||
|
response_type: 'ephemeral',
|
||||||
|
text: 'Not yet...'
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
app.action(/attack|defend|item/, checkButton, async (ctx) => {
|
||||||
|
let response = "";
|
||||||
|
const user = await initializeUser(ctx.context.userId);
|
||||||
|
const slackUser = (await ctx.client.users.info({ user: ctx.context.userId })).user.profile;
|
||||||
|
|
||||||
|
switch (ctx.payload.action_id) {
|
||||||
|
case 'attack':
|
||||||
|
if (user.opponentdefense == 'Strong') {
|
||||||
|
response = `*_${slackUser.display_name_normalized} attacks ${AllOpponents.find(x=> x.rawId == user.currentopponent).name}_*\n\n\`\`\`NO DAMAGE\`\`\``
|
||||||
|
} else if (user.opponentdefense == 'Moderate') {
|
||||||
|
if (Math.random() < 0.5) {
|
||||||
|
response = `*_${slackUser.display_name_normalized} attacks ${AllOpponents.find(x=> x.rawId == user.currentopponent).name}_*\n\n\`\`\`NO DAMAGE\`\`\``
|
||||||
|
} else {
|
||||||
|
const damage = Math.floor(Math.random() * (user.playermax - user.playermin + 1) ) + user.playermin;
|
||||||
|
await sql`UPDATE users SET opponenthealth = ${user.opponenthealth - damage} WHERE slack_id = ${ctx.context.userId};`
|
||||||
|
response = `*_${slackUser.display_name_normalized} attacks ${AllOpponents.find(x=> x.rawId == user.currentopponent).name}_*\n\n\`\`\`${damage.toLocaleString()} DAMAGE\`\`\``
|
||||||
|
}
|
||||||
|
} else if (user.opponentdefense == 'Weak') {
|
||||||
|
if (Math.random() < 0.25) {
|
||||||
|
response = `*_${slackUser.display_name_normalized} attacks ${AllOpponents.find(x=> x.rawId == user.currentopponent).name}_*\n\n\`\`\`NO DAMAGE\`\`\``
|
||||||
|
} else {
|
||||||
|
const damage = Math.floor(Math.random() * (user.playermax - user.playermin + 1) ) + user.playermin;
|
||||||
|
await sql`UPDATE users SET opponenthealth = ${user.opponenthealth - damage} WHERE slack_id = ${ctx.context.userId};`
|
||||||
|
response = `*_${slackUser.display_name_normalized} attacks ${AllOpponents.find(x=> x.rawId == user.currentopponent).name}_*\n\n\`\`\`${damage.toLocaleString()} DAMAGE\`\`\``
|
||||||
|
}
|
||||||
|
}
|
||||||
|
await sql`UPDATE users SET opponentdefense = 'None' WHERE slack_id = ${ctx.context.userId};`
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
await ctx.respond({
|
||||||
|
"blocks": [
|
||||||
|
{
|
||||||
|
"type": "section",
|
||||||
|
"text": {
|
||||||
|
"type": "mrkdwn",
|
||||||
|
"text": ""
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "actions",
|
||||||
|
"elements": [
|
||||||
|
{
|
||||||
|
"type": "button",
|
||||||
|
"text": {
|
||||||
|
"type": "plain_text",
|
||||||
|
"text": "Continue",
|
||||||
|
"emoji": true
|
||||||
|
},
|
||||||
|
"value": ctx.context.userId,
|
||||||
|
"action_id": "continue-opponent"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
app.command('/bm-eval', async (ctx) => {
|
app.command('/bm-eval', async (ctx) => {
|
||||||
await ctx.ack();
|
await ctx.ack();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue