@ -3,7 +3,7 @@ use std::collections::HashMap;
use thiserror ::Error ;
use thiserror ::Error ;
use crate ::entity ::gateway ::{ EntityGateway , GatewayError } ;
use crate ::entity ::gateway ::{ EntityGateway , GatewayError } ;
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 , ItemNote , BankName } ;
use crate ::entity ::item ::{ Meseta , NewItemEntity , ItemEntity , ItemEntityId , InventoryItemEntity , BankItemEntity } ;
use crate ::entity ::item ::{ Meseta , NewItemEntity , ItemEntity , ItemEntityId , InventoryItemEntity , BankItemEntity } ;
use crate ::entity ::item ::tool ::{ Tool , ToolType } ;
use crate ::entity ::item ::tool ::{ Tool , ToolType } ;
use crate ::entity ::item ::weapon ;
use crate ::entity ::item ::weapon ;
@ -366,13 +366,13 @@ impl ItemManager {
ItemOrMeseta ::Individual ( item_detail ) = > {
ItemOrMeseta ::Individual ( item_detail ) = > {
let entity = entity_gateway . create_item ( NewItemEntity {
let entity = entity_gateway . create_item ( NewItemEntity {
item : item_detail . clone ( ) ,
item : item_detail . clone ( ) ,
location : ItemLocation ::LocalFloor {
} ) . await ? ;
entity_gateway . add_item_note ( & entity . id , ItemNote ::EnemyDrop {
character_id : character . id ,
character_id : character . id ,
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 ,
z : item_drop . z ,
z : item_drop . z ,
}
} ) . await ? ;
} ) . await ? ;
FloorItem ::Individual ( IndividualFloorItem {
FloorItem ::Individual ( IndividualFloorItem {
entity_id : entity . id ,
entity_id : entity . id ,
@ -387,13 +387,13 @@ impl ItemManager {
ItemOrMeseta ::Stacked ( tool ) = > {
ItemOrMeseta ::Stacked ( tool ) = > {
let entity = entity_gateway . create_item ( NewItemEntity {
let entity = entity_gateway . create_item ( NewItemEntity {
item : ItemDetail ::Tool ( tool ) ,
item : ItemDetail ::Tool ( tool ) ,
location : ItemLocation ::LocalFloor {
} ) . await ? ;
entity_gateway . add_item_note ( & entity . id , ItemNote ::EnemyDrop {
character_id : character . id ,
character_id : character . id ,
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 ,
z : item_drop . z ,
z : item_drop . z ,
}
} ) . await ? ;
} ) . await ? ;
FloorItem ::Stacked ( StackedFloorItem {
FloorItem ::Stacked ( StackedFloorItem {
entity_ids : vec ! [ entity . id ] ,
entity_ids : vec ! [ entity . id ] ,
@ -438,9 +438,9 @@ impl ItemManager {
match dropped_inventory_item {
match dropped_inventory_item {
InventoryItem ::Individual ( individual_inventory_item ) = > {
InventoryItem ::Individual ( individual_inventory_item ) = > {
let individual_floor_item = shared_floor . drop_individual_inventory_item ( individual_inventory_item , item_drop_location ) ;
let individual_floor_item = shared_floor . drop_individual_inventory_item ( individual_inventory_item , item_drop_location ) ;
entity_gateway . change_item_location (
entity_gateway . add_item_note (
& individual_floor_item . entity_id ,
& individual_floor_item . entity_id ,
ItemLocation ::SharedFloor {
ItemNote ::PlayerDrop {
map_area : item_drop_location . 0 ,
map_area : item_drop_location . 0 ,
x : item_drop_location . 1 ,
x : item_drop_location . 1 ,
y : item_drop_location . 2 ,
y : item_drop_location . 2 ,
@ -451,9 +451,9 @@ impl ItemManager {
InventoryItem ::Stacked ( stacked_inventory_item ) = > {
InventoryItem ::Stacked ( stacked_inventory_item ) = > {
let stacked_floor_item = shared_floor . drop_stacked_inventory_item ( stacked_inventory_item , item_drop_location ) ;
let stacked_floor_item = shared_floor . drop_stacked_inventory_item ( stacked_inventory_item , item_drop_location ) ;
for entity_id in & stacked_floor_item . entity_ids {
for entity_id in & stacked_floor_item . entity_ids {
entity_gateway . change_item_location (
entity_gateway . add_item_note (
entity_id ,
entity_id ,
ItemLocation ::SharedFloor {
ItemNote ::PlayerDrop {
map_area : item_drop_location . 0 ,
map_area : item_drop_location . 0 ,
x : item_drop_location . 1 ,
x : item_drop_location . 1 ,
y : item_drop_location . 2 ,
y : item_drop_location . 2 ,
@ -515,9 +515,9 @@ impl ItemManager {
. ok_or ( ItemManagerError ::CouldNotSplitItem ( item_id ) ) ? ;
. ok_or ( ItemManagerError ::CouldNotSplitItem ( item_id ) ) ? ;
for entity_id in & stacked_floor_item . entity_ids {
for entity_id in & stacked_floor_item . entity_ids {
entity_gateway . change_item_location (
entity_gateway . add_item_note (
entity_id ,
entity_id ,
ItemLocation ::SharedFloor {
ItemNote ::PlayerDrop {
map_area : drop_location . map_area ,
map_area : drop_location . map_area ,
x : drop_location . x ,
x : drop_location . x ,
y : 0.0 ,
y : 0.0 ,
@ -547,8 +547,8 @@ impl ItemManager {
} ;
} ;
for entity_id in consumed_item . entity_ids ( ) {
for entity_id in consumed_item . entity_ids ( ) {
entity_gateway . change_item_location ( & entity_id ,
ItemLocation ::Consumed ) . await ? ;
entity_gateway . add_item_note ( & entity_id ,
ItemNote ::Consumed ) . await ? ;
}
}
entity_gateway . set_character_inventory ( & character . id , & inventory . as_inventory_entity ( & character . id ) ) . await ? ;
entity_gateway . set_character_inventory ( & character . id , & inventory . as_inventory_entity ( & character . id ) ) . await ? ;
@ -569,25 +569,6 @@ impl ItemManager {
let item_to_deposit = inventory . get_item_handle_by_id ( item_id ) . ok_or ( ItemManagerError ::NoSuchItemId ( item_id ) ) ? ;
let item_to_deposit = inventory . get_item_handle_by_id ( item_id ) . ok_or ( ItemManagerError ::NoSuchItemId ( item_id ) ) ? ;
let bank_item = bank . deposit_item ( item_to_deposit , amount ) . ok_or ( ItemManagerError ::Idunnoman ) ? ;
let bank_item = bank . deposit_item ( item_to_deposit , amount ) . ok_or ( ItemManagerError ::Idunnoman ) ? ;
match bank_item {
BankItem ::Individual ( individual_bank_item ) = > {
entity_gateway . change_item_location ( & individual_bank_item . entity_id ,
ItemLocation ::Bank {
character_id : character . id ,
name : BankName ( "" . to_string ( ) )
} ) . await ? ;
} ,
BankItem ::Stacked ( stacked_bank_item ) = > {
for entity_id in & stacked_bank_item . entity_ids {
entity_gateway . change_item_location ( entity_id ,
ItemLocation ::Bank {
character_id : character . id ,
name : BankName ( "" . to_string ( ) )
} ) . await ? ;
}
}
}
entity_gateway . set_character_inventory ( & character . id , & inventory . as_inventory_entity ( & character . id ) ) . await ? ;
entity_gateway . set_character_inventory ( & character . id , & inventory . as_inventory_entity ( & character . id ) ) . await ? ;
entity_gateway . set_character_bank ( & character . id , & bank . as_bank_entity ( & character . id , & BankName ( "" . into ( ) ) ) , BankName ( "" . into ( ) ) ) . await ? ;
entity_gateway . set_character_bank ( & character . id , & bank . as_bank_entity ( & character . id , & BankName ( "" . into ( ) ) ) , BankName ( "" . into ( ) ) ) . await ? ;
Ok ( ( ) )
Ok ( ( ) )
@ -608,23 +589,6 @@ impl ItemManager {
let item_to_withdraw = bank . get_item_handle_by_id ( item_id ) . ok_or ( ItemManagerError ::NoSuchItemId ( item_id ) ) ? ;
let item_to_withdraw = bank . get_item_handle_by_id ( item_id ) . ok_or ( ItemManagerError ::NoSuchItemId ( item_id ) ) ? ;
let inventory_item_slot = {
let inventory_item_slot = {
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 {
( InventoryItem ::Individual ( individual_inventory_item ) , _slot ) = > {
entity_gateway . change_item_location ( & individual_inventory_item . entity_id ,
ItemLocation ::Inventory {
character_id : character . id ,
} ) . await ? ;
} ,
( InventoryItem ::Stacked ( stacked_inventory_item ) , _slot ) = > {
for entity_id in & stacked_inventory_item . entity_ids {
entity_gateway . change_item_location ( entity_id ,
ItemLocation ::Inventory {
character_id : character . id ,
} ) . await ? ;
}
}
}
inventory_item . 1
inventory_item . 1
} ;
} ;
@ -662,7 +626,7 @@ impl ItemManager {
for entity_id in consumed_tool . entity_ids ( ) {
for entity_id in consumed_tool . entity_ids ( ) {
entity_gateway . feed_mag ( & individual_item . entity_id , & entity_id ) . await ? ;
entity_gateway . feed_mag ( & individual_item . entity_id , & entity_id ) . await ? ;
entity_gateway . change_item_location ( & entity_id , ItemLocation ::FedToMag {
entity_gateway . add_item_note ( & entity_id , ItemNote ::FedToMag {
mag : individual_item . entity_id ,
mag : individual_item . entity_id ,
} ) . await ? ;
} ) . await ? ;
}
}
@ -800,10 +764,13 @@ impl ItemManager {
if tool . is_stackable ( ) {
if tool . is_stackable ( ) {
let mut item_entities = Vec ::new ( ) ;
let mut item_entities = Vec ::new ( ) ;
for _ in 0 . . amount {
for _ in 0 . . amount {
item_entities . push ( entity_gateway . create_item ( NewItemEntity {
location : ItemLocation ::Shop ,
let item_entity = entity_gateway . create_item ( NewItemEntity {
item : ItemDetail ::Tool ( tool ) ,
item : ItemDetail ::Tool ( tool ) ,
} ) . await ? ) ;
} ) . await ? ;
entity_gateway . add_item_note ( & item_entity . id , ItemNote ::BoughtAtShop {
character_id : character . id ,
} ) . await ? ;
item_entities . push ( item_entity ) ;
}
}
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 ( ) ,
@ -817,21 +784,18 @@ impl ItemManager {
} ;
} ;
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 {
entity_gateway . change_item_location ( entity_id ,
ItemLocation ::Inventory {
character_id : character . id ,
} ) . await ? ;
}
picked_up_item . item_id
picked_up_item . item_id
} ;
} ;
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 ) ) ?
}
}
else {
else {
let item_entity = entity_gateway . create_item ( NewItemEntity {
let item_entity = entity_gateway . create_item ( NewItemEntity {
location : ItemLocation ::Shop ,
item : ItemDetail ::Tool ( tool ) ,
item : ItemDetail ::Tool ( tool ) ,
} ) . await ? ;
} ) . await ? ;
entity_gateway . add_item_note ( & item_entity . id , ItemNote ::BoughtAtShop {
character_id : character . id ,
} ) . await ? ;
let floor_item = IndividualFloorItem {
let floor_item = IndividualFloorItem {
entity_id : item_entity . id ,
entity_id : item_entity . id ,
item_id ,
item_id ,
@ -844,10 +808,6 @@ impl ItemManager {
} ;
} ;
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 ,
ItemLocation ::Inventory {
character_id : character . id ,
} ) . await ? ;
picked_up_item . item_id
picked_up_item . item_id
} ;
} ;
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 ) ) ?
@ -855,9 +815,11 @@ impl ItemManager {
} ,
} ,
item_detail = > {
item_detail = > {
let item_entity = entity_gateway . create_item ( NewItemEntity {
let item_entity = entity_gateway . create_item ( NewItemEntity {
location : ItemLocation ::Shop ,
item : item_detail . clone ( ) ,
item : item_detail . clone ( ) ,
} ) . await ? ;
} ) . await ? ;
entity_gateway . add_item_note ( & item_entity . id , ItemNote ::BoughtAtShop {
character_id : character . id ,
} ) . await ? ;
let floor_item = IndividualFloorItem {
let floor_item = IndividualFloorItem {
entity_id : item_entity . id ,
entity_id : item_entity . id ,
item_id ,
item_id ,
@ -870,10 +832,6 @@ impl ItemManager {
} ;
} ;
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 ,
ItemLocation ::Inventory {
character_id : character . id ,
} ) . await ? ;
picked_up_item . item_id
picked_up_item . item_id
} ;
} ;
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 ) ) ?
@ -1121,9 +1079,10 @@ impl<EG: EntityGateway> ItemAction<EG> for AddIndividualFloorItemToInventory {
let inventory = item_manager . character_inventory . get_mut ( & self . character . id ) . ok_or ( ItemManagerError ::NoCharacter ( self . character . id ) ) ? ;
let inventory = item_manager . character_inventory . get_mut ( & self . character . id ) . ok_or ( ItemManagerError ::NoCharacter ( self . character . id ) ) ? ;
let inv_item = inventory . add_individual_floor_item ( & self . item ) ;
let inv_item = inventory . add_individual_floor_item ( & self . item ) ;
entity_gateway . change_item_location (
entity_gateway . add_item_note (
& self . item . entity_id ,
& self . item . entity_id ,
ItemLocation ::Inventory {
ItemNote ::Pickup {
character_id : self . character . id ,
character_id : self . character . id ,
}
}
) . await ? ;
) . await ? ;