-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for item allowing to cast spell on superior level
- Loading branch information
Showing
28 changed files
with
376 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
src/app/data-accessor/selectors/character-superior-arcane-capability-selector.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import {Lvl0Character} from '../models/lvl0-character'; | ||
import {combineLatest, distinctUntilChanged, Observable, shareReplay} from 'rxjs'; | ||
import _ from 'lodash'; | ||
import {Lvl0Item} from '../models/lvl0-item'; | ||
import {selectCharacterEquipedItems} from './character-equiped-items-selector'; | ||
|
||
export type SuperiorArcaneCapability = { | ||
sourceType: 'item'; | ||
sourceId: string; | ||
label: string; | ||
manaMultiplierPerLevel?: number; | ||
damagePerLevel?: number; | ||
usageCountPerSessions?: number; | ||
maximumArcaneLevel?: number; | ||
} | ||
|
||
export class CharacterSuperiorArcaneCapabilitySelector { | ||
static selectSuperiorArcaneCapabilitySelector( | ||
equipedItems: Lvl0Item[], | ||
): SuperiorArcaneCapability[] { | ||
let result: SuperiorArcaneCapability[] = []; | ||
for (let equipedItem of equipedItems) { | ||
if (!('superiorArcane' in equipedItem.system)) { | ||
continue; | ||
} | ||
if (!equipedItem.system.superiorArcane?.active) { | ||
continue; | ||
} | ||
|
||
result.push({ | ||
label: equipedItem.name, | ||
sourceId: equipedItem.id, | ||
sourceType: 'item', | ||
...equipedItem.system.superiorArcane | ||
} as SuperiorArcaneCapability) | ||
} | ||
return result; | ||
} | ||
} | ||
|
||
export function selectSuperiorArcaneCapability() { | ||
return function (source: Observable<Lvl0Character>): Observable<SuperiorArcaneCapability[]> { | ||
return new Observable<SuperiorArcaneCapability[]>(subscriber => { | ||
return combineLatest([ | ||
source.pipe(selectCharacterEquipedItems()), | ||
]).subscribe({ | ||
next([equipedItems]: [Lvl0Item[]]) { | ||
subscriber.next(CharacterSuperiorArcaneCapabilitySelector.selectSuperiorArcaneCapabilitySelector( | ||
equipedItems, | ||
)); | ||
}, | ||
error(error) { | ||
subscriber.error(error); | ||
}, | ||
complete() { | ||
subscriber.complete(); | ||
} | ||
}) | ||
}).pipe( | ||
distinctUntilChanged((a, b) => _.isEqual(a, b)), | ||
shareReplay(1) | ||
); | ||
}; | ||
} |
Oops, something went wrong.