take ref to weapon modifier
This commit is contained in:
		
							parent
							
								
									6a2703ed6c
								
							
						
					
					
						commit
						f27c121539
					
				| @ -96,7 +96,7 @@ pub trait EntityGateway: Send + Sync { | |||||||
|         unimplemented!(); |         unimplemented!(); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     async fn add_weapon_modifier(&mut self, _item_id: &ItemEntityId, _modifier: weapon::WeaponModifier) -> Result<(), GatewayError> { |     async fn add_weapon_modifier(&mut self, _item_id: &ItemEntityId, _modifier: &weapon::WeaponModifier) -> Result<(), GatewayError> { | ||||||
|         unimplemented!(); |         unimplemented!(); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -104,7 +104,7 @@ impl EntityGateway for InMemoryGatewayTransaction { | |||||||
|         self.working_gateway.use_mag_cell(mag_item_id, mag_cell_id).await |         self.working_gateway.use_mag_cell(mag_item_id, mag_cell_id).await | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     async fn add_weapon_modifier(&mut self, item_id: &ItemEntityId, modifier: weapon::WeaponModifier) -> Result<(), GatewayError> { |     async fn add_weapon_modifier(&mut self, item_id: &ItemEntityId, modifier: &weapon::WeaponModifier) -> Result<(), GatewayError> { | ||||||
|         self.working_gateway.add_weapon_modifier(item_id, modifier).await |         self.working_gateway.add_weapon_modifier(item_id, modifier).await | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| @ -528,11 +528,11 @@ impl EntityGateway for InMemoryGateway { | |||||||
|         Ok(()) |         Ok(()) | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     async fn add_weapon_modifier(&mut self, item_id: &ItemEntityId, modifier: weapon::WeaponModifier) -> Result<(), GatewayError> { |     async fn add_weapon_modifier(&mut self, item_id: &ItemEntityId, modifier: &weapon::WeaponModifier) -> Result<(), GatewayError> { | ||||||
|         self.weapon_modifiers.lock().await |         self.weapon_modifiers.lock().await | ||||||
|             .entry(*item_id) |             .entry(*item_id) | ||||||
|             .or_insert_with(Vec::new) |             .or_insert_with(Vec::new) | ||||||
|             .push(modifier); |             .push(modifier.clone()); | ||||||
|         Ok(()) |         Ok(()) | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -380,7 +380,7 @@ async fn use_mag_cell(conn: &mut sqlx::PgConnection, mag_item_id: &ItemEntityId, | |||||||
|     Ok(()) |     Ok(()) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| async fn add_weapon_modifier(conn: &mut sqlx::PgConnection, item_id: &ItemEntityId, modifier: weapon::WeaponModifier) -> Result<(), GatewayError> | async fn add_weapon_modifier(conn: &mut sqlx::PgConnection, item_id: &ItemEntityId, modifier: &weapon::WeaponModifier) -> Result<(), GatewayError> | ||||||
| { | { | ||||||
|     sqlx::query("insert into weapon_modifier (weapon, modifier) values ($1, $2);") |     sqlx::query("insert into weapon_modifier (weapon, modifier) values ($1, $2);") | ||||||
|         .bind(item_id.0) |         .bind(item_id.0) | ||||||
| @ -688,7 +688,7 @@ impl<'t> EntityGateway for PostgresGateway<'t> { | |||||||
|         use_mag_cell(&mut *self.pool.acquire().await?, mag_item_id, mag_cell_id).await |         use_mag_cell(&mut *self.pool.acquire().await?, mag_item_id, mag_cell_id).await | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     async fn add_weapon_modifier(&mut self, item_id: &ItemEntityId, modifier: weapon::WeaponModifier) -> Result<(), GatewayError> { |     async fn add_weapon_modifier(&mut self, item_id: &ItemEntityId, modifier: &weapon::WeaponModifier) -> Result<(), GatewayError> { | ||||||
|         add_weapon_modifier(&mut *self.pool.acquire().await?, item_id, modifier).await |         add_weapon_modifier(&mut *self.pool.acquire().await?, item_id, modifier).await | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
| @ -814,7 +814,7 @@ impl<'c> EntityGateway for PostgresTransaction<'c> { | |||||||
|         use_mag_cell(&mut *self.pgtransaction.lock().await, mag_item_id, mag_cell_id).await |         use_mag_cell(&mut *self.pgtransaction.lock().await, mag_item_id, mag_cell_id).await | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     async fn add_weapon_modifier(&mut self, item_id: &ItemEntityId, modifier: weapon::WeaponModifier) -> Result<(), GatewayError> { |     async fn add_weapon_modifier(&mut self, item_id: &ItemEntityId, modifier: &weapon::WeaponModifier) -> Result<(), GatewayError> { | ||||||
|         add_weapon_modifier(&mut *self.pgtransaction.lock().await, item_id, modifier).await |         add_weapon_modifier(&mut *self.pgtransaction.lock().await, item_id, modifier).await | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -1006,7 +1006,7 @@ where | |||||||
|             match (&mut inventory_item.item, modifier) { |             match (&mut inventory_item.item, modifier) { | ||||||
|                 (InventoryItemDetail::Individual(IndividualItemDetail{entity_id, item: ItemDetail::Weapon(ref mut weapon), ..}), ItemModifier::WeaponModifier(modifier)) => { |                 (InventoryItemDetail::Individual(IndividualItemDetail{entity_id, item: ItemDetail::Weapon(ref mut weapon), ..}), ItemModifier::WeaponModifier(modifier)) => { | ||||||
|                     weapon.apply_modifier(&modifier); |                     weapon.apply_modifier(&modifier); | ||||||
|                     transaction.gateway().add_weapon_modifier(entity_id, modifier).await?; |                     transaction.gateway().add_weapon_modifier(entity_id, &modifier).await?; | ||||||
|                 }, |                 }, | ||||||
|                 _ => return Err(ItemStateError::InvalidModifier.into()) |                 _ => return Err(ItemStateError::InvalidModifier.into()) | ||||||
|             } |             } | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user