SES-160 shop on gm and player screen #85
@ -6,6 +6,7 @@ import { Either } from '../types/Either';
|
|||||||
import { ErrorResponse } from '../types/ErrorResponse';
|
import { ErrorResponse } from '../types/ErrorResponse';
|
||||||
import { switchMap } from 'rxjs/operators';
|
import { switchMap } from 'rxjs/operators';
|
||||||
import { SuccessResponse } from '../types/SuccessResponse';
|
import { SuccessResponse } from '../types/SuccessResponse';
|
||||||
|
import { ShopkeeperWithItemsDetailsViewModel } from '../types/viewmodels/shopkeeper-viewmodels/ShopkeeperWithItemsDetailsViewModel';
|
||||||
|
|
||||||
Injectable({
|
Injectable({
|
||||||
providedIn: 'root',
|
providedIn: 'root',
|
||||||
@ -33,10 +34,34 @@ export class ShopkeeperService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GetActiveShopkeeper(): Observable<ShopkeeperWithItemsDetailsViewModel> {
|
||||||
|
return this.http
|
||||||
|
.get<Either<ShopkeeperWithItemsDetailsViewModel, ErrorResponse>>(
|
||||||
|
this.baseUrl + 'getActiveShopkeeper'
|
||||||
|
)
|
||||||
|
.pipe(
|
||||||
|
switchMap((response) => {
|
||||||
|
debugger;
|
||||||
|
if (response.isLeft) {
|
||||||
|
return of(response.left);
|
||||||
|
} else {
|
||||||
|
return throwError(response.right);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
ChangeShopkeeperStatus(shopkeeperId: number, newStatus: boolean) {
|
ChangeShopkeeperStatus(shopkeeperId: number, newStatus: boolean) {
|
||||||
const params = new HttpParams()
|
const params = new HttpParams()
|
||||||
.set('shopkeeperId', shopkeeperId.toString())
|
.set('shopkeeperId', shopkeeperId.toString())
|
||||||
.set('availability', newStatus.toString());
|
.set('availability', newStatus.toString());
|
||||||
this.http.post(this.baseUrl + 'getShopkeepers', params);
|
this.http.post(this.baseUrl + 'getShopkeepers', params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RemoveShopkeeper(shopkeeperId: number, currentStatus: boolean) {
|
||||||
|
const params = new HttpParams()
|
||||||
|
.set('shopkeeperId', shopkeeperId.toString())
|
||||||
|
.set('wasAvailable', currentStatus.toString());
|
||||||
|
this.http.post(this.baseUrl + 'getShopkeepers', params);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,43 @@
|
|||||||
|
export interface ShopkeeperWithItemsDetailsViewModel {
|
||||||
|
id: number;
|
||||||
|
name: string;
|
||||||
|
isAvailable: boolean;
|
||||||
|
items: [
|
||||||
|
{
|
||||||
|
shopkeeperId: number;
|
||||||
|
armorId: number;
|
||||||
|
armor: {
|
||||||
|
id: number;
|
||||||
|
name: string;
|
||||||
|
category: string;
|
||||||
|
armorClassBase: string;
|
||||||
|
haveDexterityBonus: true;
|
||||||
|
minimumStrength: number;
|
||||||
|
haveStealthDisadvantage: boolean;
|
||||||
|
weight: number;
|
||||||
|
cost: number;
|
||||||
|
currencyType: number;
|
||||||
|
};
|
||||||
|
weaponId: number;
|
||||||
|
weapon: {
|
||||||
|
id: number;
|
||||||
|
name: string;
|
||||||
|
cost: number;
|
||||||
|
weight: number;
|
||||||
|
currencyType: number;
|
||||||
|
diceCount: number;
|
||||||
|
diceValue: number;
|
||||||
|
twoHandDiceCount: number;
|
||||||
|
twoHandDiceValue: number;
|
||||||
|
twoHandDamageType: string;
|
||||||
|
description: string;
|
||||||
|
weaponType: string;
|
||||||
|
rangeMeele: number;
|
||||||
|
rangeThrowNormal: number;
|
||||||
|
rangeThrowLong: number;
|
||||||
|
rangeLong: number;
|
||||||
|
};
|
||||||
|
amount: number;
|
||||||
|
}
|
||||||
|
];
|
||||||
|
}
|
@ -62,6 +62,10 @@ namespace SessionCompanion.Controllers
|
|||||||
{
|
{
|
||||||
await this._sessionHub.Clients.Group("Players").SendAsync("NewShopkeeperArrived");
|
await this._sessionHub.Clients.Group("Players").SendAsync("NewShopkeeperArrived");
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
await this._sessionHub.Clients.Group("Players").SendAsync("ShopkeeperLeft");
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -75,12 +79,15 @@ namespace SessionCompanion.Controllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost("removeShopkeeper")]
|
[HttpPost("removeShopkeeper")]
|
||||||
public async Task<Either<SuccessResponse, ErrorResponse>> RemoveShopkeeper([Required] int shopkeeperId)
|
public async Task<Either<SuccessResponse, ErrorResponse>> RemoveShopkeeper([Required] int shopkeeperId, bool wasAvailable)
|
||||||
{
|
{
|
||||||
await this._service.Delete(shopkeeperId);
|
await this._service.Delete(shopkeeperId);
|
||||||
await this._service.SaveAsync();
|
await this._service.SaveAsync();
|
||||||
|
|
||||||
await this._sessionHub.Clients.Group("Players").SendAsync("ShopkeeperRemoved");
|
if (wasAvailable)
|
||||||
|
{
|
||||||
|
await this._sessionHub.Clients.Group("Players").SendAsync("ShopkeeperRemoved");
|
||||||
|
}
|
||||||
|
|
||||||
return new SuccessResponse("Delete completed");
|
return new SuccessResponse("Delete completed");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user