Browse Source

appease clippy, the tyrant

pull/113/head
jake 2 years ago
parent
commit
bde70011cc
  1. 2
      src/common/leveltable.rs
  2. 6
      src/entity/gateway/postgres/postgres.rs
  3. 4
      src/entity/item/armor.rs
  4. 4
      src/entity/item/esweapon.rs
  5. 6
      src/entity/item/mag.rs
  6. 10
      src/entity/item/mod.rs
  7. 2
      src/entity/item/shield.rs
  8. 2
      src/entity/item/tool.rs
  9. 4
      src/entity/item/unit.rs
  10. 14
      src/entity/item/weapon.rs
  11. 2
      src/ship/drops/mod.rs
  12. 77
      src/ship/items/actions.rs
  13. 2
      src/ship/items/apply_item.rs
  14. 31
      src/ship/items/state.rs
  15. 30
      src/ship/location.rs
  16. 2
      src/ship/map/area.rs
  17. 2
      src/ship/map/variant.rs
  18. 17
      src/ship/packet/handler/direct_message.rs
  19. 15
      src/ship/packet/handler/trade.rs

2
src/common/leveltable.rs

@ -3,7 +3,7 @@ use std::fs::File;
use serde_json::Value;
use crate::entity::character::CharacterClass;
#[derive(Default, Copy, Clone, Debug, PartialEq)]
#[derive(Default, Copy, Clone, Debug, PartialEq, Eq)]
pub struct CharacterStats {
pub hp: u16,
pub atp: u16,

6
src/entity/gateway/postgres/postgres.rs

@ -51,11 +51,9 @@ impl PostgresGateway {
embedded::migrations::runner().run(&mut conn).unwrap();
let pool = async_std::task::block_on(async move {
let pool = PgPoolOptions::new()
PgPoolOptions::new()
.max_connections(5)
.connect(&format!("postgresql://{}:{}@{}:5432/{}", username, password, host, dbname)).await.unwrap();
pool
.connect(&format!("postgresql://{}:{}@{}:5432/{}", username, password, host, dbname)).await.unwrap()
});
PostgresGateway {

4
src/entity/item/armor.rs

@ -289,7 +289,7 @@ impl ArmorType {
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum ArmorModifier {
AddSlot {
addslot: ItemEntityId,
@ -297,7 +297,7 @@ pub enum ArmorModifier {
}
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub struct Armor {
pub armor: ArmorType,
pub dfp: u8,

4
src/entity/item/esweapon.rs

@ -121,7 +121,7 @@ impl ESWeaponType {
}
}
#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize, strum_macros::EnumIter)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize, strum_macros::EnumIter)]
pub enum ESWeaponSpecial {
Jellen = 1,
Zalure,
@ -169,7 +169,7 @@ impl ESWeaponSpecial {
}
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct ESWeapon {
pub esweapon: ESWeaponType,
pub special: Option<ESWeaponSpecial>,

6
src/entity/item/mag.rs

@ -519,7 +519,7 @@ pub enum MagCellError {
IsRareMag,
}
#[derive(Debug, Clone, PartialEq)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum MagModifier {
FeedMag{
food: ItemEntityId,
@ -529,7 +529,7 @@ pub enum MagModifier {
OwnerChange(CharacterClass, SectionID)
}
#[derive(Debug, Copy, Clone, PartialEq, Serialize, Deserialize, enum_utils::FromStr)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, enum_utils::FromStr)]
pub enum PhotonBlast {
Farlla,
Estlla,
@ -539,7 +539,7 @@ pub enum PhotonBlast {
MyllaYoulla,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct Mag {
pub mag: MagType,
def: u16,

10
src/entity/item/mod.rs

@ -13,7 +13,7 @@ use crate::entity::character::CharacterEntityId;
use crate::ship::map::MapArea;
use crate::ship::drops::ItemDropType;
#[derive(PartialEq, Copy, Clone, Debug, Hash, Eq, PartialOrd, Ord, Serialize, Deserialize)]
#[derive(PartialEq, Eq, Copy, Clone, Debug, Hash, PartialOrd, Ord, Serialize, Deserialize)]
pub struct ItemEntityId(pub u32);
#[derive(Hash, PartialEq, Eq, Debug, Clone)]
pub struct ItemId(u32);
@ -70,7 +70,7 @@ pub enum ItemNote {
},
}
#[derive(Debug, Copy, Clone, PartialEq)]
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub struct Meseta(pub u32);
impl Meseta {
@ -95,12 +95,12 @@ pub enum ItemType {
ESWeapon(esweapon::ESWeaponType),
}
#[derive(Clone, Debug, PartialEq)]
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum ItemParseError {
InvalidBytes
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub enum ItemDetail {
Weapon(weapon::Weapon),
Armor(armor::Armor),
@ -186,7 +186,7 @@ pub struct NewItemEntity {
pub item: ItemDetail,
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct ItemEntity {
pub id: ItemEntityId,
pub item: ItemDetail,

2
src/entity/item/shield.rs

@ -519,7 +519,7 @@ impl ShieldType {
}
#[derive(Debug, Copy, Clone, PartialEq, Serialize, Deserialize)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct Shield {
pub shield: ShieldType,
pub dfp: u8,

2
src/entity/item/tool.rs

@ -642,7 +642,7 @@ impl ToolType {
}
#[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)]
#[derive(Copy, Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct Tool {
pub tool: ToolType,
}

4
src/entity/item/unit.rs

@ -323,7 +323,7 @@ impl UnitType {
}
}
#[derive(Debug, Copy, Clone, PartialEq, Serialize, Deserialize)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum UnitModifier {
PlusPlus,
Plus,
@ -331,7 +331,7 @@ pub enum UnitModifier {
MinusMinus,
}
#[derive(Debug, Copy, Clone, PartialEq, Serialize, Deserialize)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct Unit {
pub unit: UnitType,
pub modifier: Option<UnitModifier>,

14
src/entity/item/weapon.rs

@ -10,7 +10,7 @@ pub enum ItemParseError {
InvalidWeaponAttribute,
}
#[derive(Debug, Copy, Clone, PartialEq, Hash, Eq, Ord, PartialOrd, Serialize, Deserialize)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize)]
pub enum Attribute {
Native = 1,
ABeast,
@ -32,7 +32,7 @@ impl Attribute {
}
}
#[derive(Debug, Copy, Clone, PartialEq, Serialize, Deserialize)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct WeaponAttribute {
pub attr: Attribute,
pub value: i8,
@ -45,7 +45,7 @@ impl WeaponAttribute {
}
#[derive(Debug, Copy, Clone, PartialEq, Serialize, Deserialize, strum_macros::EnumIter)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize, strum_macros::EnumIter)]
pub enum WeaponSpecial {
Draw = 1,
Drain,
@ -1424,14 +1424,14 @@ impl WeaponType {
}
#[derive(Debug, Copy, Clone, PartialEq, Serialize, Deserialize)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum TekSpecialModifier {
Plus,
Neutral,
Minus,
}
#[derive(Debug, Copy, Clone, PartialEq, Serialize, Deserialize)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum TekPercentModifier {
PlusPlus,
Plus,
@ -1440,7 +1440,7 @@ pub enum TekPercentModifier {
MinusMinus,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum WeaponModifier {
AddPercents {
attr: WeaponAttribute,
@ -1457,7 +1457,7 @@ pub enum WeaponModifier {
},
}
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub struct Weapon {
pub weapon: WeaponType,
pub special: Option<WeaponSpecial>,

2
src/ship/drops/mod.rs

@ -89,7 +89,7 @@ pub struct MonsterDropStats {
pub max_meseta: u32,
}
#[derive(Clone, Debug, PartialEq)]
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum ItemDropType {
Weapon(weapon::Weapon),
Armor(armor::Armor),

77
src/ship/items/actions.rs

@ -1,3 +1,5 @@
// TODO: replace various u32s and usizes denoting item amounts for ItemAmount(u32) for consistency
use crate::ship::items::ClientItemId;
use crate::entity::item::{Meseta, ItemNote};
use std::future::Future;
@ -14,7 +16,7 @@ use crate::entity::item::tool::Tool;
use crate::entity::item::ItemModifier;
use crate::ship::shops::ShopItem;
use crate::ship::trade::TradeItem;
use crate::ship::location::{AreaClient, RoomId};
use crate::ship::location::AreaClient;
use crate::ship::drops::{ItemDrop, ItemDropType};
pub enum TriggerCreateItem {
@ -107,7 +109,7 @@ fn take_item_from_inventory(character_id: CharacterEntityId, item_id: ClientItem
move |(mut item_state, mut transaction), _| {
Box::pin(async move {
let mut inventory = item_state.inventory(&character_id)?;
let item = inventory.take_item(&item_id, amount).ok_or_else (|| ItemStateError::NoFloorItem(item_id))?;
let item = inventory.take_item(&item_id, amount).ok_or (ItemStateError::NoFloorItem(item_id))?;
transaction.gateway().set_character_inventory(&character_id, &inventory.as_inventory_entity(&character_id)).await?;
item_state.set_inventory(inventory);
@ -235,7 +237,7 @@ fn add_meseta_to_shared_floor(character_id: CharacterEntityId, amount: u32, map_
let floor_item = FloorItem {
item_id: item_state.new_item_id()?,
item: FloorItemDetail::Meseta(Meseta(amount)),
map_area: map_area,
map_area,
x: drop_position.0,
y: 0.0,
z: drop_position.1,
@ -352,7 +354,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()
let ((item_state_proxy, transaction), _) = ItemStateAction::default()
.act(take_meseta_from_inventory(character.id, amount))
.act(add_meseta_to_bank(character.id, amount))
.commit((item_state_proxy, transaction))
@ -369,7 +371,7 @@ fn take_item_from_bank(character_id: CharacterEntityId, item_id: ClientItemId, a
move |(mut item_state, mut transaction), _| {
Box::pin(async move {
let mut bank = item_state.bank(&character_id)?;
let item = bank.take_item(&item_id, amount).ok_or_else(|| ItemStateError::NoBankItem(item_id))?;
let item = bank.take_item(&item_id, amount).ok_or(ItemStateError::NoBankItem(item_id))?;
transaction.gateway().set_character_bank(&character_id, &bank.as_bank_entity(), &bank.name).await?;
item_state.set_bank(bank);
@ -440,7 +442,7 @@ where
.act(take_item_from_bank(character.id, *item_id, amount))
//.act(bank_item_to_inventory_item)
//.act(add_item_to_inventory)
.act(add_bank_item_to_inventory(&character))
.act(add_bank_item_to_inventory(character))
.commit((item_state_proxy, transaction))
.await?;
item_state_proxy.commit();
@ -664,10 +666,10 @@ fn feed_mag_item(character: CharacterEntity, mag_item_id: ClientItemId)
Box::pin(async move {
let mut inventory = item_state.inventory(&character.id)?;
let mag_entity = inventory.get_by_client_id_mut(&mag_item_id)
.ok_or_else(|| ItemStateError::InvalidItemId(mag_item_id))?
.ok_or(ItemStateError::InvalidItemId(mag_item_id))?
.item
.as_individual_mut()
.ok_or_else(|| ItemStateError::NotAMag(mag_item_id))?;
.ok_or(ItemStateError::NotAMag(mag_item_id))?;
let mag_entity_id = mag_entity.entity_id;
let mut transaction = tool.with_entity_id(transaction, |mut transaction, entity_id| {
@ -683,13 +685,13 @@ fn feed_mag_item(character: CharacterEntity, mag_item_id: ClientItemId)
let food_tool = tool
.item
.stacked()
.ok_or_else(|| ItemStateError::NotMagFood(tool.item_id))?
.ok_or(ItemStateError::NotMagFood(tool.item_id))?
.tool
.tool;
let mag_entity = mag_entity
.as_mag_mut()
.ok_or_else(|| ItemStateError::NotAMag(mag_item_id))?;
.ok_or(ItemStateError::NotAMag(mag_item_id))?;
mag_entity.feed(food_tool);
@ -745,7 +747,7 @@ fn add_bought_item_to_inventory<'a>(character_id: CharacterEntityId,
item: ItemDetail::Tool(tool),
}).await?;
transaction.gateway().add_item_note(&item_entity.id, ItemNote::BoughtAtShop {
character_id: character_id,
character_id,
}).await?;
item_entities.push(item_entity);
}
@ -754,7 +756,7 @@ fn add_bought_item_to_inventory<'a>(character_id: CharacterEntityId,
item_id,
item: InventoryItemDetail::Stacked(StackedItemDetail {
entity_ids: item_entities.into_iter().map(|i| i.id).collect(),
tool: tool,
tool,
})
};
inventory.add_item(inventory_item)?.1
@ -764,7 +766,7 @@ fn add_bought_item_to_inventory<'a>(character_id: CharacterEntityId,
item: item_detail.clone(),
}).await?;
transaction.gateway().add_item_note(&item_entity.id, ItemNote::BoughtAtShop {
character_id: character_id,
character_id,
}).await?;
let inventory_item = InventoryItem {
@ -816,7 +818,7 @@ fn sell_inventory_item<'a>(character_id: CharacterEntityId)
-> impl Fn((ItemStateProxy<'a>, Box<dyn EntityGatewayTransaction + 'a>), InventoryItem)
-> Pin<Box<dyn Future<Output=Result<((ItemStateProxy<'a>, Box<dyn EntityGatewayTransaction + 'a>), InventoryItem), ItemStateError>> + Send + 'a>>
{
move |(mut item_state, mut transaction), inventory_item| {
move |(mut item_state, transaction), inventory_item| {
Box::pin(async move {
let mut inventory = item_state.inventory(&character_id)?;
let price = inventory_item.item.sell_price()?;
@ -899,7 +901,7 @@ where
-> Pin<Box<dyn Future<Output=Result<((ItemStateProxy<'a>, Box<dyn EntityGatewayTransaction + 'a>), O), ItemStateError>> + Send + 'a>> + Send + Sync,
T: Clone + Send + Sync,
{
move |(mut item_state, mut transaction), arg| {
move |(item_state, transaction), arg| {
let input = input.clone();
let func = func.clone();
println!("i {:?} {:?}", input, arg);
@ -958,18 +960,6 @@ where
}
}
fn clear<'a, T: Send + Clone + 'a>()
-> impl Fn((ItemStateProxy<'a>, Box<dyn EntityGatewayTransaction + 'a>), T)
-> Pin<Box<dyn Future<Output=Result<((ItemStateProxy<'a>, Box<dyn EntityGatewayTransaction + 'a>), ()), ItemStateError>> + Send + 'a>>
{
move |state, _| {
Box::pin(async move {
Ok((state, ()))
})
}
}
fn insert<'a, T: Send + Clone + 'a>(element: T)
-> impl Fn((ItemStateProxy<'a>, Box<dyn EntityGatewayTransaction + 'a>), ())
-> Pin<Box<dyn Future<Output=Result<((ItemStateProxy<'a>, Box<dyn EntityGatewayTransaction + 'a>), T), ItemStateError>> + Send + 'a>>
@ -986,26 +976,10 @@ fn add_item_to_inventory(character: CharacterEntity)
-> impl for<'a> Fn((ItemStateProxy<'a>, Box<dyn EntityGatewayTransaction + 'a>), InventoryItem)
-> Pin<Box<dyn Future<Output=Result<((ItemStateProxy<'a>, Box<dyn EntityGatewayTransaction + 'a>), InventoryItem), ItemStateError>> + Send + 'a>> + Clone
{
let character = character.clone();
move |(mut item_state, transaction), inventory_item| {
let character = character.clone();
Box::pin(async move {
//let bank_name = item_state.bank(&character.id)?.name;
let mut inventory = item_state.inventory(&character.id)?;
let character_id = character.id;
/*
let transaction = bank_item.with_entity_id(transaction, |mut transaction, entity_id| {
let bank_name = bank_name.clone();
async move {
transaction.gateway().add_item_note(&entity_id, ItemNote::Withdraw {
character_id,
bank: bank_name,
}).await?;
Ok(transaction)
}}).await?;
*/
let mut transaction = inventory_item.with_mag(transaction, |mut transaction, entity_id, _mag| {
let character = character.clone();
async move {
@ -1060,7 +1034,6 @@ fn assign_new_item_id()
pub async fn trade_items<'a, EG> (
item_state: &'a mut ItemState,
entity_gateway: &mut EG,
room_id: RoomId,
p1: (&AreaClient, &CharacterEntity, &Vec<TradeItem>, Meseta),
p2: (&AreaClient, &CharacterEntity, &Vec<TradeItem>, Meseta))
-> Result<(Vec<InventoryItem>, Vec<InventoryItem>), ItemStateError>
@ -1137,9 +1110,9 @@ pub async fn take_meseta<'a, EG> (
where
EG: EntityGateway,
{
entity_gateway.with_transaction(|mut transaction| async move {
entity_gateway.with_transaction(|transaction| async move {
let item_state_proxy = ItemStateProxy::new(item_state);
let ((item_state_proxy, transaction), p1_removed_items) = ItemStateAction::default()
let ((item_state_proxy, transaction), _) = ItemStateAction::default()
.act(take_meseta_from_inventory(*character_id, meseta.0))
.commit((item_state_proxy, transaction))
.await?;
@ -1270,7 +1243,7 @@ pub async fn enemy_drops_item<'a, EG> (
where
EG: EntityGateway,
{
entity_gateway.with_transaction(|mut transaction| async move {
entity_gateway.with_transaction(|transaction| async move {
let item_state_proxy = ItemStateProxy::new(item_state);
let ((item_state_proxy, transaction), floor_item) = ItemStateAction::default()
.act(convert_item_drop_to_floor_item(character_id, item_drop))
@ -1283,17 +1256,17 @@ where
}).await
}
fn apply_modifier_to_inventory_item(character_id: CharacterEntityId, modifier: ItemModifier)
fn apply_modifier_to_inventory_item(modifier: ItemModifier)
-> impl for<'a> Fn((ItemStateProxy<'a>, Box<dyn EntityGatewayTransaction + 'a>), InventoryItem)
-> Pin<Box<dyn Future<Output=Result<((ItemStateProxy<'a>, Box<dyn EntityGatewayTransaction + 'a>), InventoryItem), ItemStateError>> + Send + 'a>>
{
move |(item_state, mut transaction), mut inventory_item| {
let modifier = modifier.clone();
Box::pin(async move {
match (&inventory_item.item, modifier) {
(InventoryItemDetail::Individual(IndividualItemDetail{entity_id, item: ItemDetail::Weapon(mut weapon), ..}), ItemModifier::WeaponModifier(modifier)) => {
match (&mut inventory_item.item, modifier) {
(InventoryItemDetail::Individual(IndividualItemDetail{entity_id, item: ItemDetail::Weapon(ref mut weapon), ..}), ItemModifier::WeaponModifier(modifier)) => {
weapon.apply_modifier(&modifier);
transaction.gateway().add_weapon_modifier(&entity_id, modifier).await?;
transaction.gateway().add_weapon_modifier(entity_id, modifier).await?;
},
_ => return Err(ItemStateError::InvalidModifier)
}
@ -1334,7 +1307,7 @@ where
let item_state_proxy = ItemStateProxy::new(item_state);
let ((item_state_proxy, transaction), item) = ItemStateAction::default()
.act(take_item_from_inventory(character.id, item_id, 1))
.act(apply_modifier_to_inventory_item(character.id, modifier))
.act(apply_modifier_to_inventory_item(modifier))
.act(add_item_to_inventory(character.clone()))
.act(as_individual_item())
.commit((item_state_proxy, transaction))

2
src/ship/items/apply_item.rs

@ -109,7 +109,7 @@ where
let mut inventory = item_state.inventory(&character.id)?;
let (mag_entity_id, mag) = inventory.equipped_mag_mut()
.ok_or_else(|| ApplyItemError::ItemNotEquipped)?;
.ok_or(ApplyItemError::ItemNotEquipped)?;
mag.apply_mag_cell(mag_cell_type)?;
entity_gateway.use_mag_cell(&mag_entity_id, &cell_entity_id).await?;

31
src/ship/items/state.rs

@ -492,15 +492,6 @@ pub enum FloorItemDetail {
Meseta(Meseta),
}
impl FloorItemDetail {
fn stacked(&self) -> Option<&StackedItemDetail> {
match self {
FloorItemDetail::Stacked(sitem) => Some(sitem),
_ => None,
}
}
}
#[derive(Debug, Clone)]
pub struct FloorItem {
pub item_id: ClientItemId,
@ -767,7 +758,7 @@ impl InventoryState {
Some(InventoryItem {
item_id: ClientItemId(self.item_id_counter),
item: InventoryItemDetail::Stacked(StackedItemDetail {
entity_ids: entity_ids,
entity_ids,
tool: stacked_item.tool,
})})
}
@ -870,7 +861,7 @@ impl InventoryState {
.find(|(entity_id, _)| *entity_id == mag_id)
}
pub fn sort(&mut self, item_ids: &Vec<ClientItemId>) {
pub fn sort(&mut self, item_ids: &[ClientItemId]) {
self.inventory.0.sort_by(|a, b| {
let a_index = item_ids.iter().position(|item_id| *item_id == a.item_id);
let b_index = item_ids.iter().position(|item_id| *item_id == b.item_id);
@ -984,7 +975,7 @@ impl BankState {
if self.meseta.0 + amount > 999999 {
return Err(ItemStateError::FullOfMeseta)
}
self.meseta.0 += self.meseta.0 + amount;
self.meseta.0 += amount;
Ok(())
}
@ -1070,7 +1061,7 @@ impl BankState {
Some(BankItem {
item_id: ClientItemId(self.item_id_counter),
item: BankItemDetail::Stacked(StackedItemDetail {
entity_ids: entity_ids,
entity_ids,
tool: stacked_item.tool,
})})
}
@ -1223,7 +1214,7 @@ impl FloorState {
InventoryItemDetail::Individual(individual_item) => FloorItemDetail::Individual(individual_item),
InventoryItemDetail::Stacked(stacked_item) => FloorItemDetail::Stacked(stacked_item),
},
map_area: map_area,
map_area,
x: position.0,
y: position.1,
z: position.2,
@ -1271,13 +1262,13 @@ impl Default for ItemState {
impl ItemState {
pub fn get_character_inventory(&self, character: &CharacterEntity) -> Result<&InventoryState, ItemStateError> {
Ok(self.character_inventory.get(&character.id)
.ok_or(ItemStateError::NoCharacter(character.id))?)
self.character_inventory.get(&character.id)
.ok_or(ItemStateError::NoCharacter(character.id))
}
pub fn get_character_bank(&self, character: &CharacterEntity) -> Result<&BankState, ItemStateError> {
Ok(self.character_bank.get(&character.id)
.ok_or(ItemStateError::NoCharacter(character.id))?)
self.character_bank.get(&character.id)
.ok_or(ItemStateError::NoCharacter(character.id))
}
}
@ -1327,7 +1318,7 @@ impl ItemState {
character_id: character.id,
item_id_counter: 0,
inventory: Inventory(inventory_items),
equipped: equipped,
equipped,
meseta: character_meseta,
};
@ -1408,7 +1399,7 @@ impl ItemState {
.find(|item| item.item_id == *item_id)
.map(|item| (item, FloorType::Shared))
})
.ok_or_else(|| ItemStateError::NoFloorItem(*item_id))
.ok_or(ItemStateError::NoFloorItem(*item_id))
}
}

30
src/ship/location.rs

@ -12,7 +12,7 @@ pub enum AreaType {
}
#[derive(Debug, Copy, Clone, PartialEq)]
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub struct LobbyId(pub usize);
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq, derive_more::Display)]
@ -25,7 +25,7 @@ impl LobbyId {
}
#[derive(Error, Debug, PartialEq)]
#[derive(Error, Debug, PartialEq, Eq)]
#[error("create room")]
pub enum CreateRoomError {
NoOpenSlots,
@ -33,7 +33,7 @@ pub enum CreateRoomError {
JoinError,
}
#[derive(Error, Debug, PartialEq)]
#[derive(Error, Debug, PartialEq, Eq)]
#[error("join room")]
pub enum JoinRoomError {
RoomDoesNotExist,
@ -41,7 +41,7 @@ pub enum JoinRoomError {
ClientInAreaAlready,
}
#[derive(Error, Debug, PartialEq)]
#[derive(Error, Debug, PartialEq, Eq)]
#[error("join lobby")]
pub enum JoinLobbyError {
LobbyDoesNotExist,
@ -49,7 +49,7 @@ pub enum JoinLobbyError {
ClientInAreaAlready,
}
#[derive(Error, Debug, PartialEq)]
#[derive(Error, Debug, PartialEq, Eq)]
#[error("get area")]
pub enum GetAreaError {
NotInRoom,
@ -57,28 +57,28 @@ pub enum GetAreaError {
InvalidClient,
}
#[derive(Error, Debug, PartialEq)]
#[derive(Error, Debug, PartialEq, Eq)]
#[error("client removal")]
pub enum ClientRemovalError {
ClientNotInArea,
InvalidArea,
}
#[derive(Error, Debug, PartialEq)]
#[derive(Error, Debug, PartialEq, Eq)]
#[error("get clients")]
pub enum GetClientsError {
InvalidClient,
InvalidArea,
}
#[derive(Error, Debug, PartialEq)]
#[derive(Error, Debug, PartialEq, Eq)]
#[error("get neighbor")]
pub enum GetNeighborError {
InvalidClient,
InvalidArea,
}
#[derive(Error, Debug, PartialEq)]
#[derive(Error, Debug, PartialEq, Eq)]
#[error("get leader")]
pub enum GetLeaderError {
InvalidClient,
@ -86,7 +86,7 @@ pub enum GetLeaderError {
NoClientInArea,
}
#[derive(Error, Debug, PartialEq)]
#[derive(Error, Debug, PartialEq, Eq)]
#[error("clientlocation")]
pub enum ClientLocationError {
CreateRoomError(#[from] CreateRoomError),
@ -100,7 +100,7 @@ pub enum ClientLocationError {
}
#[derive(Debug, Copy, Clone, PartialEq)]
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub struct LocalClientId(usize);
impl LocalClientId {
@ -115,19 +115,19 @@ impl PartialEq<u8> for LocalClientId {
}
}
#[derive(Debug, Copy, Clone, PartialEq)]
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub struct AreaClient {
pub client: ClientId,
pub local_client: LocalClientId,
time_join: SystemTime,
}
#[derive(Debug, Copy, Clone, PartialEq)]
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
struct Lobby([Option<AreaClient>; 12]);
#[derive(Debug, Copy, Clone, PartialEq)]
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
struct Room([Option<AreaClient>; 4]);
#[derive(Debug, Copy, Clone, PartialEq)]
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum RoomLobby {
Room(RoomId),
Lobby(LobbyId),

2
src/ship/map/area.rs

@ -4,7 +4,7 @@ use std::collections::HashMap;
use thiserror::Error;
use crate::ship::room::Episode;
#[derive(Debug, Copy, Clone, PartialEq, Serialize, Deserialize)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub enum MapArea {
Pioneer2Ep1,
Forest1,

2
src/ship/map/variant.rs

@ -5,7 +5,7 @@ use rand::Rng;
// TODO: don't use *
use crate::ship::map::*;
#[derive(Debug, PartialEq)]
#[derive(Debug, PartialEq, Eq)]
pub enum MapVariantMode {
Online,
Offline,

17
src/ship/packet/handler/direct_message.rs

@ -24,15 +24,11 @@ const SHOP_OPTION_TOOL: u8 = 0;
const SHOP_OPTION_WEAPON: u8 = 1;
const SHOP_OPTION_ARMOR: u8 = 2;
const INVENTORY_MESETA_CAPACITY: u32 = 999999;
const BANK_MESETA_CAPACITY: u32 = 999999;
//const BANK_ACTION_: u8 = 1;
#[derive(thiserror::Error, Debug)]
#[error("")]
pub enum MessageError {
#[error("invalid tek {0}")]
InvalidTek(ClientItemId),
#[error("mismatched tek {0} {1}")]
MismatchedTekIds(ClientItemId, ClientItemId),
}
@ -158,7 +154,7 @@ where
};
//match item_manager.character_picks_up_item(entity_gateway, &mut client.character, ClientItemId(pickup_item.item_id)).await {
match pick_up_item(item_state, entity_gateway, &mut client.character, &ClientItemId(pickup_item.item_id)).await {
match pick_up_item(item_state, entity_gateway, &client.character, &ClientItemId(pickup_item.item_id)).await {
Ok(trigger_create_item) => {
let remove_packets: Box<dyn Iterator<Item=(ClientId, SendShipPacket)> + Send> = match floor_type {
FloorType::Local => {
@ -374,7 +370,7 @@ where
}
};
let inventory_item = buy_shop_item(item_state, entity_gateway, &mut client.character, item, ClientItemId(buy_item.item_id), buy_item.amount as u32).await?;
let inventory_item = buy_shop_item(item_state, entity_gateway, &client.character, item, ClientItemId(buy_item.item_id), buy_item.amount as u32).await?;
let create = builder::message::create_withdrawn_inventory_item(area_client, &inventory_item)?;
if remove {
@ -432,11 +428,10 @@ where
let inventory = item_state.get_character_inventory(&client.character)?;
let item = inventory.get_by_client_id(&ClientItemId(tek_request.item_id))
.ok_or(ItemStateError::WrongItemType(ClientItemId(tek_request.item_id)))?;
let mut weapon = item.item.as_individual()
let mut weapon = *item.item.as_individual()
.ok_or(ItemStateError::WrongItemType(ClientItemId(tek_request.item_id)))?
.as_weapon()
.ok_or(ItemStateError::WrongItemType(ClientItemId(tek_request.item_id)))?
.clone();
.ok_or(ItemStateError::WrongItemType(ClientItemId(tek_request.item_id)))?;
weapon.apply_modifier(&item::weapon::WeaponModifier::Tekked {
special: special_mod,

15
src/ship/packet/handler/trade.rs

@ -10,10 +10,8 @@ use crate::ship::trade::{TradeItem, TradeState, TradeStatus};
use crate::entity::gateway::EntityGateway;
use crate::ship::packet::builder;
use crate::ship::items::actions::trade_items;
use crate::entity::item::ItemDetail;
use crate::entity::item::tool::Tool;
use crate::ship::location::AreaClient;
use crate::entity::item::{Meseta, ItemNote};
use crate::ship::location::{AreaClient, RoomId};
use crate::entity::item::Meseta;
pub const MESETA_ITEM_ID: ClientItemId = ClientItemId(0xFFFFFF01);
pub const OTHER_MESETA_ITEM_ID: ClientItemId = ClientItemId(0xFFFFFFFF);
@ -441,9 +439,9 @@ where
{
enum TradeReady<'a> {
OnePlayer,
BothPlayers(crate::ship::location::RoomId,
(crate::ship::location::AreaClient, &'a crate::ship::ship::ClientState, crate::ship::trade::ClientTradeState),
(crate::ship::location::AreaClient, &'a crate::ship::ship::ClientState, crate::ship::trade::ClientTradeState)),
BothPlayers(RoomId,
(AreaClient, &'a crate::ship::ship::ClientState, crate::ship::trade::ClientTradeState),
(AreaClient, &'a crate::ship::ship::ClientState, crate::ship::trade::ClientTradeState)),
}
let trade_instructions = trades
@ -476,7 +474,7 @@ where
TradeReady::OnePlayer => {
Ok(Box::new(None.into_iter()) as Box<dyn Iterator<Item = (ClientId, SendShipPacket)> + Send>)
},
TradeReady::BothPlayers(room_id, (this_local_client, this_client, this), (other_local_client, other_client, other)) => {
TradeReady::BothPlayers(_room_id, (this_local_client, this_client, this), (other_local_client, other_client, other)) => {
let remove_item_packets = this.items
.clone()
.into_iter()
@ -495,7 +493,6 @@ where
let (this_new_items, other_new_items) = trade_items(item_state,
entity_gateway,
room_id,
(&this_local_client, &this_client.character, &this.items, Meseta(this.meseta as u32)),
(&other_local_client, &other_client.character, &other.items, Meseta(other.meseta as u32))).await?;

Loading…
Cancel
Save