1
0
Fork 0

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
This commit is contained in:
Jordan Tucker 2022-08-04 20:03:10 -05:00 committed by GitHub
parent 98782ac94c
commit 1f2985467f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 52 additions and 2 deletions

View file

@ -0,0 +1,6 @@
// Author: jordanbtucker
const TEST = "dropWithExtraLife";
it(TEST, () => {
expect(TEST).toPassE2ESimulation();
});
export { };

View file

@ -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

View file

View file

@ -1,6 +1,6 @@
import { createMaterialStack, ItemStack } from "data/item"; import { createEquipmentStack, createMaterialStack, ItemStack, ItemType } from "data/item";
import { Slots } from "./Slots"; import { Slots } from "./Slots";
import { createMaterialMockItem } from "./SlotsTestHelpers"; import { createEquipmentMockItem, createMaterialMockItem } from "./SlotsTestHelpers";
describe("Slots.remove", ()=>{ describe("Slots.remove", ()=>{
it("Does nothing if item doesn't exist", ()=>{ it("Does nothing if item doesn't exist", ()=>{
@ -87,4 +87,40 @@ describe("Slots.remove", ()=>{
expect(removed).toBe(2); expect(removed).toBe(2);
expect(slots.getSlotsRef()).toEqualItemStacks(expected); 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);
});
}); });

View file

@ -79,6 +79,12 @@ export class Slots {
// find the right slot // find the right slot
s++; s++;
}else{ }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<count){ if(count<0 || stack.count<count){
// this stack not enough to remove all // this stack not enough to remove all
count-=stack.count; count-=stack.count;