disallow trading dead entities

This commit is contained in:
crabman 2024-02-12 23:55:05 +01:00
parent 8285162967
commit e225da7a75
No known key found for this signature in database

View File

@ -10,7 +10,7 @@ use common::{
agent::{Agent, AgentEvent},
group::GroupManager,
invite::{Invite, InviteKind, InviteResponse, PendingInvites},
ChatType, Group, Pos,
ChatType, Group, Health, Pos,
},
consts::MAX_TRADE_RANGE,
event::{InitiateInviteEvent, InviteResponseEvent},
@ -48,6 +48,7 @@ impl ServerEvent for InitiateInviteEvent {
ReadStorage<'a, Client>,
ReadStorage<'a, Pos>,
ReadStorage<'a, Group>,
ReadStorage<'a, Health>,
);
fn handle(
@ -64,6 +65,7 @@ impl ServerEvent for InitiateInviteEvent {
clients,
positions,
groups,
healths,
): Self::SystemData<'_>,
) {
for InitiateInviteEvent(inviter, invitee_uid, kind) in events {
@ -92,8 +94,11 @@ impl ServerEvent for InitiateInviteEvent {
}
if matches!(kind, InviteKind::Trade) {
// Check whether the inviter is in range of the invitee
if !within_trading_range(positions.get(inviter), positions.get(invitee)) {
// Check whether the inviter is in range of the invitee or dead
if !within_trading_range(positions.get(inviter), positions.get(invitee))
|| healths.get(inviter).is_some_and(|h| h.is_dead)
|| healths.get(invitee).is_some_and(|h| h.is_dead)
{
continue;
}
}