Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/inbound attacks event #821

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions client/src/views/account/components/Subscriptions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,16 @@
</select>
</div>
</div>

<div class="row pt-1 pb-1">
<label for="playerInboundAttacks" class="col-12 col-sm-6 col-form-label">Game - Incoming Attacks</label>
<div class="col-12 col-sm-6">
<select class="form-control" id="playerInboundAttacks" v-model="subscriptions.discord.playerInboundAttacks" :disabled="isSaving">
<option :value="true">Enabled</option>
<option :value="false">Disabled</option>
</select>
</div>
</div>

<div class="row pt-1 pb-1">
<label for="playerRenownReceived" class="col-12 col-sm-6 col-form-label">Game - Renown Received</label>
Expand Down
6 changes: 5 additions & 1 deletion client/src/views/game/components/eventLog/EventLog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
<menu-title title="Event Log" @onCloseRequested="onCloseRequested"/>
</div>

<events-list class="pt-2" @onOpenPlayerDetailRequested="onOpenPlayerDetailRequested"/>
<events-list class="pt-2" @onOpenPlayerDetailRequested="onOpenPlayerDetailRequested"
@onOpenCarrierDetailRequested="onOpenCarrierDetailRequested"/>
</div>
</template>

Expand Down Expand Up @@ -41,6 +42,9 @@ export default {
onOpenPlayerDetailRequested (e) {
this.$emit('onOpenPlayerDetailRequested', e)
},
onOpenCarrierDetailRequested(e) {
this.$emit('onOpenCarrierDetailRequested', e)
},
async checkForUnreadEvents () {
try {
let response = await EventApiService.getUnreadCount(this.$store.state.game._id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@
<player-gift-sent :event="event" v-if="event.type === 'playerGiftSent'"
@onOpenPlayerDetailRequested="onOpenPlayerDetailRequested"/>
<player-galactic-cycle-complete :event="event" v-if="event.type === 'playerGalacticCycleComplete'"/>
<player-inbound-attacks :event="event" v-if="event.type === 'playerInboundAttacks'"
@onOpenPlayerDetailRequested="onOpenPlayerDetailRequested"
@onOpenCarrierDetailRequested="onOpenCarrierDetailRequested"/>
<player-renown-received :event="event" v-if="event.type === 'playerRenownReceived'"
@onOpenPlayerDetailRequested="onOpenPlayerDetailRequested"/>
<player-renown-sent :event="event" v-if="event.type === 'playerRenownSent'"
Expand Down Expand Up @@ -88,6 +91,7 @@ import PlayerCreditsSpecialistsSentVue from './PlayerCreditsSpecialistsSent'
import PlayerGiftReceivedVue from './PlayerGiftReceived'
import PlayerGiftSentVue from './PlayerGiftSent'
import PlayerGalacticCycleCompleteEventVue from './PlayerGalacticCycleCompleteEvent'
import PlayerInboundAttacksEventVue from './PlayerInboundAttacksEvent'
import PlayerRenownReceivedVue from './PlayerRenownReceived'
import PlayerRenownSentVue from './PlayerRenownSent'
import PlayerResearchCompleteVue from './PlayerResearchComplete'
Expand Down Expand Up @@ -130,6 +134,8 @@ export default {
'player-gift-received': PlayerGiftReceivedVue,
'player-gift-sent': PlayerGiftSentVue,
'player-galactic-cycle-complete': PlayerGalacticCycleCompleteEventVue,
'player-inbound-attacks': PlayerInboundAttacksEventVue,

'player-renown-received': PlayerRenownReceivedVue,
'player-renown-sent': PlayerRenownSentVue,
'player-research-complete': PlayerResearchCompleteVue,
Expand All @@ -154,6 +160,9 @@ export default {
onOpenPlayerDetailRequested (e) {
this.$emit('onOpenPlayerDetailRequested', e)
},
onOpenCarrierDetailRequested (e) {
this.$emit('onOpenCarrierDetailRequested', e)
},
async markAsRead () {
if (this.isRead) {
return
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
<template>
<div>
<p>
Hostile carriers sighted en route to your stars
</p>

<span v-if="carrierTimers">

<table class="table table-sm">

<thead class="table-dark">
<th>Star</th>
<th>Attacker</th>
<th>Ships</th>
<th class="text-end">ETA</th>
</thead>

<tbody>
<tr v-for="attack of sortedAttacks" :key="attack.carrierId">
<td>
<star-label :starId="attack.starId" :starName="getStarById(attack.starId).name" />
</td>
<td>
<a href="javascript:;" @click="onOpenPlayerDetailRequested(attack.attackingPlayerId)">
<span class="player-icon">
<player-icon-shape :filled="true" :iconColour="getPlayerColor(attack.attackingPlayerId)"
:shape="getPlayerShape(attack.attackingPlayerId)" />
</span>{{ getPlayerById(attack.attackingPlayerId).alias }}
</a>
</td>
<td>
<specialist-icon :type="'carrier'" :defaultIcon="'rocket'"
:specialist="attack.specialist"></specialist-icon>
<a href="javascript:;" @click="onOpenCarrierDetailRequested(attack.carrierId)">{{ attack.ships ?
attack.ships : "???" }}
</a>
</td>
<td class="text-end">
<span v-if="carrierTimers.some(t => t.carrier._id === attack.carrierId)">
{{ carrierTimers.find(t => t.carrier._id === attack.carrierId).timeRemainingEta }}
</span>
</td>

</tr>

</tbody>
</table>

</span>

</div>
</template>

<script>

import GameHelper from '../../../../../services/gameHelper'
import StarLabelVue from '../../star/StarLabel'
import SpecialistIconVue from '../../specialist/SpecialistIcon.vue'
import PlayerIconShape from '../../player/PlayerIconShape.vue'


export default {
components: {
PlayerIconShape,
'star-label': StarLabelVue,
'specialist-icon': SpecialistIconVue,
},
props: {
event: Object
},
data() {
return {
sortedAttacks: null,
carrierTimers: null,
intervalFunction: null,
}
},
mounted() {

this.carrierTimers = this.event.data.attacks.map(attack => {
let c = GameHelper.getCarrierById(this.$store.state.game, attack.carrierId)
if (!c) return null

return {
carrier: c,
timeRemainingEta: '',
}
}).filter(t => t)

this.recalculateTimeRemaining()

this.sortedAttacks = this.event.data.attacks.sort((a, b) => {
// First, compare by time in ascending order

let aTicks = this.getCarrierTicksEtaFromTimers(a.carrierId)
let bTicks = this.getCarrierTicksEtaFromTimers(b.carrierId)

if (aTicks && bTicks) {
if (aTicks < bTicks) {
return -1;
} else if (aTicks > bTicks) {
return 1;
}
}

// If ticksEta values are equal, sort by ships in descending order
if (a.ships === null && b.ships !== null) {
return -1;
} else if (a.ships !== null && b.ships === null) {
return 1;
} else if (a.ships > b.ships) {
return -1;
} else if (a.ships < b.ships) {
return 1;
}

// If both ticksEta and ships are equal, sort by has specialist
if (!a.specialist && b.specialist) {
return 1;
} else if (a.specialist && !b.specialist) {
return -1;
}

// If ticksEta, ships, and has specialist are equal, sort by something else
return b.carrierId.toString().localeCompare(a.carrierId.toString())
})


if (GameHelper.isGameInProgress(this.$store.state.game) || GameHelper.isGamePendingStart(this.$store.state.game)) {
this.intervalFunction = setInterval(this.recalculateTimeRemaining, 500)
this.recalculateTimeRemaining()
}
},
destroyed() {
clearInterval(this.intervalFunction)
},
methods: {
getPlayerById(playerId) {
return GameHelper.getPlayerById(this.$store.state.game, playerId)
},
getStarById(starId) {
return GameHelper.getStarById(this.$store.state.game, starId)
},
getPlayerColor(playerId) {
return GameHelper.getPlayerColour(this.$store.state.game, playerId)
},
getPlayerShape(playerId) {
return GameHelper.getPlayerById(this.$store.state.game, playerId).shape;
},
recalculateTimeRemaining() {
for (let timerData of this.carrierTimers) {
let carrier = timerData.carrier
if (!carrier) return
if (carrier.ticksEta) {
let timeString = GameHelper.getCountdownTimeStringByTicks(this.$store.state.game, carrier.ticksEta)
timerData.timeRemainingEta = timeString
}

}
},
getCarrierTicksEtaFromTimers(carrierId) {
// vue doesn't like question mark?, manually check each reference?
if (!carrierId) return 0

let timerEntry = this.carrierTimers.find(t => {
if (t.carrier === undefined) return false
return t.carrier._id === carrierId
})
if (!timerEntry) return 0

let carrier = timerEntry.carrier
if (!carrier) return 0

let waypoints = carrier.waypoints
if (!waypoints) return 0

let nextWaypoint = waypoints[0]
if (!nextWaypoint) return 0

return nextWaypoint.ticksEta
},
onOpenPlayerDetailRequested(e) {
this.$emit('onOpenPlayerDetailRequested', e)
},
onOpenCarrierDetailRequested(e) {
//check that the carrier is still visible, maybe show some error?
if (GameHelper.getCarrierById(this.$store.state.game, e)) {
this.$emit('onOpenCarrierDetailRequested', e)
}
},
},
}
</script>

<style scoped>
.player-icon {
display: inline-flex;
align-items: center;
}

.player-icon svg {
width: 12px;
height: 12px;
margin-right: 10px;
}
</style>
3 changes: 2 additions & 1 deletion client/src/views/game/components/menu/MainBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@
@onOpenPlayerDetailRequested="onOpenPlayerDetailRequested"/>
<event-log v-if="menuState == MENU_STATES.EVENT_LOG"
@onCloseRequested="onCloseRequested"
@onOpenPlayerDetailRequested="onOpenPlayerDetailRequested"/>
@onOpenPlayerDetailRequested="onOpenPlayerDetailRequested"
@onOpenCarrierDetailRequested="onOpenCarrierDetailRequested"/>
<intel v-if="menuState == MENU_STATES.INTEL" @onCloseRequested="onCloseRequested" :compareWithPlayerId="menuArguments"/>
<galaxy v-if="menuState == MENU_STATES.GALAXY"
:tab="menuArguments"
Expand Down
3 changes: 2 additions & 1 deletion server/db/models/schemas/star.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ const schema = new Schema({
location: {
x: { type: Types.Number, required: true, default: 0 },
y: { type: Types.Number, required: true, default: 0 }
}
},
inboundAttacksNotified: [{ type: Types.ObjectId, required: false, default: [] }], // carrier ids
});

export default schema;
Loading
Loading