Fixed stat allocation issues (#10344)

This commit is contained in:
Keith Holliday
2018-05-08 08:54:50 -05:00
committed by GitHub
parent e9ce968f88
commit 21eac3cc94

View File

@@ -55,7 +55,6 @@
h3(v-if="label !== 'skip'") {{ label }} h3(v-if="label !== 'skip'") {{ label }}
h3(v-else) {{ $t('background') }} h3(v-else) {{ $t('background') }}
.row.pet-mount-row .row.pet-mount-row
.col-12.col-md-6 .col-12.col-md-6
h2.text-center(v-once) {{ $t('pets') }} h2.text-center(v-once) {{ $t('pets') }}
@@ -134,15 +133,15 @@
.row .row
.col-12.col-md-3(v-for='(statInfo, stat) in allocateStatsList') .col-12.col-md-3(v-for='(statInfo, stat) in allocateStatsList')
.box.white.row.col-12 .box.white.row.col-12
.col-12.col-md-8 .col-12.col-md-9
div(:class='stat') {{ $t(stats[stat].title) }} div(:class='stat') {{ $t(stats[stat].title) }}
.number {{ user.stats[stat] }} .number {{ user.stats[stat] }}
.points {{$t('pts')}} .points {{$t('pts')}}
.col-12.col-md-4 .col-12.col-md-3
div div
.up(v-if='user.stats.points', @click='allocate(stat)') .up(v-if='user.stats.points', @click='allocate(stat)')
div div
.down(@click='deallocate(stat)') .down(@click='deallocate(stat)', v-if='user.stats.points')
.row.save-row .row.save-row
.col-12.col-md-6.offset-md-3.text-center .col-12.col-md-6.offset-md-3.text-center
button.btn.btn-primary(@click='saveAttributes()', :disabled='loading') {{ this.loading ? $t('loading') : $t('save') }} button.btn.btn-primary(@click='saveAttributes()', :disabled='loading') {{ this.loading ? $t('loading') : $t('save') }}
@@ -212,7 +211,7 @@
popover: 'perText', popover: 'perText',
}, },
}, },
statsAtStart: { statUpdates: {
str: 0, str: 0,
int: 0, int: 0,
con: 0, con: 0,
@@ -221,9 +220,6 @@
content: Content, content: Content,
}; };
}, },
mounted () {
this.statsAtStart = Object.assign({}, this.user.stats);
},
computed: { computed: {
...mapState({ ...mapState({
flatGear: 'content.gear.flat', flatGear: 'content.gear.flat',
@@ -291,19 +287,20 @@
}, },
allocate (stat) { allocate (stat) {
allocate(this.user, {query: { stat }}); allocate(this.user, {query: { stat }});
this.statUpdates[stat] += 1;
}, },
deallocate (stat) { deallocate (stat) {
if (this.user.stats[stat] === 0) return; if (this.user.stats[stat] === 0) return;
this.user.stats[stat] -= 1; this.user.stats[stat] -= 1;
this.user.stats.points += 1; this.user.stats.points += 1;
this.statUpdates[stat] -= 1;
}, },
async saveAttributes () { async saveAttributes () {
this.loading = true; this.loading = true;
const statUpdates = {}; const statUpdates = {};
['str', 'int', 'per', 'con'].forEach(stat => { ['str', 'int', 'per', 'con'].forEach(stat => {
const diff = this.user.stats[stat] - this.statsAtStart[stat]; if (this.statUpdates[stat] > 0) statUpdates[stat] = this.statUpdates[stat];
statUpdates[stat] = diff;
}); });
await axios.post('/api/v3/user/allocate-bulk', { await axios.post('/api/v3/user/allocate-bulk', {