Browse Source

fix item pickup tests

kill_counters
jake 3 years ago
committed by andy
parent
commit
4a077c30f1
  1. 3
      src/ship/items/actions.rs
  2. 20
      src/ship/items/state.rs
  3. 2
      tests/test_item_pickup.rs

3
src/ship/items/actions.rs

@ -63,6 +63,7 @@ fn add_floor_item_to_inventory(character: &CharacterEntity)
let add_result = inventory.add_floor_item(floor_item)?;
transaction.gateway().set_character_inventory(&character.id, &inventory.as_inventory_entity(&character.id)).await?;
transaction.gateway().set_character_meseta(&character_id, inventory.meseta).await?;
item_state.set_inventory(inventory);
Ok(((item_state, transaction),
@ -158,7 +159,7 @@ where
entity_gateway.with_transaction(|transaction| async move {
let item_state_proxy = ItemStateProxy::new(item_state);
let ((item_state_proxy, transaction), result) = ItemStateAction::default()
.act(take_item_from_inventory(character.id, *item_id, 1))
.act(take_item_from_inventory(character.id, *item_id, 0))
.act(add_inventory_item_to_shared_floor(character.id, map_area, drop_position))
.commit((item_state_proxy, transaction))
.await?;

20
src/ship/items/state.rs

@ -358,7 +358,7 @@ impl BankItem {
}
}
#[derive(Clone)]
#[derive(Debug, Clone)]
pub enum FloorItemDetail {
Individual(IndividualItemDetail),
Stacked(StackedItemDetail),
@ -374,7 +374,7 @@ impl FloorItemDetail {
}
}
#[derive(Clone)]
#[derive(Debug, Clone)]
pub struct FloorItem {
pub item_id: ClientItemId,
pub item: FloorItemDetail,
@ -465,12 +465,10 @@ pub enum AddItemResult {
Meseta,
}
#[derive(Clone, Default)]
#[derive(Debug, Clone, Default)]
pub struct LocalFloor(Vec<FloorItem>);
#[derive(Clone, Default)]
#[derive(Debug, Clone, Default)]
pub struct SharedFloor(Vec<FloorItem>);
#[derive(Clone)]
pub struct RoomFloorItems(Vec<FloorItem>);
#[derive(Clone)]
pub struct InventoryState {
@ -549,7 +547,7 @@ impl InventoryState {
Err(InventoryError::MesetaFull)
}
else {
self.meseta.0 = std::cmp::min(self.meseta.0 + meseta.0 ,999999);
self.meseta.0 = std::cmp::min(self.meseta.0 + meseta.0, 999999);
Ok(AddItemResult::Meseta)
}
},
@ -607,7 +605,7 @@ impl InventoryState {
Some(self.inventory.0.remove(idx))
},
InventoryItemDetail::Stacked(stacked_item) => {
let remove_all = match stacked_item.entity_ids.len().cmp(&(amount as usize)) {
let remove_all = (amount == 0) || match stacked_item.entity_ids.len().cmp(&(amount as usize)) {
Ordering::Equal => true,
Ordering::Greater => false,
Ordering::Less => return None,
@ -708,7 +706,6 @@ impl InventoryState {
match (a_index, b_index) {
(Some(a_index), Some(b_index)) => {
dbg!("sort!", a.item_id, a_index, b.item_id, b_index);
a_index.cmp(&b_index)
},
_ => Ordering::Equal
@ -1025,6 +1022,7 @@ impl std::cmp::Ord for BankItem {
}
}
#[derive(Debug)]
pub struct FloorState {
character_id: CharacterEntityId,
local: LocalFloor,
@ -1123,7 +1121,7 @@ impl ItemState {
Ok(match item {
InventoryItemEntity::Individual(item) => {
InventoryItem {
item_id: self.new_item_id()?,
item_id: ClientItemId(0),
item: InventoryItemDetail::Individual(IndividualItemDetail {
entity_id: item.id,
item: item.item,
@ -1132,7 +1130,7 @@ impl ItemState {
},
InventoryItemEntity::Stacked(items) => {
InventoryItem {
item_id: self.new_item_id()?,
item_id: ClientItemId(0),
item: InventoryItemDetail::Stacked(StackedItemDetail {
entity_ids: items.iter().map(|i| i.id).collect(),
tool: items.get(0)

2
tests/test_item_pickup.rs

@ -739,7 +739,7 @@ async fn test_player_drops_partial_stack_and_other_player_picks_it_up() {
ship.handle(ClientId(2), &RecvShipPacket::DirectMessage(DirectMessage::new(0, GameMessage::PickupItem(PickupItem {
client: 0,
target: 0,
item_id: 0x00810001,
item_id: 0x10003,
map_area: 0,
unknown: [0; 3]
})))).await.unwrap().for_each(drop);

Loading…
Cancel
Save