Improved log entries for actions
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import spendResources from '/imports/api/creature/actions/spendResources.js'
|
||||
import embedInlineCalculations from '/imports/api/creature/computation/afterComputation/embedInlineCalculations.js';
|
||||
|
||||
export default function applyAction({prop, log}){
|
||||
spendResources(prop);
|
||||
@@ -6,4 +7,18 @@ export default function applyAction({prop, log}){
|
||||
if (log.content.length){
|
||||
log.content.push({name: prop.name});
|
||||
}
|
||||
if (prop.summary){
|
||||
log.content.push({
|
||||
details: embedInlineCalculations(
|
||||
prop.summary, prop.summaryCalculations
|
||||
),
|
||||
});
|
||||
}
|
||||
if (prop.description){
|
||||
log.content.push({
|
||||
details: embedInlineCalculations(
|
||||
prop.description, prop.descriptionCalculations
|
||||
),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,18 +36,31 @@ export default function applyDamage({
|
||||
damageType: prop.damageType,
|
||||
amount: result,
|
||||
});
|
||||
insertCreatureLog.call({
|
||||
log: {
|
||||
text: `Recieved ${damageDealt} ${prop.damageType}${prop.damageType !== 'healing'? ' damage': ''}`,
|
||||
creatureId: target._id,
|
||||
}
|
||||
});
|
||||
if (target._id !== creature._id){
|
||||
if (target._id === creature._id){
|
||||
log.content.push({
|
||||
result: damageDealt,
|
||||
details: `${prop.damageType}${prop.damageType !== 'healing'? ' damage': ''}` +
|
||||
details: `${prop.damageType}`+
|
||||
`${prop.damageType !== 'healing' ? ' damage': ''} to self`,
|
||||
});
|
||||
} else {
|
||||
log.content.push({
|
||||
resultPrefix: 'Dealt ',
|
||||
result: damageDealt,
|
||||
details: `${prop.damageType}` +
|
||||
`${prop.damageType !== 'healing'? ' damage': ''}` +
|
||||
`${target.name && ' to '}${target.name}`,
|
||||
});
|
||||
insertCreatureLog.call({
|
||||
log: {
|
||||
content: [{
|
||||
resultPrefix: 'Recieved ',
|
||||
result: damageDealt,
|
||||
details: `${prop.damageType}` +
|
||||
`${prop.damageType !== 'healing'? ' damage': ''}`
|
||||
}],
|
||||
creatureId: target._id,
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
} else {
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
export default function embedInlineCalculations(string, calculations){
|
||||
if (!string) return '';
|
||||
let index = 0;
|
||||
return string.replace(/\{([^{}]*)\}/g, () => {
|
||||
let comp = calculations && calculations[index++];
|
||||
return comp && comp.result;
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user