|
@ -1,12 +1,11 @@ |
|
|
use crate::ship::items::ClientItemId;
|
|
|
use crate::ship::items::ClientItemId;
|
|
|
use std::collections::{HashMap, BTreeMap};
|
|
|
|
|
|
|
|
|
use std::collections::HashMap;
|
|
|
use thiserror::Error;
|
|
|
use thiserror::Error;
|
|
|
use crate::entity::gateway::EntityGateway;
|
|
|
use crate::entity::gateway::EntityGateway;
|
|
|
use crate::entity::character::{CharacterEntity, CharacterEntityId, TechLevel};
|
|
|
use crate::entity::character::{CharacterEntity, CharacterEntityId, TechLevel};
|
|
|
use crate::entity::item::{ItemDetail, ItemLocation, BankName};
|
|
|
use crate::entity::item::{ItemDetail, ItemLocation, BankName};
|
|
|
use crate::entity::item::{Meseta, NewItemEntity, ItemEntity, InventoryItemEntity, EquippedEntity, InventoryEntity, BankItemEntity, BankEntity};
|
|
|
|
|
|
|
|
|
use crate::entity::item::{Meseta, NewItemEntity, ItemEntity, InventoryItemEntity, BankItemEntity};
|
|
|
use crate::entity::item::tool::{Tool, ToolType};
|
|
|
use crate::entity::item::tool::{Tool, ToolType};
|
|
|
use crate::entity::item::unit;
|
|
|
|
|
|
use crate::entity::item::weapon;
|
|
|
use crate::entity::item::weapon;
|
|
|
use crate::ship::map::MapArea;
|
|
|
use crate::ship::map::MapArea;
|
|
|
use crate::ship::ship::ItemDropLocation;
|
|
|
use crate::ship::ship::ItemDropLocation;
|
|
@ -237,7 +236,7 @@ impl ItemManager { |
|
|
Some(FloorItem::Individual(individual_floor_item)) => {
|
|
|
Some(FloorItem::Individual(individual_floor_item)) => {
|
|
|
let new_inventory_item = inventory.pick_up_individual_floor_item(individual_floor_item);
|
|
|
let new_inventory_item = inventory.pick_up_individual_floor_item(individual_floor_item);
|
|
|
match new_inventory_item {
|
|
|
match new_inventory_item {
|
|
|
Some((new_inventory_item, slot)) => {
|
|
|
|
|
|
|
|
|
Some((new_inventory_item, _slot)) => {
|
|
|
entity_gateway.change_item_location(
|
|
|
entity_gateway.change_item_location(
|
|
|
&new_inventory_item.entity_id,
|
|
|
&new_inventory_item.entity_id,
|
|
|
ItemLocation::Inventory {
|
|
|
ItemLocation::Inventory {
|
|
@ -258,7 +257,7 @@ impl ItemManager { |
|
|
let new_inventory_item = inventory.pick_up_stacked_floor_item(stacked_floor_item);
|
|
|
let new_inventory_item = inventory.pick_up_stacked_floor_item(stacked_floor_item);
|
|
|
|
|
|
|
|
|
match new_inventory_item {
|
|
|
match new_inventory_item {
|
|
|
Some((new_inventory_item, slot)) => {
|
|
|
|
|
|
|
|
|
Some((new_inventory_item, _slot)) => {
|
|
|
for entity_id in &new_inventory_item.entity_ids {
|
|
|
for entity_id in &new_inventory_item.entity_ids {
|
|
|
entity_gateway.change_item_location(
|
|
|
entity_gateway.change_item_location(
|
|
|
entity_id,
|
|
|
entity_id,
|
|
@ -337,7 +336,7 @@ impl ItemManager { |
|
|
}).await?;
|
|
|
}).await?;
|
|
|
FloorItem::Individual(IndividualFloorItem {
|
|
|
FloorItem::Individual(IndividualFloorItem {
|
|
|
entity_id: entity.id,
|
|
|
entity_id: entity.id,
|
|
|
item_id: item_id,
|
|
|
|
|
|
|
|
|
item_id,
|
|
|
item: item_detail,
|
|
|
item: item_detail,
|
|
|
map_area: item_drop.map_area,
|
|
|
map_area: item_drop.map_area,
|
|
|
x: item_drop.x,
|
|
|
x: item_drop.x,
|
|
@ -358,8 +357,8 @@ impl ItemManager { |
|
|
}).await?;
|
|
|
}).await?;
|
|
|
FloorItem::Stacked(StackedFloorItem {
|
|
|
FloorItem::Stacked(StackedFloorItem {
|
|
|
entity_ids: vec![entity.id],
|
|
|
entity_ids: vec![entity.id],
|
|
|
item_id: item_id,
|
|
|
|
|
|
tool: tool,
|
|
|
|
|
|
|
|
|
item_id,
|
|
|
|
|
|
tool,
|
|
|
map_area: item_drop.map_area,
|
|
|
map_area: item_drop.map_area,
|
|
|
x: item_drop.x,
|
|
|
x: item_drop.x,
|
|
|
y: item_drop.y,
|
|
|
y: item_drop.y,
|
|
@ -368,8 +367,8 @@ impl ItemManager { |
|
|
},
|
|
|
},
|
|
|
ItemOrMeseta::Meseta(meseta) => {
|
|
|
ItemOrMeseta::Meseta(meseta) => {
|
|
|
FloorItem::Meseta(MesetaFloorItem {
|
|
|
FloorItem::Meseta(MesetaFloorItem {
|
|
|
item_id: item_id,
|
|
|
|
|
|
meseta: meseta,
|
|
|
|
|
|
|
|
|
item_id,
|
|
|
|
|
|
meseta,
|
|
|
map_area: item_drop.map_area,
|
|
|
map_area: item_drop.map_area,
|
|
|
x: item_drop.x,
|
|
|
x: item_drop.x,
|
|
|
y: item_drop.y,
|
|
|
y: item_drop.y,
|
|
@ -445,7 +444,7 @@ impl ItemManager { |
|
|
|
|
|
|
|
|
let item_id = self.room_item_id_counter.get_mut(room_id).ok_or(ItemManagerError::NoCharacter(character.id))?();
|
|
|
let item_id = self.room_item_id_counter.get_mut(room_id).ok_or(ItemManagerError::NoCharacter(character.id))?();
|
|
|
let floor_item = FloorItem::Meseta(MesetaFloorItem {
|
|
|
let floor_item = FloorItem::Meseta(MesetaFloorItem {
|
|
|
item_id: item_id,
|
|
|
|
|
|
|
|
|
item_id,
|
|
|
meseta: Meseta(amount),
|
|
|
meseta: Meseta(amount),
|
|
|
map_area: drop_location.map_area,
|
|
|
map_area: drop_location.map_area,
|
|
|
x: drop_location.x,
|
|
|
x: drop_location.x,
|
|
@ -571,13 +570,13 @@ impl ItemManager { |
|
|
let inventory_item = inventory.withdraw_item(item_to_withdraw, amount).ok_or(ItemManagerError::Idunnoman)?;
|
|
|
let inventory_item = inventory.withdraw_item(item_to_withdraw, amount).ok_or(ItemManagerError::Idunnoman)?;
|
|
|
|
|
|
|
|
|
match inventory_item {
|
|
|
match inventory_item {
|
|
|
(InventoryItem::Individual(individual_inventory_item), slot) => {
|
|
|
|
|
|
|
|
|
(InventoryItem::Individual(individual_inventory_item), _slot) => {
|
|
|
entity_gateway.change_item_location(&individual_inventory_item.entity_id,
|
|
|
entity_gateway.change_item_location(&individual_inventory_item.entity_id,
|
|
|
ItemLocation::Inventory {
|
|
|
ItemLocation::Inventory {
|
|
|
character_id: character.id,
|
|
|
character_id: character.id,
|
|
|
}).await?;
|
|
|
}).await?;
|
|
|
},
|
|
|
},
|
|
|
(InventoryItem::Stacked(stacked_inventory_item), slot) => {
|
|
|
|
|
|
|
|
|
(InventoryItem::Stacked(stacked_inventory_item), _slot) => {
|
|
|
for entity_id in &stacked_inventory_item.entity_ids {
|
|
|
for entity_id in &stacked_inventory_item.entity_ids {
|
|
|
entity_gateway.change_item_location(entity_id,
|
|
|
entity_gateway.change_item_location(entity_id,
|
|
|
ItemLocation::Inventory {
|
|
|
ItemLocation::Inventory {
|
|
@ -768,8 +767,8 @@ impl ItemManager { |
|
|
}
|
|
|
}
|
|
|
let floor_item = StackedFloorItem {
|
|
|
let floor_item = StackedFloorItem {
|
|
|
entity_ids: item_entities.into_iter().map(|i| i.id).collect(),
|
|
|
entity_ids: item_entities.into_iter().map(|i| i.id).collect(),
|
|
|
item_id: item_id,
|
|
|
|
|
|
tool: tool,
|
|
|
|
|
|
|
|
|
item_id,
|
|
|
|
|
|
tool,
|
|
|
// TODO: this is gonna choke if I ever require the item being near the player for pickup
|
|
|
// TODO: this is gonna choke if I ever require the item being near the player for pickup
|
|
|
map_area: MapArea::Pioneer2Ep1,
|
|
|
map_area: MapArea::Pioneer2Ep1,
|
|
|
x: 0.0,
|
|
|
x: 0.0,
|
|
@ -777,7 +776,7 @@ impl ItemManager { |
|
|
z: 0.0,
|
|
|
z: 0.0,
|
|
|
};
|
|
|
};
|
|
|
let item_id = {
|
|
|
let item_id = {
|
|
|
let (picked_up_item, slot) = inventory.pick_up_stacked_floor_item(&floor_item).ok_or(ItemManagerError::CouldNotAddBoughtItemToInventory)?;
|
|
|
|
|
|
|
|
|
let (picked_up_item, _slot) = inventory.pick_up_stacked_floor_item(&floor_item).ok_or(ItemManagerError::CouldNotAddBoughtItemToInventory)?;
|
|
|
for entity_id in &picked_up_item.entity_ids {
|
|
|
for entity_id in &picked_up_item.entity_ids {
|
|
|
entity_gateway.change_item_location(entity_id,
|
|
|
entity_gateway.change_item_location(entity_id,
|
|
|
ItemLocation::Inventory {
|
|
|
ItemLocation::Inventory {
|
|
@ -795,7 +794,7 @@ impl ItemManager { |
|
|
}).await?;
|
|
|
}).await?;
|
|
|
let floor_item = IndividualFloorItem {
|
|
|
let floor_item = IndividualFloorItem {
|
|
|
entity_id: item_entity.id,
|
|
|
entity_id: item_entity.id,
|
|
|
item_id: item_id,
|
|
|
|
|
|
|
|
|
item_id,
|
|
|
item: ItemDetail::Tool(tool),
|
|
|
item: ItemDetail::Tool(tool),
|
|
|
// TODO: this is gonna choke if I ever require the item being near the player for pickup
|
|
|
// TODO: this is gonna choke if I ever require the item being near the player for pickup
|
|
|
map_area: MapArea::Pioneer2Ep1,
|
|
|
map_area: MapArea::Pioneer2Ep1,
|
|
@ -804,7 +803,7 @@ impl ItemManager { |
|
|
z: 0.0,
|
|
|
z: 0.0,
|
|
|
};
|
|
|
};
|
|
|
let item_id = {
|
|
|
let item_id = {
|
|
|
let (picked_up_item, slot) = inventory.pick_up_individual_floor_item(&floor_item).ok_or(ItemManagerError::CouldNotAddBoughtItemToInventory)?;
|
|
|
|
|
|
|
|
|
let (picked_up_item, _slot) = inventory.pick_up_individual_floor_item(&floor_item).ok_or(ItemManagerError::CouldNotAddBoughtItemToInventory)?;
|
|
|
entity_gateway.change_item_location(&picked_up_item.entity_id,
|
|
|
entity_gateway.change_item_location(&picked_up_item.entity_id,
|
|
|
ItemLocation::Inventory {
|
|
|
ItemLocation::Inventory {
|
|
|
character_id: character.id,
|
|
|
character_id: character.id,
|
|
@ -814,14 +813,14 @@ impl ItemManager { |
|
|
inventory.get_item_by_id(item_id).ok_or(ItemManagerError::ItemIdNotInInventory(item_id))?
|
|
|
inventory.get_item_by_id(item_id).ok_or(ItemManagerError::ItemIdNotInInventory(item_id))?
|
|
|
}
|
|
|
}
|
|
|
},
|
|
|
},
|
|
|
item_detail @ _ => {
|
|
|
|
|
|
|
|
|
item_detail => {
|
|
|
let item_entity = entity_gateway.create_item(NewItemEntity {
|
|
|
let item_entity = entity_gateway.create_item(NewItemEntity {
|
|
|
location: ItemLocation::Shop,
|
|
|
location: ItemLocation::Shop,
|
|
|
item: item_detail.clone(),
|
|
|
item: item_detail.clone(),
|
|
|
}).await?;
|
|
|
}).await?;
|
|
|
let floor_item = IndividualFloorItem {
|
|
|
let floor_item = IndividualFloorItem {
|
|
|
entity_id: item_entity.id,
|
|
|
entity_id: item_entity.id,
|
|
|
item_id: item_id,
|
|
|
|
|
|
|
|
|
item_id,
|
|
|
item: item_detail,
|
|
|
item: item_detail,
|
|
|
// TODO: this is gonna choke if I ever require the item being near the player for pickup
|
|
|
// TODO: this is gonna choke if I ever require the item being near the player for pickup
|
|
|
map_area: MapArea::Pioneer2Ep1,
|
|
|
map_area: MapArea::Pioneer2Ep1,
|
|
@ -830,7 +829,7 @@ impl ItemManager { |
|
|
z: 0.0,
|
|
|
z: 0.0,
|
|
|
};
|
|
|
};
|
|
|
let item_id = {
|
|
|
let item_id = {
|
|
|
let (picked_up_item, slot) = inventory.pick_up_individual_floor_item(&floor_item).ok_or(ItemManagerError::CouldNotAddBoughtItemToInventory)?;
|
|
|
|
|
|
|
|
|
let (picked_up_item, _slot) = inventory.pick_up_individual_floor_item(&floor_item).ok_or(ItemManagerError::CouldNotAddBoughtItemToInventory)?;
|
|
|
entity_gateway.change_item_location(&picked_up_item.entity_id,
|
|
|
entity_gateway.change_item_location(&picked_up_item.entity_id,
|
|
|
ItemLocation::Inventory {
|
|
|
ItemLocation::Inventory {
|
|
|
character_id: character.id,
|
|
|
character_id: character.id,
|
|
@ -911,8 +910,8 @@ impl ItemManager { |
|
|
entity_gateway.add_weapon_modifier(&entity_id, tek).await?;
|
|
|
entity_gateway.add_weapon_modifier(&entity_id, tek).await?;
|
|
|
|
|
|
|
|
|
inventory.add_item(InventoryItem::Individual(IndividualInventoryItem {
|
|
|
inventory.add_item(InventoryItem::Individual(IndividualInventoryItem {
|
|
|
entity_id: entity_id,
|
|
|
|
|
|
item_id: item_id,
|
|
|
|
|
|
|
|
|
entity_id,
|
|
|
|
|
|
item_id,
|
|
|
item: ItemDetail::Weapon(weapon.clone()),
|
|
|
item: ItemDetail::Weapon(weapon.clone()),
|
|
|
}))?;
|
|
|
}))?;
|
|
|
|
|
|
|
|
|