Damage multipliers now compute and show up on the character sheet
This commit is contained in:
@@ -1,13 +1,14 @@
|
||||
import { ValidatedMethod } from 'meteor/mdg:validated-method';
|
||||
import SimpleSchema from 'simpl-schema';
|
||||
import deathSaveSchema from '/imports/api/properties/subSchemas/DeathSavesSchema.js'
|
||||
import ColorSchema from '/imports/api/properties/subSchemas/ColorSchema.js';
|
||||
import SharingSchema from '/imports/api/sharing/SharingSchema.js';
|
||||
import {assertEditPermission, assertOwnership} from '/imports/api/sharing/sharingPermissions.js';
|
||||
import {assertEditPermission} from '/imports/api/sharing/sharingPermissions.js';
|
||||
|
||||
import '/imports/api/creature/removeCreature.js';
|
||||
|
||||
//set up the collection for creatures
|
||||
Creatures = new Mongo.Collection('creatures');
|
||||
let Creatures = new Mongo.Collection('creatures');
|
||||
|
||||
let CreatureSettingsSchema = new SimpleSchema({
|
||||
//slowed down by carrying too much?
|
||||
@@ -34,13 +35,6 @@ let CreatureSchema = new SimpleSchema({
|
||||
defaultValue: '',
|
||||
optional: true,
|
||||
},
|
||||
urlName: {
|
||||
type: String,
|
||||
optional: true,
|
||||
autoValue: function() {
|
||||
return getSlug(this.field('name').value, {maintainCase: true}) || '-';
|
||||
},
|
||||
},
|
||||
alignment: {
|
||||
type: String,
|
||||
optional: true
|
||||
@@ -76,6 +70,11 @@ let CreatureSchema = new SimpleSchema({
|
||||
defaultValue: 'pc',
|
||||
allowedValues: ['pc', 'npc', 'monster'],
|
||||
},
|
||||
damageMultipliers: {
|
||||
type: Object,
|
||||
blackbox: true,
|
||||
defaultValue: {}
|
||||
},
|
||||
variables: {
|
||||
type: Object,
|
||||
blackbox: true,
|
||||
@@ -118,7 +117,7 @@ const insertCreature = new ValidatedMethod({
|
||||
|
||||
const updateCreature = new ValidatedMethod({
|
||||
name: 'Creatures.methods.update',
|
||||
validate({_id, path, value}){
|
||||
validate({_id, path}){
|
||||
if (!_id) return false;
|
||||
// Allowed fields
|
||||
let allowedFields = ['name', 'alignment', 'gender', 'picture', 'settings'];
|
||||
@@ -137,4 +136,4 @@ const updateCreature = new ValidatedMethod({
|
||||
});
|
||||
|
||||
export default Creatures;
|
||||
export { CreatureSchema, insertCreature, removeCreature, updateCreature };
|
||||
export { CreatureSchema, insertCreature, updateCreature };
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import Creatures from '/imports/api/creature/Creatures.js';
|
||||
import CreatureProperties from '/imports/api/creature/CreatureProperties.js';
|
||||
|
||||
export default function getCalculationProperties(creatureId){
|
||||
export default function getCalculationProperties(creatureId, types){
|
||||
// First get ids of disabled properties and unequiped items
|
||||
let disabledAncestorIds = CreatureProperties.find({
|
||||
'ancestors.id': creatureId,
|
||||
@@ -30,7 +30,7 @@ export default function getCalculationProperties(creatureId){
|
||||
$nin: disabledAncestorIds,
|
||||
},
|
||||
removed: {$ne: true},
|
||||
type: {$in: [
|
||||
type: {$in: types || [
|
||||
'attribute',
|
||||
'skill',
|
||||
'damageMultiplier',
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { Meteor } from 'meteor/meteor'
|
||||
import { ValidatedMethod } from 'meteor/mdg:validated-method';
|
||||
import SimpleSchema from 'simpl-schema';
|
||||
import { assertEditPermission } from '/imports/api/creature/creaturePermissions.js';
|
||||
@@ -7,6 +6,7 @@ import computeMemo from '/imports/api/creature/computation/computeMemo.js';
|
||||
import getCalculationProperties from '/imports/api/creature/computation/getCalculationProperties.js';
|
||||
import writeAlteredProperties from '/imports/api/creature/computation/writeAlteredProperties.js';
|
||||
import writeCreatureVariables from '/imports/api/creature/computation/writeCreatureVariables.js';
|
||||
import { recomputeDamageMultipliersById } from '/imports/api/creature/damageMultiplierDenormalise/recomputeDamageMultipliers.js'
|
||||
|
||||
export const recomputeCreature = new ValidatedMethod({
|
||||
|
||||
@@ -69,5 +69,6 @@ export function recomputeCreatureById(creatureId){
|
||||
writeAlteredProperties(computationMemo);
|
||||
writeCreatureVariables(computationMemo, creatureId);
|
||||
// if(Meteor.isClient) console.log(computationMemo);
|
||||
recomputeDamageMultipliersById(creatureId);
|
||||
return computationMemo;
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import Creatures from '/imports/api/creature/Creatures.js';
|
||||
import {
|
||||
assertEditPermission as editPermission,
|
||||
assertViewPermission as viewPermission,
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
import { ValidatedMethod } from 'meteor/mdg:validated-method';
|
||||
import SimpleSchema from 'simpl-schema';
|
||||
import { assertEditPermission } from '/imports/api/creature/creaturePermissions.js';
|
||||
import Creatures from '/imports/api/creature/Creatures.js';
|
||||
import getCalculationProperties from '/imports/api/creature/computation/getCalculationProperties.js'
|
||||
|
||||
export const recomputeDamageMultipliers = new ValidatedMethod({
|
||||
|
||||
name: 'Creatures.methods.recomputeDamageMultipliers',
|
||||
|
||||
validate: new SimpleSchema({
|
||||
creatureId: { type: String }
|
||||
}).validator(),
|
||||
|
||||
run({creatureId}) {
|
||||
// Permission
|
||||
assertEditPermission(creatureId, this.userId);
|
||||
// Work, call this direcly if you are already in a method that has checked
|
||||
// for permission to edit a given character
|
||||
recomputeDamageMultipliersById(creatureId);
|
||||
},
|
||||
|
||||
});
|
||||
|
||||
export function recomputeDamageMultipliersById(creatureId){
|
||||
if (!creatureId) throw 'Creature ID is required';
|
||||
let props = getCalculationProperties(creatureId, ['damageMultiplier']);
|
||||
|
||||
// Count of how many weakness, resistances and immunities each damage type has
|
||||
let multipliersByName = {};
|
||||
props.forEach(dm => {
|
||||
dm.damageTypes.forEach(damageType => {
|
||||
if (!multipliersByName[damageType]){
|
||||
multipliersByName[damageType] = {
|
||||
weaknesses: 0,
|
||||
resistances: 0,
|
||||
immunities: 0,
|
||||
};
|
||||
}
|
||||
if (dm.value === 0){
|
||||
multipliersByName[damageType].immunities++;
|
||||
} else if (dm.value === 0.5){
|
||||
multipliersByName[damageType].resistances++;
|
||||
} else if (dm.value === 2){
|
||||
multipliersByName[damageType].weaknesses++;
|
||||
}
|
||||
});
|
||||
});
|
||||
// Make an Object with keys of all the damage types that have a resulting
|
||||
// immunity, weakness, or resistance
|
||||
let damageMultipliers = {};
|
||||
for (let damageType in multipliersByName){
|
||||
let multiplier = multipliersByName[damageType];
|
||||
if (multiplier.immunities){
|
||||
damageMultipliers[damageType] = 0;
|
||||
} else if (multiplier.resistances && !multiplier.weaknesses){
|
||||
damageMultipliers[damageType] = 0.5;
|
||||
} else if (multiplier.weaknesses && !multiplier.resistances){
|
||||
damageMultipliers[damageType] = 2;
|
||||
}
|
||||
}
|
||||
// Store the Object on the creature document
|
||||
Creatures.update(creatureId, {$set: {damageMultipliers}});
|
||||
}
|
||||
Reference in New Issue
Block a user