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
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
use crate::bad_json::deserialize_bad_location_as_none;
use crate::ErrorResponse;
use serde::{Deserialize, Serialize};

#[derive(Debug, Serialize)]
pub(crate) struct MoveItemRequest<'a, T> {
    pub(crate) data: &'a [T],
    pub(crate) tm: u64,
}

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub(crate) struct RagfairResponseData {
    pub(crate) items: serde_json::Value,
    #[serde(rename = "badRequest")]
    pub(crate) errors: Vec<ErrorResponse>,
}

/// Changes to the player's inventory after interacting with traders or the flea market.
#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct InventoryUpdate {
    /// New items in inventory.
    pub new: Option<Vec<Item>>,
    /// Changed items in inventory.
    pub change: Option<Vec<Item>>,
    /// Deleted items in inventory.
    pub del: Option<Vec<DeletedItem>>,
}

/// Item deleted from inventory.
#[derive(Debug, Deserialize, Clone, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct DeletedItem {
    /// Item ID
    #[serde(rename = "_id")]
    pub id: String,
}

/// In-game item
#[derive(Debug, Deserialize, Clone, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct Item {
    /// Item ID
    #[serde(rename = "_id")]
    pub id: String,
    /// Item localization schema ID
    #[serde(rename = "_tpl")]
    pub schema_id: String,
    /// Item parent ID
    pub parent_id: Option<String>,
    /// Item slot ID
    pub slot_id: Option<String>,
    /// Item attachments/options
    pub upd: Option<Upd>,
    /// Item location
    #[serde(default, deserialize_with = "deserialize_bad_location_as_none")]
    pub location: Option<Location>,
}

/// Item location
#[derive(Debug, Deserialize, Clone, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct Location {
    /// Inventory slot x
    pub x: u64,
    /// Inventory slot y
    pub y: u64,
    /// Inventory slot rotation
    pub r: u64,
    /// Item is searched (if searchable)
    pub is_searched: Option<bool>,
}

/// Item options
#[derive(Debug, Deserialize, Clone, PartialEq)]
#[serde(rename_all = "PascalCase")]
pub struct Upd {
    /// Item stack count
    pub stack_objects_count: Option<u64>,
    /// Item spawned in session
    pub spawned_in_session: Option<bool>,
    /// Item is medkit
    pub med_kit: Option<UpdMedkit>,
    /// Item is repairable
    pub repairable: Option<UpdRepairable>,
    /// Item has a light attachment
    pub light: Option<UpdLight>,
    /// Unlimited stack
    pub unlimited_count: Option<bool>,
    /// ?
    pub buy_restriction_max: Option<u64>,
    /// ?
    pub buy_restriction_current: Option<u64>,
    /// Key info
    pub key: Option<UpdKey>,
}

/// Medkit item info
#[derive(Debug, Deserialize, Clone, PartialEq)]
#[serde(rename_all = "PascalCase")]
pub struct UpdMedkit {
    /// Health
    pub hp_resource: f64,
}

/// Repairable item info
#[derive(Debug, Deserialize, Clone, PartialEq)]
#[serde(rename_all = "PascalCase")]
pub struct UpdRepairable {
    /// Maximum durability
    pub max_durability: Option<f64>,
    /// Current durability
    pub durability: f64,
}

/// Light attachment info
#[derive(Debug, Deserialize, Clone, PartialEq)]
#[serde(rename_all = "PascalCase")]
pub struct UpdLight {
    /// Light is active
    pub is_active: bool,
    /// Light mode
    pub selected_mode: u64,
}

/// Key info
#[derive(Debug, Deserialize, Clone, PartialEq)]
#[serde(rename_all = "PascalCase")]
pub struct UpdKey {
    /// Number of usage
    pub number_of_usages: u64,
}

/// Inventory item for trading.
#[derive(Debug, Serialize, Clone, PartialEq)]
pub struct BarterItem {
    /// Item ID from player's inventory.
    pub id: String,
    /// Amount of items.
    pub count: f64,
}