public Model.HitPointChange GetHit(Model.CreatureAttributes creatureAttributes) { Model.HitPointChange hitPointChange = new Model.HitPointChange(); bool askForInput = true; string feedback = null; while (askForInput) { SetSelectedWeapon(); View.HitPointChangeDialog damageDialog = new View.HitPointChangeDialog(feedback); damageDialog.DataContext = this; if (damageDialog.ShowDialog() == true) { List <int> damage = new List <int>(); try { if (Healing != "") { int healing = Convert.ToInt32(Healing); hitPointChange = new Model.Heal(healing); } else { if (Damage1 != "") { damage.Add(Convert.ToInt32(Damage1)); } if (Damage2 != "") { damage.Add(Convert.ToInt32(Damage2)); } if (Damage3 != "") { damage.Add(Convert.ToInt32(Damage3)); } Model.Weapon weapon = GetWeapon(); hitPointChange = new Model.Hit(damage, weapon, creatureAttributes); } askForInput = false; } catch (FormatException) { // Failed to parse input feedback = "Invalid format"; } } else { askForInput = false; } } return(hitPointChange); }
public HitPointChangeDialogViewModel(FullyObservableCollection <Model.WeaponSet> weaponList, string currentActorName, Model.HitPointChange hitPointChange) { _weaponList = weaponList; _currentActorName = currentActorName; _damageTypeSelectorViewModel1 = new DamageTypeSelectorViewModel(); _damageTypeSelectorViewModel2 = new DamageTypeSelectorViewModel(); _damageTypeSelectorViewModel3 = new DamageTypeSelectorViewModel(); if (hitPointChange is Model.Hit) { Model.Hit hit = hitPointChange as Model.Hit; _healing = ""; _damage1 = ""; _damage2 = ""; _damage3 = ""; _damage1 = hit.DamageSets[0].Amount.ToString(); if (hit.DamageSets.Count > 1) { _damage2 = hit.DamageSets[1].Amount.ToString(); if (hit.DamageSets.Count > 2) { _damage3 = hit.DamageSets[2].Amount.ToString(); } } int weaponIndex = GetWeaponIndexInList(hit.Weapon); if (weaponIndex >= 0) { SelectedWeapon = weaponIndex; } } else if (hitPointChange is Model.Heal) { Model.Heal heal = hitPointChange as Model.Heal; _healing = heal.Amount.ToString(); _damage1 = ""; _damage2 = ""; _damage3 = ""; _selectedWeapon = 0; _abilityDamage = false; } else { _damage1 = ""; _damage2 = ""; _damage3 = ""; _healing = ""; _selectedWeapon = 0; _abilityDamage = false; } }
private void ExecuteAddHitPointChange() { HitPointChangeDialogViewModel hitPointChangeDialogViewModel = new HitPointChangeDialogViewModel(WeaponList, CurrentActorName); Model.HitPointChange hitPointChange = hitPointChangeDialogViewModel.GetHit(Actor.GetEffectiveAttributes()); if (hitPointChange != null && (hitPointChange is Model.Heal || hitPointChange is Model.Hit)) { Actor.AddHitPointChange(hitPointChange); ActorUpdated(); } }