Skip to content

Commit

Permalink
Merge pull request #25 from ZakisM/development
Browse files Browse the repository at this point in the history
Fix ability points after changing character level/experience
  • Loading branch information
ZakisM authored Sep 10, 2021
2 parents 4f4e7f2 + ab3cae6 commit 2bbbb78
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 39 deletions.
92 changes: 57 additions & 35 deletions bl3_save_edit_core/src/bl3_save/character_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ use crate::protos::oak_shared::{
};
use crate::vehicle_data::{VehicleName, VehicleStats};

pub const MAX_CHARACTER_LEVEL: usize = 72;

#[derive(Derivative)]
#[derivative(Debug, Clone, Default, Eq, PartialEq, Ord, PartialOrd)]
pub struct CharacterData {
Expand Down Expand Up @@ -367,25 +369,33 @@ impl CharacterData {
}

pub fn set_player_class(&mut self, player_class: PlayerClass) -> Result<()> {
let player_class_data = self
.character
.player_class_data
.as_mut()
.with_context(|| "failed to read Player Class data")?;
if player_class != self.player_class {
let player_class_data = self
.character
.player_class_data
.as_mut()
.with_context(|| "failed to read Player Class data")?;

player_class_data.player_class_path = player_class.get_serializations()[0].to_string();
player_class_data.player_class_path = player_class.get_serializations()[0].to_string();

let ability_data = self
.character
.ability_data
.as_mut()
.context("failed to read Player ability data")?;
let ability_data = self
.character
.ability_data
.as_mut()
.context("failed to read Player ability data")?;

if self.player_level > 2 {
ability_data.ability_points = self.player_level - 2;
}
//Reset our skill tree also
ability_data
.tree_item_list
.iter_mut()
.for_each(|ti| ti.points = 0);

self.player_class = player_class;
if self.player_level > 2 {
ability_data.ability_points = self.player_level - 2;
}

self.player_class = player_class;
}

Ok(())
}
Expand All @@ -395,31 +405,43 @@ impl CharacterData {
}

pub fn set_player_level(&mut self, experience_points: i32) -> Result<()> {
self.player_level = experience_to_level(experience_points).with_context(|| {
format!(
"failed to set level for experience points: {}",
experience_points
)
})?;
if experience_points != self.character.experience_points {
self.player_level = experience_to_level(experience_points).with_context(|| {
format!(
"failed to set level for experience points: {}",
experience_points
)
})?;

self.character.experience_points = experience_points;
self.character.experience_points = experience_points;

self.set_game_stat(LEVEL_STAT, self.player_level);
self.set_game_stat(LEVEL_STAT, self.player_level);

let ability_data = self
.character
.ability_data
.as_mut()
.context("failed to read Player ability data")?;
let ability_data = self
.character
.ability_data
.as_mut()
.context("failed to read Player ability data")?;

//Unlock skill tree
if self.player_level > 1 && ability_data.tree_grade == 0 {
ability_data.tree_grade = 2;
}
//Reset existing skill tree
ability_data
.tree_item_list
.iter_mut()
.for_each(|ti| ti.points = 0);

for (challenge_level, challenge_obj) in LEVEL_CHALLENGES {
if self.player_level >= challenge_level {
self.unlock_challenge_obj(challenge_obj, 1, 0)?;
//Unlock skill tree
if self.player_level > 1 && ability_data.tree_grade == 0 {
ability_data.tree_grade = 2;
}

if self.player_level > 2 {
ability_data.ability_points = self.player_level - 2;
}

for (challenge_level, challenge_obj) in LEVEL_CHALLENGES {
if self.player_level >= challenge_level {
self.unlock_challenge_obj(challenge_obj, 1, 0)?;
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion bl3_save_edit_ui/src/views/item_editor/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use iced::{
};

use bl3_save_edit_core::bl3_item::{BalancePart, Bl3Item, InvDataPart, ManufacturerPart};
use bl3_save_edit_core::bl3_save::character_data::MAX_CHARACTER_LEVEL;
use bl3_save_edit_core::resources::{
INVENTORY_BALANCE_PARTS, INVENTORY_INV_DATA_PARTS, INVENTORY_MANUFACTURER_PARTS,
INVENTORY_PARTS_ALL_CATEGORIZED, INVENTORY_SERIAL_DB_PARTS_CATEGORIZED,
Expand All @@ -15,7 +16,6 @@ use crate::resources::fonts::{JETBRAINS_MONO, JETBRAINS_MONO_BOLD};
use crate::views::item_editor::available_parts::AvailableParts;
use crate::views::item_editor::current_parts::CurrentParts;
use crate::views::item_editor::ItemEditorInteractionMessage;
use crate::views::manage_save::character::MAX_CHARACTER_LEVEL;
use crate::views::InteractionExt;
use crate::widgets::labelled_element::LabelledElement;
use crate::widgets::number_input::NumberInput;
Expand Down
2 changes: 1 addition & 1 deletion bl3_save_edit_ui/src/views/item_editor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use bl3_save_edit_core::bl3_item::{
MAX_BL3_ITEM_PARTS,
};
use bl3_save_edit_core::bl3_profile::Bl3Profile;
use bl3_save_edit_core::bl3_save::character_data::MAX_CHARACTER_LEVEL;
use bl3_save_edit_core::bl3_save::Bl3Save;
use bl3_save_edit_core::resources::INVENTORY_SERIAL_DB;

Expand All @@ -22,7 +23,6 @@ use crate::views::item_editor::available_parts::AvailablePartTypeIndex;
use crate::views::item_editor::current_parts::CurrentPartTypeIndex;
use crate::views::item_editor::item_editor_list_item::ItemEditorListItem;
use crate::views::item_editor::parts_tab_bar::{AvailablePartType, CurrentPartType};
use crate::views::manage_save::character::MAX_CHARACTER_LEVEL;
use crate::views::InteractionExt;
use crate::widgets::labelled_element::LabelledElement;
use crate::widgets::notification::{Notification, NotificationSentiment};
Expand Down
3 changes: 1 addition & 2 deletions bl3_save_edit_ui/src/views/manage_save/character/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use iced::{
pick_list, text_input, tooltip, Align, Column, Container, Length, PickList, Row, Tooltip,
};

use bl3_save_edit_core::bl3_save::character_data::MAX_CHARACTER_LEVEL;
use bl3_save_edit_core::bl3_save::player_class::PlayerClass;
use bl3_save_edit_core::bl3_save::util::REQUIRED_XP_LIST;
use bl3_save_edit_core::game_data::GameDataKv;
Expand All @@ -24,8 +25,6 @@ mod gear;
mod sdu;
mod skins;

pub const MAX_CHARACTER_LEVEL: usize = 72;

#[derive(Debug, Default)]
pub struct CharacterState {
pub name_input: String,
Expand Down

0 comments on commit 2bbbb78

Please sign in to comment.