From b16e700de570e3a12aaccc9f1e89c5bd7aca11c0 Mon Sep 17 00:00:00 2001 From: negue Date: Sun, 29 Jul 2018 20:12:30 +0200 Subject: [PATCH] auto revive --- .../client/components/achievements/death.vue | 8 ------- website/client/components/notifications.vue | 23 ++++++++++++++++--- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/website/client/components/achievements/death.vue b/website/client/components/achievements/death.vue index 5d3595e723..6333c66bf5 100644 --- a/website/client/components/achievements/death.vue +++ b/website/client/components/achievements/death.vue @@ -23,7 +23,6 @@ p.death-penalty {{ $t('deathPenaltyDetails') }} .modal-footer .col-12.text-center - button.btn.btn-danger(@click='revive()') {{ $t('refillHealthTryAgain') }} h4.text-center(v-html="$t('dyingOftenTips')") @@ -37,10 +36,8 @@ diff --git a/website/client/components/notifications.vue b/website/client/components/notifications.vue index 75e6b55c30..5fb3f54ce3 100644 --- a/website/client/components/notifications.vue +++ b/website/client/components/notifications.vue @@ -118,6 +118,8 @@ import ultimateGear from './achievements/ultimateGear'; import wonChallenge from './achievements/wonChallenge'; import loginIncentives from './achievements/login-incentives'; +import revive from '../../common/script/ops/revive'; + const NOTIFICATIONS = { CHALLENGE_JOINED_ACHIEVEMENT: { achievement: true, @@ -218,6 +220,7 @@ export default { isRunningYesterdailies: false, nextCron: null, handledNotifications, + reviveRunning: false, }; }, computed: { @@ -245,8 +248,7 @@ export default { userHp (after, before) { if (this.user.needsCron) return; if (after <= 0) { - alert('userHp'); - this.showNotificationWithModal('DEATH'); + this.showDeathNotification(); // @TODO: {keyboard:false, backdrop:'static'} } else if (after <= 30 && !this.user.flags.warnedLowHealth) { this.$root.$emit('bv::show::modal', 'low-health'); @@ -346,6 +348,21 @@ export default { document.removeEventListener('keydown', this.checkNextCron); }, methods: { + showDeathNotification () { + if (this.reviveRunning) return; + + this.reviveRunning = true; + this.showNotificationWithModal('DEATH'); + + // if there is an api call still running (which removes health) + // a call to "revive" wouldn't do anything since the user is still alive on the server + // wait a second until the prior api call is done + setTimeout(async () => { + await axios.post('/api/v4/user/revive'); + revive(this.user); + this.reviveRunning = false; + }, 1000); + }, showNotificationWithModal (type, forceToModal) { const config = NOTIFICATIONS[type]; @@ -380,7 +397,7 @@ export default { } if (this.user.stats.hp <= 0) { - this.showNotificationWithModal('DEATH'); + this.showDeathNotification(); } if (this.questCompleted) {