Item -> ItemEntity
This commit is contained in:
		
							parent
							
								
									0954d85e5a
								
							
						
					
					
						commit
						44c35f350d
					
				| @ -41,15 +41,15 @@ pub trait EntityGateway { | ||||
|         unimplemented!(); | ||||
|     } | ||||
| 
 | ||||
|     fn new_item(&mut self, _item: ItemDetail, _location: ItemLocation) -> Item { | ||||
|     fn new_item(&mut self, _item: ItemDetail, _location: ItemLocation) -> ItemEntity { | ||||
|         unimplemented!(); | ||||
|     } | ||||
| 
 | ||||
|     fn set_item(&self, _item: &Item) { | ||||
|     fn set_item(&self, _item: &ItemEntity) { | ||||
|         unimplemented!(); | ||||
|     } | ||||
| 
 | ||||
|     fn get_items_by_character(&self, _char: &CharacterEntity) -> Vec<Item> { | ||||
|     fn get_items_by_character(&self, _char: &CharacterEntity) -> Vec<ItemEntity> { | ||||
|         unimplemented!(); | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -16,7 +16,7 @@ pub struct InMemoryGateway { | ||||
|     users: Arc<Mutex<HashMap<u32, UserAccount>>>, | ||||
|     user_settings: Arc<Mutex<HashMap<u32, UserSettings>>>, | ||||
|     characters: Arc<Mutex<HashMap<CharacterEntityId, CharacterEntity>>>, | ||||
|     items: Arc<Mutex<HashMap<ItemEntityId, Item>>>, | ||||
|     items: Arc<Mutex<HashMap<ItemEntityId, ItemEntity>>>, | ||||
| } | ||||
| 
 | ||||
| impl InMemoryGateway { | ||||
| @ -105,13 +105,13 @@ impl EntityGateway for InMemoryGateway { | ||||
|         GuildCardData::default() | ||||
|     } | ||||
| 
 | ||||
|     fn new_item(&mut self, item: ItemDetail, location: ItemLocation) -> Item { | ||||
|     fn new_item(&mut self, item: ItemDetail, location: ItemLocation) -> ItemEntity { | ||||
|         let mut items = self.items.lock().unwrap(); | ||||
|         let id = items | ||||
|             .iter() | ||||
|             .fold(0, |sum, (i, _)| std::cmp::max(sum, i.0)) | ||||
|             + 1; | ||||
|         let new_item = Item { | ||||
|         let new_item = ItemEntity { | ||||
|             id: ItemEntityId(id), | ||||
|             location: location, | ||||
|             item: item, | ||||
| @ -120,12 +120,12 @@ impl EntityGateway for InMemoryGateway { | ||||
|         new_item | ||||
|     } | ||||
| 
 | ||||
|     fn set_item(&self, item: &Item) { | ||||
|     fn set_item(&self, item: &ItemEntity) { | ||||
|         let mut items = self.items.lock().unwrap(); | ||||
|         items.insert(item.id, item.clone()); | ||||
|     } | ||||
| 
 | ||||
|     fn get_items_by_character(&self, character: &CharacterEntity) -> Vec<Item> { | ||||
|     fn get_items_by_character(&self, character: &CharacterEntity) -> Vec<ItemEntity> { | ||||
|         let items = self.items.lock().unwrap(); | ||||
|         items | ||||
|             .iter() | ||||
|  | ||||
| @ -87,7 +87,7 @@ impl ItemDetail { | ||||
| 
 | ||||
| 
 | ||||
| #[derive(Clone, Debug, PartialEq)] | ||||
| pub struct Item { | ||||
| pub struct ItemEntity { | ||||
|     pub id: ItemEntityId, | ||||
|     pub location: ItemLocation, | ||||
|     pub item: ItemDetail, | ||||
|  | ||||
| @ -4,7 +4,7 @@ use libpso::character::character::InventoryItem; | ||||
| 
 | ||||
| use crate::entity::gateway::EntityGateway; | ||||
| use crate::entity::character::CharacterEntity; | ||||
| use crate::entity::item::{Item, ItemId, ItemDetail, ItemLocation}; | ||||
| use crate::entity::item::{ItemEntity, ItemId, ItemDetail, ItemLocation}; | ||||
| use crate::entity::item::weapon::Weapon; | ||||
| use crate::entity::item::armor::Armor; | ||||
| use crate::entity::item::shield::Shield; | ||||
| @ -15,8 +15,8 @@ use crate::entity::item::mag::Mag; | ||||
| 
 | ||||
| #[derive(Debug, PartialEq)] | ||||
| pub enum StackedItem { | ||||
|     Individual(Item), | ||||
|     Stacked(Vec<Item>), | ||||
|     Individual(ItemEntity), | ||||
|     Stacked(Vec<ItemEntity>), | ||||
| } | ||||
| 
 | ||||
| #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] | ||||
| @ -68,12 +68,12 @@ impl ActiveInventory { | ||||
| 
 | ||||
|                 // does this do anything?
 | ||||
|                 inventory[index].equipped = match item.item { | ||||
|                     StackedItem::Individual(Item {location: ItemLocation::Inventory{ equipped: true, ..}, ..}) => 1, | ||||
|                     StackedItem::Individual(ItemEntity {location: ItemLocation::Inventory{ equipped: true, ..}, ..}) => 1, | ||||
|                     _ => 0, | ||||
|                 }; | ||||
|                 // because this actually equips the item
 | ||||
|                 inventory[index].flags |= match item.item { | ||||
|                     StackedItem::Individual(Item {location: ItemLocation::Inventory{ equipped: true, ..}, ..}) => 8, | ||||
|                     StackedItem::Individual(ItemEntity {location: ItemLocation::Inventory{ equipped: true, ..}, ..}) => 8, | ||||
|                     _ => 0, | ||||
|                 }; | ||||
|                 inventory | ||||
| @ -102,7 +102,7 @@ fn inventory_item_index(item: &StackedItem) -> usize { | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| fn stack_items(items: Vec<Item>) -> Vec<StackedItem> { | ||||
| fn stack_items(items: Vec<ItemEntity>) -> Vec<StackedItem> { | ||||
|     let mut stacks = HashMap::new(); | ||||
| 
 | ||||
|     for item in items { | ||||
| @ -174,10 +174,10 @@ mod test { | ||||
|     use super::*; | ||||
|     use crate::entity::character::CharacterEntityId; | ||||
|     use crate::entity::item; | ||||
|     use crate::entity::item::{Item, ItemDetail, ItemEntityId, ItemLocation}; | ||||
|     use crate::entity::item::{ItemEntity, ItemDetail, ItemEntityId, ItemLocation}; | ||||
|     #[test] | ||||
|     fn test_stack_items() { | ||||
|         let item1 = Item { | ||||
|         let item1 = ItemEntity { | ||||
|             id: ItemEntityId(1), | ||||
|             location: ItemLocation::Inventory { | ||||
|                 character_id: CharacterEntityId(0), | ||||
| @ -192,7 +192,7 @@ mod test { | ||||
|                 tekked: true, | ||||
|             }) | ||||
|         }; | ||||
|         let item2 = Item { | ||||
|         let item2 = ItemEntity { | ||||
|             id: ItemEntityId(2), | ||||
|             location: ItemLocation::Inventory { | ||||
|                 character_id: CharacterEntityId(0), | ||||
| @ -203,7 +203,7 @@ mod test { | ||||
|                 tool: item::tool::ToolType::Monofluid, | ||||
|             }) | ||||
|         }; | ||||
|         let item3 = Item { | ||||
|         let item3 = ItemEntity { | ||||
|             id: ItemEntityId(3), | ||||
|             location: ItemLocation::Inventory { | ||||
|                 character_id: CharacterEntityId(0), | ||||
| @ -218,7 +218,7 @@ mod test { | ||||
|                 tekked: true, | ||||
|             }) | ||||
|         }; | ||||
|         let item4  = Item { | ||||
|         let item4  = ItemEntity { | ||||
|             id: ItemEntityId(4), | ||||
|             location: ItemLocation::Inventory { | ||||
|                 character_id: CharacterEntityId(0), | ||||
| @ -229,7 +229,7 @@ mod test { | ||||
|                 tool: item::tool::ToolType::Monofluid, | ||||
|             }) | ||||
|         }; | ||||
|         let item5 = Item { | ||||
|         let item5 = ItemEntity { | ||||
|             id: ItemEntityId(5), | ||||
|             location: ItemLocation::Inventory { | ||||
|                 character_id: CharacterEntityId(0), | ||||
| @ -240,7 +240,7 @@ mod test { | ||||
|                 tool: item::tool::ToolType::Monofluid, | ||||
|             }) | ||||
|         }; | ||||
|         let item6 = Item { | ||||
|         let item6 = ItemEntity { | ||||
|             id: ItemEntityId(6), | ||||
|             location: ItemLocation::Inventory { | ||||
|                 character_id: CharacterEntityId(0), | ||||
| @ -255,7 +255,7 @@ mod test { | ||||
|                 tekked: true, | ||||
|             }) | ||||
|         }; | ||||
|         let item7 = Item { | ||||
|         let item7 = ItemEntity { | ||||
|             id: ItemEntityId(7), | ||||
|             location: ItemLocation::Inventory { | ||||
|                 character_id: CharacterEntityId(0), | ||||
| @ -266,7 +266,7 @@ mod test { | ||||
|                 tool: item::tool::ToolType::Monomate, | ||||
|             }) | ||||
|         }; | ||||
|         let item8 = Item { | ||||
|         let item8 = ItemEntity { | ||||
|             id: ItemEntityId(8), | ||||
|             location: ItemLocation::Inventory { | ||||
|                 character_id: CharacterEntityId(0), | ||||
| @ -277,7 +277,7 @@ mod test { | ||||
|                 tool: item::tool::ToolType::Monomate, | ||||
|             }) | ||||
|         }; | ||||
|         let item9 = Item { | ||||
|         let item9 = ItemEntity { | ||||
|             id: ItemEntityId(9), | ||||
|             location: ItemLocation::Inventory { | ||||
|                 character_id: CharacterEntityId(0), | ||||
|  | ||||
| @ -19,7 +19,7 @@ use crate::common::leveltable::CharacterLevelTable; | ||||
| use crate::entity::gateway::EntityGateway; | ||||
| use crate::entity::account::{UserAccount, UserSettings, USERFLAG_NEWCHAR, USERFLAG_DRESSINGROOM}; | ||||
| use crate::entity::character::CharacterEntity; | ||||
| use crate::entity::item::{ItemLocation, Item}; | ||||
| use crate::entity::item::{ItemLocation, ItemEntity}; | ||||
| use crate::login::login::get_login_status; | ||||
| use crate::ship::location::{ClientLocation, LobbyId, RoomId, AreaType, MAX_ROOMS}; | ||||
| use crate::ship::character::{CharacterBytesBuilder, FullCharacterBytesBuilder}; | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user