Browse Source

server unequips units now. formatting and cleanup unuseds. fix merge conflict

pbs
andy 4 years ago
parent
commit
555171d11d
  1. 2
      src/bin/main.rs
  2. 12
      src/ship/items/inventory.rs
  3. 1
      src/ship/items/manager.rs
  4. 34
      src/ship/packet/handler/message.rs

2
src/bin/main.rs

@ -247,7 +247,7 @@ fn main() {
NewItemEntity {
item: ItemDetail::Unit(
item::unit::Unit {
unit: item::unit::UnitType::KnightPower,
unit: item::unit::UnitType::HeavenlyPower,
modifier: Some(item::unit::UnitModifier::PlusPlus),
}
),

12
src/ship/items/inventory.rs

@ -408,13 +408,9 @@ impl CharacterInventory {
let (slot, _) = self.items.iter()
.enumerate()
.filter(|(_, item)| {
if let InventoryItem::Individual(individual_inventory_item) = item {
if let ItemDetail::Mag(_) = &individual_inventory_item.item {
return individual_inventory_item.equipped
}
}
if let InventoryItem::Individual(individual_inventory_item) = item {if let ItemDetail::Mag(_) = &individual_inventory_item.item {return individual_inventory_item.equipped }}
false
})
})
.nth(0)?;
Some(InventoryItemHandle {
inventory: self,
@ -573,5 +569,9 @@ impl CharacterInventory {
pub fn iter(&self) -> impl Iterator<Item = &InventoryItem> {
self.items.iter()
}
pub fn items(&self) -> &Vec<InventoryItem> {
&self.items
}
}

1
src/ship/items/manager.rs

@ -678,7 +678,6 @@ impl ItemManager {
Ok(())
}
pub async fn use_item<EG: EntityGateway>(&mut self,
used_item: ConsumedItem,
entity_gateway: &mut EG,

34
src/ship/packet/handler/message.rs

@ -1,13 +1,11 @@
use libpso::packet::ship::*;
use libpso::packet::messages::*;
use crate::entity::gateway::EntityGateway;
use crate::entity::item::ItemDetail;
use crate::entity::item::tool::ToolType;
use crate::entity::item::{ItemType};
use crate::common::serverstate::ClientId;
use crate::common::leveltable::CharacterLevelTable;
use crate::ship::ship::{SendShipPacket, ShipError, Rooms, Clients, ItemDropLocation};
use crate::ship::location::{ClientLocation, ClientLocationError};
use crate::ship::map::{MapArea};
use crate::ship::items::{ItemManager, ClientItemId};
use crate::ship::packet::builder;
@ -275,7 +273,7 @@ pub async fn player_used_medical_center<EG>(id: ClientId,
clients: &mut Clients)
-> Result<Box<dyn Iterator<Item = (ClientId, SendShipPacket)> + Send>, ShipError>
where
EG: EntityGateway
EG: EntityGateway
{
let client = clients.get_mut(&id).ok_or(ShipError::ClientNotFound(id))?;
if client.character.meseta >= 10 {
@ -332,7 +330,29 @@ where
EG: EntityGateway
{
let client = clients.get(&id).ok_or(ShipError::ClientNotFound(id))?;
item_manager.player_unequips_item(entity_gateway, &client.character, ClientItemId(pkt.item_id)).await?;
Ok(Box::new(None.into_iter()))
}
let equipped_unit_ids: Vec<ClientItemId> = {
item_manager.player_unequips_item(entity_gateway, &client.character, ClientItemId(pkt.item_id)).await?;
let inventory = item_manager.get_character_inventory(&client.character).unwrap();
let ue_item = inventory.get_item_by_id(ClientItemId(pkt.item_id)).ok_or(ShipError::ItemError)?;
if let ItemType::Armor(_) = ue_item.item_type() {
inventory.items()
.iter()
.filter(|inv_item| {
if let ItemType::Unit(_) = inv_item.item_type() {
return inv_item.equipped()
}
false
})
.map(|u| u.item_id())
.collect()
} else {
Vec::new()
}
};
for unit_id in equipped_unit_ids {
item_manager.player_unequips_item(entity_gateway, &client.character, unit_id).await;
}
Ok(Box::new(None.into_iter()))
}
Loading…
Cancel
Save