From 1f2985467fb84b9825700057cf1b5b3e533d6080 Mon Sep 17 00:00:00 2001 From: Jordan Tucker Date: Thu, 4 Aug 2022 20:03:10 -0500 Subject: [PATCH] Drop weapons, bows, and shields instead of reducing durability (#11) * fix: drop weapons, bows, and shields instead of reducing durability * test: test dropping multiple equipment with extra life * test: unit test Slots.remove with extra life equipment --- src/__tests__/dropWithExtraLife.e2e.ts | 6 ++++ src/__tests__/dropWithExtraLife.in.txt | 2 ++ src/__tests__/dropWithExtraLife.out.txt | 0 src/core/Slots/Slots.remove.test.ts | 40 +++++++++++++++++++++++-- src/core/Slots/Slots.ts | 6 ++++ 5 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 src/__tests__/dropWithExtraLife.e2e.ts create mode 100644 src/__tests__/dropWithExtraLife.in.txt create mode 100644 src/__tests__/dropWithExtraLife.out.txt diff --git a/src/__tests__/dropWithExtraLife.e2e.ts b/src/__tests__/dropWithExtraLife.e2e.ts new file mode 100644 index 0000000..18771f0 --- /dev/null +++ b/src/__tests__/dropWithExtraLife.e2e.ts @@ -0,0 +1,6 @@ +// Author: jordanbtucker +const TEST = "dropWithExtraLife"; +it(TEST, () => { + expect(TEST).toPassE2ESimulation(); +}); +export { }; diff --git a/src/__tests__/dropWithExtraLife.in.txt b/src/__tests__/dropWithExtraLife.in.txt new file mode 100644 index 0000000..812eab8 --- /dev/null +++ b/src/__tests__/dropWithExtraLife.in.txt @@ -0,0 +1,2 @@ +Get 1 Weapon[life=80000] 2 Bow[life=80000] 1 Shield 1 Shield[life=80000] +Drop 1 Weapon 2 Bow 2 Shield diff --git a/src/__tests__/dropWithExtraLife.out.txt b/src/__tests__/dropWithExtraLife.out.txt new file mode 100644 index 0000000..e69de29 diff --git a/src/core/Slots/Slots.remove.test.ts b/src/core/Slots/Slots.remove.test.ts index 68cfa27..08d4a8e 100644 --- a/src/core/Slots/Slots.remove.test.ts +++ b/src/core/Slots/Slots.remove.test.ts @@ -1,6 +1,6 @@ -import { createMaterialStack, ItemStack } from "data/item"; +import { createEquipmentStack, createMaterialStack, ItemStack, ItemType } from "data/item"; import { Slots } from "./Slots"; -import { createMaterialMockItem } from "./SlotsTestHelpers"; +import { createEquipmentMockItem, createMaterialMockItem } from "./SlotsTestHelpers"; describe("Slots.remove", ()=>{ it("Does nothing if item doesn't exist", ()=>{ @@ -87,4 +87,40 @@ describe("Slots.remove", ()=>{ expect(removed).toBe(2); expect(slots.getSlotsRef()).toEqualItemStacks(expected); }); + it("Removes weapons with increased durability", ()=>{ + const mockItem1 = createEquipmentMockItem("WeaponA", ItemType.Weapon); + const stackToRemove = createEquipmentStack(mockItem1, 1000, false); + + const stacks: ItemStack[] = [createEquipmentStack(mockItem1, 80000, false)]; + const slots = new Slots(stacks); + + const removed = slots.remove(stackToRemove, 0); + const expected: ItemStack[] = []; + expect(removed).toBe(1); + expect(slots.getSlotsRef()).toEqualItemStacks(expected); + }); + it("Removes bows with increased durability", ()=>{ + const mockItem1 = createEquipmentMockItem("WeaponA", ItemType.Bow); + const stackToRemove = createEquipmentStack(mockItem1, 1000, false); + + const stacks: ItemStack[] = [createEquipmentStack(mockItem1, 80000, false)]; + const slots = new Slots(stacks); + + const removed = slots.remove(stackToRemove, 0); + const expected: ItemStack[] = []; + expect(removed).toBe(1); + expect(slots.getSlotsRef()).toEqualItemStacks(expected); + }); + it("Removes shields with increased durability", ()=>{ + const mockItem1 = createEquipmentMockItem("WeaponA", ItemType.Shield); + const stackToRemove = createEquipmentStack(mockItem1, 1000, false); + + const stacks: ItemStack[] = [createEquipmentStack(mockItem1, 80000, false)]; + const slots = new Slots(stacks); + + const removed = slots.remove(stackToRemove, 0); + const expected: ItemStack[] = []; + expect(removed).toBe(1); + expect(slots.getSlotsRef()).toEqualItemStacks(expected); + }); }); diff --git a/src/core/Slots/Slots.ts b/src/core/Slots/Slots.ts index 1770bc8..a6ba7cd 100644 --- a/src/core/Slots/Slots.ts +++ b/src/core/Slots/Slots.ts @@ -79,6 +79,12 @@ export class Slots { // find the right slot s++; }else{ + // fully remove weapons, bows, and shields instead of reducing their life + if(stack.item.type === ItemType.Weapon || stack.item.type === ItemType.Bow || stack.item.type === ItemType.Shield){ + this.internalSlots[i] = stack.modify({count:0}); + break; + } + if(count<0 || stack.count