Skip to content
This repository has been archived by the owner on Jan 5, 2019. It is now read-only.

Commit

Permalink
Added block via shield properties
Browse files Browse the repository at this point in the history
  • Loading branch information
eps1lon committed Mar 2, 2018
1 parent d71ced5 commit 638668a
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/calculator/stat_applications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const applications: { [key: string]: Application } = {
type: 'flat',
},
'additional_block_%': {
classification: [],
classification: ['block'],
type: 'flat',
},
'additional_block_chance_against_projectiles_%': {
Expand Down Expand Up @@ -653,7 +653,7 @@ const applications: { [key: string]: Application } = {
type: 'inc',
},
'local_additional_block_chance_%': {
classification: [],
classification: ['local', 'block'],
type: 'flat',
},
local_always_hit: {
Expand Down
19 changes: 19 additions & 0 deletions src/containers/item/components/properties/ShieldProperties.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import ArmourProperties from './ArmourProperties';
import Stat from '../../../../calculator/Stat';
import ValueRange from '../../../../calculator/ValueRange';
import Value from '../../../../calculator/Value';

export default class ShieldProperties extends ArmourProperties {
public block() {
const { shield_type } = this.parent.baseitem;

if (shield_type === undefined) {
throw new Error('shield_type not set in baseitem');
}

const { block } = shield_type;
const base_block = new Value([block, block], ['local', 'block'])

return base_block.augmentWith(Object.values(this.parent.stats())).compute();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { createTables } from '../../../../../__fixtures__/util';
import ShieldProperties from '../ShieldProperties';

const { items, mods } = createTables();

it('should consider have a base block', () => {
const buckler = items.fromName('Goathide Buckler');

expect((buckler.properties as ShieldProperties).block().value).toEqual(25);
});

it('should consider stats that improve block', () => {
const eva_shield = items
.fromName('Goathide Buckler')
.addMod(mods.fromId('AdditionalBlockChance1'));
expect((eva_shield.properties as ShieldProperties).block().value).toEqual([
26,
28,
]);

const str_shield = items
.fromName('Goathide Buckler')
.addMod(mods.fromId('AdditionalBlockChance1'))
.addMod(
mods.fromId(
'LocalIncreasedPhysicalDamageReductionRatingPercentAndAdditionalBlockChance1',
),
);
expect((str_shield.properties as ShieldProperties).block().value).toEqual([
28,
30,
]);
});
5 changes: 4 additions & 1 deletion src/containers/item/components/properties/build.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import ItemProperties, { Builder } from './Properties';
import ArmourProperties from './ArmourProperties';
import ShieldProperties from './ShieldProperties';
import Item from '../..';

export default function build(item: Item, builder: Builder): ItemProperties {
if (item.meta_data.isA('AbstractArmour')) {
if (item.meta_data.isA('AbstractShield')) {
return new ShieldProperties(item, builder);
} else if (item.meta_data.isA('AbstractArmour')) {
return new ArmourProperties(item, builder);
} else {
return new ItemProperties(item, builder);
Expand Down

0 comments on commit 638668a

Please sign in to comment.