move the tech level adjustment to prevent underflow for new FOs. let characters use tech disks
This commit is contained in:
parent
99f5f4eb5f
commit
55c393b7a8
@ -173,7 +173,7 @@ impl CharacterTechniques {
|
||||
}
|
||||
|
||||
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
|
||||
@ -182,7 +182,7 @@ impl CharacterTechniques {
|
||||
self.techs.iter()
|
||||
.fold([0xFF; 20], |mut techlist, (tech, level)| {
|
||||
let index = tech.as_value();
|
||||
techlist[index as usize] = level.0 - 1;
|
||||
techlist[index as usize] = level.0;
|
||||
techlist
|
||||
})
|
||||
}
|
||||
|
@ -2,7 +2,7 @@ use crate::ship::items::ClientItemId;
|
||||
use std::collections::{HashMap, BTreeMap};
|
||||
use thiserror::Error;
|
||||
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::{Meseta, NewItemEntity, ItemEntity, InventoryItemEntity, EquippedEntity, InventoryEntity, BankItemEntity, BankEntity};
|
||||
use crate::entity::item::tool::{Tool, ToolType};
|
||||
@ -490,7 +490,7 @@ impl ItemManager {
|
||||
|
||||
pub async fn player_consumes_tool<EG: EntityGateway>(&mut self,
|
||||
entity_gateway: &mut EG,
|
||||
character: &CharacterEntity,
|
||||
character: &mut CharacterEntity,
|
||||
item_id: ClientItemId,
|
||||
amount: usize)
|
||||
-> Result<ConsumedItem, ItemManagerError> {
|
||||
@ -498,6 +498,11 @@ impl ItemManager {
|
||||
let used_item = inventory.get_item_handle_by_id(item_id).ok_or(ItemManagerError::NoSuchItemId(item_id))?;
|
||||
let consumed_item = used_item.consume(amount)?;
|
||||
|
||||
if let ItemDetail::TechniqueDisk(tech_disk) = consumed_item.item() {
|
||||
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() {
|
||||
entity_gateway.change_item_location(&entity_id,
|
||||
ItemLocation::Consumed).await?;
|
||||
|
@ -261,7 +261,7 @@ where
|
||||
EG: EntityGateway
|
||||
{
|
||||
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?;
|
||||
Ok(Box::new(None.into_iter()))
|
||||
|
@ -266,3 +266,20 @@ async fn test_use_materials() {
|
||||
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…
x
Reference in New Issue
Block a user