|
|
@ -630,6 +630,77 @@ 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> {
|
|
|
|
if amount > self.meseta.0 {
|
|
|
|
return Err(ItemStateError::InvalidMesetaRemoval(amount))
|
|
|
|
}
|
|
|
|
self.meseta.0 -= amount;
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn equip(&mut self, item_id: &ClientItemId, equip_slot: u8) {
|
|
|
|
for item in &self.inventory.0 {
|
|
|
|
if let InventoryItemDetail::Individual(inventory_item) = &item.item {
|
|
|
|
if item.item_id == *item_id {
|
|
|
|
match inventory_item.item {
|
|
|
|
ItemDetail::Weapon(_) => self.equipped.weapon = Some(inventory_item.entity_id),
|
|
|
|
ItemDetail::Armor(_) => self.equipped.armor = Some(inventory_item.entity_id),
|
|
|
|
ItemDetail::Shield(_) => self.equipped.shield = Some(inventory_item.entity_id),
|
|
|
|
ItemDetail::Unit(_) => {
|
|
|
|
if let Some(unit) = self.equipped.unit.get_mut(equip_slot as usize) {
|
|
|
|
*unit = Some(inventory_item.entity_id)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ItemDetail::Mag(_) => self.equipped.mag = Some(inventory_item.entity_id),
|
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn unequip(&mut self, item_id: &ClientItemId) {
|
|
|
|
for item in &self.inventory.0 {
|
|
|
|
if let InventoryItemDetail::Individual(inventory_item) = &item.item {
|
|
|
|
if item.item_id == *item_id {
|
|
|
|
match inventory_item.item {
|
|
|
|
ItemDetail::Weapon(_) => self.equipped.weapon = None,
|
|
|
|
ItemDetail::Armor(_) => {
|
|
|
|
self.equipped.armor = None;
|
|
|
|
self.equipped.unit = [None; 4];
|
|
|
|
}
|
|
|
|
ItemDetail::Shield(_) => self.equipped.shield = None,
|
|
|
|
ItemDetail::Unit(_) => {
|
|
|
|
for unit in self.equipped.unit.iter_mut() {
|
|
|
|
if *unit == Some(inventory_item.entity_id) {
|
|
|
|
*unit = None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ItemDetail::Mag(_) => self.equipped.mag = Some(inventory_item.entity_id),
|
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn as_inventory_entity(&self, _character_id: &CharacterEntityId) -> InventoryEntity {
|
|
|
|
InventoryEntity {
|
|
|
|
items: self.inventory.0.iter()
|
|
|
@ -657,29 +728,10 @@ 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 as_equipped_entity(&self) -> EquippedEntity {
|
|
|
|
self.equipped.clone()
|
|
|
|
}
|
|
|
|
|
|
|
|
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> {
|
|
|
|
if amount > self.meseta.0 {
|
|
|
|
return Err(ItemStateError::InvalidMesetaRemoval(amount))
|
|
|
|
}
|
|
|
|
self.meseta.0 -= amount;
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn as_client_inventory_items(&self) -> [character::InventoryItem; 30] {
|
|
|
|
self.inventory.0.iter()
|
|
|
|