roominfo #112
@ -58,7 +58,7 @@ fn add_floor_item_to_inventory(character: &CharacterEntity)
 | 
			
		||||
                }}).await?;
 | 
			
		||||
 | 
			
		||||
            let add_result = inventory.add_floor_item(floor_item)?;
 | 
			
		||||
            transaction.gateway().set_character_inventory(&character.id, &inventory.inventory.as_inventory_entity(&character.id)).await?;
 | 
			
		||||
            transaction.gateway().set_character_inventory(&character.id, &inventory.as_inventory_entity(&character.id)).await?;
 | 
			
		||||
            item_state.set_inventory(inventory);
 | 
			
		||||
 | 
			
		||||
            Ok(((item_state, transaction),
 | 
			
		||||
 | 
			
		||||
@ -3,6 +3,7 @@ use crate::ship::items::ClientItemId;
 | 
			
		||||
use crate::entity::item::{Meseta, ItemEntityId, ItemDetail, ItemEntity, InventoryEntity, InventoryItemEntity};
 | 
			
		||||
use std::future::Future;
 | 
			
		||||
 | 
			
		||||
use crate::ship::map::MapArea;
 | 
			
		||||
use crate::ship::location::RoomId;
 | 
			
		||||
use crate::entity::character::CharacterEntityId;
 | 
			
		||||
use crate::entity::gateway::GatewayError;
 | 
			
		||||
@ -253,6 +254,10 @@ impl FloorItemDetail {
 | 
			
		||||
pub struct FloorItem {
 | 
			
		||||
    item_id: ClientItemId,
 | 
			
		||||
    item: FloorItemDetail,
 | 
			
		||||
    map_area: MapArea,
 | 
			
		||||
    x: f32,
 | 
			
		||||
    y: f32,
 | 
			
		||||
    z: f32,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl FloorItem {
 | 
			
		||||
@ -294,35 +299,6 @@ impl FloorItem {
 | 
			
		||||
#[derive(Clone, Debug)]
 | 
			
		||||
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)]
 | 
			
		||||
pub enum InventoryError {
 | 
			
		||||
@ -349,7 +325,7 @@ pub struct RoomFloorItems(Vec<FloorItem>);
 | 
			
		||||
 | 
			
		||||
pub struct InventoryState {
 | 
			
		||||
    character_id: CharacterEntityId,
 | 
			
		||||
    pub inventory: Inventory,
 | 
			
		||||
    inventory: Inventory,
 | 
			
		||||
    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 {
 | 
			
		||||
@ -434,6 +443,22 @@ impl FloorState {
 | 
			
		||||
                .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);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user