Skip to content

Commit

Permalink
fix(mercantile): sell value is appropriately multiplied for quick sel…
Browse files Browse the repository at this point in the history
…l, and all other sell methods.
  • Loading branch information
seiyria committed Mar 28, 2023
1 parent e96e59a commit fec45c0
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/app/pages/character/inventory/inventory.page.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
</ion-item>

<ion-item class="cursor-pointer" (click)="quickSell(item)">
Quick Sell ({{ (item.value || 1) * (item.quantity || 1) }} coins)
Quick Sell ({{ realSellValue(item) | number }} coins)
</ion-item>

<ion-item class="cursor-pointer" (click)="sell(item)" *ngIf="mercantileUnlocked$ | async">
Expand Down
10 changes: 8 additions & 2 deletions src/app/pages/character/inventory/inventory.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ import { Observable, Subscription } from 'rxjs';
import { IGameItem } from '../../../../interfaces';
import { CharSelectState, CombatState, MercantileState } from '../../../../stores';
import { OOCEatFood } from '../../../../stores/combat/combat.actions';
import { NotifyWarning } from '../../../../stores/game/game.actions';
import { QuickSellItemFromInventory, SellItem, SendToStockpile } from '../../../../stores/mercantile/mercantile.actions';
import { maxShopCounterSize, shopRegisterMultiplier } from '../../../../stores/mercantile/mercantile.functions';
import { itemValue } from '../../../helpers';
import { setDiscordStatus } from '../../../helpers/electron';
import { maxShopCounterSize } from '../../../../stores/mercantile/mercantile.functions';
import { NotifyWarning } from '../../../../stores/game/game.actions';

@Component({
selector: 'app-inventory',
Expand Down Expand Up @@ -73,6 +74,11 @@ export class InventoryPage implements OnInit, OnDestroy {
return sortBy((items || []).filter(x => (x?.quantity ?? 0) > 0).filter(item => item.category === category), 'name');
}

realSellValue(item: IGameItem) {
return itemValue(item,
shopRegisterMultiplier(this.store.selectSnapshot(state => state.mercantile.shop.saleBonusLevel ?? 0))) * (item.quantity ?? 1);
}

eat(item: IGameItem) {
this.store.dispatch(new OOCEatFood(item));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
</ion-item>

<ion-item class="cursor-pointer" (click)="quickSell(item)">
Quick Sell ({{ (item.value || 1) * (item.quantity || 1) }} coins)
Quick Sell ({{ realSellValue(item) | number }} coins)
</ion-item>

<ion-item class="cursor-pointer" (click)="sell(item)">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@ import { LocalStorage } from 'ngx-webstorage';
import { Observable, Subscription } from 'rxjs';
import { IGameItem, IGameMercantileStockpile } from '../../../../../../interfaces';
import { CharSelectState, MercantileState } from '../../../../../../stores';
import { NotifyWarning } from '../../../../../../stores/game/game.actions';
import {
QuickSellAllFromStockpile, QuickSellItemFromStockpile,
SellItem, SendToInventory, UpgradeStockpileSize
} from '../../../../../../stores/mercantile/mercantile.actions';
import { maxShopCounterSize, maxStockpileLevel,
maxStockpileSizeUpgradeCost } from '../../../../../../stores/mercantile/mercantile.functions';
import { NotifyWarning } from '../../../../../../stores/game/game.actions';
import {
maxShopCounterSize, maxStockpileLevel,
maxStockpileSizeUpgradeCost,
shopRegisterMultiplier
} from '../../../../../../stores/mercantile/mercantile.functions';
import { itemValue } from '../../../../../helpers';

@Component({
selector: 'app-stockpile',
Expand Down Expand Up @@ -72,6 +76,11 @@ export class StockpilePage implements OnInit, OnDestroy {
return sortBy(items.filter(x => (x?.quantity ?? 0) > 0).filter(item => item.category === category), 'name');
}

realSellValue(item: IGameItem) {
return itemValue(item,
shopRegisterMultiplier(this.store.selectSnapshot(state => state.mercantile.shop.saleBonusLevel ?? 0))) * (item.quantity ?? 1);
}

canUpgradeStorage(currentCoins: number, currentLevel: number): boolean {
if(this.isStockpileStorageMaxLevel(currentLevel)) {
return false;
Expand Down
16 changes: 9 additions & 7 deletions src/stores/mercantile/mercantile.functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export function maxShopRegisterUpgradeCost(currentLevel: number): number {
}

export function shopRegisterMultiplier(currentLevel: number): number {
return currentLevel * 0.1;
return 1 + (currentLevel * 0.1);
}

// decoration functions
Expand Down Expand Up @@ -154,7 +154,7 @@ export function decreaseDuration(ctx: StateContext<IGameMercantile>, { ticks }:
ctx.dispatch(new IncrementStat(AchievementStat.MercantileSellItems, soldItems.length));
}

const soldValue = sum(soldItems.map(item => itemValue(item, 1 + 2 + shopRegisterMultiplier(state.level))));
const soldValue = sum(soldItems.map(item => itemValue(item, 2 + shopRegisterMultiplier(state.shop.saleBonusLevel))));
gainCoins(ctx, { amount: soldValue });

const newItems = items.filter(item => !soldItems.includes(item));
Expand All @@ -171,7 +171,7 @@ export function sendToStockpile(ctx: StateContext<IGameMercantile>, { item }: Se

const maxSize = maxStockpileSize(state.stockpile.limitLevel);
if(state.stockpile.items.length >= maxSize) {
gainCoins(ctx, { amount: itemValue(item) });
gainCoins(ctx, { amount: itemValue(item, shopRegisterMultiplier(state.shop.saleBonusLevel)) });
return;
}

Expand All @@ -198,7 +198,7 @@ export function sellItem(ctx: StateContext<IGameMercantile>, { item }: SellItem)

const maxSize = maxShopCounterSize(state.shop.saleCounterLevel);
if(state.shop.forSale.length >= maxSize) {
gainCoins(ctx, { amount: itemValue(item) });
gainCoins(ctx, { amount: itemValue(item, shopRegisterMultiplier(state.shop.saleBonusLevel)) });
return;
}

Expand All @@ -224,20 +224,22 @@ export function unsellItem(ctx: StateContext<IGameMercantile>, { item }: UnsellI
}

export function quickSellFromInventory(ctx: StateContext<IGameMercantile>, { item }: QuickSellItemFromInventory) {
gainCoins(ctx, { amount: itemValue(item) });
const state = ctx.getState();
gainCoins(ctx, { amount: itemValue(item, shopRegisterMultiplier(state.shop.saleBonusLevel)) });
ctx.dispatch(new PlaySFX('action-sell'));
}

export function quickSellItemFromStockpile(ctx: StateContext<IGameMercantile>, { item }: QuickSellItemFromStockpile) {
gainCoins(ctx, { amount: itemValue(item) });
const state = ctx.getState();
gainCoins(ctx, { amount: itemValue(item, shopRegisterMultiplier(state.shop.saleBonusLevel)) });
removeFromStockpile(ctx, { item });
ctx.dispatch(new PlaySFX('action-sell'));
}

export function quickSellAllFromStockpile(ctx: StateContext<IGameMercantile>) {
const state = ctx.getState();

const value = sum(state.stockpile.items.map(item => itemValue(item)));
const value = sum(state.stockpile.items.map(item => itemValue(item, shopRegisterMultiplier(state.shop.saleBonusLevel))));

gainCoins(ctx, { amount: value });

Expand Down

0 comments on commit fec45c0

Please sign in to comment.