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: {