diff --git a/website/common/locales/en/character.json b/website/common/locales/en/character.json index 18029b6b20..0b6620cd1c 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/chat/group-chat.js b/website/server/libs/chat/group-chat.js index e9db7a4169..e8309eb63f 100644 --- a/website/server/libs/chat/group-chat.js +++ b/website/server/libs/chat/group-chat.js @@ -85,6 +85,19 @@ 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; @@ -112,6 +125,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('`')) { diff --git a/website/server/libs/spells.js b/website/server/libs/spells.js index c31bb61e1b..fab4199aa4 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, @@ -241,7 +242,49 @@ async function castSpell (req, res, { isV3 = false }) { }); if (party && !spell.silent) { - if (targetType === 'user') { + const lastMessage = await Chat.findOne({ groupId: party._id }) + .sort('-timestamp') + .exec(); + 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 + 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, + }, + }); + await newChatMessage.save(); + await lastMessage.remove(); + } + } 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: { @@ -250,6 +293,7 @@ async function castSpell (req, res, { isV3 = false }) { class: klass, spell: spellId, target: partyMembers.profile.name, + times: 1, }, }); await newChatMessage.save(); @@ -261,6 +305,7 @@ async function castSpell (req, res, { isV3 = false }) { user: user.profile.name, class: klass, spell: spellId, + times: 1, }, }); await newChatMessage.save();