From 8c7d3e6ce6d635b5ecd44e4d2d0395fffc310b46 Mon Sep 17 00:00:00 2001 From: Justin DuJardin Date: Thu, 27 Oct 2022 14:59:17 -0700 Subject: [PATCH] feat(inventory): only show equippable items for each player - we used to show all equippable items for any class. Now we narrow it down to the items that can be equipped by the current player class that the UI is showing. --- .../party-inventory.component.ts | 42 ++++++++++++------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/src/app/components/party-inventory/party-inventory.component.ts b/src/app/components/party-inventory/party-inventory.component.ts index 8b84a9c8..84a89934 100644 --- a/src/app/components/party-inventory/party-inventory.component.ts +++ b/src/app/components/party-inventory/party-inventory.component.ts @@ -17,7 +17,7 @@ import { Component, Input, OnDestroy } from '@angular/core'; import { Store } from '@ngrx/store'; import * as Immutable from 'immutable'; import { BehaviorSubject, Observable, Subject, Subscription } from 'rxjs'; -import { combineLatest, map, switchMap, take, withLatestFrom } from 'rxjs/operators'; +import { combineLatest, switchMap, take, withLatestFrom } from 'rxjs/operators'; import { AppState } from '../../app.model'; import { CombatService } from '../../models/combat/combat.service'; import { @@ -26,6 +26,7 @@ import { EntityWithEquipment, } from '../../models/entity/entity.model'; import { EntityItemTypes } from '../../models/entity/entity.reducer'; +import { EQUIPMENT_SLOTS } from '../../models/game-data/game-data.model'; import { GameStateEquipItemAction, GameStateUnequipItemAction, @@ -56,19 +57,6 @@ export class PartyInventoryComponent implements OnDestroy { party$: Observable> = this.store.select(getGameParty); - /** Stream of all inventory excluding items */ - inventory$: Observable> = this.store - .select(getGameInventory) - .pipe( - map((inventory: Immutable.List) => { - return inventory - .filter((i: EntityItemTypes) => { - return i.type !== 'item'; - }) - .toList(); - }) - ); - /** * Emit on this subject to update the current index. */ @@ -112,7 +100,31 @@ export class PartyInventoryComponent implements OnDestroy { return this.store.select(getEntityEquipment(entity?.eid)); }) ); - + /** Stream of inventory that the currentEntity$ can equip */ + inventory$: Observable> = this.store + .select(getGameInventory) + .pipe( + combineLatest( + this.currentEntity$, + (inventory: Immutable.List, member: EntityWithEquipment) => { + return inventory + .filter((i: EntityItemTypes) => { + // Is an item with a known equipment slot + if (EQUIPMENT_SLOTS.indexOf(i.type) !== -1) { + // If usedby is empty, anyone can use it + if ((i.usedby || []).length === 0) { + return true; + } + // If the player type is in the usedby array + if (i.usedby.includes(member.type)) { + return true; + } + } + }) + .toList(); + } + ) + ); /** Action generator from equip stream */ private _equipSubscription: Subscription = this.doEquip$ .pipe(