Don't collapse different spell targets in party chat (#14775)

* fix(spells): don't collapse different targets

* fix(lint): indentation

---------

Co-authored-by: SabreCat <sabe@habitica.com>
This commit is contained in:
Sabe Jones
2023-07-25 14:15:12 -05:00
committed by GitHub
parent 7c9b0f207c
commit 683649ff1a

View File

@@ -245,9 +245,10 @@ async function castSpell (req, res, { isV3 = false }) {
const lastMessage = await Chat.findOne({ groupId: party._id }) const lastMessage = await Chat.findOne({ groupId: party._id })
.sort('-timestamp') .sort('-timestamp')
.exec(); .exec();
if (lastMessage && lastMessage.info.spell === spellId if (targetType === 'user') { // Single target spell, check for repeat
&& lastMessage.info.user === user.profile.name) { if (lastMessage && lastMessage.info.spell === spellId
if (targetType === 'user') { && lastMessage.info.user === user.profile.name
&& lastMessage.info.target === partyMembers.profile.name) {
const newChatMessage = party.sendChat({ const newChatMessage = party.sendChat({
message: `\`${common.i18n.t('chatCastSpellUserTimes', { message: `\`${common.i18n.t('chatCastSpellUserTimes', {
username: user.profile.name, username: user.profile.name,
@@ -266,39 +267,40 @@ async function castSpell (req, res, { isV3 = false }) {
}); });
await newChatMessage.save(); await newChatMessage.save();
await lastMessage.remove(); await lastMessage.remove();
} else { } else { // Single target spell, not repeated
const newChatMessage = party.sendChat({ const newChatMessage = party.sendChat({
message: `\`${common.i18n.t('chatCastSpellPartyTimes', { message: `\`${common.i18n.t('chatCastSpellUser', { username: user.profile.name, spell: spell.text(), target: partyMembers.profile.name }, 'en')}\``,
username: user.profile.name,
spell: spell.text(),
times: lastMessage.info.times + 1,
}, 'en')}\``,
info: { info: {
type: 'spell_cast_party_multi', type: 'spell_cast_user',
user: user.profile.name, user: user.profile.name,
class: klass, class: klass,
spell: spellId, spell: spellId,
times: lastMessage.info.times + 1, target: partyMembers.profile.name,
times: 1,
}, },
}); });
await newChatMessage.save(); await newChatMessage.save();
await lastMessage.remove();
} }
} else if (targetType === 'user') { } else if (lastMessage && lastMessage.info.spell === spellId // Party spell, check for repeat
&& lastMessage.info.user === user.profile.name) {
const newChatMessage = party.sendChat({ const newChatMessage = party.sendChat({
message: `\`${common.i18n.t('chatCastSpellUser', { username: user.profile.name, spell: spell.text(), target: partyMembers.profile.name }, 'en')}\``, message: `\`${common.i18n.t('chatCastSpellPartyTimes', {
username: user.profile.name,
spell: spell.text(),
times: lastMessage.info.times + 1,
}, 'en')}\``,
info: { info: {
type: 'spell_cast_user', type: 'spell_cast_party_multi',
user: user.profile.name, user: user.profile.name,
class: klass, class: klass,
spell: spellId, spell: spellId,
target: partyMembers.profile.name, times: lastMessage.info.times + 1,
times: 1,
}, },
}); });
await newChatMessage.save(); await newChatMessage.save();
await lastMessage.remove();
} else { } else {
const newChatMessage = party.sendChat({ const newChatMessage = party.sendChat({ // Non-repetitive partywide spell
message: `\`${common.i18n.t('chatCastSpellParty', { username: user.profile.name, spell: spell.text() }, 'en')}\``, message: `\`${common.i18n.t('chatCastSpellParty', { username: user.profile.name, spell: spell.text() }, 'en')}\``,
info: { info: {
type: 'spell_cast_party', type: 'spell_cast_party',