Browse Source

add unit armour slots. equip the unit into the right slot and save correctly

pbs
andy 4 years ago
parent
commit
790668f6f7
  1. 40
      src/bin/main.rs
  2. 4
      src/entity/item/unit.rs
  3. 2
      src/ship/drops/generic_unit.rs
  4. 1
      src/ship/drops/rare_drop_table.rs
  5. 50
      src/ship/items/manager.rs
  6. 2
      src/ship/packet/handler/message.rs
  7. 1
      src/ship/shops/armor.rs

40
src/bin/main.rs

@ -234,6 +234,7 @@ fn main() {
item::unit::Unit {
unit: item::unit::UnitType::PriestMind,
modifier: Some(item::unit::UnitModifier::Minus),
armour_slot: 0,
}
),
location: ItemLocation::Inventory {
@ -247,8 +248,9 @@ fn main() {
NewItemEntity {
item: ItemDetail::Unit(
item::unit::Unit {
unit: item::unit::UnitType::HeavenlyPower,
modifier: Some(item::unit::UnitModifier::PlusPlus),
unit: item::unit::UnitType::PriestMind,
modifier: Some(item::unit::UnitModifier::Minus),
armour_slot: 1,
}
),
location: ItemLocation::Inventory {
@ -258,6 +260,38 @@ fn main() {
}
}
).await;
entity_gateway.create_item(
NewItemEntity {
item: ItemDetail::Unit(
item::unit::Unit {
unit: item::unit::UnitType::PriestMind,
modifier: Some(item::unit::UnitModifier::Minus),
armour_slot: 2,
}
),
location: ItemLocation::Inventory {
character_id: character.id,
slot: 9,
equipped: true,
}
}
).await;
entity_gateway.create_item(
NewItemEntity {
item: ItemDetail::Unit(
item::unit::Unit {
unit: item::unit::UnitType::PriestMind,
modifier: Some(item::unit::UnitModifier::Minus),
armour_slot: 3,
}
),
location: ItemLocation::Inventory {
character_id: character.id,
slot: 10,
equipped: true,
}
}
).await;
entity_gateway.create_item(
NewItemEntity {
item: ItemDetail::Mag(
@ -265,7 +299,7 @@ fn main() {
),
location: ItemLocation::Inventory {
character_id: character.id,
slot: 9,
slot: 11,
equipped: true,
}
}

4
src/entity/item/unit.rs

@ -335,6 +335,7 @@ pub enum UnitModifier {
pub struct Unit {
pub unit: UnitType,
pub modifier: Option<UnitModifier>,
pub armour_slot: u8, // 0 - 3 = armour slot 1 - 4
}
@ -361,7 +362,7 @@ impl Unit {
},
}
}
result[4] = self.armour_slot;
result
}
@ -379,6 +380,7 @@ impl Unit {
Ok(Unit{
unit: u.unwrap(),
modifier: m,
armour_slot: data[4],
})
}
else {

2
src/ship/drops/generic_unit.rs

@ -89,6 +89,7 @@ impl GenericUnitTable {
ItemDropType::Unit(Unit {
unit: unit_type,
modifier: unit_modifier,
armour_slot: 0,
})
})
}
@ -116,6 +117,7 @@ mod test {
assert!(gut.get_drop(&area, &mut rng) == Some(ItemDropType::Unit(Unit {
unit: unit,
modifier: umod,
armour_slot: 0,
})));
}
}

1
src/ship/drops/rare_drop_table.rs

