diff --git a/osrs-toolbox/Models/CombatLevelModel.cs b/osrs-toolbox/Models/CombatLevelModel.cs new file mode 100644 index 0000000..132872f --- /dev/null +++ b/osrs-toolbox/Models/CombatLevelModel.cs @@ -0,0 +1,177 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Input; + +namespace osrs_toolbox +{ + public abstract class CombatLevelModel : ModelBase + { + private string _userName; + private int _attack; + private int _strength; + private int _hitpoints; + private int _defense; + private int _ranged; + private int _magic; + private int _prayer; + + private ICommand _loadPlayer; + + public string UserName + { + get { return _userName; } + set { SetProperty(ref _userName, value, nameof(UserName)); } + } + public int Attack + { + get { return _attack; } + set + { + SetProperty(ref _attack, value, nameof(Attack)); + UpdateOutput(); + } + } + public int Strength + { + get { return _strength; } + set + { + SetProperty(ref _strength, value, nameof(Strength)); + UpdateOutput(); + } + } + public int Hitpoints + { + get { return _hitpoints; } + set + { + SetProperty(ref _hitpoints, value, nameof(Hitpoints)); + UpdateOutput(); + } + } + public int Defense + { + get { return _defense; } + set + { + SetProperty(ref _defense, value, nameof(Defense)); + UpdateOutput(); + } + } + public int Ranged + { + get { return _ranged; } + set + { + SetProperty(ref _ranged, value, nameof(Ranged)); + UpdateOutput(); + } + } + public int Magic + { + get { return _magic; } + set + { + SetProperty(ref _magic, value, nameof(Magic)); + UpdateOutput(); + } + } + public int Prayer + { + get { return _prayer; } + set + { + SetProperty(ref _prayer, value, nameof(Prayer)); + UpdateOutput(); + } + } + + public ICommand LoadPlayer + { + get { return _loadPlayer; } + set { SetProperty(ref _loadPlayer, value, nameof(LoadPlayer)); } + } + + private void UpdateOutput() + { + OnPropertyChanged(nameof(CombatLevel)); + OnPropertyChanged(nameof(NextLevel)); + OnPropertyChanged(nameof(NeededAttack)); + OnPropertyChanged(nameof(NeededStrength)); + OnPropertyChanged(nameof(NeededDefense)); + OnPropertyChanged(nameof(NeededHitpoints)); + OnPropertyChanged(nameof(NeededRanged)); + OnPropertyChanged(nameof(NeededMagic)); + OnPropertyChanged(nameof(NeededPrayer)); + } + + public double CombatLevel => Math.Floor(0.25d * (Defense + Hitpoints + Math.Floor(Prayer / 2d)) + (0.325 * Math.Max(Math.Max(Attack + Strength, Ranged * 1.5d), Magic * 1.5d))); + public double NextLevel => Math.Min(126, CombatLevel + 1); + public string NeededAttack + { + get + { + double AttackCalc = Math.Ceiling((NextLevel - (0.25d * Defense) - (0.25d * Hitpoints) - (0.25d * Math.Floor(Prayer / 2d)) - (0.325 * Strength)) / 0.325d) - Attack; + if (AttackCalc + Attack > 99) return "-"; + else return AttackCalc.ToString(); + } + } + public string NeededStrength + { + get + { + double StrengthCalc = Math.Ceiling((NextLevel - (0.25d * Defense) - (0.25d * Hitpoints) - (0.25d * Math.Floor(Prayer / 2d)) - (0.325 * Attack)) / 0.325d) - Strength; + if (StrengthCalc + Strength > 99) return "-"; + else return StrengthCalc.ToString(); + } + } + public string NeededDefense + { + get + { + double DefenseCalc = Math.Ceiling((NextLevel - (0.25 * Hitpoints) - (0.25 * Math.Floor(Prayer / 2d)) - (0.325 * Math.Max(Math.Max(Attack + Strength, Ranged * 1.5d), Magic * 1.5d))) / 0.25) - Defense; + if (DefenseCalc + Defense > 99) return "-"; + else return DefenseCalc.ToString(); + } + } + public string NeededHitpoints + { + get + { + double HitpointsCalc = Math.Ceiling((NextLevel - (0.25d * Defense) - (0.25d * Math.Floor(Prayer / 2d)) - (0.325 * Math.Max(Math.Max(Attack + Strength, Ranged * 1.5d), Magic * 1.5d))) / 0.25d) - Hitpoints; + if (HitpointsCalc + Hitpoints > 99) return "-"; + else return HitpointsCalc.ToString(); + } + } + public string NeededRanged + { + get + { + double RangedCalc = Math.Ceiling((NextLevel - (0.25 * (Defense + Hitpoints + Math.Floor(Prayer / 2d)))) / 0.4875d) - Ranged; + if (RangedCalc + Ranged > 99) return "-"; + else return RangedCalc.ToString(); + } + } + public string NeededMagic + { + get + { + double MagicCalc = Math.Ceiling((NextLevel - (0.25 * (Defense + Hitpoints + Math.Floor(Prayer / 2d)))) / 0.4875d) - Magic; + if (MagicCalc + Magic > 99) return "-"; + else return MagicCalc.ToString(); + } + } + public string NeededPrayer + { + get + { + double PrayerCalc = Math.Ceiling((NextLevel - (0.25d * Hitpoints) - (0.25d * Defense) - (0.325 * Math.Max(Math.Max(Attack + Strength, Ranged * 1.5d), Magic * 1.5d))) / 0.125d) - Prayer; + if (PrayerCalc + Prayer > 99) return "-"; + else return PrayerCalc.ToString(); + } + } + } +} diff --git a/osrs-toolbox/Models/HomePageModel.cs b/osrs-toolbox/Models/HomePageModel.cs index da167d0..5a038c5 100644 --- a/osrs-toolbox/Models/HomePageModel.cs +++ b/osrs-toolbox/Models/HomePageModel.cs @@ -13,6 +13,7 @@ namespace osrs_toolbox { private ICommand _openCompetitionOverlaySettings; private ICommand _openDropChanceCalculator; + private ICommand _openCombatLevelCalculator; public ICommand OpenCompetitionOverlaySettings { @@ -25,5 +26,11 @@ namespace osrs_toolbox get { return _openDropChanceCalculator; } set { SetProperty(ref _openDropChanceCalculator, value, nameof(OpenDropChanceCalculator)); } } + + public ICommand OpenCombatLevelCalculator + { + get { return _openCombatLevelCalculator; } + set { SetProperty(ref _openCombatLevelCalculator, value, nameof(OpenCombatLevelCalculator)); } + } } } diff --git a/osrs-toolbox/ViewModels/CombatLevelViewModel.cs b/osrs-toolbox/ViewModels/CombatLevelViewModel.cs new file mode 100644 index 0000000..13b173a --- /dev/null +++ b/osrs-toolbox/ViewModels/CombatLevelViewModel.cs @@ -0,0 +1,62 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace osrs_toolbox +{ + public class CombatLevelViewModel : CombatLevelModel + { + public CombatLevelViewModel() + { + InitializeVariables(); + InitializeCommands(); + } + + private void InitializeVariables() + { + UserName = string.Empty; + Attack = 1; + Strength = 1; + Defense = 1; + Hitpoints = 10; + Ranged = 1; + Prayer = 1; + Magic = 1; + } + + private void InitializeCommands() + { + LoadPlayer = new RelayCommand(DoLoadPlayer); + } + + private void DoLoadPlayer(object obj) + { + Player p; + try + { + p = WiseOldMan.GetPlayer(UserName); + } + catch + { + InitializeVariables(); + UserName = "User Not Found on Wise Old Man"; + return; + } + if (p.latestSnapshot is null) + { + InitializeVariables(); + UserName = "User Not Found on Wise Old Man"; + return; + } + Attack = p.latestSnapshot.data.skills.attack.level; + Strength = p.latestSnapshot.data.skills.strength.level; + Defense = p.latestSnapshot.data.skills.defence.level; + Hitpoints = p.latestSnapshot.data.skills.hitpoints.level; + Ranged = p.latestSnapshot.data.skills.ranged.level; + Prayer = p.latestSnapshot.data.skills.prayer.level; + Magic = p.latestSnapshot.data.skills.magic.level; + } + } +} diff --git a/osrs-toolbox/ViewModels/HomePageViewModel.cs b/osrs-toolbox/ViewModels/HomePageViewModel.cs index bf6d503..1b55c12 100644 --- a/osrs-toolbox/ViewModels/HomePageViewModel.cs +++ b/osrs-toolbox/ViewModels/HomePageViewModel.cs @@ -24,6 +24,7 @@ namespace osrs_toolbox { OpenCompetitionOverlaySettings = new RelayCommand(DoOpenCompetitionOverlaySettings); OpenDropChanceCalculator = new RelayCommand(DoOpenDropChanceCalculator); + OpenCombatLevelCalculator = new RelayCommand(DoOpenCombatLevelCalculator); } private void DoOpenCompetitionOverlaySettings(object obj) @@ -53,5 +54,19 @@ namespace osrs_toolbox dcv.Show(); } } + + private void DoOpenCombatLevelCalculator(object obj) + { + if (CombatLevelView.Current != null) + { + CombatLevelView.Current.Close(); + CombatLevelView.Current = null; + } + else + { + CombatLevelView clv = new CombatLevelView(); + clv.Show(); + } + } } } diff --git a/osrs-toolbox/Views/CombatLevelView.xaml b/osrs-toolbox/Views/CombatLevelView.xaml new file mode 100644 index 0000000..c2c5179 --- /dev/null +++ b/osrs-toolbox/Views/CombatLevelView.xaml @@ -0,0 +1,61 @@ + + + + + + + + + + + + + + + + + + + + + + + + + +