Skip to content

Commit

Permalink
feat(inventory): only show equippable items for each player
Browse files Browse the repository at this point in the history
 - 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.
  • Loading branch information
justindujardin committed Oct 27, 2022
1 parent 033b8d5 commit 8c7d3e6
Showing 1 changed file with 27 additions and 15 deletions.
42 changes: 27 additions & 15 deletions src/app/components/party-inventory/party-inventory.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
Expand Down Expand Up @@ -56,19 +57,6 @@ export class PartyInventoryComponent implements OnDestroy {

party$: Observable<Immutable.List<Entity>> = this.store.select(getGameParty);

/** Stream of all inventory excluding items */
inventory$: Observable<Immutable.List<EntityItemTypes>> = this.store
.select(getGameInventory)
.pipe(
map((inventory: Immutable.List<EntityItemTypes>) => {
return inventory
.filter((i: EntityItemTypes) => {
return i.type !== 'item';
})
.toList();
})
);

/**
* Emit on this subject to update the current index.
*/
Expand Down Expand Up @@ -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<Immutable.List<EntityItemTypes>> = this.store
.select(getGameInventory)
.pipe(
combineLatest(
this.currentEntity$,
(inventory: Immutable.List<EntityItemTypes>, 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(
Expand Down

0 comments on commit 8c7d3e6

Please sign in to comment.