ed_journals/modules/state/models/resolvers/shipyard_state_resolver/
ship_entry.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
use crate::ship::ShipType;
use chrono::{DateTime, TimeDelta, Utc};
use serde::Serialize;
use std::ops::Add;

#[derive(Debug, Serialize)]
pub struct ShipEntry {
    pub ship_type: ShipType,
    pub status: ShipStatus,
}

/// The status of the ship.
#[derive(Debug, Serialize)]
pub enum ShipStatus {
    /// The current status of the ship is not known.
    Unknown,

    /// The ship is the current active ship for the player.
    Active,

    /// The ship is currently stored.
    Stored(u64),

    /// The ship is currently being transferred between two locations.
    Transferring(TransferringShipStatus),
}

/// Information about the current transfer status.
#[derive(Debug, Serialize)]
pub struct TransferringShipStatus {
    /// The timestamp when the transfer was initiated.
    pub started_at: DateTime<Utc>,

    /// The total transfer time duration in seconds.
    pub transfer_time: u64,

    /// The market id the ship is transferred from.
    pub from_market_id: u64,

    /// The market id the ship is transferred to.
    pub to_market_id: u64,
}

impl TransferringShipStatus {
    pub fn completed_at(&self) -> DateTime<Utc> {
        self.started_at
            .add(TimeDelta::new((self.transfer_time as i64).clamp(0, 10000000), 0).unwrap())
    }

    pub fn done_transferring(&self, timestamp: &DateTime<Utc>) -> bool {
        &self.completed_at() <= timestamp
    }
}