add/move stuff around for itemstate
This commit is contained in:
		
							parent
							
								
									867aa3537e
								
							
						
					
					
						commit
						9d8eecfd5d
					
				| @ -58,7 +58,7 @@ fn add_floor_item_to_inventory(character: &CharacterEntity) | |||||||
|                 }}).await?; |                 }}).await?; | ||||||
| 
 | 
 | ||||||
|             let add_result = inventory.add_floor_item(floor_item)?; |             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); |             item_state.set_inventory(inventory); | ||||||
| 
 | 
 | ||||||
|             Ok(((item_state, transaction), |             Ok(((item_state, transaction), | ||||||
|  | |||||||
| @ -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); | ||||||
|  |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user