add kill counter field to weapons and increment it when a client kills a monster
This commit is contained in:
		
							parent
							
								
									13017084ee
								
							
						
					
					
						commit
						b0eb494660
					
				| @ -116,7 +116,7 @@ fn main() { | |||||||
|                                     Some(item::weapon::WeaponAttribute{attr: item::weapon::Attribute::Dark, value: 30}), |                                     Some(item::weapon::WeaponAttribute{attr: item::weapon::Attribute::Dark, value: 30}), | ||||||
|                                     None,], |                                     None,], | ||||||
|                             tekked: true, |                             tekked: true, | ||||||
|                             kills: Some(22999), |                             kills: Some(22995), | ||||||
|                         } |                         } | ||||||
|                     ), |                     ), | ||||||
|                 }).await.unwrap(); |                 }).await.unwrap(); | ||||||
|  | |||||||
| @ -157,6 +157,17 @@ pub trait EntityGateway: Send + Sync { | |||||||
|     async fn create_trade(&mut self, _char_id1: &CharacterEntityId, _char_id2: &CharacterEntityId) -> Result<TradeEntity, GatewayError> { |     async fn create_trade(&mut self, _char_id1: &CharacterEntityId, _char_id2: &CharacterEntityId) -> Result<TradeEntity, GatewayError> { | ||||||
|         unimplemented!(); |         unimplemented!(); | ||||||
|     } |     } | ||||||
|  |     async fn increment_kill_counter(&mut self, _item_entity_id: &ItemEntityId) -> Result<(), GatewayError> { | ||||||
|  |         unimplemented!(); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     async fn get_kill_counter() { | ||||||
|  |         unimplemented!(); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     async fn set_kill_counter() { | ||||||
|  |         unimplemented!(); | ||||||
|  |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -527,4 +527,19 @@ impl EntityGateway for InMemoryGateway { | |||||||
|         trades.push(new_trade.clone()); |         trades.push(new_trade.clone()); | ||||||
|         Ok(new_trade) |         Ok(new_trade) | ||||||
|     } |     } | ||||||
|  | 
 | ||||||
|  |     async fn increment_kill_counter(&mut self, item_id: &ItemEntityId) -> Result<(), GatewayError> { | ||||||
|  |         if let Some(item_entity) = self.items.lock().unwrap().get_mut(item_id) { | ||||||
|  |             item_entity.increase_kill_counter(); | ||||||
|  |         } | ||||||
|  |         Ok(()) | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     async fn get_kill_counter() { | ||||||
|  |         println!("src/entity/gateway/inmemory.rs::get_kill_counter() - unimplemented!"); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     async fn set_kill_counter() { | ||||||
|  |         println!("src/entity/gateway/inmemory.rs::set_kill_counter() - unimplemented!"); | ||||||
|  |     } | ||||||
| } | } | ||||||
|  | |||||||
| @ -186,7 +186,6 @@ impl ItemDetail { | |||||||
|             ItemDetail::Armor(_a) => false, |             ItemDetail::Armor(_a) => false, | ||||||
|             ItemDetail::Shield(_s) => false, |             ItemDetail::Shield(_s) => false, | ||||||
|             ItemDetail::Unit(u) => u.kills.is_some(), |             ItemDetail::Unit(u) => u.kills.is_some(), | ||||||
|             // ItemDetail::Unit(_u) => false,
 |  | ||||||
|             ItemDetail::Tool(_t) => false, |             ItemDetail::Tool(_t) => false, | ||||||
|             ItemDetail::TechniqueDisk(_d) => false, |             ItemDetail::TechniqueDisk(_d) => false, | ||||||
|             ItemDetail::Mag(_m) => false, |             ItemDetail::Mag(_m) => false, | ||||||
|  | |||||||
| @ -1684,4 +1684,10 @@ impl Weapon { | |||||||
|                 | WeaponType::Scepter |                 | WeaponType::Scepter | ||||||
|         ) |         ) | ||||||
|     } |     } | ||||||
|  | 
 | ||||||
|  |     pub fn increment_kill_counter(&mut self) { | ||||||
|  |         if let Some(kills) = self.kills { | ||||||
|  |             self.kills = Some(kills + 1); | ||||||
|  |         } | ||||||
|  |     } | ||||||
| } | } | ||||||
|  | |||||||
| @ -110,6 +110,7 @@ impl RareDropTable { | |||||||
|                     dropped_weapon.kills = Some(0); |                     dropped_weapon.kills = Some(0); | ||||||
|                 }; |                 }; | ||||||
|                 ItemDropType::Weapon(dropped_weapon) |                 ItemDropType::Weapon(dropped_weapon) | ||||||
|  |                 }) | ||||||
|             }, |             }, | ||||||
|             RareDropItem::Armor(armor) => { |             RareDropItem::Armor(armor) => { | ||||||
|                 ItemDropType::Armor(Armor { |                 ItemDropType::Armor(Armor { | ||||||
|  | |||||||
| @ -498,7 +498,6 @@ impl InventoryState { | |||||||
|         self.equipped.clone() |         self.equipped.clone() | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
|     pub fn as_client_inventory_items(&self) -> [character::InventoryItem; 30] { |     pub fn as_client_inventory_items(&self) -> [character::InventoryItem; 30] { | ||||||
|         self.inventory.0.iter() |         self.inventory.0.iter() | ||||||
|             .enumerate() |             .enumerate() | ||||||
|  | |||||||
| @ -1415,6 +1415,41 @@ impl<EG: EntityGateway> ItemAction<EG> for TradeMeseta { | |||||||
|             dest_meseta.0 += self.amount as u32; |             dest_meseta.0 += self.amount as u32; | ||||||
|             entity_gateway.set_character_meseta(&self.dest_character_id, *dest_meseta).await?; |             entity_gateway.set_character_meseta(&self.dest_character_id, *dest_meseta).await?; | ||||||
|         } |         } | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     pub async fn increase_kill_counters<EG: EntityGateway>(  &mut self, | ||||||
|  |                                                             entity_gateway: &mut EG, | ||||||
|  |                                                             character: &CharacterEntity, | ||||||
|  |                                                             equipped_items: &EquippedEntity) | ||||||
|  |                                                             -> Result<(), anyhow::Error> { | ||||||
|  |         let inventory = self.character_inventory.get_mut(&character.id).ok_or(ItemManagerError::NoCharacter(character.id))?; | ||||||
|  |         if let Some(weapon_entity) = equipped_items.weapon { | ||||||
|  |             println!("updating weapon kill counter for weapon {:?}", weapon_entity); | ||||||
|  |             // weapon_entity = &InventoryItem
 | ||||||
|  | 
 | ||||||
|  |             // let weapon_id = weapon_entity.item_id();
 | ||||||
|  |             let weapon_id = inventory.get_item_by_entity_id(weapon_entity).ok_or(ItemManagerError::EntityIdNotInInventory(weapon_entity))?.item_id(); | ||||||
|  |             let mut weapon_handle = inventory.get_item_handle_by_id(weapon_id).ok_or(ItemManagerError::NoSuchItemId(weapon_id))?; | ||||||
|  |             // weapon_handle = InventoryItemHandle
 | ||||||
|  |             let individual_item = weapon_handle.item_mut() | ||||||
|  |                 .ok_or(ItemManagerError::NoSuchItemId(weapon_id))? | ||||||
|  |                 .individual_mut() | ||||||
|  |                 .ok_or(ItemManagerError::WrongItemType(weapon_id))?; | ||||||
|  |             let weapon = individual_item | ||||||
|  |                 .weapon_mut() | ||||||
|  |                 .ok_or(ItemManagerError::WrongItemType(weapon_id))?; | ||||||
|  | 
 | ||||||
|  |             weapon.increment_kill_counter(); | ||||||
|  |             entity_gateway.increment_kill_counter(&weapon_entity).await?; | ||||||
|  |             entity_gateway.set_character_inventory(&character.id, &inventory.as_inventory_entity(&character.id)).await?; | ||||||
|  |         } | ||||||
|  |         // for units in equipped_items.unit {
 | ||||||
|  |         //     if let Some(unit_id) = units {
 | ||||||
|  |         //         println!("UNIMPLEMENTED - updating unit kill counter for unit {:?}", unit_id);
 | ||||||
|  |         //         // entity_gateway.increase_kill_counter(&unit_id).await?;
 | ||||||
|  |         //         // let unit = inventory.get_item_by_entity_id(&unit_id)
 | ||||||
|  |         //     }
 | ||||||
|  |         // }
 | ||||||
|         Ok(()) |         Ok(()) | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | |||||||
| @ -405,7 +405,8 @@ where | |||||||
|     EG: EntityGateway |     EG: EntityGateway | ||||||
| { | { | ||||||
|     let client = clients.get_mut(&id).ok_or(ShipError::ClientNotFound(id))?; |     let client = clients.get_mut(&id).ok_or(ShipError::ClientNotFound(id))?; | ||||||
|     item_manager.player_sells_item(entity_gateway, &mut client.character, ClientItemId(sold_item.item_id), sold_item.amount as usize).await?; |     sell_item(item_state, entity_gateway, &client.character, ClientItemId(sold_item.item_id), sold_item.amount as u32).await?; | ||||||
|  |     // TODO: send the packet to other clients
 | ||||||
|     Ok(Box::new(None.into_iter())) // TODO: Do clients care about the order of other clients items?
 |     Ok(Box::new(None.into_iter())) // TODO: Do clients care about the order of other clients items?
 | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user