adds buy/sell endpoints
This commit is contained in:
@@ -44,7 +44,16 @@ export const Api = {
|
||||
updateWealth (player_id, value_in_gp) {
|
||||
const payload = { player_id, value_in_gp: Number(value_in_gp) };
|
||||
return this.__doFetch("players/update-wealth", 'PUT', payload);
|
||||
}
|
||||
},
|
||||
buyItems (player_id, items) {
|
||||
const payload = { player_id, items };
|
||||
return this.__doFetch("players/buy", 'POST', payload);
|
||||
},
|
||||
sellItems (player_id, items) {
|
||||
const payload = { player_id, items };
|
||||
return this.__doFetch("players/sell", 'POST', payload);
|
||||
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@@ -117,15 +126,15 @@ export const AppStorage = {
|
||||
},
|
||||
updatePlayerWealth (goldValue) {
|
||||
return Api.updateWealth(this.state.player_id, goldValue)
|
||||
.then(response => {
|
||||
// Update player wealth
|
||||
var diff = response;
|
||||
.then(diff => this.__updatePlayerWealth(diff));
|
||||
},
|
||||
// TODO: Weird private name denotes a conflict
|
||||
__updatePlayerWealth (diff) {
|
||||
if (this.debug) console.log('updatePlayerWealth', diff)
|
||||
this.state.player_list[this.state.player_id].cp += diff[0];
|
||||
this.state.player_list[this.state.player_id].sp += diff[1];
|
||||
this.state.player_list[this.state.player_id].gp += diff[2];
|
||||
this.state.player_list[this.state.player_id].pp += diff[3];
|
||||
});
|
||||
},
|
||||
// Put a claim on an item from group chest.
|
||||
putRequest (itemId) {
|
||||
@@ -136,6 +145,22 @@ export const AppStorage = {
|
||||
this.state.player_claims[playerId].push(itemId);
|
||||
});
|
||||
},
|
||||
buyItems (items) {
|
||||
return Api.buyItems(this.state.player_id, items)
|
||||
.then(diff => this.__updatePlayerWealth(diff))
|
||||
.then(() => {
|
||||
// Add items to the player loot
|
||||
console.log(items);
|
||||
});
|
||||
},
|
||||
sellItems (items) {
|
||||
return Api.sellItems(this.state.player_id, items)
|
||||
.then(diff => this.__updatePlayerWealth(diff))
|
||||
.then(() => {
|
||||
// Remove items from player chest
|
||||
console.log(items);
|
||||
});
|
||||
},
|
||||
// Withdraws a claim.
|
||||
cancelRequest(itemId) {
|
||||
const playerId = this.state.player_id
|
||||
|
||||
@@ -89,8 +89,12 @@
|
||||
methods: {
|
||||
buySelectedItems () {
|
||||
const items = this.items.filter(i => this.selected_items.includes(i.id));
|
||||
this.$emit("buy", items);
|
||||
this.selected_items.length = 0;
|
||||
var payload = [];
|
||||
items.forEach(item => {
|
||||
payload.push([item.id, null]);
|
||||
});
|
||||
this.$emit("buy", payload);
|
||||
this.selected_items = [];
|
||||
},
|
||||
sellSelectedItems () {
|
||||
if (!this.is_selling) {
|
||||
@@ -99,7 +103,11 @@
|
||||
this.is_selling = false;
|
||||
if (this.selected_items.length > 0) {
|
||||
const items = this.items.filter(i => this.selected_items.includes(i.id));
|
||||
this.$emit("sell", items);
|
||||
var payload = [];
|
||||
items.forEach(item => {
|
||||
payload.push([item.id, null]);
|
||||
});
|
||||
this.$emit("sell", payload);
|
||||
this.selected_items = [];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,10 +22,12 @@ export default {
|
||||
|
||||
},
|
||||
buyItems(items) {
|
||||
this.notifications.push(`Would buy ${items.length} items`);
|
||||
AppStorage.buyItems(items)
|
||||
.then(_ => this.notifications.push(`Bought ${items.length} items`))
|
||||
},
|
||||
sellItems (items) {
|
||||
this.notifications.push(`Would sell ${items.length} items`);
|
||||
AppStorage.sellItems(items)
|
||||
.then(_ => this.notifications.push(`Sold ${items.length} items`))
|
||||
},
|
||||
parseLoot (items) {
|
||||
this.loot = [];
|
||||
|
||||
Reference in New Issue
Block a user