Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] Wear armor calculations #121

Merged
merged 3 commits into from
May 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
import { ABFActorDataSourceData } from '../../../../../../types/Actor';
import { calculateMovementInMetersFromMovementType } from './calculations/calculateMovementInMetersFromMovementType';
import { getEquippedArmors } from '../../../utils/getEquippedArmors';
import { calculateNaturalPenaltyWithoutWearArmor } from '../natural-penalty/calculations/calculateWearArmorNaturalPenalty';

export const mutateMovementType = (data: ABFActorDataSourceData) => {
const calculateArmorsMovementTypeModifier = (data: ABFActorDataSourceData): number => {
const armorsMovementRestrictions = getEquippedArmors(data).reduce(
(prev, curr) => prev + curr.data.movementRestriction.final.value,
0
);

const totalWearRequirement = calculateNaturalPenaltyWithoutWearArmor(data);
const wearArmor = data.combat.wearArmor.value;

const wearArmorModifier = Math.floor(Math.max(0, wearArmor - totalWearRequirement) / 50);

return Math.min(0, wearArmorModifier + armorsMovementRestrictions);
};

export const mutateMovementType = (data: ABFActorDataSourceData) => {
const armorsMovementRestrictions = calculateArmorsMovementTypeModifier(data);

const { movementType } = data.characteristics.secondaries;

movementType.final.value =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { ABFActorDataSourceData } from '../../../../../../../types/Actor';
import { getEquippedArmors } from '../../../../utils/getEquippedArmors';

export const calculateNaturalPenaltyWithoutWearArmor = (data: ABFActorDataSourceData): number => {
return getEquippedArmors(data).reduce((prev, curr) => prev + curr.data.wearArmorRequirement.final.value, 0);
};

export const calculateWearArmorNaturalPenalty = (data: ABFActorDataSourceData): number => {
const totalWearRequirement = getEquippedArmors(data).reduce(
(prev, curr) => prev + curr.data.wearArmorRequirement.final.value,
0
);
const totalWearRequirement = calculateNaturalPenaltyWithoutWearArmor(data);

return data.combat.wearArmor.value - totalWearRequirement;
};
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,7 @@ export const calculateSecondaryStealth = (data: ABFActorDataSourceData): number
naturalPenaltyWithoutEquippedArmorsPenalty / 2
) + equippedArmorsPenalty;

return data.secondaries.subterfuge.stealth.base.value + data.general.modifiers.allActions.final.value + armorPenalty;
return Math.round(
data.secondaries.subterfuge.stealth.base.value + data.general.modifiers.allActions.final.value + armorPenalty
);
};
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { ABFActorDataSourceData } from '../../../../../../../types/Actor';
import { calculateNaturalPenaltyWithoutWearArmor } from '../../natural-penalty/calculations/calculateWearArmorNaturalPenalty';

export const calculateSecondarySwim = (data: ABFActorDataSourceData): number => {
const naturalPenalty = -calculateNaturalPenaltyWithoutWearArmor(data);

return (
data.secondaries.athletics.swim.base.value +
data.general.modifiers.allActions.final.value +
data.general.modifiers.physicalActions.value +
data.general.modifiers.naturalPenalty.byArmors.value +
naturalPenalty +
data.general.modifiers.naturalPenalty.byWearArmorRequirement.value
);
};