fix(chat): collapse repetitive spells for real now

This commit is contained in:
SabreCat 2023-07-11 17:01:17 -05:00
parent 74ba5c0b27
commit 106a0c9ed8
3 changed files with 48 additions and 22 deletions

View file

@ -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",

View file

@ -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;

View file

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