private void _miEditDrop_Click(object sender, RoutedEventArgs e) { if (_lv.SelectedItems.Count <= 0) { return; } Table <int, ReadableTuple <int> > btable = _tab.ProjectDatabase.GetMetaTable <int>(ServerDbs.Mobs); try { var selectedItem = (MobDropView)_lv.SelectedItem; DropEditDialog dialog = new DropEditDialog(selectedItem.ID.ToString(CultureInfo.InvariantCulture), selectedItem.DropOriginal.ToString(CultureInfo.InvariantCulture), ServerDbs.Items, _tab.ProjectDatabase); dialog.Owner = WpfUtilities.TopWindow; if (dialog.ShowDialog() == true) { string sid = dialog.Id; string svalue = dialog.DropChance; int value; int id; Int32.TryParse(sid, out id); if (!Extensions.GetIntFromFloatValue(svalue, out value)) { ErrorHandler.HandleException("Invalid format (integer or float value only)"); return; } if (id <= 0) { return; } try { btable.Commands.Begin(); btable.Commands.Set(selectedItem.Tuple, selectedItem.AttributeIndex, id); btable.Commands.Set(selectedItem.Tuple, selectedItem.AttributeIndex + 1, value); } finally { btable.Commands.EndEdit(); } selectedItem.Update(); } } catch (Exception err) { ErrorHandler.HandleException(err); } btable.Commands.EndEdit(); }
private void _miAddDrop_Click(object sender, RoutedEventArgs e) { if (_lv.Items.Count >= 3) { ErrorHandler.HandleException("You cannot add more than 3 MVP drops. Delete an item and then add a new one."); return; } Table <int, ReadableTuple <int> > btable = _tab.ProjectDatabase.GetMetaTable <int>(ServerDbs.Mobs); try { DropEditDialog dialog = new DropEditDialog("", "", ServerDbs.Items, _tab.ProjectDatabase, false, (DbPathLocator.IsYamlMob() ? 2 : 0)); dialog.Owner = WpfUtilities.TopWindow; if (dialog.ShowDialog() == true) { string sid = dialog.Id; string svalue = dialog.DropChance; string randGroup = ""; int value; int id; if (DbPathLocator.IsYamlMob()) { randGroup = dialog.RandGroup; } Int32.TryParse(sid, out id); if (id <= 0) { return; } if (!Extensions.GetIntFromFloatValue(svalue, out value)) { ErrorHandler.HandleException("Invalid format (integer or float value only)"); return; } TValue item = (TValue)_tab.List.SelectedItem; try { btable.Commands.Begin(); int startIndex = ServerMobAttributes.Mvp1ID.Index; for (int i = 0; i < 6; i += 2) { if (item.GetValue <int>(startIndex + i) == 0) { btable.Commands.Set((ReadableTuple <int>)(object) item, startIndex + i, id); btable.Commands.Set((ReadableTuple <int>)(object) item, startIndex + i + 1, value); if (DbPathLocator.IsYamlMob()) { btable.Commands.Set((ReadableTuple <int>)(object) item, ServerMobAttributes.Mvp1RandomOptionGroup.Index + (i / 2), randGroup); } break; } } } finally { btable.Commands.EndEdit(); } _lv.ItemsSource = null; _updateAction(item); } } catch (Exception err) { ErrorHandler.HandleException(err); } }
private void _miPaste_Click(object sender, RoutedEventArgs e) { try { if (_lv.Items.Count >= 3) { ErrorHandler.HandleException("You cannot add more than 3 drops. Delete an item and then add a new one."); return; } if (_tab.List.SelectedItem == null) { return; } if (!Clipboard.ContainsText()) { return; } string text = Clipboard.GetText(); string[] elementsToAdd = text.Split(','); if (DbPathLocator.IsYamlMob()) { if (elementsToAdd.Length % 3 != 0) { throw new Exception("The number of arguments must be even."); } Table <int, ReadableTuple <int> > btable = _tab.ProjectDatabase.GetMetaTable <int>(ServerDbs.Mobs); try { TValue item = (TValue)_tab.List.SelectedItem; try { btable.Commands.Begin(); int startIndex = ServerMobAttributes.Mvp1ID.Index; int i = 0; for (int j = 0; j < elementsToAdd.Length; j += 3) { string sid = elementsToAdd[j]; string svalue = elementsToAdd[j + 1]; string randGroup = elementsToAdd[j + 2]; int value; int id; Int32.TryParse(sid, out id); if (id <= 0) { return; } if (!Extensions.GetIntFromFloatValue(svalue, out value)) { ErrorHandler.HandleException("Invalid format (integer or float value only)"); return; } for (; i < 6; i += 2) { if (item.GetValue <int>(startIndex + i) == 0) { btable.Commands.Set((ReadableTuple <int>)(object) item, startIndex + i, id); btable.Commands.Set((ReadableTuple <int>)(object) item, startIndex + i + 1, value); btable.Commands.Set((ReadableTuple <int>)(object) item, ServerMobAttributes.Mvp1RandomOptionGroup.Index + (i / 2), randGroup); i += 2; break; } } } } finally { btable.Commands.EndEdit(); } _lv.ItemsSource = null; _updateAction(item); } catch (Exception err) { ErrorHandler.HandleException(err); } } else { if (elementsToAdd.Length % 2 != 0) { throw new Exception("The number of arguments must be even."); } Table <int, ReadableTuple <int> > btable = _tab.ProjectDatabase.GetMetaTable <int>(ServerDbs.Mobs); try { TValue item = (TValue)_tab.List.SelectedItem; try { btable.Commands.Begin(); int startIndex = ServerMobAttributes.Mvp1ID.Index; int i = 0; for (int j = 0; j < elementsToAdd.Length; j += 2) { string sid = elementsToAdd[j]; string svalue = elementsToAdd[j + 1]; int value; int id; Int32.TryParse(sid, out id); if (id <= 0) { return; } if (!Extensions.GetIntFromFloatValue(svalue, out value)) { ErrorHandler.HandleException("Invalid format (integer or float value only)"); return; } for (; i < 6; i += 2) { if (item.GetValue <int>(startIndex + i) == 0) { btable.Commands.Set((ReadableTuple <int>)(object) item, startIndex + i, id); btable.Commands.Set((ReadableTuple <int>)(object) item, startIndex + i + 1, value); i += 2; break; } } } } finally { btable.Commands.EndEdit(); } _lv.ItemsSource = null; _updateAction(item); } catch (Exception err) { ErrorHandler.HandleException(err); } } } catch (Exception err) { ErrorHandler.HandleException(err); } }
private void _miAddDrop_Click(object sender, RoutedEventArgs e) { if (_lv.Items.Count >= 10) { ErrorHandler.HandleException("You cannot add more than 10 drops. Delete an item and then add a new one."); return; } Table <int, ReadableTuple <int> > btable = _tab.ProjectDatabase.GetMetaTable <int>(ServerDbs.Mobs); try { DropEditDialog dialog = new DropEditDialog("", "", ServerDbs.Items, _tab.ProjectDatabase, true); dialog.Owner = WpfUtilities.TopWindow; if (dialog.ShowDialog() == true) { string sid = dialog.Id; string svalue = dialog.DropChance; int value; int id; Int32.TryParse(sid, out id); if (id <= 0) { return; } if (!Extensions.GetIntFromFloatValue(svalue, out value)) { ErrorHandler.HandleException("Invalid format (integer or float value only)"); return; } TValue item = (TValue)_tab.List.SelectedItem; try { btable.Commands.Begin(); int startIndex = ServerMobAttributes.Drop1ID.Index; for (int i = 0; i < 18; i += 2) { if (item.GetValue <int>(startIndex + i) == 0) { btable.Commands.Set((ReadableTuple <int>)(object) item, startIndex + i, id); btable.Commands.Set((ReadableTuple <int>)(object) item, startIndex + i + 1, value); break; } } } finally { btable.Commands.EndEdit(); } //_lv.Items.OfType<MobDropView>().ToList().ForEach(p => p.RemoveEvents()); _lv.ItemsSource = null; _updateAction(item); } } catch (Exception err) { ErrorHandler.HandleException(err); } }
private void _miEditDrop_Click(object sender, RoutedEventArgs e) { if (_lv.SelectedItems.Count <= 0) { return; } Table <int, ReadableTuple <int> > btable = _tab.ProjectDatabase.GetMetaTable <int>(ServerDbs.Mobs); try { var selectedItem = (MobDropView)_lv.SelectedItem; DropEditDialog dialog = new DropEditDialog(selectedItem.ID.ToString(CultureInfo.InvariantCulture), selectedItem.DropOriginal.ToString(CultureInfo.InvariantCulture), ServerDbs.Items, _tab.ProjectDatabase, false, DbPathLocator.IsYamlMob() ? 3 : 0); if (DbPathLocator.IsYamlMob()) { dialog._tbRandGroup.Text = selectedItem.RandomOptionGroup; dialog._tbStealProtected.IsChecked = selectedItem.StealProtected; } dialog.Owner = WpfUtilities.TopWindow; if (dialog.ShowDialog() == true) { string sid = dialog.Id; string svalue = dialog.DropChance; string randGroup = ""; bool stealProtected = false; int value; int id; if (DbPathLocator.IsYamlMob()) { randGroup = dialog.RandGroup; stealProtected = dialog.StealProtected; } Int32.TryParse(sid, out id); if (!Extensions.GetIntFromFloatValue(svalue, out value)) { ErrorHandler.HandleException("Invalid format (integer or float value only)"); return; } if (id <= 0) { return; } try { btable.Commands.Begin(); btable.Commands.Set(selectedItem.Tuple, selectedItem.AttributeIndex, id); btable.Commands.Set(selectedItem.Tuple, selectedItem.AttributeIndex + 1, value); if (DbPathLocator.IsYamlMob()) { int b = (selectedItem.AttributeIndex - ServerMobAttributes.Drop1ID.Index) / 2; int distRandGroup = ServerMobAttributes.Drop1RandomOptionGroup.Index + b; int distSteal = ServerMobAttributes.Drop1Flags.Index + b; btable.Commands.Set(selectedItem.Tuple, distRandGroup, randGroup); btable.Commands.Set(selectedItem.Tuple, distSteal, stealProtected.ToString()); } } finally { btable.Commands.EndEdit(); } selectedItem.Update(); } } catch (Exception err) { ErrorHandler.HandleException(err); } btable.Commands.EndEdit(); }
private void _miEditDrop_Click(object sender, RoutedEventArgs e) { if (_lv.SelectedItems.Count <= 0) { return; } Table <int, ReadableTuple <int> > btable = _tab.ProjectDatabase.GetMetaTable <int>(ServerDbs.Mobs); int startIndex; try { var selectedItem = (MobDropView)_lv.SelectedItem; var p = btable.GetTuple(selectedItem.ID); string id = ((ReadableTuple <int>)_tab.List.SelectedItem).GetKey <int>().ToString(CultureInfo.InvariantCulture); InputDialog dialog = new InputDialog("Enter the new drop rate (integer or float)", "Drop rate", selectedItem.DropOriginal.ToString(CultureInfo.InvariantCulture)); dialog.Owner = WpfUtilities.TopWindow; dialog.TextBoxInput.Loaded += delegate { dialog.TextBoxInput.SelectAll(); dialog.TextBoxInput.Focus(); }; if (dialog.ShowDialog() == true) { string dResult = dialog.Input; int value; if (!Extensions.GetIntFromFloatValue(dResult, out value)) { ErrorHandler.HandleException("Invalid format (integer or float value only)"); return; } btable.Commands.Begin(); startIndex = ServerMobAttributes.Mvp1ID.Index; for (int j = 0; j < 6; j += 2) { if ((string)p.GetRawValue(startIndex + j) == id) { btable.Commands.Set(p, startIndex + j + 1, value); } } startIndex = ServerMobAttributes.Drop1ID.Index; for (int j = 0; j < 20; j += 2) { if ((string)p.GetRawValue(startIndex + j) == id) { btable.Commands.Set(p, startIndex + j + 1, value); break; } } } } catch (Exception err) { ErrorHandler.HandleException(err); } btable.Commands.EndEdit(); }
private void _miAddDrop_Click(bool mvp) { TValue item = (TValue)_tab.List.SelectedItem; Table <int, ReadableTuple <int> > btable = _tab.ProjectDatabase.GetMetaTable <int>(ServerDbs.Mobs); try { DropEditDialog dialog = new DropEditDialog("", "10.0 %", ServerDbs.Mobs, _tab.ProjectDatabase, true); dialog.Owner = WpfUtilities.TopWindow; if (dialog.ShowDialog() == true) { string sid = dialog.Id; string svalue = dialog.DropChance; int value; int id; Int32.TryParse(sid, out id); if (id <= 0) { return; } if (!Extensions.GetIntFromFloatValue(svalue, out value)) { ErrorHandler.HandleException("Invalid format (integer or float value only)"); return; } var tuple = btable.TryGetTuple(id); if (tuple == null) { ErrorHandler.HandleException("Mob id not found."); return; } try { btable.Commands.Begin(); bool added = false; if (mvp) { int startIndex = ServerMobAttributes.Mvp1ID.Index; for (int i = 0; i < 6; i += 2) { if (tuple.GetValue <int>(startIndex + i) == 0) { btable.Commands.Set(tuple, startIndex + i, item.GetKey <int>()); btable.Commands.Set(tuple, startIndex + i + 1, value); added = true; break; } } } else { int startIndex = ServerMobAttributes.Drop1ID.Index; for (int i = 0; i < 18; i += 2) { if (tuple.GetValue <int>(startIndex + i) == 0) { btable.Commands.Set(tuple, startIndex + i, item.GetKey <int>()); btable.Commands.Set(tuple, startIndex + i + 1, value); added = true; break; } } } if (!added) { ErrorHandler.HandleException("Couldn't add the item (no space left)."); } } finally { btable.Commands.EndEdit(); } _lv.ItemsSource = null; _update(item); } } catch (Exception err) { ErrorHandler.HandleException(err); } btable.Commands.EndEdit(); }
private void _miEditRequirement_Click(object sender, RoutedEventArgs e) { if (_lvRequirements.SelectedItems.Count <= 0 || _tab.List.SelectedItem == null) { return; } TValue item = (TValue)_tab.List.SelectedItem; var btable = _tab.Table; try { var selectedItem = (PetEvolutionTargetView)_lvRequirements.SelectedItem; DropEditDialog dialog = new DropEditDialog(selectedItem.ID.ToString(CultureInfo.InvariantCulture), selectedItem.Amount.ToString(CultureInfo.InvariantCulture), ServerDbs.Items, _tab.ProjectDatabase); dialog.Owner = WpfUtilities.TopWindow; dialog.Element2 = "Amount"; if (dialog.ShowDialog() == true) { string sid = dialog.Id; string svalue = dialog.DropChance; int value; int id; Int32.TryParse(sid, out id); if (!Extensions.GetIntFromFloatValue(svalue, out value)) { ErrorHandler.HandleException("Invalid format (integer or float value only)"); return; } if (id <= 0) { return; } try { btable.Commands.Begin(); _evolution = new Evolution(); foreach (var targetEv in _lv.Items.OfType <PetEvolutionView>()) { if (targetEv == _lv.SelectedItem) { List <Utilities.Extension.Tuple <object, int> > requirements = new List <Utilities.Extension.Tuple <object, int> >(); foreach (var requirement in _lvRequirements.Items.OfType <PetEvolutionTargetView>()) { if (requirement == _lvRequirements.SelectedItem) { requirements.Add(new Utilities.Extension.Tuple <object, int>(dialog.Id, value)); } else { requirements.Add(requirement.Requirement); } } targetEv.EvolutionTarget.ItemRequirements = requirements; } _evolution.Targets.Add(targetEv.EvolutionTarget); } btable.Commands.Set(item, ServerPetAttributes.Evolution, _evolution.ToString()); } finally { btable.Commands.EndEdit(); } _update(item); } } catch (Exception err) { ErrorHandler.HandleException(err); } btable.Commands.EndEdit(); }
private void _miAddCardDrop_Click(object sender, RoutedEventArgs e) { TValue item = (TValue)_tab.List.SelectedItem; if (item.GetValue <int>(ServerMobAttributes.DropCardid) != 0) { _lv.SelectedItem = _lv.Items.OfType <MobDropView>().FirstOrDefault(p => p.IsCard); _miEditDrop_Click(sender, e); return; } Table <int, ReadableTuple <int> > btable = _tab.GenericDatabase.GetMetaTable <int>(ServerDbs.Mobs); try { DropEdit dialog = new DropEdit("", "", ServerDbs.Items, _tab.GenericDatabase); dialog.Owner = WpfUtilities.TopWindow; if (dialog.ShowDialog() == true) { string sid = dialog.Id; string svalue = dialog.DropChance; int value; int id; Int32.TryParse(sid, out id); if (id <= 0) { return; } if (!Extensions.GetIntFromFloatValue(svalue, out value)) { ErrorHandler.HandleException("Invalid format (integer or float value only)"); return; } try { btable.Commands.BeginEdit(new GroupCommand <TKey, TValue>()); int startIndex = ServerMobAttributes.DropCardid.Index; for (int i = 0; i < 2; i += 2) { if (item.GetValue <int>(startIndex + i) == 0) { btable.Commands.Set((ReadableTuple <int>)(object) item, startIndex + i, id); btable.Commands.Set((ReadableTuple <int>)(object) item, startIndex + i + 1, value); break; } } } finally { btable.Commands.EndEdit(); } //_lv.Items.OfType<MobDropView>().ToList().ForEach(p => p.RemoveEvents()); _lv.ItemsSource = null; _updateAction(item); } } catch (Exception err) { ErrorHandler.HandleException(err); } }