|
@ -1,19 +1,13 @@ |
|
|
use std::collections::HashMap;
|
|
|
use std::collections::HashMap;
|
|
|
use crate::ship::items::ClientItemId;
|
|
|
use crate::ship::items::ClientItemId;
|
|
|
use crate::entity::item::{Meseta, ItemEntityId, ItemDetail, ItemEntity, ItemType, InventoryEntity, InventoryItemEntity, EquippedEntity, ItemNote};
|
|
|
|
|
|
use std::cell::{RefMut, RefCell};
|
|
|
|
|
|
use std::ops::{Deref, DerefMut};
|
|
|
|
|
|
use std::convert::{From, Into};
|
|
|
|
|
|
|
|
|
use crate::entity::item::{Meseta, ItemEntityId, ItemDetail, ItemEntity, InventoryEntity, InventoryItemEntity};
|
|
|
use std::future::Future;
|
|
|
use std::future::Future;
|
|
|
use std::pin::Pin;
|
|
|
|
|
|
use async_std::sync::{Arc, Mutex};
|
|
|
|
|
|
use std::borrow::BorrowMut;
|
|
|
|
|
|
|
|
|
|
|
|
use crate::ship::location::{AreaClient, RoomId};
|
|
|
|
|
|
use crate::entity::character::{CharacterEntity, CharacterEntityId, TechLevel};
|
|
|
|
|
|
use crate::entity::gateway::{EntityGateway, GatewayError};
|
|
|
|
|
|
|
|
|
use crate::ship::location::RoomId;
|
|
|
|
|
|
use crate::entity::character::CharacterEntityId;
|
|
|
|
|
|
use crate::entity::gateway::GatewayError;
|
|
|
use crate::entity::gateway::entitygateway::EntityGatewayTransaction;
|
|
|
use crate::entity::gateway::entitygateway::EntityGatewayTransaction;
|
|
|
use crate::entity::item::tool::{Tool, ToolType};
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
@ -139,6 +133,7 @@ where |
|
|
O: Send + Sync,
|
|
|
O: Send + Sync,
|
|
|
P::Error: Send + Sync,
|
|
|
P::Error: Send + Sync,
|
|
|
{
|
|
|
{
|
|
|
|
|
|
#[allow(clippy::type_complexity)]
|
|
|
pub fn act<O2, G, GFut>(self, g: G) -> ItemActionStage<O2, ItemActionStage<O, P, F, Fut, S, E>, G, GFut, S, E>
|
|
|
pub fn act<O2, G, GFut>(self, g: G) -> ItemActionStage<O2, ItemActionStage<O, P, F, Fut, S, E>, G, GFut, S, E>
|
|
|
where
|
|
|
where
|
|
|
S: Send + Sync,
|
|
|
S: Send + Sync,
|
|
@ -196,13 +191,13 @@ pub enum InventoryItemDetail { |
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
impl InventoryItemDetail {
|
|
|
impl InventoryItemDetail {
|
|
|
fn stacked<'a>(&'a self) -> Option<&'a StackedItemDetail> {
|
|
|
|
|
|
|
|
|
fn stacked(&self) -> Option<&StackedItemDetail> {
|
|
|
match self {
|
|
|
match self {
|
|
|
InventoryItemDetail::Stacked(sitem) => Some(sitem),
|
|
|
InventoryItemDetail::Stacked(sitem) => Some(sitem),
|
|
|
_ => None,
|
|
|
_ => None,
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
fn stacked_mut <'a>(&'a mut self) -> Option<&'a mut StackedItemDetail> {
|
|
|
|
|
|
|
|
|
fn stacked_mut(&mut self) -> Option<&mut StackedItemDetail> {
|
|
|
match self {
|
|
|
match self {
|
|
|
InventoryItemDetail::Stacked(sitem) => Some(sitem),
|
|
|
InventoryItemDetail::Stacked(sitem) => Some(sitem),
|
|
|
_ => None,
|
|
|
_ => None,
|
|
@ -225,11 +220,11 @@ impl InventoryItem { |
|
|
{
|
|
|
{
|
|
|
match &self.item {
|
|
|
match &self.item {
|
|
|
InventoryItemDetail::Individual(individual_item) => {
|
|
|
InventoryItemDetail::Individual(individual_item) => {
|
|
|
param = func(param, individual_item.entity_id.clone()).await;
|
|
|
|
|
|
|
|
|
param = func(param, individual_item.entity_id).await;
|
|
|
},
|
|
|
},
|
|
|
InventoryItemDetail::Stacked(stacked_item) => {
|
|
|
InventoryItemDetail::Stacked(stacked_item) => {
|
|
|
for entity_id in &stacked_item.entity_ids {
|
|
|
for entity_id in &stacked_item.entity_ids {
|
|
|
param = func(param, entity_id.clone()).await;
|
|
|
|
|
|
|
|
|
param = func(param, *entity_id).await;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@ -246,7 +241,7 @@ pub enum FloorItemDetail { |
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
impl FloorItemDetail {
|
|
|
impl FloorItemDetail {
|
|
|
fn stacked<'a>(&'a self) -> Option<&'a StackedItemDetail> {
|
|
|
|
|
|
|
|
|
fn stacked(&self) -> Option<&StackedItemDetail> {
|
|
|
match self {
|
|
|
match self {
|
|
|
FloorItemDetail::Stacked(sitem) => Some(sitem),
|
|
|
FloorItemDetail::Stacked(sitem) => Some(sitem),
|
|
|
_ => None,
|
|
|
_ => None,
|
|
@ -268,11 +263,11 @@ impl FloorItem { |
|
|
{
|
|
|
{
|
|
|
match &self.item {
|
|
|
match &self.item {
|
|
|
FloorItemDetail::Individual(individual_item) => {
|
|
|
FloorItemDetail::Individual(individual_item) => {
|
|
|
param = func(param, individual_item.entity_id.clone()).await;
|
|
|
|
|
|
|
|
|
param = func(param, individual_item.entity_id).await;
|
|
|
},
|
|
|
},
|
|
|
FloorItemDetail::Stacked(stacked_item) => {
|
|
|
FloorItemDetail::Stacked(stacked_item) => {
|
|
|
for entity_id in &stacked_item.entity_ids {
|
|
|
for entity_id in &stacked_item.entity_ids {
|
|
|
param = func(param, entity_id.clone()).await;
|
|
|
|
|
|
|
|
|
param = func(param, *entity_id).await;
|
|
|
}
|
|
|
}
|
|
|
},
|
|
|
},
|
|
|
FloorItemDetail::Meseta(_meseta) => {},
|
|
|
FloorItemDetail::Meseta(_meseta) => {},
|
|
@ -286,18 +281,11 @@ impl FloorItem { |
|
|
F: FnMut(T, ItemEntityId, Mag) -> Fut,
|
|
|
F: FnMut(T, ItemEntityId, Mag) -> Fut,
|
|
|
Fut: Future<Output=T>,
|
|
|
Fut: Future<Output=T>,
|
|
|
{
|
|
|
{
|
|
|
match &self.item {
|
|
|
|
|
|
FloorItemDetail::Individual(individual_item) => {
|
|
|
|
|
|
match &individual_item.item {
|
|
|
|
|
|
ItemDetail::Mag(mag) => {
|
|
|
|
|
|
param = func(param, individual_item.entity_id.clone(), mag.clone()).await;
|
|
|
|
|
|
|
|
|
if let FloorItemDetail::Individual(individual_item) = &self.item {
|
|
|
|
|
|
if let ItemDetail::Mag(mag) = &individual_item.item {
|
|
|
|
|
|
param = func(param, individual_item.entity_id, mag.clone()).await;
|
|
|
}
|
|
|
}
|
|
|
_ => {}
|
|
|
|
|
|
}
|
|
|
}
|
|
|
},
|
|
|
|
|
|
_ => {}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
param
|
|
|
param
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@ -370,7 +358,7 @@ impl InventoryState { |
|
|
match item.item {
|
|
|
match item.item {
|
|
|
FloorItemDetail::Individual(iitem) => {
|
|
|
FloorItemDetail::Individual(iitem) => {
|
|
|
if self.inventory.0.len() >= 30 {
|
|
|
if self.inventory.0.len() >= 30 {
|
|
|
return Err(InventoryError::InventoryFull)
|
|
|
|
|
|
|
|
|
Err(InventoryError::InventoryFull)
|
|
|
}
|
|
|
}
|
|
|
else {
|
|
|
else {
|
|
|
self.inventory.0.push(InventoryItem {
|
|
|
self.inventory.0.push(InventoryItem {
|
|
@ -390,7 +378,7 @@ impl InventoryState { |
|
|
match existing_stack {
|
|
|
match existing_stack {
|
|
|
Some(existing_stack) => {
|
|
|
Some(existing_stack) => {
|
|
|
if existing_stack.entity_ids.len() + sitem.entity_ids.len() > sitem.tool.max_stack() {
|
|
|
if existing_stack.entity_ids.len() + sitem.entity_ids.len() > sitem.tool.max_stack() {
|
|
|
return Err(InventoryError::StackFull)
|
|
|
|
|
|
|
|
|
Err(InventoryError::StackFull)
|
|
|
}
|
|
|
}
|
|
|
else {
|
|
|
else {
|
|
|
existing_stack.entity_ids.append(&mut sitem.entity_ids.clone());
|
|
|
existing_stack.entity_ids.append(&mut sitem.entity_ids.clone());
|
|
@ -399,7 +387,7 @@ impl InventoryState { |
|
|
},
|
|
|
},
|
|
|
None => {
|
|
|
None => {
|
|
|
if self.inventory.0.len() >= 30 {
|
|
|
if self.inventory.0.len() >= 30 {
|
|
|
return Err(InventoryError::InventoryFull)
|
|
|
|
|
|
|
|
|
Err(InventoryError::InventoryFull)
|
|
|
}
|
|
|
}
|
|
|
else {
|
|
|
else {
|
|
|
self.inventory.0.push(InventoryItem {
|
|
|
self.inventory.0.push(InventoryItem {
|
|
@ -477,6 +465,7 @@ impl Default for ItemState { |
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Default)]
|
|
|
struct ProxiedItemState {
|
|
|
struct ProxiedItemState {
|
|
|
character_inventory: HashMap<CharacterEntityId, Inventory>,
|
|
|
character_inventory: HashMap<CharacterEntityId, Inventory>,
|
|
|
//character_bank: HashMap<CharacterEntityId, RefCell<Bank>>,
|
|
|
//character_bank: HashMap<CharacterEntityId, RefCell<Bank>>,
|
|
@ -491,6 +480,7 @@ struct ProxiedItemState { |
|
|
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
impl Default for ProxiedItemState {
|
|
|
impl Default for ProxiedItemState {
|
|
|
fn default() -> Self {
|
|
|
fn default() -> Self {
|
|
|
ProxiedItemState {
|
|
|
ProxiedItemState {
|
|
@ -505,6 +495,7 @@ impl Default for ProxiedItemState { |
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
pub struct ItemStateProxy<'a> {
|
|
|
pub struct ItemStateProxy<'a> {
|
|
|
item_state: &'a mut ItemState,
|
|
|
item_state: &'a mut ItemState,
|
|
@ -529,7 +520,7 @@ where |
|
|
{
|
|
|
{
|
|
|
let existing_element = master.get(&key).ok_or_else(|| err(key))?;
|
|
|
let existing_element = master.get(&key).ok_or_else(|| err(key))?;
|
|
|
Ok(proxy.entry(key)
|
|
|
Ok(proxy.entry(key)
|
|
|
.or_insert(existing_element.clone()).clone())
|
|
|
|
|
|
|
|
|
.or_insert_with(|| existing_element.clone()).clone())
|
|
|
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
@ -544,8 +535,8 @@ 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> {
|
|
|
Ok(InventoryState {
|
|
|
Ok(InventoryState {
|
|
|
character_id: *character_id,
|
|
|
character_id: *character_id,
|
|
|
inventory: get_or_clone(&self.item_state.character_inventory, &mut self.proxied_state.character_inventory, *character_id, |c| ItemStateError::NoCharacter(c))?,
|
|
|
|
|
|
meseta: get_or_clone(&self.item_state.character_meseta, &mut self.proxied_state.character_meseta, *character_id, |c| ItemStateError::NoCharacter(c))?,
|
|
|
|
|
|
|
|
|
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)?,
|
|
|
})
|
|
|
})
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
@ -555,16 +546,16 @@ impl<'a> ItemStateProxy<'a> { |
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
pub fn floor(&mut self, character_id: &CharacterEntityId) -> Result<FloorState, ItemStateError> {
|
|
|
pub fn floor(&mut self, character_id: &CharacterEntityId) -> Result<FloorState, ItemStateError> {
|
|
|
let room_id = get_or_clone(&self.item_state.character_room, &mut self.proxied_state.character_room, *character_id, |c| ItemStateError::NoCharacter(c))?;
|
|
|
|
|
|
|
|
|
let room_id = get_or_clone(&self.item_state.character_room, &mut self.proxied_state.character_room, *character_id, ItemStateError::NoCharacter)?;
|
|
|
Ok(FloorState {
|
|
|
Ok(FloorState {
|
|
|
character_id: *character_id,
|
|
|
character_id: *character_id,
|
|
|
local: get_or_clone(&self.item_state.character_floor, &mut self.proxied_state.character_floor, *character_id, |c| ItemStateError::NoCharacter(c))?,
|
|
|
|
|
|
shared: get_or_clone(&self.item_state.room_floor, &mut self.proxied_state.room_floor, room_id, |r| ItemStateError::NoRoom(r))?,
|
|
|
|
|
|
|
|
|
local: get_or_clone(&self.item_state.character_floor, &mut self.proxied_state.character_floor, *character_id, ItemStateError::NoCharacter)?,
|
|
|
|
|
|
shared: get_or_clone(&self.item_state.room_floor, &mut self.proxied_state.room_floor, room_id, ItemStateError::NoRoom)?,
|
|
|
})
|
|
|
})
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
pub fn set_floor(&mut self, floor: FloorState) {
|
|
|
pub fn set_floor(&mut self, floor: FloorState) {
|
|
|
let room_id = get_or_clone(&self.item_state.character_room, &mut self.proxied_state.character_room, floor.character_id, |c| ItemStateError::NoCharacter(c)).unwrap();
|
|
|
|
|
|
|
|
|
let room_id = get_or_clone(&self.item_state.character_room, &mut self.proxied_state.character_room, floor.character_id, ItemStateError::NoCharacter).unwrap();
|
|
|
self.proxied_state.character_floor.insert(floor.character_id, floor.local);
|
|
|
self.proxied_state.character_floor.insert(floor.character_id, floor.local);
|
|
|
self.proxied_state.room_floor.insert(room_id, floor.shared);
|
|
|
self.proxied_state.room_floor.insert(room_id, floor.shared);
|
|
|
}
|
|
|
}
|
|
|