Browse Source

Merge pull request 'techs' (#264) from techs into master

pbs
jake 4 years ago
parent
commit
a25d400624
  1. 4
      src/entity/character.rs
  2. 10
      src/ship/items/manager.rs
  3. 2
      src/ship/packet/handler/message.rs
  4. 17
      tests/test_item_use.rs

4
src/entity/character.rs

@ -173,7 +173,7 @@ impl CharacterTechniques {
} }
pub fn set_tech(&mut self, tech: Technique, level: TechLevel) { pub fn set_tech(&mut self, tech: Technique, level: TechLevel) {
self.techs.insert(tech, level);
self.techs.insert(tech, TechLevel(level.0 - 1));
} }
// from_bytes // from_bytes
@ -182,7 +182,7 @@ impl CharacterTechniques {
self.techs.iter() self.techs.iter()
.fold([0xFF; 20], |mut techlist, (tech, level)| { .fold([0xFF; 20], |mut techlist, (tech, level)| {
let index = tech.as_value(); let index = tech.as_value();
techlist[index as usize] = level.0 - 1;
techlist[index as usize] = level.0;
techlist techlist
}) })
} }

10
src/ship/items/manager.rs

@ -2,7 +2,7 @@ use crate::ship::items::ClientItemId;
use std::collections::{HashMap, BTreeMap}; use std::collections::{HashMap, BTreeMap};
use thiserror::Error; use thiserror::Error;
use crate::entity::gateway::EntityGateway; use crate::entity::gateway::EntityGateway;
use crate::entity::character::{CharacterEntity, CharacterEntityId};
use crate::entity::character::{CharacterEntity, CharacterEntityId, TechLevel};
use crate::entity::item::{ItemDetail, ItemLocation, BankName}; use crate::entity::item::{ItemDetail, ItemLocation, BankName};
use crate::entity::item::{Meseta, NewItemEntity, ItemEntity, InventoryItemEntity, EquippedEntity, InventoryEntity, BankItemEntity, BankEntity}; use crate::entity::item::{Meseta, NewItemEntity, ItemEntity, InventoryItemEntity, EquippedEntity, InventoryEntity, BankItemEntity, BankEntity};
use crate::entity::item::tool::{Tool, ToolType}; use crate::entity::item::tool::{Tool, ToolType};
@ -490,13 +490,19 @@ impl ItemManager {
pub async fn player_consumes_tool<EG: EntityGateway>(&mut self, pub async fn player_consumes_tool<EG: EntityGateway>(&mut self,
entity_gateway: &mut EG, entity_gateway: &mut EG,
character: &CharacterEntity,
character: &mut CharacterEntity,
item_id: ClientItemId, item_id: ClientItemId,
amount: usize) amount: usize)
-> Result<ConsumedItem, ItemManagerError> { -> Result<ConsumedItem, ItemManagerError> {
let inventory = self.character_inventory.get_mut(&character.id).ok_or(ItemManagerError::NoCharacter(character.id))?; let inventory = self.character_inventory.get_mut(&character.id).ok_or(ItemManagerError::NoCharacter(character.id))?;
let used_item = inventory.get_item_handle_by_id(item_id).ok_or(ItemManagerError::NoSuchItemId(item_id))?; let used_item = inventory.get_item_handle_by_id(item_id).ok_or(ItemManagerError::NoSuchItemId(item_id))?;
let consumed_item = used_item.consume(amount)?; let consumed_item = used_item.consume(amount)?;
if let ItemDetail::TechniqueDisk(tech_disk) = consumed_item.item() {
// TODO: validate tech level in packet is in bounds [1..30]
character.techs.set_tech(tech_disk.tech, TechLevel(tech_disk.level as u8));
entity_gateway.save_character(character).await?;
};
for entity_id in consumed_item.entity_ids() { for entity_id in consumed_item.entity_ids() {
entity_gateway.change_item_location(&entity_id, entity_gateway.change_item_location(&entity_id,

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

@ -261,7 +261,7 @@ where
EG: EntityGateway EG: EntityGateway
{ {
let client = clients.get_mut(&id).ok_or(ShipError::ClientNotFound(id))?; let client = clients.get_mut(&id).ok_or(ShipError::ClientNotFound(id))?;
let item_used_type = item_manager.player_consumes_tool(entity_gateway, &client.character, ClientItemId(player_use_tool.item_id), 1).await?;
let item_used_type = item_manager.player_consumes_tool(entity_gateway, &mut client.character, ClientItemId(player_use_tool.item_id), 1).await?;
item_manager.use_item(item_used_type, entity_gateway, &mut client.character).await?; item_manager.use_item(item_used_type, entity_gateway, &mut client.character).await?;
Ok(Box::new(None.into_iter())) Ok(Box::new(None.into_iter()))

17
tests/test_item_use.rs

@ -266,3 +266,20 @@ async fn test_use_materials() {
assert!(char.materials.luck == 2); assert!(char.materials.luck == 2);
} }
#[async_std::test]
pub async fn test_learn_new_tech() {}
#[async_std::test]
pub async fn test_new_fo_has_foie_1() {}
#[async_std::test]
pub async fn test_char_cannot_use_lower_level_tech() {}
#[async_std::test]
pub async fn test_char_cannot_learn_wrong_tech() {}
#[async_std::test]
pub async fn test_char_cannot_learn_high_level_tech() {}
#[async_std::test]
pub async fn test_android_cannot_learn_tech() {}
Loading…
Cancel
Save