|
@ -3,6 +3,7 @@ use crate::ship::items::ClientItemId; |
|
|
use crate::entity::item::{Meseta, ItemEntityId, ItemDetail, ItemEntity, InventoryEntity, InventoryItemEntity};
|
|
|
use crate::entity::item::{Meseta, ItemEntityId, ItemDetail, ItemEntity, InventoryEntity, InventoryItemEntity};
|
|
|
use std::future::Future;
|
|
|
use std::future::Future;
|
|
|
|
|
|
|
|
|
|
|
|
use crate::ship::map::MapArea;
|
|
|
use crate::ship::location::RoomId;
|
|
|
use crate::ship::location::RoomId;
|
|
|
use crate::entity::character::CharacterEntityId;
|
|
|
use crate::entity::character::CharacterEntityId;
|
|
|
use crate::entity::gateway::GatewayError;
|
|
|
use crate::entity::gateway::GatewayError;
|
|
@ -253,6 +254,10 @@ impl FloorItemDetail { |
|
|
pub struct FloorItem {
|
|
|
pub struct FloorItem {
|
|
|
item_id: ClientItemId,
|
|
|
item_id: ClientItemId,
|
|
|
item: FloorItemDetail,
|
|
|
item: FloorItemDetail,
|
|
|
|
|
|
map_area: MapArea,
|
|
|
|
|
|
x: f32,
|
|
|
|
|
|
y: f32,
|
|
|
|
|
|
z: f32,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
impl FloorItem {
|
|
|
impl FloorItem {
|
|
@ -294,35 +299,6 @@ impl FloorItem { |
|
|
#[derive(Clone, Debug)]
|
|
|
#[derive(Clone, Debug)]
|
|
|
pub struct Inventory(Vec<InventoryItem>);
|
|
|
pub struct Inventory(Vec<InventoryItem>);
|
|
|
|
|
|
|
|
|
impl Inventory {
|
|
|
|
|
|
pub fn as_inventory_entity(&self, _character_id: &CharacterEntityId) -> InventoryEntity {
|
|
|
|
|
|
InventoryEntity {
|
|
|
|
|
|
items: self.0.iter()
|
|
|
|
|
|
.map(|item| {
|
|
|
|
|
|
match &item.item {
|
|
|
|
|
|
InventoryItemDetail::Individual(item) => {
|
|
|
|
|
|
InventoryItemEntity::Individual(ItemEntity {
|
|
|
|
|
|
id: item.entity_id,
|
|
|
|
|
|
item: item.item.clone(),
|
|
|
|
|
|
})
|
|
|
|
|
|
},
|
|
|
|
|
|
InventoryItemDetail::Stacked(items) => {
|
|
|
|
|
|
InventoryItemEntity::Stacked(items.entity_ids.iter()
|
|
|
|
|
|
.map(|id| {
|
|
|
|
|
|
ItemEntity {
|
|
|
|
|
|
id: *id,
|
|
|
|
|
|
item: ItemDetail::Tool(items.tool)
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
.collect())
|
|
|
|
|
|
},
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
.collect()
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(thiserror::Error, Debug)]
|
|
|
#[derive(thiserror::Error, Debug)]
|
|
|
pub enum InventoryError {
|
|
|
pub enum InventoryError {
|
|
@ -349,7 +325,7 @@ pub struct RoomFloorItems(Vec<FloorItem>); |
|
|
|
|
|
|
|
|
pub struct InventoryState {
|
|
|
pub struct InventoryState {
|
|
|
character_id: CharacterEntityId,
|
|
|
character_id: CharacterEntityId,
|
|
|
pub inventory: Inventory,
|
|
|
|
|
|
|
|
|
inventory: Inventory,
|
|
|
meseta: Meseta,
|
|
|
meseta: Meseta,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
@ -411,6 +387,39 @@ impl InventoryState { |
|
|
},
|
|
|
},
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn take_item(&mut self, item_id: &ClientItemId) -> Option<InventoryItem> {
|
|
|
|
|
|
self.inventory.0
|
|
|
|
|
|
.drain_filter(|i| i.item_id == *item_id)
|
|
|
|
|
|
.next()
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn as_inventory_entity(&self, _character_id: &CharacterEntityId) -> InventoryEntity {
|
|
|
|
|
|
InventoryEntity {
|
|
|
|
|
|
items: self.inventory.0.iter()
|
|
|
|
|
|
.map(|item| {
|
|
|
|
|
|
match &item.item {
|
|
|
|
|
|
InventoryItemDetail::Individual(item) => {
|
|
|
|
|
|
InventoryItemEntity::Individual(ItemEntity {
|
|
|
|
|
|
id: item.entity_id,
|
|
|
|
|
|
item: item.item.clone(),
|
|
|
|
|
|
})
|
|
|
|
|
|
},
|
|
|
|
|
|
InventoryItemDetail::Stacked(items) => {
|
|
|
|
|
|
InventoryItemEntity::Stacked(items.entity_ids.iter()
|
|
|
|
|
|
.map(|id| {
|
|
|
|
|
|
ItemEntity {
|
|
|
|
|
|
id: *id,
|
|
|
|
|
|
item: ItemDetail::Tool(items.tool)
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
.collect())
|
|
|
|
|
|
},
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
.collect()
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
pub struct FloorState {
|
|
|
pub struct FloorState {
|
|
@ -434,6 +443,22 @@ impl FloorState { |
|
|
.next()
|
|
|
.next()
|
|
|
})
|
|
|
})
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn add_inventory_item(&mut self, inventory_item: InventoryItem, map_area: MapArea, position: (f32, f32, f32)) {
|
|
|
|
|
|
let floor_item = FloorItem {
|
|
|
|
|
|
item_id: inventory_item.item_id,
|
|
|
|
|
|
item: match inventory_item.item {
|
|
|
|
|
|
InventoryItemDetail::Individual(individual_item) => FloorItemDetail::Individual(individual_item),
|
|
|
|
|
|
InventoryItemDetail::Stacked(stacked_item) => FloorItemDetail::Stacked(stacked_item),
|
|
|
|
|
|
},
|
|
|
|
|
|
map_area: map_area,
|
|
|
|
|
|
x: position.0,
|
|
|
|
|
|
y: position.1,
|
|
|
|
|
|
z: position.2,
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
self.shared.0.push(floor_item);
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|