From 2d71a902f188b5526f2acecb45ac153191f94d9b Mon Sep 17 00:00:00 2001 From: Phillip Thelen Date: Mon, 10 Jul 2023 16:27:31 +0200 Subject: [PATCH 1/7] Merge skill casting messages together --- website/server/libs/spells.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/website/server/libs/spells.js b/website/server/libs/spells.js index 4a132f290b..1a14be9919 100644 --- a/website/server/libs/spells.js +++ b/website/server/libs/spells.js @@ -222,6 +222,18 @@ async function castSpell (req, res, { isV3 = false }) { }); if (party && !spell.silent) { + const lastMessages = await Chat.find({ groupId: group._id }) + .limit(1) + .sort('-timestamp') + .exec(); + if (lastMessages.size == 1) { + const lastMessage = lastMessages[0]; + if (lastMessage.info.spell == spellId && lastMessage.info.user == user.profile.name) { + lastMessage.info.times += 1; + await lastMessage.save(); + return; + } + } if (targetType === 'user') { const newChatMessage = party.sendChat({ message: `\`${common.i18n.t('chatCastSpellUser', { username: user.profile.name, spell: spell.text(), target: partyMembers.profile.name }, 'en')}\``, @@ -231,6 +243,7 @@ async function castSpell (req, res, { isV3 = false }) { class: klass, spell: spellId, target: partyMembers.profile.name, + times: 1 }, }); await newChatMessage.save(); @@ -242,6 +255,7 @@ async function castSpell (req, res, { isV3 = false }) { user: user.profile.name, class: klass, spell: spellId, + times: 1 }, }); await newChatMessage.save(); From 2308961de6ebdc48888b4ce68a257fd73459bf38 Mon Sep 17 00:00:00 2001 From: SabreCat Date: Mon, 10 Jul 2023 15:11:22 -0500 Subject: [PATCH 2/7] fix(lint): address fatal errors --- website/server/libs/spells.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/website/server/libs/spells.js b/website/server/libs/spells.js index 1a14be9919..cc1b6078cd 100644 --- a/website/server/libs/spells.js +++ b/website/server/libs/spells.js @@ -1,4 +1,5 @@ import { model as User } from '../models/user'; +import { chatModel as Chat } from '../models/message'; import * as Tasks from '../models/task'; import { NotFound, @@ -222,13 +223,13 @@ async function castSpell (req, res, { isV3 = false }) { }); if (party && !spell.silent) { - const lastMessages = await Chat.find({ groupId: group._id }) + const lastMessages = await Chat.find({ groupId: party._id }) .limit(1) .sort('-timestamp') .exec(); - if (lastMessages.size == 1) { + if (lastMessages.size === 1) { const lastMessage = lastMessages[0]; - if (lastMessage.info.spell == spellId && lastMessage.info.user == user.profile.name) { + if (lastMessage.info.spell === spellId && lastMessage.info.user === user.profile.name) { lastMessage.info.times += 1; await lastMessage.save(); return; @@ -243,7 +244,7 @@ async function castSpell (req, res, { isV3 = false }) { class: klass, spell: spellId, target: partyMembers.profile.name, - times: 1 + times: 1, }, }); await newChatMessage.save(); @@ -255,7 +256,7 @@ async function castSpell (req, res, { isV3 = false }) { user: user.profile.name, class: klass, spell: spellId, - times: 1 + times: 1, }, }); await newChatMessage.save(); From bb54a6532d205e913a9e237680b0ad800af88206 Mon Sep 17 00:00:00 2001 From: SabreCat Date: Mon, 10 Jul 2023 15:37:46 -0500 Subject: [PATCH 3/7] fix(chat): correct bad length check --- website/server/libs/spells.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/server/libs/spells.js b/website/server/libs/spells.js index ad8a1935ae..6ab4d655a1 100644 --- a/website/server/libs/spells.js +++ b/website/server/libs/spells.js @@ -246,7 +246,7 @@ async function castSpell (req, res, { isV3 = false }) { .limit(1) .sort('-timestamp') .exec(); - if (lastMessages.size === 1) { + if (lastMessages.length === 1) { const lastMessage = lastMessages[0]; if (lastMessage.info.spell === spellId && lastMessage.info.user === user.profile.name) { lastMessage.info.times += 1; From 74ba5c0b27956f63e574b11e8f6ecf6a15b57fe6 Mon Sep 17 00:00:00 2001 From: Phillip Thelen Date: Tue, 11 Jul 2023 15:10:50 +0200 Subject: [PATCH 4/7] bring merging to MVP --- website/common/locales/en/character.json | 2 ++ website/server/libs/spells.js | 13 +++++++++++++ 2 files changed, 15 insertions(+) diff --git a/website/common/locales/en/character.json b/website/common/locales/en/character.json index 18029b6b20..e105f61a69 100644 --- a/website/common/locales/en/character.json +++ b/website/common/locales/en/character.json @@ -150,6 +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.", "critBonus": "Critical Hit! Bonus: ", "gainedGold": "You gained some Gold", "gainedMana": "You gained some Mana", diff --git a/website/server/libs/spells.js b/website/server/libs/spells.js index 6ab4d655a1..8192a9952f 100644 --- a/website/server/libs/spells.js +++ b/website/server/libs/spells.js @@ -250,6 +250,19 @@ async function castSpell (req, res, { isV3 = false }) { 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', { + 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; } From 106a0c9ed830fa27549c77ad8b1fad4cce9d18db Mon Sep 17 00:00:00 2001 From: SabreCat Date: Tue, 11 Jul 2023 17:01:17 -0500 Subject: [PATCH 5/7] fix(chat): collapse repetitive spells for real now --- website/common/locales/en/character.json | 4 +- website/server/libs/chat/group-chat.js | 8 ++++ website/server/libs/spells.js | 58 ++++++++++++++++-------- 3 files changed, 48 insertions(+), 22 deletions(-) diff --git a/website/common/locales/en/character.json b/website/common/locales/en/character.json index e105f61a69..0b6620cd1c 100644 --- a/website/common/locales/en/character.json +++ b/website/common/locales/en/character.json @@ -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", diff --git a/website/server/libs/chat/group-chat.js b/website/server/libs/chat/group-chat.js index e9db7a4169..095cdec4f0 100644 --- a/website/server/libs/chat/group-chat.js +++ b/website/server/libs/chat/group-chat.js @@ -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); + break; + case 'quest_cancel': msg = shared.i18n.t('chatQuestCancelled', { username: info.user, questName: questScrolls[info.quest].text(lang) }, lang); break; diff --git a/website/server/libs/spells.js b/website/server/libs/spells.js index 8192a9952f..afeb9a3741 100644 --- a/website/server/libs/spells.js +++ b/website/server/libs/spells.js @@ -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); + 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: { From 259f7ef58842fb75f237b713b9d1438ac7aae7ae Mon Sep 17 00:00:00 2001 From: SabreCat Date: Tue, 11 Jul 2023 18:25:59 -0500 Subject: [PATCH 6/7] fix(chat): add default to switch block --- website/server/libs/chat/group-chat.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/website/server/libs/chat/group-chat.js b/website/server/libs/chat/group-chat.js index 095cdec4f0..e73af4af51 100644 --- a/website/server/libs/chat/group-chat.js +++ b/website/server/libs/chat/group-chat.js @@ -120,6 +120,9 @@ export function translateMessage (lang, info) { case 'claim_task': msg = shared.i18n.t('userIsClamingTask', { username: info.user, task: info.task }, lang); break; + + default: + msg = "Error translating party chat. Unknown message type."; } if (!msg.includes('`')) { From 067a1de49eb964b75f8d56096de745a6162784e5 Mon Sep 17 00:00:00 2001 From: SabreCat Date: Tue, 18 Jul 2023 10:20:58 -0500 Subject: [PATCH 7/7] fix(lint): newlines, console --- website/server/libs/chat/group-chat.js | 9 +++++++-- website/server/libs/spells.js | 1 - 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/website/server/libs/chat/group-chat.js b/website/server/libs/chat/group-chat.js index e73af4af51..e8309eb63f 100644 --- a/website/server/libs/chat/group-chat.js +++ b/website/server/libs/chat/group-chat.js @@ -90,7 +90,12 @@ export function translateMessage (lang, info) { 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); + msg = shared.i18n.t('chatCastSpellUserTimes', { + username: info.user, + spell: spells[info.class][info.spell].text(lang), + target: info.target, + times: info.times, + }, lang); break; case 'quest_cancel': @@ -122,7 +127,7 @@ export function translateMessage (lang, info) { break; default: - msg = "Error translating party chat. Unknown message type."; + msg = 'Error translating party chat. Unknown message type.'; } if (!msg.includes('`')) { diff --git a/website/server/libs/spells.js b/website/server/libs/spells.js index afeb9a3741..fab4199aa4 100644 --- a/website/server/libs/spells.js +++ b/website/server/libs/spells.js @@ -281,7 +281,6 @@ async function castSpell (req, res, { isV3 = false }) { times: lastMessage.info.times + 1, }, }); - console.log(newChatMessage); await newChatMessage.save(); await lastMessage.remove(); }