Skip to content

Commit

Permalink
fix(chat): collapse repetitive spells for real now
Browse files Browse the repository at this point in the history
  • Loading branch information
SabreCat committed Jul 11, 2023
1 parent 74ba5c0 commit 106a0c9
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 22 deletions.
4 changes: 2 additions & 2 deletions website/common/locales/en/character.json
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@
"youCastParty": "You cast <%= spell %> for the party.",
"chatCastSpellParty": "<%= username %> casts <%= spell %> for the party.",
"chatCastSpellUser": "<%= username %> casts <%= spell %> on <%= target %>.",
"chatCastSpellPartyTimes": "<%= username %> casts <%= spell %> for the party <%= times =%> times.",
"chatCastSpellUserTimes": "<%= username %> casts <%= spell %> on <%= target %> <%= times =%> times.",
"chatCastSpellPartyTimes": "<%= username %> casts <%= spell %> for the party <%= times %> times.",
"chatCastSpellUserTimes": "<%= username %> casts <%= spell %> on <%= target %> <%= times %> times.",
"critBonus": "Critical Hit! Bonus: ",
"gainedGold": "You gained some Gold",
"gainedMana": "You gained some Mana",
Expand Down
8 changes: 8 additions & 0 deletions website/server/libs/chat/group-chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@ export function translateMessage (lang, info) {
msg = shared.i18n.t('chatCastSpellUser', { username: info.user, spell: spells[info.class][info.spell].text(lang), target: info.target }, lang);
break;

case 'spell_cast_party_multi':
msg = shared.i18n.t('chatCastSpellPartyTimes', { username: info.user, spell: spells[info.class][info.spell].text(lang), times: info.times }, lang);
break;

case 'spell_cast_user_multi':
msg = shared.i18n.t('chatCastSpellUserTimes', { username: info.user, spell: spells[info.class][info.spell].text(lang), target: info.target, times: info.times }, lang);

Check failure on line 93 in website/server/libs/chat/group-chat.js

View workflow job for this annotation

GitHub Actions / lint (14.x)

Expected a line break after this opening brace

Check failure on line 93 in website/server/libs/chat/group-chat.js

View workflow job for this annotation

GitHub Actions / lint (14.x)

Expected a line break before this closing brace
break;

case 'quest_cancel':
msg = shared.i18n.t('chatQuestCancelled', { username: info.user, questName: questScrolls[info.quest].text(lang) }, lang);
break;
Expand Down
58 changes: 38 additions & 20 deletions website/server/libs/spells.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,32 +242,50 @@ async function castSpell (req, res, { isV3 = false }) {
});

if (party && !spell.silent) {
const lastMessages = await Chat.find({ groupId: party._id })
.limit(1)
const lastMessage = await Chat.findOne({ groupId: party._id })
.sort('-timestamp')
.exec();
if (lastMessages.length === 1) {
const lastMessage = lastMessages[0];
if (lastMessage.info.spell === spellId && lastMessage.info.user === user.profile.name) {
lastMessage.info.times += 1;
lastMessage.timestamp = Number(new Date());
if (targetType === 'user') {
lastMessage.message = `\`${common.i18n.t('chatCastSpellUserTimes', {
if (lastMessage && lastMessage.info.spell === spellId
&& lastMessage.info.user === user.profile.name) {
if (targetType === 'user') {
const newChatMessage = party.sendChat({
message: `\`${common.i18n.t('chatCastSpellUserTimes', {
username: user.profile.name,
spell: spell.text(),
target: partyMembers.profile.name,
times: lastMessage.info.times,
}, 'en')}\``;
} else {
lastMessage.message = `\`${common.i18n.t('chatCastSpellPartyTimes', {
username: user.profile.name, spell: spell.text(), times: lastMessage.info.times,
}, 'en')}\``;
}
await lastMessage.save();
return;
times: lastMessage.info.times + 1,
}, 'en')}\``,
info: {
type: 'spell_cast_user_multi',
user: user.profile.name,
class: klass,
spell: spellId,
target: partyMembers.profile.name,
times: lastMessage.info.times + 1,
},
});
await newChatMessage.save();
await lastMessage.remove();
} else {
const newChatMessage = party.sendChat({
message: `\`${common.i18n.t('chatCastSpellPartyTimes', {
username: user.profile.name,
spell: spell.text(),
times: lastMessage.info.times + 1,
}, 'en')}\``,
info: {
type: 'spell_cast_party_multi',
user: user.profile.name,
class: klass,
spell: spellId,
times: lastMessage.info.times + 1,
},
});
console.log(newChatMessage);

Check warning on line 284 in website/server/libs/spells.js

View workflow job for this annotation

GitHub Actions / lint (14.x)

Unexpected console statement
await newChatMessage.save();
await lastMessage.remove();
}
}
if (targetType === 'user') {
} else if (targetType === 'user') {
const newChatMessage = party.sendChat({
message: `\`${common.i18n.t('chatCastSpellUser', { username: user.profile.name, spell: spell.text(), target: partyMembers.profile.name }, 'en')}\``,
info: {
Expand Down

0 comments on commit 106a0c9

Please sign in to comment.