@ -2,7 +2,7 @@ use std::cmp::Ordering;
use std ::collections ::HashMap ;
use std ::collections ::HashMap ;
use libpso ::character ::character ;
use libpso ::character ::character ;
use crate ::ship ::items ::ClientItemId ;
use crate ::ship ::items ::ClientItemId ;
use crate ::entity ::item ::{ Meseta , ItemEntityId , ItemDetail , ItemEntity , InventoryEntity , InventoryItemEntity , BankItemEntity , BankName , EquippedEntity } ;
use crate ::entity ::item ::{ Meseta , ItemEntityId , ItemDetail , ItemEntity , InventoryEntity , InventoryItemEntity , BankEntity , Bank ItemEntity , BankName , EquippedEntity } ;
use std ::future ::Future ;
use std ::future ::Future ;
use crate ::ship ::map ::MapArea ;
use crate ::ship ::map ::MapArea ;
@ -13,6 +13,7 @@ use crate::entity::item::tool::Tool;
use crate ::entity ::item ::mag ::Mag ;
use crate ::entity ::item ::mag ::Mag ;
use crate ::ship ::drops ::ItemDrop ;
use crate ::ship ::drops ::ItemDrop ;
// TODO: Commit trait that ItemStateProxy and EntityTransaction implement that .commit requires and acts on upon everything succeeding (like 3 less lines of code!)
#[ derive(thiserror::Error, Debug) ]
#[ derive(thiserror::Error, Debug) ]
pub enum ItemStateError {
pub enum ItemStateError {
@ -23,9 +24,15 @@ pub enum ItemStateError {
#[ error( " floor item {0} not found " ) ]
#[ error( " floor item {0} not found " ) ]
NoFloorItem ( ClientItemId ) ,
NoFloorItem ( ClientItemId ) ,
#[ error( " bank item {0} not found " ) ]
NoBankItem ( ClientItemId ) ,
#[ error( " inventory error {0} " ) ]
#[ error( " inventory error {0} " ) ]
InventoryError ( #[ from ] InventoryError ) ,
InventoryError ( #[ from ] InventoryError ) ,
#[ error( " bank error {0} " ) ]
BankError ( #[ from ] BankError ) ,
#[ error( " invalid drop? {0:?} (this shouldn't occur) " ) ]
#[ error( " invalid drop? {0:?} (this shouldn't occur) " ) ]
BadItemDrop ( ItemDrop ) ,
BadItemDrop ( ItemDrop ) ,
@ -35,8 +42,11 @@ pub enum ItemStateError {
#[ error( " gateway " ) ]
#[ error( " gateway " ) ]
GatewayError ( #[ from ] GatewayError ) ,
GatewayError ( #[ from ] GatewayError ) ,
#[ error( " tried to drop more meseta than in inventory: {0} " ) ]
InvalidMesetaDrop ( u32 ) ,
#[ error( " tried to remove more meseta than exists: {0} " ) ]
InvalidMesetaRemoval ( u32 ) ,
#[ error( " tried to add meseta when there is no more room " ) ]
FullOfMeseta ,
#[ error( " stacked item " ) ]
#[ error( " stacked item " ) ]
StackedItemError ( Vec < ItemEntity > ) ,
StackedItemError ( Vec < ItemEntity > ) ,
@ -247,8 +257,8 @@ impl InventoryItemDetail {
#[ derive(Clone, Debug) ]
#[ derive(Clone, Debug) ]
pub struct InventoryItem {
pub struct InventoryItem {
item_id : ClientItemId ,
item : InventoryItemDetail ,
pub item_id : ClientItemId ,
pub item : InventoryItemDetail ,
}
}
impl InventoryItem {
impl InventoryItem {
@ -270,6 +280,19 @@ impl InventoryItem {
param
param
}
}
pub async fn with_mag < F , Fut , T > ( & self , mut param : T , mut func : F ) -> T
where
F : FnMut ( T , ItemEntityId , Mag ) -> Fut ,
Fut : Future < Output = T > ,
{
if let InventoryItemDetail ::Individual ( individual_item ) = & self . item {
if let ItemDetail ::Mag ( mag ) = & individual_item . item {
param = func ( param , individual_item . entity_id , mag . clone ( ) ) . await ;
}
}
param
}
}
}
@ -280,6 +303,13 @@ pub enum BankItemDetail {
}
}
impl BankItemDetail {
impl BankItemDetail {
fn stacked_mut ( & mut self ) -> Option < & mut StackedItemDetail > {
match self {
BankItemDetail ::Stacked ( sitem ) = > Some ( sitem ) ,
_ = > None ,
}
}
pub fn as_client_bytes ( & self ) -> [ u8 ; 16 ] {
pub fn as_client_bytes ( & self ) -> [ u8 ; 16 ] {
match self {
match self {
BankItemDetail ::Individual ( item ) = > {
BankItemDetail ::Individual ( item ) = > {
@ -303,8 +333,29 @@ impl BankItemDetail {
#[ derive(Clone, Debug) ]
#[ derive(Clone, Debug) ]
pub struct BankItem {
pub struct BankItem {
item_id : ClientItemId ,
item : BankItemDetail ,
pub item_id : ClientItemId ,
pub item : BankItemDetail ,
}
impl BankItem {
pub async fn with_entity_id < F , Fut , T > ( & self , mut param : T , mut func : F ) -> T
where
F : FnMut ( T , ItemEntityId ) -> Fut ,
Fut : Future < Output = T > ,
{
match & self . item {
BankItemDetail ::Individual ( individual_item ) = > {
param = func ( param , individual_item . entity_id ) . await ;
} ,
BankItemDetail ::Stacked ( stacked_item ) = > {
for entity_id in & stacked_item . entity_ids {
param = func ( param , * entity_id ) . await ;
}
}
}
param
}
}
}
#[ derive(Clone) ]
#[ derive(Clone) ]
@ -397,6 +448,16 @@ pub enum InventoryError {
MesetaFull ,
MesetaFull ,
}
}
#[ derive(thiserror::Error, Debug) ]
pub enum BankError {
#[ error( " bank full " ) ]
BankFull ,
#[ error( " stack full " ) ]
StackFull ,
#[ error( " meseta full " ) ]
MesetaFull ,
}
#[ derive(Clone) ]
#[ derive(Clone) ]
pub enum AddItemResult {
pub enum AddItemResult {
NewItem ,
NewItem ,
@ -428,6 +489,11 @@ impl InventoryState {
self . item_id_counter = base_item_id + self . inventory . 0. len ( ) as u32 + 1 ;
self . item_id_counter = base_item_id + self . inventory . 0. len ( ) as u32 + 1 ;
}
}
pub fn new_item_id ( & mut self ) -> ClientItemId {
self . item_id_counter + = 1 ;
ClientItemId ( self . item_id_counter )
}
pub fn count ( & self ) -> usize {
pub fn count ( & self ) -> usize {
self . inventory . 0. len ( )
self . inventory . 0. len ( )
}
}
@ -490,43 +556,77 @@ impl InventoryState {
}
}
}
}
pub fn take_item ( & mut self , item_id : & ClientItemId ) -> Option < InventoryItem > {
self . inventory . 0
. drain_filter ( | i | i . item_id = = * item_id )
. next ( )
pub fn add_item ( & mut self , item : InventoryItem ) -> Result < AddItemResult , InventoryError > {
match & item . item {
InventoryItemDetail ::Individual ( _ ) = > {
if self . inventory . 0. len ( ) > = 30 {
Err ( InventoryError ::InventoryFull )
}
else {
self . inventory . 0. push ( item ) ;
Ok ( AddItemResult ::NewItem )
}
} ,
InventoryItemDetail ::Stacked ( sitem ) = > {
let existing_stack = self . inventory . 0
. iter_mut ( )
. filter_map ( | item | item . item . stacked_mut ( ) )
. find ( | item | {
item . tool = = sitem . tool
} ) ;
match existing_stack {
Some ( existing_stack ) = > {
if existing_stack . entity_ids . len ( ) + sitem . entity_ids . len ( ) > sitem . tool . max_stack ( ) {
Err ( InventoryError ::StackFull )
}
else {
existing_stack . entity_ids . append ( & mut sitem . entity_ids . clone ( ) ) ;
Ok ( AddItemResult ::AddToStack )
}
} ,
None = > {
if self . inventory . 0. len ( ) > = 30 {
Err ( InventoryError ::InventoryFull )
}
else {
self . inventory . 0. push ( item ) ;
Ok ( AddItemResult ::NewItem )
}
}
}
}
}
}
}
pub fn take_partial_item ( & mut self , item_id : & ClientItemId , amount : u32 ) -> Option < StackedItemDetail > {
let amount = amount as usize ;
let ( idx , _ , stacked_item ) = self . inventory . 0
. iter_mut ( )
. enumerate ( )
. filter_map ( | ( k , item ) | {
match item . item {
InventoryItemDetail ::Stacked ( ref mut stacked_item ) = > Some ( ( k , item . item_id , stacked_item ) ) ,
_ = > None
pub fn take_item ( & mut self , item_id : & ClientItemId , amount : u32 ) -> Option < InventoryItem > {
let idx = self . inventory . 0
. iter ( )
. position ( | i | i . item_id = = * item_id ) ? ;
match & mut self . inventory . 0 [ idx ] . item {
InventoryItemDetail ::Individual ( _individual_item ) = > {
Some ( self . inventory . 0. remove ( idx ) )
} ,
InventoryItemDetail ::Stacked ( stacked_item ) = > {
let remove_all = match stacked_item . entity_ids . len ( ) . cmp ( & ( amount as usize ) ) {
Ordering ::Equal = > true ,
Ordering ::Greater = > false ,
Ordering ::Less = > return None ,
} ;
if remove_all {
Some ( self . inventory . 0. remove ( idx ) )
}
}
} )
. find ( | ( _ , id , _ ) | * id = = * item_id ) ? ;
let remove_all = match stacked_item . entity_ids . len ( ) . cmp ( & amount ) {
Ordering ::Equal = > true ,
Ordering ::Greater = > false ,
Ordering ::Less = > return None ,
} ;
if remove_all {
let stacked_item = stacked_item . clone ( ) ;
self . inventory . 0. remove ( idx ) ;
Some ( stacked_item )
}
else {
let entity_ids = stacked_item . entity_ids . drain ( . . amount ) . collect ( ) ;
Some ( StackedItemDetail {
entity_ids : entity_ids ,
tool : stacked_item . tool ,
} )
else {
let entity_ids = stacked_item . entity_ids . drain ( . . ( amount as usize ) ) . collect ( ) ;
self . item_id_counter + = 1 ;
Some ( InventoryItem {
item_id : ClientItemId ( self . item_id_counter ) ,
item : InventoryItemDetail ::Stacked ( StackedItemDetail {
entity_ids : entity_ids ,
tool : stacked_item . tool ,
} ) } )
}
}
}
}
}
}
@ -557,9 +657,25 @@ impl InventoryState {
}
}
}
}
pub fn add_meseta ( & mut self , amount : u32 ) -> Result < ( ) , ItemStateError > {
if self . meseta . 0 = = 999999 {
return Err ( ItemStateError ::FullOfMeseta )
}
self . meseta . 0 = std ::cmp ::min ( self . meseta . 0 + amount , 999999 ) ;
Ok ( ( ) )
}
pub fn add_meseta_no_overflow ( & mut self , amount : u32 ) -> Result < ( ) , ItemStateError > {
if self . meseta . 0 + amount > 999999 {
return Err ( ItemStateError ::FullOfMeseta )
}
self . meseta . 0 + = amount ;
Ok ( ( ) )
}
pub fn remove_meseta ( & mut self , amount : u32 ) -> Result < ( ) , ItemStateError > {
pub fn remove_meseta ( & mut self , amount : u32 ) -> Result < ( ) , ItemStateError > {
if amount > self . meseta . 0 {
if amount > self . meseta . 0 {
return Err ( ItemStateError ::InvalidMesetaDrop ( amount ) )
return Err ( ItemStateError ::InvalidMesetaRemoval ( amount ) )
}
}
self . meseta . 0 - = amount ;
self . meseta . 0 - = amount ;
Ok ( ( ) )
Ok ( ( ) )
@ -601,16 +717,130 @@ pub struct Bank(Vec<BankItem>);
pub struct BankState {
pub struct BankState {
character_id : CharacterEntityId ,
character_id : CharacterEntityId ,
item_id_counter : u32 ,
item_id_counter : u32 ,
pub name : BankName ,
bank : Bank ,
bank : Bank ,
pub meseta : Meseta ,
pub meseta : Meseta ,
}
}
impl BankState {
impl BankState {
pub fn new ( character_id : CharacterEntityId , name : BankName , mut bank : Bank , meseta : Meseta ) -> BankState {
bank . 0. sort ( ) ;
BankState {
character_id ,
item_id_counter : 0 ,
name ,
bank ,
meseta ,
}
}
pub fn count ( & self ) -> usize {
self . bank . 0. len ( )
}
pub fn initialize_item_ids ( & mut self , base_item_id : u32 ) {
pub fn initialize_item_ids ( & mut self , base_item_id : u32 ) {
for ( i , item ) in self . bank . 0. iter_mut ( ) . enumerate ( ) {
for ( i , item ) in self . bank . 0. iter_mut ( ) . enumerate ( ) {
item . item_id = ClientItemId ( base_item_id + i as u32 ) ;
item . item_id = ClientItemId ( base_item_id + i as u32 ) ;
}
}
self . item_id_counter = base_item_id + self . bank . 0. len ( ) as u32 + 1 ;
self . item_id_counter = base_item_id + self . bank . 0. len ( ) as u32 ;
}
pub fn add_meseta ( & mut self , amount : u32 ) -> Result < ( ) , ItemStateError > {
if self . meseta . 0 + amount > 999999 {
return Err ( ItemStateError ::FullOfMeseta )
}
self . meseta . 0 + = self . meseta . 0 + amount ;
Ok ( ( ) )
}
pub fn remove_meseta ( & mut self , amount : u32 ) -> Result < ( ) , ItemStateError > {
if amount > self . meseta . 0 {
return Err ( ItemStateError ::InvalidMesetaRemoval ( amount ) )
}
self . meseta . 0 - = amount ;
Ok ( ( ) )
}
pub fn add_inventory_item ( & mut self , item : InventoryItem ) -> Result < AddItemResult , BankError > {
match item . item {
InventoryItemDetail ::Individual ( iitem ) = > {
if self . bank . 0. len ( ) > = 30 {
Err ( BankError ::BankFull )
}
else {
self . bank . 0. push ( BankItem {
item_id : item . item_id ,
item : BankItemDetail ::Individual ( iitem )
} ) ;
self . bank . 0. sort ( ) ;
Ok ( AddItemResult ::NewItem )
}
} ,
InventoryItemDetail ::Stacked ( sitem ) = > {
let existing_stack = self . bank . 0
. iter_mut ( )
. filter_map ( | item | item . item . stacked_mut ( ) )
. find ( | item | {
item . tool = = sitem . tool
} ) ;
match existing_stack {
Some ( existing_stack ) = > {
if existing_stack . entity_ids . len ( ) + sitem . entity_ids . len ( ) > sitem . tool . max_stack ( ) {
Err ( BankError ::StackFull )
}
else {
existing_stack . entity_ids . append ( & mut sitem . entity_ids . clone ( ) ) ;
Ok ( AddItemResult ::AddToStack )
}
} ,
None = > {
if self . bank . 0. len ( ) > = 30 {
Err ( BankError ::BankFull )
}
else {
self . bank . 0. push ( BankItem {
item_id : item . item_id ,
item : BankItemDetail ::Stacked ( sitem )
} ) ;
self . bank . 0. sort ( ) ;
Ok ( AddItemResult ::NewItem )
}
}
}
}
}
}
pub fn take_item ( & mut self , item_id : & ClientItemId , amount : u32 ) -> Option < BankItem > {
let idx = self . bank . 0
. iter ( )
. position ( | i | i . item_id = = * item_id ) ? ;
match & mut self . bank . 0 [ idx ] . item {
BankItemDetail ::Individual ( _individual_item ) = > {
Some ( self . bank . 0. remove ( idx ) )
} ,
BankItemDetail ::Stacked ( stacked_item ) = > {
let remove_all = match stacked_item . entity_ids . len ( ) . cmp ( & ( amount as usize ) ) {
Ordering ::Equal = > true ,
Ordering ::Greater = > false ,
Ordering ::Less = > return None ,
} ;
if remove_all {
Some ( self . bank . 0. remove ( idx ) )
}
else {
let entity_ids = stacked_item . entity_ids . drain ( . . ( amount as usize ) ) . collect ( ) ;
self . item_id_counter + = 1 ;
Some ( BankItem {
item_id : ClientItemId ( self . item_id_counter ) ,
item : BankItemDetail ::Stacked ( StackedItemDetail {
entity_ids : entity_ids ,
tool : stacked_item . tool ,
} ) } )
}
}
}
}
}
pub fn as_client_bank_items ( & self ) -> character ::Bank {
pub fn as_client_bank_items ( & self ) -> character ::Bank {
@ -626,6 +856,106 @@ impl BankState {
bank
bank
} )
} )
}
}
pub fn as_client_bank_request ( & self ) -> Vec < character ::BankItem > {
self . bank . 0. iter ( )
. map ( | item | {
let bytes = item . item . as_client_bytes ( ) ;
let mut data1 = [ 0 ; 12 ] ;
let mut data2 = [ 0 ; 4 ] ;
data1 . copy_from_slice ( & bytes [ 0 . . 12 ] ) ;
data2 . copy_from_slice ( & bytes [ 12 . . 16 ] ) ;
let amount = match & item . item {
BankItemDetail ::Individual ( _individual_bank_item ) = > {
1
} ,
BankItemDetail ::Stacked ( stacked_bank_item ) = > {
stacked_bank_item . count ( )
} ,
} ;
character ::BankItem {
data1 ,
data2 ,
item_id : item . item_id . 0 ,
amount : amount as u16 ,
flags : 1 ,
}
} )
. collect ( )
}
pub fn as_bank_entity ( & self ) -> BankEntity {
BankEntity {
items : self . bank . 0. iter ( )
. map ( | item | {
match & item . item {
BankItemDetail ::Individual ( item ) = > {
BankItemEntity ::Individual ( ItemEntity {
id : item . entity_id ,
item : item . item . clone ( ) ,
} )
} ,
BankItemDetail ::Stacked ( items ) = > {
BankItemEntity ::Stacked ( items . entity_ids . iter ( )
. map ( | id | {
ItemEntity {
id : * id ,
item : ItemDetail ::Tool ( items . tool )
}
} )
. collect ( ) )
} ,
}
} )
. collect ( )
}
}
}
impl std ::cmp ::PartialEq for BankItem {
fn eq ( & self , other : & BankItem ) -> bool {
let mut self_bytes = [ 0 u8 ; 4 ] ;
let mut other_bytes = [ 0 u8 ; 4 ] ;
self_bytes . copy_from_slice ( & self . item . as_client_bytes ( ) [ 0 . . 4 ] ) ;
other_bytes . copy_from_slice ( & other . item . as_client_bytes ( ) [ 0 . . 4 ] ) ;
let self_value = u32 ::from_be_bytes ( self_bytes ) ;
let other_value = u32 ::from_be_bytes ( other_bytes ) ;
self_value . eq ( & other_value )
}
}
impl std ::cmp ::Eq for BankItem { }
impl std ::cmp ::PartialOrd for BankItem {
fn partial_cmp ( & self , other : & BankItem ) -> Option < std ::cmp ::Ordering > {
let mut self_bytes = [ 0 u8 ; 4 ] ;
let mut other_bytes = [ 0 u8 ; 4 ] ;
self_bytes . copy_from_slice ( & self . item . as_client_bytes ( ) [ 0 . . 4 ] ) ;
other_bytes . copy_from_slice ( & other . item . as_client_bytes ( ) [ 0 . . 4 ] ) ;
let self_value = u32 ::from_be_bytes ( self_bytes ) ;
let other_value = u32 ::from_be_bytes ( other_bytes ) ;
self_value . partial_cmp ( & other_value )
}
}
impl std ::cmp ::Ord for BankItem {
fn cmp ( & self , other : & BankItem ) -> std ::cmp ::Ordering {
let mut self_bytes = [ 0 u8 ; 4 ] ;
let mut other_bytes = [ 0 u8 ; 4 ] ;
self_bytes . copy_from_slice ( & self . item . as_client_bytes ( ) [ 0 . . 4 ] ) ;
other_bytes . copy_from_slice ( & other . item . as_client_bytes ( ) [ 0 . . 4 ] ) ;
let self_value = u32 ::from_le_bytes ( self_bytes ) ;
let other_value = u32 ::from_le_bytes ( other_bytes ) ;
self_value . cmp ( & other_value )
}
}
}
pub struct FloorState {
pub struct FloorState {
@ -677,14 +1007,11 @@ impl FloorState {
pub struct ItemState {
pub struct ItemState {
character_inventory : HashMap < CharacterEntityId , InventoryState > ,
character_inventory : HashMap < CharacterEntityId , InventoryState > ,
character_bank : HashMap < CharacterEntityId , BankState > ,
character_bank : HashMap < CharacterEntityId , BankState > ,
//character_meseta: HashMap<CharacterEntityId, Meseta>,
//bank_meseta: HashMap<CharacterEntityId, Meseta>,
character_room : HashMap < CharacterEntityId , RoomId > ,
character_room : HashMap < CharacterEntityId , RoomId > ,
character_floor : HashMap < CharacterEntityId , LocalFloor > ,
character_floor : HashMap < CharacterEntityId , LocalFloor > ,
room_floor : HashMap < RoomId , SharedFloor > ,
room_floor : HashMap < RoomId , SharedFloor > ,
//room_item_id_counter: Arc<RefCell<HashMap<RoomId, Box<dyn FnMut() -> ClientItemId + Send + Sync>>>>,
room_item_id_counter : u32 ,
room_item_id_counter : u32 ,
}
}
@ -693,8 +1020,6 @@ impl Default for ItemState {
ItemState {
ItemState {
character_inventory : HashMap ::new ( ) ,
character_inventory : HashMap ::new ( ) ,
character_bank : HashMap ::new ( ) ,
character_bank : HashMap ::new ( ) ,
//character_meseta: HashMap::new(),
//bank_meseta: HashMap::new(),
character_room : HashMap ::new ( ) ,
character_room : HashMap ::new ( ) ,
character_floor : HashMap ::new ( ) ,
character_floor : HashMap ::new ( ) ,
room_floor : HashMap ::new ( ) ,
room_floor : HashMap ::new ( ) ,
@ -795,13 +1120,8 @@ impl ItemState {
} )
} )
. collect ::< Result < Vec < _ > , _ > > ( ) ? ;
. collect ::< Result < Vec < _ > , _ > > ( ) ? ;
let bank_meseta = entity_gateway . get_bank_meseta ( & character . id , BankName ( "" . into ( ) ) ) . await ? ;
let bank_state = BankState {
character_id : character . id ,
item_id_counter : 0 ,
bank : Bank ( bank_items ) ,
meseta : bank_meseta ,
} ;
let bank_meseta = entity_gateway . get_bank_meseta ( & character . id , & BankName ( "" . into ( ) ) ) . await ? ;
let bank_state = BankState ::new ( character . id , BankName ( "" . into ( ) ) , Bank ( bank_items ) , bank_meseta ) ;
self . character_inventory . insert ( character . id , inventory_state ) ;
self . character_inventory . insert ( character . id , inventory_state ) ;
self . character_bank . insert ( character . id , bank_state ) ;
self . character_bank . insert ( character . id , bank_state ) ;
@ -820,14 +1140,6 @@ impl ItemState {
self . character_room . insert ( character . id , room_id ) ;
self . character_room . insert ( character . id , room_id ) ;
self . character_floor . insert ( character . id , LocalFloor ::default ( ) ) ;
self . character_floor . insert ( character . id , LocalFloor ::default ( ) ) ;
self . room_floor . entry ( room_id ) . or_insert_with ( SharedFloor ::default ) ;
self . room_floor . entry ( room_id ) . or_insert_with ( SharedFloor ::default ) ;
/*
let mut inc = 0x00810000 ;
self . room_item_id_counter . borrow_mut ( ) . entry ( room_id ) . or_insert_with ( | | Box ::new ( move | | {
inc + = 1 ;
ClientItemId ( inc )
} ) ) ;
* /
}
}
pub fn remove_character_from_room ( & mut self , character : & CharacterEntity ) {
pub fn remove_character_from_room ( & mut self , character : & CharacterEntity ) {
@ -864,34 +1176,12 @@ impl ItemState {
struct ProxiedItemState {
struct ProxiedItemState {
character_inventory : HashMap < CharacterEntityId , InventoryState > ,
character_inventory : HashMap < CharacterEntityId , InventoryState > ,
character_bank : HashMap < CharacterEntityId , BankState > ,
character_bank : HashMap < CharacterEntityId , BankState > ,
//character_meseta: HashMap<CharacterEntityId, Meseta>,
//bank_meseta: HashMap<CharacterEntityId, Meseta>,
character_room : HashMap < CharacterEntityId , RoomId > ,
character_room : HashMap < CharacterEntityId , RoomId > ,
character_floor : HashMap < CharacterEntityId , LocalFloor > ,
character_floor : HashMap < CharacterEntityId , LocalFloor > ,
room_floor : HashMap < RoomId , SharedFloor > ,
room_floor : HashMap < RoomId , SharedFloor > ,
//room_item_id_counter: HashMap<RoomId, Box<dyn FnMut() -> ClientItemId + Send>>,
}
}
/*
impl Default for ProxiedItemState {
fn default ( ) -> Self {
ProxiedItemState {
character_inventory : HashMap ::new ( ) ,
//character_bank: HashMap::new(),
character_meseta : HashMap ::new ( ) ,
//bank_meseta: HashMap::new(),
character_floor : HashMap ::new ( ) ,
character_room : HashMap ::new ( ) ,
room_floor : HashMap ::new ( ) ,
//room_item_id_counter: HashMap::new(),
}
}
}
* /
pub struct ItemStateProxy < 'a > {
pub struct ItemStateProxy < 'a > {
item_state : & 'a mut ItemState ,
item_state : & 'a mut ItemState ,
proxied_state : ProxiedItemState ,
proxied_state : ProxiedItemState ,
@ -901,7 +1191,6 @@ impl<'a> ItemStateProxy<'a> {
pub fn commit ( self ) {
pub fn commit ( self ) {
self . item_state . character_inventory . extend ( self . proxied_state . character_inventory . clone ( ) ) ;
self . item_state . character_inventory . extend ( self . proxied_state . character_inventory . clone ( ) ) ;
self . item_state . character_bank . extend ( self . proxied_state . character_bank . clone ( ) ) ;
self . item_state . character_bank . extend ( self . proxied_state . character_bank . clone ( ) ) ;
//self.item_state.character_meseta.extend(self.proxied_state.character_meseta.clone());
self . item_state . character_room . extend ( self . proxied_state . character_room . clone ( ) ) ;
self . item_state . character_room . extend ( self . proxied_state . character_room . clone ( ) ) ;
self . item_state . character_floor . extend ( self . proxied_state . character_floor . clone ( ) ) ;
self . item_state . character_floor . extend ( self . proxied_state . character_floor . clone ( ) ) ;
self . item_state . room_floor . extend ( self . proxied_state . room_floor . clone ( ) ) ;
self . item_state . room_floor . extend ( self . proxied_state . room_floor . clone ( ) ) ;
@ -930,19 +1219,18 @@ impl<'a> ItemStateProxy<'a> {
pub fn inventory ( & mut self , character_id : & CharacterEntityId ) -> Result < InventoryState , ItemStateError > {
pub fn inventory ( & mut self , character_id : & CharacterEntityId ) -> Result < InventoryState , ItemStateError > {
get_or_clone ( & self . item_state . character_inventory , & mut self . proxied_state . character_inventory , * character_id , ItemStateError ::NoCharacter )
get_or_clone ( & self . item_state . character_inventory , & mut self . proxied_state . character_inventory , * character_id , ItemStateError ::NoCharacter )
/*
Ok ( InventoryState {
character_id : * character_id ,
inventory : get_or_clone ( & self . item_state . character_inventory , & mut self . proxied_state . character_inventory , * character_id , ItemStateError ::NoCharacter ) ? ,
meseta : get_or_clone ( & self . item_state . character_meseta , & mut self . proxied_state . character_meseta , * character_id , ItemStateError ::NoCharacter ) ? ,
} )
* /
}
}
pub fn set_inventory ( & mut self , inventory : InventoryState ) {
pub fn set_inventory ( & mut self , inventory : InventoryState ) {
self . proxied_state . character_inventory . insert ( inventory . character_id , inventory ) ;
self . proxied_state . character_inventory . insert ( inventory . character_id , inventory ) ;
//self.proxied_state.character_inventory.insert(inventory.character_id, inventory.inventory);
//self.proxied_state.character_meseta.insert(inventory.character_id, inventory.meseta);
}
pub fn bank ( & mut self , character_id : & CharacterEntityId ) -> Result < BankState , ItemStateError > {
get_or_clone ( & self . item_state . character_bank , & mut self . proxied_state . character_bank , * character_id , ItemStateError ::NoCharacter )
}
pub fn set_bank ( & mut self , bank : BankState ) {
self . proxied_state . character_bank . insert ( bank . character_id , bank ) ;
}
}
pub fn floor ( & mut self , character_id : & CharacterEntityId ) -> Result < FloorState , ItemStateError > {
pub fn floor ( & mut self , character_id : & CharacterEntityId ) -> Result < FloorState , ItemStateError > {