mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 14:47:53 +01:00
Implemented requested changes
This commit is contained in:
@@ -127,7 +127,14 @@ describe('POST /groups/:groupId/quests/abort', () => {
|
|||||||
members: {},
|
members: {},
|
||||||
});
|
});
|
||||||
expect(Group.prototype.sendChat).to.be.calledOnce;
|
expect(Group.prototype.sendChat).to.be.calledOnce;
|
||||||
expect(Group.prototype.sendChat).to.be.calledWithMatch(/aborted the party quest Wail of the Whale.`/);
|
expect(Group.prototype.sendChat).to.be.calledWithMatch({
|
||||||
|
// message: /aborted the party quest Wail of the Whale.`/,
|
||||||
|
info: {
|
||||||
|
quest: 'whale',
|
||||||
|
type: 'quest_abort',
|
||||||
|
// user: '1526651788146ce91216'
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
stub.restore();
|
stub.restore();
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -205,7 +205,16 @@ describe('Group Model', () => {
|
|||||||
party = await Group.findOne({_id: party._id});
|
party = await Group.findOne({_id: party._id});
|
||||||
|
|
||||||
expect(Group.prototype.sendChat).to.be.calledOnce;
|
expect(Group.prototype.sendChat).to.be.calledOnce;
|
||||||
expect(Group.prototype.sendChat).to.be.calledWith('`Participating Member attacks Wailing Whale for 5.0 damage. Wailing Whale attacks party for 7.5 damage.`');
|
expect(Group.prototype.sendChat).to.be.calledWith({
|
||||||
|
message: '`Participating Member attacks Wailing Whale for 5.0 damage. Wailing Whale attacks party for 7.5 damage.`',
|
||||||
|
info: {
|
||||||
|
bossDamage: '7.5',
|
||||||
|
quest: 'whale',
|
||||||
|
type: 'boss_damage',
|
||||||
|
user: 'Participating Member',
|
||||||
|
userDamage: '5.0',
|
||||||
|
},
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('applies damage only to participating members of party', async () => {
|
it('applies damage only to participating members of party', async () => {
|
||||||
@@ -271,7 +280,10 @@ describe('Group Model', () => {
|
|||||||
party = await Group.findOne({_id: party._id});
|
party = await Group.findOne({_id: party._id});
|
||||||
|
|
||||||
expect(Group.prototype.sendChat).to.be.calledTwice;
|
expect(Group.prototype.sendChat).to.be.calledTwice;
|
||||||
expect(Group.prototype.sendChat).to.be.calledWith('`You defeated Wailing Whale! Questing party members receive the rewards of victory.`');
|
expect(Group.prototype.sendChat).to.be.calledWith({
|
||||||
|
message: '`You defeated Wailing Whale! Questing party members receive the rewards of victory.`',
|
||||||
|
info: { quest: 'whale', type: 'boss_defeated' },
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('calls finishQuest when boss has <= 0 hp', async () => {
|
it('calls finishQuest when boss has <= 0 hp', async () => {
|
||||||
@@ -314,7 +326,10 @@ describe('Group Model', () => {
|
|||||||
|
|
||||||
party = await Group.findOne({_id: party._id});
|
party = await Group.findOne({_id: party._id});
|
||||||
|
|
||||||
expect(Group.prototype.sendChat).to.be.calledWith(quest.boss.rage.effect('en'));
|
expect(Group.prototype.sendChat).to.be.calledWith({
|
||||||
|
message: quest.boss.rage.effect('en'),
|
||||||
|
info: { quest: 'trex_undead', type: 'boss_rage' },
|
||||||
|
});
|
||||||
expect(party.quest.progress.hp).to.eql(383.5);
|
expect(party.quest.progress.hp).to.eql(383.5);
|
||||||
expect(party.quest.progress.rage).to.eql(0);
|
expect(party.quest.progress.rage).to.eql(0);
|
||||||
});
|
});
|
||||||
@@ -364,7 +379,10 @@ describe('Group Model', () => {
|
|||||||
|
|
||||||
party = await Group.findOne({_id: party._id});
|
party = await Group.findOne({_id: party._id});
|
||||||
|
|
||||||
expect(Group.prototype.sendChat).to.be.calledWith(quest.boss.rage.effect('en'));
|
expect(Group.prototype.sendChat).to.be.calledWith({
|
||||||
|
message: quest.boss.rage.effect('en'),
|
||||||
|
info: { quest: 'lostMasterclasser4', type: 'boss_rage' },
|
||||||
|
});
|
||||||
expect(party.quest.progress.rage).to.eql(0);
|
expect(party.quest.progress.rage).to.eql(0);
|
||||||
|
|
||||||
let drainedUser = await User.findById(participatingMember._id);
|
let drainedUser = await User.findById(participatingMember._id);
|
||||||
@@ -415,7 +433,15 @@ describe('Group Model', () => {
|
|||||||
party = await Group.findOne({_id: party._id});
|
party = await Group.findOne({_id: party._id});
|
||||||
|
|
||||||
expect(Group.prototype.sendChat).to.be.calledOnce;
|
expect(Group.prototype.sendChat).to.be.calledOnce;
|
||||||
expect(Group.prototype.sendChat).to.be.calledWith('`Participating Member found 5 Bars of Soap.`');
|
expect(Group.prototype.sendChat).to.be.calledWith({
|
||||||
|
message: '`Participating Member found 5 Bars of Soap.`',
|
||||||
|
info: {
|
||||||
|
items: { soapBars: 5 },
|
||||||
|
quest: 'atom1',
|
||||||
|
type: 'user_found_items',
|
||||||
|
user: 'Participating Member',
|
||||||
|
},
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('sends a chat message if no progress is made', async () => {
|
it('sends a chat message if no progress is made', async () => {
|
||||||
@@ -426,7 +452,15 @@ describe('Group Model', () => {
|
|||||||
party = await Group.findOne({_id: party._id});
|
party = await Group.findOne({_id: party._id});
|
||||||
|
|
||||||
expect(Group.prototype.sendChat).to.be.calledOnce;
|
expect(Group.prototype.sendChat).to.be.calledOnce;
|
||||||
expect(Group.prototype.sendChat).to.be.calledWith('`Participating Member found 0 Bars of Soap.`');
|
expect(Group.prototype.sendChat).to.be.calledWith({
|
||||||
|
message: '`Participating Member found 0 Bars of Soap.`',
|
||||||
|
info: {
|
||||||
|
items: { soapBars: 0 },
|
||||||
|
quest: 'atom1',
|
||||||
|
type: 'user_found_items',
|
||||||
|
user: 'Participating Member',
|
||||||
|
},
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('sends a chat message if no progress is made on quest with multiple items', async () => {
|
it('sends a chat message if no progress is made on quest with multiple items', async () => {
|
||||||
@@ -443,9 +477,15 @@ describe('Group Model', () => {
|
|||||||
party = await Group.findOne({_id: party._id});
|
party = await Group.findOne({_id: party._id});
|
||||||
|
|
||||||
expect(Group.prototype.sendChat).to.be.calledOnce;
|
expect(Group.prototype.sendChat).to.be.calledOnce;
|
||||||
expect(Group.prototype.sendChat).to.be.calledWithMatch(/`Participating Member found/);
|
expect(Group.prototype.sendChat).to.be.calledWith({
|
||||||
expect(Group.prototype.sendChat).to.be.calledWithMatch(/0 Blue Fins/);
|
message: '`Participating Member found 0 Fire Coral, 0 Blue Fins.`',
|
||||||
expect(Group.prototype.sendChat).to.be.calledWithMatch(/0 Fire Coral/);
|
info: {
|
||||||
|
items: { blueFins: 0, fireCoral: 0 },
|
||||||
|
quest: 'dilatoryDistress1',
|
||||||
|
type: 'user_found_items',
|
||||||
|
user: 'Participating Member',
|
||||||
|
},
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('handles collection quests with multiple items', async () => {
|
it('handles collection quests with multiple items', async () => {
|
||||||
@@ -462,8 +502,15 @@ describe('Group Model', () => {
|
|||||||
party = await Group.findOne({_id: party._id});
|
party = await Group.findOne({_id: party._id});
|
||||||
|
|
||||||
expect(Group.prototype.sendChat).to.be.calledOnce;
|
expect(Group.prototype.sendChat).to.be.calledOnce;
|
||||||
expect(Group.prototype.sendChat).to.be.calledWithMatch(/`Participating Member found/);
|
expect(Group.prototype.sendChat).to.be.calledWithMatch({
|
||||||
expect(Group.prototype.sendChat).to.be.calledWithMatch(/\d* (Tracks|Broken Twigs)/);
|
// message: "`Participating Member found \d* Broken Twigs, \d* Tracks.`",
|
||||||
|
info: {
|
||||||
|
// items: { branches: \d*, tracks: \d* },
|
||||||
|
quest: 'evilsanta2',
|
||||||
|
type: 'user_found_items',
|
||||||
|
user: 'Participating Member',
|
||||||
|
},
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('sends message about victory', async () => {
|
it('sends message about victory', async () => {
|
||||||
@@ -474,7 +521,10 @@ describe('Group Model', () => {
|
|||||||
party = await Group.findOne({_id: party._id});
|
party = await Group.findOne({_id: party._id});
|
||||||
|
|
||||||
expect(Group.prototype.sendChat).to.be.calledTwice;
|
expect(Group.prototype.sendChat).to.be.calledTwice;
|
||||||
expect(Group.prototype.sendChat).to.be.calledWith('`All items found! Party has received their rewards.`');
|
expect(Group.prototype.sendChat).to.be.calledWith({
|
||||||
|
message: '`All items found! Party has received their rewards.`',
|
||||||
|
info: { type: 'all_items_found' },
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('calls finishQuest when all items are found', async () => {
|
it('calls finishQuest when all items are found', async () => {
|
||||||
@@ -1123,20 +1173,22 @@ describe('Group Model', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('formats message', () => {
|
it('formats message', () => {
|
||||||
const chatMessage = party.sendChat('a new message', {
|
const chatMessage = party.sendChat({
|
||||||
_id: 'user-id',
|
message: 'a new message', user: {
|
||||||
profile: { name: 'user name' },
|
_id: 'user-id',
|
||||||
contributor: {
|
profile: { name: 'user name' },
|
||||||
toObject () {
|
contributor: {
|
||||||
return 'contributor object';
|
toObject () {
|
||||||
|
return 'contributor object';
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
backer: {
|
||||||
backer: {
|
toObject () {
|
||||||
toObject () {
|
return 'backer object';
|
||||||
return 'backer object';
|
},
|
||||||
},
|
},
|
||||||
},
|
}}
|
||||||
});
|
);
|
||||||
|
|
||||||
const chat = chatMessage;
|
const chat = chatMessage;
|
||||||
|
|
||||||
@@ -1153,7 +1205,7 @@ describe('Group Model', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('formats message as system if no user is passed in', () => {
|
it('formats message as system if no user is passed in', () => {
|
||||||
const chat = party.sendChat('a system message');
|
const chat = party.sendChat({message: 'a system message'});
|
||||||
|
|
||||||
expect(chat.text).to.eql('a system message');
|
expect(chat.text).to.eql('a system message');
|
||||||
expect(validator.isUUID(chat.id)).to.eql(true);
|
expect(validator.isUUID(chat.id)).to.eql(true);
|
||||||
@@ -1174,7 +1226,7 @@ describe('Group Model', () => {
|
|||||||
|
|
||||||
expect(party.chat).to.have.a.lengthOf(220);
|
expect(party.chat).to.have.a.lengthOf(220);
|
||||||
|
|
||||||
party.sendChat('message');
|
party.sendChat({message: 'message'});
|
||||||
|
|
||||||
expect(party.chat).to.have.a.lengthOf(200);
|
expect(party.chat).to.have.a.lengthOf(200);
|
||||||
});
|
});
|
||||||
@@ -1188,13 +1240,13 @@ describe('Group Model', () => {
|
|||||||
|
|
||||||
expect(party.chat).to.have.a.lengthOf(420);
|
expect(party.chat).to.have.a.lengthOf(420);
|
||||||
|
|
||||||
party.sendChat('message');
|
party.sendChat({message: 'message'});
|
||||||
|
|
||||||
expect(party.chat).to.have.a.lengthOf(400);
|
expect(party.chat).to.have.a.lengthOf(400);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('updates users about new messages in party', () => {
|
it('updates users about new messages in party', () => {
|
||||||
party.sendChat('message');
|
party.sendChat({message: 'message'});
|
||||||
|
|
||||||
expect(User.update).to.be.calledOnce;
|
expect(User.update).to.be.calledOnce;
|
||||||
expect(User.update).to.be.calledWithMatch({
|
expect(User.update).to.be.calledWithMatch({
|
||||||
@@ -1208,7 +1260,7 @@ describe('Group Model', () => {
|
|||||||
type: 'guild',
|
type: 'guild',
|
||||||
});
|
});
|
||||||
|
|
||||||
group.sendChat('message');
|
group.sendChat({message: 'message'});
|
||||||
|
|
||||||
expect(User.update).to.be.calledOnce;
|
expect(User.update).to.be.calledOnce;
|
||||||
expect(User.update).to.be.calledWithMatch({
|
expect(User.update).to.be.calledWithMatch({
|
||||||
@@ -1218,7 +1270,7 @@ describe('Group Model', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('does not send update to user that sent the message', () => {
|
it('does not send update to user that sent the message', () => {
|
||||||
party.sendChat('message', {_id: 'user-id', profile: { name: 'user' }});
|
party.sendChat({message: 'message', user: {_id: 'user-id', profile: { name: 'user' }}});
|
||||||
|
|
||||||
expect(User.update).to.be.calledOnce;
|
expect(User.update).to.be.calledOnce;
|
||||||
expect(User.update).to.be.calledWithMatch({
|
expect(User.update).to.be.calledWithMatch({
|
||||||
@@ -1230,7 +1282,7 @@ describe('Group Model', () => {
|
|||||||
it('skips sending new message notification for guilds with > 5000 members', () => {
|
it('skips sending new message notification for guilds with > 5000 members', () => {
|
||||||
party.memberCount = 5001;
|
party.memberCount = 5001;
|
||||||
|
|
||||||
party.sendChat('message');
|
party.sendChat({message: 'message'});
|
||||||
|
|
||||||
expect(User.update).to.not.be.called;
|
expect(User.update).to.not.be.called;
|
||||||
});
|
});
|
||||||
@@ -1238,7 +1290,7 @@ describe('Group Model', () => {
|
|||||||
it('skips sending messages to the tavern', () => {
|
it('skips sending messages to the tavern', () => {
|
||||||
party._id = TAVERN_ID;
|
party._id = TAVERN_ID;
|
||||||
|
|
||||||
party.sendChat('message');
|
party.sendChat({message: 'message'});
|
||||||
|
|
||||||
expect(User.update).to.not.be.called;
|
expect(User.update).to.not.be.called;
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -179,7 +179,7 @@ api.postChat = {
|
|||||||
throw new NotAuthorized(res.t('messageGroupChatSpam'));
|
throw new NotAuthorized(res.t('messageGroupChatSpam'));
|
||||||
}
|
}
|
||||||
|
|
||||||
const newChatMessage = group.sendChat(req.body.message, user);
|
const newChatMessage = group.sendChat({message: req.body.message, user});
|
||||||
let toSave = [newChatMessage.save()];
|
let toSave = [newChatMessage.save()];
|
||||||
|
|
||||||
if (group.type === 'party') {
|
if (group.type === 'party') {
|
||||||
|
|||||||
@@ -434,10 +434,13 @@ api.abortQuest = {
|
|||||||
if (user._id !== group.leader && user._id !== group.quest.leader) throw new NotAuthorized(res.t('onlyLeaderAbortQuest'));
|
if (user._id !== group.leader && user._id !== group.quest.leader) throw new NotAuthorized(res.t('onlyLeaderAbortQuest'));
|
||||||
|
|
||||||
let questName = questScrolls[group.quest.key].text('en');
|
let questName = questScrolls[group.quest.key].text('en');
|
||||||
const newChatMessage = group.sendChat(`\`${common.i18n.t('chatQuestAborted', {username: user.profile.name, questName}, 'en')}\``, null, null, {
|
const newChatMessage = group.sendChat({
|
||||||
type: 'quest_abort',
|
message: `\`${common.i18n.t('chatQuestAborted', {username: user.profile.name, questName}, 'en')}\``,
|
||||||
user: user.profile.name,
|
info: {
|
||||||
quest: group.quest.key,
|
type: 'quest_abort',
|
||||||
|
user: user.profile.name,
|
||||||
|
quest: group.quest.key,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
await newChatMessage.save();
|
await newChatMessage.save();
|
||||||
|
|
||||||
|
|||||||
@@ -209,10 +209,13 @@ api.assignTask = {
|
|||||||
// User is claiming the task
|
// User is claiming the task
|
||||||
if (user._id === assignedUserId) {
|
if (user._id === assignedUserId) {
|
||||||
let message = res.t('userIsClamingTask', {username: user.profile.name, task: task.text});
|
let message = res.t('userIsClamingTask', {username: user.profile.name, task: task.text});
|
||||||
const newMessage = group.sendChat(message, null, null, {
|
const newMessage = group.sendChat({
|
||||||
type: 'claim_task',
|
message,
|
||||||
user: user.profile.name,
|
info: {
|
||||||
task: task.text,
|
type: 'claim_task',
|
||||||
|
user: user.profile.name,
|
||||||
|
task: task.text,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
promises.push(newMessage.save());
|
promises.push(newMessage.save());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -131,20 +131,26 @@ api.castSpell = {
|
|||||||
|
|
||||||
if (party && !spell.silent) {
|
if (party && !spell.silent) {
|
||||||
if (targetType === 'user') {
|
if (targetType === 'user') {
|
||||||
const newChatMessage = party.sendChat(`\`${common.i18n.t('chatCastSpellUser', {username: user.profile.name, spell: spell.text(), target: partyMembers.profile.name}, 'en')}\``, null, null, {
|
const newChatMessage = party.sendChat({
|
||||||
type: 'spell_cast_user',
|
message: `\`${common.i18n.t('chatCastSpellUser', {username: user.profile.name, spell: spell.text(), target: partyMembers.profile.name}, 'en')}\``,
|
||||||
user: user.profile.name,
|
info: {
|
||||||
class: klass,
|
type: 'spell_cast_user',
|
||||||
spell: spellId,
|
user: user.profile.name,
|
||||||
target: partyMembers.profile.name,
|
class: klass,
|
||||||
|
spell: spellId,
|
||||||
|
target: partyMembers.profile.name,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
await newChatMessage.save();
|
await newChatMessage.save();
|
||||||
} else {
|
} else {
|
||||||
const newChatMessage = party.sendChat(`\`${common.i18n.t('chatCastSpellParty', {username: user.profile.name, spell: spell.text()}, 'en')}\``, null, null, {
|
const newChatMessage = party.sendChat({
|
||||||
type: 'spell_cast_party',
|
message: `\`${common.i18n.t('chatCastSpellParty', {username: user.profile.name, spell: spell.text()}, 'en')}\``,
|
||||||
user: user.profile.name,
|
info: {
|
||||||
class: klass,
|
type: 'spell_cast_party',
|
||||||
spell: spellId,
|
user: user.profile.name,
|
||||||
|
class: klass,
|
||||||
|
spell: spellId,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
await newChatMessage.save();
|
await newChatMessage.save();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -323,66 +323,90 @@ schema.statics.getGroups = async function getGroups (options = {}) {
|
|||||||
return groupsArray;
|
return groupsArray;
|
||||||
};
|
};
|
||||||
|
|
||||||
function _translateSystemMessages (group, user) {
|
function _translateMessage (lang, info) {
|
||||||
|
let msg;
|
||||||
let foundText = '';
|
let foundText = '';
|
||||||
let lang = user.preferences.language;
|
let spells = shared.content.spells;
|
||||||
for (let i = 0; i < group.chat.length; i++) {
|
let quests = shared.content.quests;
|
||||||
if (!_.isEmpty(group.chat[i].info)) {
|
|
||||||
let msg;
|
switch (info.type) {
|
||||||
switch (group.chat[i].info.type) {
|
case 'quest_start':
|
||||||
case 'quest_start':
|
msg = `\`${shared.i18n.t('chatQuestStarted', {questName: questScrolls[info.quest].text(lang)}, lang)}\``;
|
||||||
msg = `\`${shared.i18n.t('chatQuestStarted', {questName: questScrolls[group.chat[i].info.quest].text(lang)}, lang)}\``;
|
break;
|
||||||
break;
|
|
||||||
case 'boss_damage':
|
case 'boss_damage':
|
||||||
msg = `\`${shared.i18n.t('chatBossDamage', {username: group.chat[i].info.user, bossName: questScrolls[group.chat[i].info.quest].boss.name(lang), userDamage: group.chat[i].info.userDamage, bossDamage: group.chat[i].info.bossDamage}, lang)}\``;
|
msg = `\`${shared.i18n.t('chatBossDamage', {username: info.user, bossName: questScrolls[info.quest].boss.name(lang), userDamage: info.userDamage, bossDamage: info.bossDamage}, lang)}\``;
|
||||||
break;
|
break;
|
||||||
case 'boss_dont_attack':
|
|
||||||
msg = `\`${shared.i18n.t('chatBossDontAttack', {username: group.chat[i].info.user, bossName: questScrolls[group.chat[i].info.quest].boss.name(lang), userDamage: group.chat[i].info.userDamage}, lang)}\``;
|
case 'boss_dont_attack':
|
||||||
break;
|
msg = `\`${shared.i18n.t('chatBossDontAttack', {username: info.user, bossName: questScrolls[info.quest].boss.name(lang), userDamage: info.userDamage}, lang)}\``;
|
||||||
case 'boss_rage':
|
break;
|
||||||
msg = `\`${questScrolls[group.chat[i].info.quest].boss.rage.effect(lang)}\``;
|
|
||||||
break;
|
case 'boss_rage':
|
||||||
case 'boss_defeated':
|
msg = `\`${questScrolls[info.quest].boss.rage.effect(lang)}\``;
|
||||||
msg = `\`${shared.i18n.t('chatBossDefeated', {bossName: questScrolls[group.chat[i].info.quest].boss.name(lang)}, lang)}\``;
|
break;
|
||||||
break;
|
|
||||||
case 'user_found_items':
|
case 'boss_defeated':
|
||||||
foundText = _.reduce(group.chat[i].info.items, (m, v, k) => {
|
msg = `\`${shared.i18n.t('chatBossDefeated', {bossName: questScrolls[info.quest].boss.name(lang)}, lang)}\``;
|
||||||
m.push(`${v} ${questScrolls[group.chat[i].info.quest].collect[k].text(lang)}`);
|
break;
|
||||||
return m;
|
|
||||||
}, []).join(', ');
|
case 'user_found_items':
|
||||||
msg = `\`${shared.i18n.t('chatFindItems', {username: group.chat[i].info.user, items: foundText}, lang)}\``;
|
foundText = _.reduce(info.items, (m, v, k) => {
|
||||||
break;
|
m.push(`${v} ${questScrolls[info.quest].collect[k].text(lang)}`);
|
||||||
case 'all_items_found':
|
return m;
|
||||||
msg = `\`${shared.i18n.t('chatItemQuestFinish', lang)}\``;
|
}, []).join(', ');
|
||||||
break;
|
msg = `\`${shared.i18n.t('chatFindItems', {username: info.user, items: foundText}, lang)}\``;
|
||||||
case 'spell_cast_party':
|
break;
|
||||||
msg = `\`${shared.i18n.t('chatCastSpellParty', {username: group.chat[i].info.user, spell: shared.content.spells[group.chat[i].info.class][group.chat[i].info.spell].text(lang)}, lang)}\``;
|
|
||||||
break;
|
case 'all_items_found':
|
||||||
case 'spell_cast_user':
|
msg = `\`${shared.i18n.t('chatItemQuestFinish', lang)}\``;
|
||||||
msg = `\`${shared.i18n.t('chatCastSpellUser', {username: group.chat[i].info.user, spell: shared.content.spells[group.chat[i].info.class][group.chat[i].info.spell].text(lang), target: group.chat[i].info.target}, lang)}\``;
|
break;
|
||||||
break;
|
|
||||||
case 'quest_abort':
|
case 'spell_cast_party':
|
||||||
msg = `\`${shared.i18n.t('chatQuestAborted', {username: group.chat[i].info.user, questName: questScrolls[group.chat[i].info.quest].text(lang)}, lang)}\``;
|
msg = `\`${shared.i18n.t('chatCastSpellParty', {username: info.user, spell: spells[info.class][info.spell].text(lang)}, lang)}\``;
|
||||||
break;
|
break;
|
||||||
case 'tavern_quest_completed':
|
|
||||||
msg = `\`${shared.content.quests[group.chat[i].info.quest].completionChat(lang)}\``;
|
case 'spell_cast_user':
|
||||||
break;
|
msg = `\`${shared.i18n.t('chatCastSpellUser', {username: info.user, spell: spells[info.class][info.spell].text(lang), target: info.target}, lang)}\``;
|
||||||
case 'tavern_boss_rage_tired':
|
break;
|
||||||
msg = `\`${shared.i18n.t('tavernBossTired', {rageName: shared.content.quests[group.chat[i].info.quest].boss.rage.title(lang), bossName: shared.content.quests[group.chat[i].info.quest].boss.name(lang)}, lang)}\``;
|
|
||||||
break;
|
case 'quest_abort':
|
||||||
case 'tavern_boss_rage':
|
msg = `\`${shared.i18n.t('chatQuestAborted', {username: info.user, questName: questScrolls[info.quest].text(lang)}, lang)}\``;
|
||||||
msg = `\`${shared.content.quests[group.chat[i].info.quest].boss.rage[group.chat[i].info.scene](lang)}\``;
|
break;
|
||||||
break;
|
|
||||||
case 'tavern_boss_desperation':
|
case 'tavern_quest_completed':
|
||||||
msg = `\`${shared.content.quests[group.chat[i].info.quest].boss.desperation.text(lang)}\``;
|
msg = `\`${quests[info.quest].completionChat(lang)}\``;
|
||||||
break;
|
break;
|
||||||
case 'claim_task':
|
|
||||||
msg = `${shared.i18n.t('userIsClamingTask', {username: group.chat[i].info.user, task: group.chat[i].info.task}, lang)}`;
|
case 'tavern_boss_rage_tired':
|
||||||
break;
|
msg = `\`${shared.i18n.t('tavernBossTired', {rageName: quests[info.quest].boss.rage.title(lang), bossName: quests[info.quest].boss.name(lang)}, lang)}\``;
|
||||||
}
|
break;
|
||||||
group.chat[i].text = msg;
|
|
||||||
}
|
case 'tavern_boss_rage':
|
||||||
|
msg = `\`${quests[info.quest].boss.rage[info.scene](lang)}\``;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'tavern_boss_desperation':
|
||||||
|
msg = `\`${quests[info.quest].boss.desperation.text(lang)}\``;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'claim_task':
|
||||||
|
msg = `${shared.i18n.t('userIsClamingTask', {username: info.user, task: info.task}, lang)}`;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return msg;
|
||||||
|
}
|
||||||
|
|
||||||
|
function _translateSystemMessages (group, user) {
|
||||||
|
let lang = user.preferences.language;
|
||||||
|
|
||||||
|
group.chat.forEach((chat, i, chatArray) => {
|
||||||
|
if (!_.isEmpty(chat.info)) {
|
||||||
|
chatArray[i].text = _translateMessage(lang, chat.info);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
return group;
|
return group;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -612,7 +636,8 @@ function setUserStyles (newMessage, user) {
|
|||||||
newMessage.markModified('userStyles');
|
newMessage.markModified('userStyles');
|
||||||
}
|
}
|
||||||
|
|
||||||
schema.methods.sendChat = function sendChat (message, user, metaData, info = {}) {
|
schema.methods.sendChat = function sendChat (options = {}) {
|
||||||
|
const {message, user, metaData, info = {}} = options;
|
||||||
let newMessage = chatDefaults(message, user, info);
|
let newMessage = chatDefaults(message, user, info);
|
||||||
let newChatMessage = new Chat();
|
let newChatMessage = new Chat();
|
||||||
newChatMessage = Object.assign(newChatMessage, newMessage);
|
newChatMessage = Object.assign(newChatMessage, newMessage);
|
||||||
@@ -785,11 +810,15 @@ schema.methods.startQuest = async function startQuest (user) {
|
|||||||
},
|
},
|
||||||
}, { multi: true }).exec();
|
}, { multi: true }).exec();
|
||||||
|
|
||||||
const newMessage = this.sendChat(`\`${shared.i18n.t('chatQuestStarted', {questName: quest.text('en')}, 'en')}\``, null, {
|
const newMessage = this.sendChat({
|
||||||
participatingMembers: this.getParticipatingQuestMembers().join(', '),
|
message: `\`${shared.i18n.t('chatQuestStarted', {questName: quest.text('en')}, 'en')}\``,
|
||||||
}, {
|
metaData: {
|
||||||
type: 'quest_start',
|
participatingMembers: this.getParticipatingQuestMembers().join(', '),
|
||||||
quest: quest.key,
|
},
|
||||||
|
info: {
|
||||||
|
type: 'quest_start',
|
||||||
|
quest: quest.key,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
await newMessage.save();
|
await newMessage.save();
|
||||||
|
|
||||||
@@ -1047,20 +1076,26 @@ schema.methods._processBossQuest = async function processBossQuest (options) {
|
|||||||
|
|
||||||
group.quest.progress.hp -= progress.up;
|
group.quest.progress.hp -= progress.up;
|
||||||
if (CRON_SAFE_MODE || CRON_SEMI_SAFE_MODE) {
|
if (CRON_SAFE_MODE || CRON_SEMI_SAFE_MODE) {
|
||||||
const groupMessage = group.sendChat(`\`${shared.i18n.t('chatBossDontAttack', {bossName: quest.boss.name('en')}, 'en')}\``, null, null, {
|
const groupMessage = group.sendChat({
|
||||||
type: 'boss_dont_attack',
|
message: `\`${shared.i18n.t('chatBossDontAttack', {bossName: quest.boss.name('en')}, 'en')}\``,
|
||||||
user: user.profile.name,
|
info: {
|
||||||
quest: group.quest.key,
|
type: 'boss_dont_attack',
|
||||||
userDamage: progress.up.toFixed(1),
|
user: user.profile.name,
|
||||||
|
quest: group.quest.key,
|
||||||
|
userDamage: progress.up.toFixed(1),
|
||||||
|
},
|
||||||
});
|
});
|
||||||
promises.push(groupMessage.save());
|
promises.push(groupMessage.save());
|
||||||
} else {
|
} else {
|
||||||
const groupMessage = group.sendChat(`\`${shared.i18n.t('chatBossDamage', {username: user.profile.name, bossName: quest.boss.name('en'), userDamage: progress.up.toFixed(1), bossDamage: Math.abs(down).toFixed(1)}, user.preferences.language)}\``, null, null, {
|
const groupMessage = group.sendChat({
|
||||||
type: 'boss_damage',
|
message: `\`${shared.i18n.t('chatBossDamage', {username: user.profile.name, bossName: quest.boss.name('en'), userDamage: progress.up.toFixed(1), bossDamage: Math.abs(down).toFixed(1)}, user.preferences.language)}\``,
|
||||||
user: user.profile.name,
|
info: {
|
||||||
quest: group.quest.key,
|
type: 'boss_damage',
|
||||||
userDamage: progress.up.toFixed(1),
|
user: user.profile.name,
|
||||||
bossDamage: Math.abs(down).toFixed(1),
|
quest: group.quest.key,
|
||||||
|
userDamage: progress.up.toFixed(1),
|
||||||
|
bossDamage: Math.abs(down).toFixed(1),
|
||||||
|
},
|
||||||
});
|
});
|
||||||
promises.push(groupMessage.save());
|
promises.push(groupMessage.save());
|
||||||
}
|
}
|
||||||
@@ -1069,9 +1104,12 @@ schema.methods._processBossQuest = async function processBossQuest (options) {
|
|||||||
if (quest.boss.rage) {
|
if (quest.boss.rage) {
|
||||||
group.quest.progress.rage += Math.abs(down);
|
group.quest.progress.rage += Math.abs(down);
|
||||||
if (group.quest.progress.rage >= quest.boss.rage.value) {
|
if (group.quest.progress.rage >= quest.boss.rage.value) {
|
||||||
const rageMessage = group.sendChat(quest.boss.rage.effect('en'), null, null, {
|
const rageMessage = group.sendChat({
|
||||||
type: 'boss_rage',
|
message: quest.boss.rage.effect('en'),
|
||||||
quest: quest.key,
|
info: {
|
||||||
|
type: 'boss_rage',
|
||||||
|
quest: quest.key,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
promises.push(rageMessage.save());
|
promises.push(rageMessage.save());
|
||||||
group.quest.progress.rage = 0;
|
group.quest.progress.rage = 0;
|
||||||
@@ -1100,9 +1138,12 @@ schema.methods._processBossQuest = async function processBossQuest (options) {
|
|||||||
|
|
||||||
// Boss slain, finish quest
|
// Boss slain, finish quest
|
||||||
if (group.quest.progress.hp <= 0) {
|
if (group.quest.progress.hp <= 0) {
|
||||||
const questFinishChat = group.sendChat(`\`${shared.i18n.t('chatBossDefeated', {bossName: quest.boss.name('en')}, 'en')}\``, null, null, {
|
const questFinishChat = group.sendChat({
|
||||||
type: 'boss_defeated',
|
message: `\`${shared.i18n.t('chatBossDefeated', {bossName: quest.boss.name('en')}, 'en')}\``,
|
||||||
quest: quest.key,
|
info: {
|
||||||
|
type: 'boss_defeated',
|
||||||
|
quest: quest.key,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
promises.push(questFinishChat.save());
|
promises.push(questFinishChat.save());
|
||||||
|
|
||||||
@@ -1156,11 +1197,14 @@ schema.methods._processCollectionQuest = async function processCollectionQuest (
|
|||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
foundText = foundText.join(', ');
|
foundText = foundText.join(', ');
|
||||||
const foundChat = group.sendChat(`\`${shared.i18n.t('chatFindItems', {username: user.profile.name, items: foundText}, 'en')}\``, null, null, {
|
const foundChat = group.sendChat({
|
||||||
type: 'user_found_items',
|
message: `\`${shared.i18n.t('chatFindItems', {username: user.profile.name, items: foundText}, 'en')}\``,
|
||||||
user: user.profile.name,
|
info: {
|
||||||
quest: quest.key,
|
type: 'user_found_items',
|
||||||
items: itemsFound,
|
user: user.profile.name,
|
||||||
|
quest: quest.key,
|
||||||
|
items: itemsFound,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
group.markModified('quest.progress.collect');
|
group.markModified('quest.progress.collect');
|
||||||
|
|
||||||
@@ -1174,8 +1218,11 @@ schema.methods._processCollectionQuest = async function processCollectionQuest (
|
|||||||
}
|
}
|
||||||
|
|
||||||
await group.finishQuest(quest);
|
await group.finishQuest(quest);
|
||||||
const allItemsFoundChat = group.sendChat(`\`${shared.i18n.t('chatItemQuestFinish', 'en')}\``, null, null, {
|
const allItemsFoundChat = group.sendChat({
|
||||||
type: 'all_items_found',
|
message: `\`${shared.i18n.t('chatItemQuestFinish', 'en')}\``,
|
||||||
|
info: {
|
||||||
|
type: 'all_items_found',
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const promises = [group.save(), foundChat.save(), allItemsFoundChat.save()];
|
const promises = [group.save(), foundChat.save(), allItemsFoundChat.save()];
|
||||||
@@ -1237,9 +1284,12 @@ schema.statics.tavernBoss = async function tavernBoss (user, progress) {
|
|||||||
const chatPromises = [];
|
const chatPromises = [];
|
||||||
|
|
||||||
if (tavern.quest.progress.hp <= 0) {
|
if (tavern.quest.progress.hp <= 0) {
|
||||||
const completeChat = tavern.sendChat(quest.completionChat('en'), null, null, {
|
const completeChat = tavern.sendChat({
|
||||||
type: 'tavern_quest_completed',
|
message: quest.completionChat('en'),
|
||||||
quest: quest.key,
|
info: {
|
||||||
|
type: 'tavern_quest_completed',
|
||||||
|
quest: quest.key,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
chatPromises.push(completeChat.save());
|
chatPromises.push(completeChat.save());
|
||||||
await tavern.finishQuest(quest);
|
await tavern.finishQuest(quest);
|
||||||
@@ -1269,17 +1319,23 @@ schema.statics.tavernBoss = async function tavernBoss (user, progress) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!scene) {
|
if (!scene) {
|
||||||
const tiredChat = tavern.sendChat(`\`${shared.i18n.t('tavernBossTired', {rageName: quest.boss.rage.title('en'), bossName: quest.boss.name('en')}, 'en')}\``, null, null, {
|
const tiredChat = tavern.sendChat({
|
||||||
type: 'tavern_boss_rage_tired',
|
message: `\`${shared.i18n.t('tavernBossTired', {rageName: quest.boss.rage.title('en'), bossName: quest.boss.name('en')}, 'en')}\``,
|
||||||
quest: quest.key,
|
info: {
|
||||||
|
type: 'tavern_boss_rage_tired',
|
||||||
|
quest: quest.key,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
chatPromises.push(tiredChat.save());
|
chatPromises.push(tiredChat.save());
|
||||||
tavern.quest.progress.rage = 0; // quest.boss.rage.value;
|
tavern.quest.progress.rage = 0; // quest.boss.rage.value;
|
||||||
} else {
|
} else {
|
||||||
const rageChat = tavern.sendChat(quest.boss.rage[scene]('en'), null, null, {
|
const rageChat = tavern.sendChat({
|
||||||
type: 'tavern_boss_rage',
|
message: quest.boss.rage[scene]('en'),
|
||||||
quest: quest.key,
|
info: {
|
||||||
scene,
|
type: 'tavern_boss_rage',
|
||||||
|
quest: quest.key,
|
||||||
|
scene,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
chatPromises.push(rageChat.save());
|
chatPromises.push(rageChat.save());
|
||||||
tavern.quest.extra.worldDmg[scene] = true;
|
tavern.quest.extra.worldDmg[scene] = true;
|
||||||
@@ -1292,9 +1348,12 @@ schema.statics.tavernBoss = async function tavernBoss (user, progress) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (quest.boss.desperation && tavern.quest.progress.hp < quest.boss.desperation.threshold && !tavern.quest.extra.desperate) {
|
if (quest.boss.desperation && tavern.quest.progress.hp < quest.boss.desperation.threshold && !tavern.quest.extra.desperate) {
|
||||||
const progressChat = tavern.sendChat(quest.boss.desperation.text('en'), null, null, {
|
const progressChat = tavern.sendChat({
|
||||||
type: 'tavern_boss_desperation',
|
message: quest.boss.desperation.text('en'),
|
||||||
quest: quest.key,
|
info: {
|
||||||
|
type: 'tavern_boss_desperation',
|
||||||
|
quest: quest.key,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
chatPromises.push(progressChat.save());
|
chatPromises.push(progressChat.save());
|
||||||
tavern.quest.extra.desperate = true;
|
tavern.quest.extra.desperate = true;
|
||||||
|
|||||||
Reference in New Issue
Block a user