@ -128,6 +128,7 @@ impl RareDropTable {
ItemDropType::Unit(Unit {
unit: unit,
modifier: None,
armour_slot: 0,
})
},
RareDropItem::Tool(tool) => {

50
src/ship/items/manager.rs

@ -4,8 +4,9 @@ use thiserror::Error;
use crate::entity::gateway::EntityGateway;
use crate::entity::character::{CharacterEntity, CharacterEntityId};
use crate::entity::item::{ItemDetail, ItemLocation, BankName};
use crate::entity::item::{Meseta, NewItemEntity};
use crate::entity::item::{Meseta, NewItemEntity, ItemEntity};
use crate::entity::item::tool::{Tool, ToolType};
use crate::entity::item::unit;
use crate::ship::map::MapArea;
use crate::ship::ship::ItemDropLocation;
use crate::ship::drops::{ItemDrop, ItemDropType};
@ -898,20 +899,43 @@ impl ItemManager {
pub async fn player_equips_item<EG: EntityGateway>(&mut self,
entity_gateway: &mut EG,
character: &CharacterEntity,
item_id: ClientItemId)
item_id: ClientItemId,
equip_slot: u8)
-> Result<(), ItemManagerError> {
let inventory = self.character_inventory.get_mut(&character.id).ok_or(ItemManagerError::NoCharacter(character.id))?;
let mut inventory_item_handle = inventory.get_item_handle_by_id(item_id).ok_or(ItemManagerError::NoSuchItemId(item_id))?;
let slot = inventory_item_handle.get_slot();
let inventory_item = inventory_item_handle.item_mut().ok_or(ItemManagerError::CannotGetMutItem)?.individual().ok_or(ItemManagerError::CannotGetIndividualItem)?;
inventory_item.equipped = true;
if let ItemDetail::Unit(u) = inventory_item.item {
if equip_slot > 0 {
inventory_item.item = ItemDetail::Unit(unit::Unit {
unit: u.unit,
modifier: u.modifier,
armour_slot: ((equip_slot & 0x7) - 1) % 4,
});
} else {
inventory_item.item = ItemDetail::Unit(unit::Unit {
unit: u.unit,
modifier: u.modifier,
armour_slot: 0,
});
}
};
entity_gateway.change_item_location(&inventory_item.entity_id, ItemLocation::Inventory{
character_id: character.id,
slot: slot,
equipped: true,
}).await;
entity_gateway.save_character(character).await;
entity_gateway.save_item(&ItemEntity{
id: inventory_item.entity_id,
location: ItemLocation::Inventory{
character_id: character.id,
slot: slot,
equipped: true,
},
item: inventory_item.item.clone(),
}).await;
Ok(())
}
@ -925,13 +949,27 @@ impl ItemManager {
let slot = inventory_item_handle.get_slot();
let inventory_item = inventory_item_handle.item_mut().ok_or(ItemManagerError::CannotGetMutItem)?.individual().ok_or(ItemManagerError::CannotGetIndividualItem)?;
inventory_item.equipped = false;
if let ItemDetail::Unit(u) = inventory_item.item {
inventory_item.item = ItemDetail::Unit(unit::Unit {
unit: u.unit,
modifier: u.modifier,
armour_slot: 0,
});
};
entity_gateway.change_item_location(&inventory_item.entity_id, ItemLocation::Inventory{
character_id: character.id,
slot: slot,
equipped: false,
}).await;
entity_gateway.save_character(character).await;
entity_gateway.save_item(&ItemEntity{
id: inventory_item.entity_id,
location: ItemLocation::Inventory{
character_id: character.id,
slot: slot,
equipped: false,
},
item: inventory_item.item.clone(),
}).await;
Ok(())
}
}

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

@ -316,7 +316,7 @@ where
EG: EntityGateway
{
let client = clients.get(&id).ok_or(ShipError::ClientNotFound(id))?;
item_manager.player_equips_item(entity_gateway, &client.character, ClientItemId(pkt.item_id)).await?;
item_manager.player_equips_item(entity_gateway, &client.character, ClientItemId(pkt.item_id), pkt.sub_menu).await?;
Ok(Box::new(None.into_iter()))
}

1
src/ship/shops/armor.rs

@ -89,6 +89,7 @@ impl ShopItem for ArmorShopItem {
ItemDetail::Unit(Unit {
unit: *unit,
modifier: None,
armour_slot: 0,
})
},
}

Loading…
Cancel
Save