add unit armour slots. equip the unit into the right slot and save correctly
This commit is contained in:
		
							parent
							
								
									555171d11d
								
							
						
					
					
						commit
						790668f6f7
					
				| @ -234,6 +234,7 @@ fn main() { | |||||||
|                         item::unit::Unit { |                         item::unit::Unit { | ||||||
|                             unit: item::unit::UnitType::PriestMind, |                             unit: item::unit::UnitType::PriestMind, | ||||||
|                             modifier: Some(item::unit::UnitModifier::Minus), |                             modifier: Some(item::unit::UnitModifier::Minus), | ||||||
|  |                             armour_slot: 0, | ||||||
|                         } |                         } | ||||||
|                     ), |                     ), | ||||||
|                     location: ItemLocation::Inventory { |                     location: ItemLocation::Inventory { | ||||||
| @ -247,8 +248,9 @@ fn main() { | |||||||
|                 NewItemEntity { |                 NewItemEntity { | ||||||
|                     item: ItemDetail::Unit( |                     item: ItemDetail::Unit( | ||||||
|                         item::unit::Unit { |                         item::unit::Unit { | ||||||
|                             unit: item::unit::UnitType::HeavenlyPower, |                             unit: item::unit::UnitType::PriestMind, | ||||||
|                             modifier: Some(item::unit::UnitModifier::PlusPlus), |                             modifier: Some(item::unit::UnitModifier::Minus), | ||||||
|  |                             armour_slot: 1, | ||||||
|                         } |                         } | ||||||
|                     ), |                     ), | ||||||
|                     location: ItemLocation::Inventory { |                     location: ItemLocation::Inventory { | ||||||
| @ -258,6 +260,38 @@ fn main() { | |||||||
|                     } |                     } | ||||||
|                 } |                 } | ||||||
|             ).await; |             ).await; | ||||||
|  |             entity_gateway.create_item( | ||||||
|  |                 NewItemEntity { | ||||||
|  |                     item: ItemDetail::Unit( | ||||||
|  |                         item::unit::Unit { | ||||||
|  |                             unit: item::unit::UnitType::PriestMind, | ||||||
|  |                             modifier: Some(item::unit::UnitModifier::Minus), | ||||||
|  |                             armour_slot: 2, | ||||||
|  |                         } | ||||||
|  |                     ), | ||||||
|  |                     location: ItemLocation::Inventory { | ||||||
|  |                         character_id: character.id, | ||||||
|  |                         slot: 9, | ||||||
|  |                         equipped: true, | ||||||
|  |                     } | ||||||
|  |                 } | ||||||
|  |             ).await; | ||||||
|  |             entity_gateway.create_item( | ||||||
|  |                 NewItemEntity { | ||||||
|  |                     item: ItemDetail::Unit( | ||||||
|  |                         item::unit::Unit { | ||||||
|  |                             unit: item::unit::UnitType::PriestMind, | ||||||
|  |                             modifier: Some(item::unit::UnitModifier::Minus), | ||||||
|  |                             armour_slot: 3, | ||||||
|  |                         } | ||||||
|  |                     ), | ||||||
|  |                     location: ItemLocation::Inventory { | ||||||
|  |                         character_id: character.id, | ||||||
|  |                         slot: 10, | ||||||
|  |                         equipped: true, | ||||||
|  |                     } | ||||||
|  |                 } | ||||||
|  |             ).await; | ||||||
|             entity_gateway.create_item( |             entity_gateway.create_item( | ||||||
|                 NewItemEntity { |                 NewItemEntity { | ||||||
|                     item: ItemDetail::Mag( |                     item: ItemDetail::Mag( | ||||||
| @ -265,7 +299,7 @@ fn main() { | |||||||
|                     ), |                     ), | ||||||
|                     location: ItemLocation::Inventory { |                     location: ItemLocation::Inventory { | ||||||
|                         character_id: character.id, |                         character_id: character.id, | ||||||
|                         slot: 9, |                         slot: 11, | ||||||
|                         equipped: true, |                         equipped: true, | ||||||
|                     } |                     } | ||||||
|                 } |                 } | ||||||
|  | |||||||
| @ -335,6 +335,7 @@ pub enum UnitModifier { | |||||||
| pub struct Unit { | pub struct Unit { | ||||||
|     pub unit: UnitType, |     pub unit: UnitType, | ||||||
|     pub modifier: Option<UnitModifier>, |     pub modifier: Option<UnitModifier>, | ||||||
|  |     pub armour_slot: u8, // 0 - 3 = armour slot 1 - 4
 | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| @ -361,7 +362,7 @@ impl Unit { | |||||||
|                 }, |                 }, | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
| 
 |         result[4] = self.armour_slot; | ||||||
|         result |         result | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| @ -379,6 +380,7 @@ impl Unit { | |||||||
|             Ok(Unit{ |             Ok(Unit{ | ||||||
|                 unit: u.unwrap(), |                 unit: u.unwrap(), | ||||||
|                 modifier: m, |                 modifier: m, | ||||||
|  |                 armour_slot: data[4], | ||||||
|             }) |             }) | ||||||
|         } |         } | ||||||
|         else { |         else { | ||||||
|  | |||||||
| @ -89,6 +89,7 @@ impl GenericUnitTable { | |||||||
|             ItemDropType::Unit(Unit { |             ItemDropType::Unit(Unit { | ||||||
|                 unit: unit_type, |                 unit: unit_type, | ||||||
|                 modifier: unit_modifier, |                 modifier: unit_modifier, | ||||||
|  |                 armour_slot: 0, | ||||||
|             }) |             }) | ||||||
|         }) |         }) | ||||||
|     } |     } | ||||||
| @ -116,6 +117,7 @@ mod test { | |||||||
|             assert!(gut.get_drop(&area, &mut rng) == Some(ItemDropType::Unit(Unit { |             assert!(gut.get_drop(&area, &mut rng) == Some(ItemDropType::Unit(Unit { | ||||||
|                 unit: unit, |                 unit: unit, | ||||||
|                 modifier: umod, |                 modifier: umod, | ||||||
|  |                 armour_slot: 0, | ||||||
|             }))); |             }))); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  | |||||||
| @ -128,6 +128,7 @@ impl RareDropTable { | |||||||
|                 ItemDropType::Unit(Unit { |                 ItemDropType::Unit(Unit { | ||||||
|                     unit: unit, |                     unit: unit, | ||||||
|                     modifier: None, |                     modifier: None, | ||||||
|  |                     armour_slot: 0, | ||||||
|                 }) |                 }) | ||||||
|             }, |             }, | ||||||
|             RareDropItem::Tool(tool) => { |             RareDropItem::Tool(tool) => { | ||||||
|  | |||||||
| @ -4,8 +4,9 @@ use thiserror::Error; | |||||||
| use crate::entity::gateway::EntityGateway; | use crate::entity::gateway::EntityGateway; | ||||||
| use crate::entity::character::{CharacterEntity, CharacterEntityId}; | use crate::entity::character::{CharacterEntity, CharacterEntityId}; | ||||||
| use crate::entity::item::{ItemDetail, ItemLocation, BankName}; | use crate::entity::item::{ItemDetail, ItemLocation, BankName}; | ||||||
| use crate::entity::item::{Meseta, NewItemEntity}; | use crate::entity::item::{Meseta, NewItemEntity, ItemEntity}; | ||||||
| use crate::entity::item::tool::{Tool, ToolType}; | use crate::entity::item::tool::{Tool, ToolType}; | ||||||
|  | use crate::entity::item::unit; | ||||||
| use crate::ship::map::MapArea; | use crate::ship::map::MapArea; | ||||||
| use crate::ship::ship::ItemDropLocation; | use crate::ship::ship::ItemDropLocation; | ||||||
| use crate::ship::drops::{ItemDrop, ItemDropType}; | use crate::ship::drops::{ItemDrop, ItemDropType}; | ||||||
| @ -898,20 +899,43 @@ impl ItemManager { | |||||||
|     pub async fn player_equips_item<EG: EntityGateway>(&mut self, |     pub async fn player_equips_item<EG: EntityGateway>(&mut self, | ||||||
|                                                        entity_gateway: &mut EG, |                                                        entity_gateway: &mut EG, | ||||||
|                                                        character: &CharacterEntity, |                                                        character: &CharacterEntity, | ||||||
|                                                        item_id: ClientItemId) |                                                        item_id: ClientItemId, | ||||||
|  |                                                        equip_slot: u8) | ||||||
|                                                        -> Result<(), ItemManagerError> { |                                                        -> Result<(), ItemManagerError> { | ||||||
|         let inventory = self.character_inventory.get_mut(&character.id).ok_or(ItemManagerError::NoCharacter(character.id))?; |         let inventory = self.character_inventory.get_mut(&character.id).ok_or(ItemManagerError::NoCharacter(character.id))?; | ||||||
|         let mut inventory_item_handle = inventory.get_item_handle_by_id(item_id).ok_or(ItemManagerError::NoSuchItemId(item_id))?; |         let mut inventory_item_handle = inventory.get_item_handle_by_id(item_id).ok_or(ItemManagerError::NoSuchItemId(item_id))?; | ||||||
|         let slot = inventory_item_handle.get_slot(); |         let slot = inventory_item_handle.get_slot(); | ||||||
|         let inventory_item = inventory_item_handle.item_mut().ok_or(ItemManagerError::CannotGetMutItem)?.individual().ok_or(ItemManagerError::CannotGetIndividualItem)?; |         let inventory_item = inventory_item_handle.item_mut().ok_or(ItemManagerError::CannotGetMutItem)?.individual().ok_or(ItemManagerError::CannotGetIndividualItem)?; | ||||||
|         inventory_item.equipped = true; |         inventory_item.equipped = true; | ||||||
|  |         if let ItemDetail::Unit(u) = inventory_item.item { | ||||||
|  |             if equip_slot > 0 { | ||||||
|  |                 inventory_item.item = ItemDetail::Unit(unit::Unit { | ||||||
|  |                     unit: u.unit, | ||||||
|  |                     modifier: u.modifier, | ||||||
|  |                     armour_slot: ((equip_slot & 0x7) - 1) % 4, | ||||||
|  |                 }); | ||||||
|  |             } else { | ||||||
|  |                 inventory_item.item = ItemDetail::Unit(unit::Unit { | ||||||
|  |                     unit: u.unit, | ||||||
|  |                     modifier: u.modifier, | ||||||
|  |                     armour_slot: 0, | ||||||
|  |                 }); | ||||||
|  |             } | ||||||
|  |         }; | ||||||
|         entity_gateway.change_item_location(&inventory_item.entity_id, ItemLocation::Inventory{ |         entity_gateway.change_item_location(&inventory_item.entity_id, ItemLocation::Inventory{ | ||||||
|             character_id: character.id, |             character_id: character.id, | ||||||
|             slot: slot, |             slot: slot, | ||||||
|             equipped: true, |             equipped: true, | ||||||
|         }).await; |         }).await; | ||||||
| 
 |         entity_gateway.save_item(&ItemEntity{ | ||||||
|         entity_gateway.save_character(character).await; |             id: inventory_item.entity_id, | ||||||
|  |             location: ItemLocation::Inventory{ | ||||||
|  |                 character_id: character.id, | ||||||
|  |                 slot: slot, | ||||||
|  |                 equipped: true, | ||||||
|  |             }, | ||||||
|  |             item: inventory_item.item.clone(), | ||||||
|  |         }).await; | ||||||
|         Ok(()) |         Ok(()) | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| @ -925,13 +949,27 @@ impl ItemManager { | |||||||
|         let slot = inventory_item_handle.get_slot(); |         let slot = inventory_item_handle.get_slot(); | ||||||
|         let inventory_item = inventory_item_handle.item_mut().ok_or(ItemManagerError::CannotGetMutItem)?.individual().ok_or(ItemManagerError::CannotGetIndividualItem)?; |         let inventory_item = inventory_item_handle.item_mut().ok_or(ItemManagerError::CannotGetMutItem)?.individual().ok_or(ItemManagerError::CannotGetIndividualItem)?; | ||||||
|         inventory_item.equipped = false; |         inventory_item.equipped = false; | ||||||
|  |         if let ItemDetail::Unit(u) = inventory_item.item { | ||||||
|  |             inventory_item.item = ItemDetail::Unit(unit::Unit { | ||||||
|  |                 unit: u.unit, | ||||||
|  |                 modifier: u.modifier, | ||||||
|  |                 armour_slot: 0, | ||||||
|  |             }); | ||||||
|  |         }; | ||||||
|         entity_gateway.change_item_location(&inventory_item.entity_id, ItemLocation::Inventory{ |         entity_gateway.change_item_location(&inventory_item.entity_id, ItemLocation::Inventory{ | ||||||
|             character_id: character.id, |             character_id: character.id, | ||||||
|             slot: slot, |             slot: slot, | ||||||
|             equipped: false, |             equipped: false, | ||||||
|         }).await; |         }).await; | ||||||
| 
 |         entity_gateway.save_item(&ItemEntity{ | ||||||
|         entity_gateway.save_character(character).await; |             id: inventory_item.entity_id, | ||||||
|  |             location: ItemLocation::Inventory{ | ||||||
|  |                 character_id: character.id, | ||||||
|  |                 slot: slot, | ||||||
|  |                 equipped: false, | ||||||
|  |             }, | ||||||
|  |             item: inventory_item.item.clone(), | ||||||
|  |         }).await; | ||||||
|         Ok(()) |         Ok(()) | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | |||||||
| @ -316,7 +316,7 @@ where | |||||||
|     EG: EntityGateway |     EG: EntityGateway | ||||||
| { | { | ||||||
|     let client = clients.get(&id).ok_or(ShipError::ClientNotFound(id))?; |     let client = clients.get(&id).ok_or(ShipError::ClientNotFound(id))?; | ||||||
|     item_manager.player_equips_item(entity_gateway, &client.character, ClientItemId(pkt.item_id)).await?; |     item_manager.player_equips_item(entity_gateway, &client.character, ClientItemId(pkt.item_id), pkt.sub_menu).await?; | ||||||
|     Ok(Box::new(None.into_iter())) |     Ok(Box::new(None.into_iter())) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -89,6 +89,7 @@ impl ShopItem for ArmorShopItem { | |||||||
|                 ItemDetail::Unit(Unit { |                 ItemDetail::Unit(Unit { | ||||||
|                     unit: *unit, |                     unit: *unit, | ||||||
|                     modifier: None, |                     modifier: None, | ||||||
|  |                     armour_slot: 0, | ||||||
|                 }) |                 }) | ||||||
|             }, |             }, | ||||||
|         } |         } | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user