/// <summary> /// Data binding for entry selection combo box on change /// </summary> /// <param name="sender">The object initiating the event (unused)</param> /// <param name="e">The event args (unused)</param> private void onEntryComboChanged(object sender, EventArgs e) { if (_lock) { return; } _lock = true; ItemJSON item = null; foreach (KeyValuePair <string, ItemJSON> kvp in ItemDatabaseJSON.Instance.Database) { if (kvp.Key == _entryCombo.Text) { item = kvp.Value; _itemTypeCombo.SelectedIndex = (int)Enum.Parse(typeof(ItemType), item.Type) - 1; _nameText.Text = item.Name; break; } } if (item == null) { setAddItemMode(); } else { setReplaceItemMode(); } setItemDefaults(); _lock = false; }
/// <summary> /// Inititializes a new instance of the Technique class from a JSON specification /// </summary> /// <param name="json">The JSON specification to initialize from.</param> public Technique(ItemJSON json) : base(json) { if (json.Technique == null) { throw new Exception("Invalid Technique JSON specification!"); } TechType = (TechniqueType)Enum.Parse(typeof(TechniqueType), json.Technique.TechType); RequiredMST = json.Technique.RequirementMST; string levelValue = string.Empty; int index = Name.Length - 1; var nameArr = Name.ToCharArray(); while (char.IsDigit(nameArr[index]) && index > 0) { levelValue = nameArr[index] + levelValue; index--; } if (levelValue.Length > 0) { Level = int.Parse(levelValue); } }
/// <summary> /// Creates an Item from an ItemJSON specification /// </summary> /// <param name="json">The ItemJSON specification to create the item from</param> /// <returns>The created item</returns> public static Item MakeItemFromJSON(ItemJSON json) { ItemType itemType = (ItemType)Enum.Parse(typeof(ItemType), json.Type); if (itemType == ItemType.Weapon) { return(new Weapon(json)); } else if (itemType == ItemType.Frame || itemType == ItemType.Barrier) { return(new DefenseItem(json)); } else if (itemType == ItemType.Unit) { return(new Unit(json)); } else if (itemType == ItemType.Mag) { return(new Mag(json)); } else if (itemType == ItemType.Technique) { return(new Technique(json)); } else if (itemType == ItemType.Tool) { return(new Tool(json)); } throw new Exception("Unsupported item type!"); }
/// <summary> /// Inititializes a new instance of the Item class from a JSON specification /// </summary> /// <param name="json">The JSON specification to initialize from.</param> public Item(ItemJSON json) { Name = json.Name; HexString = json.Hex; Type = (ItemType)Enum.Parse(typeof(ItemType), json.Type); Rarity = json.Rarity; MaxStack = json.MaxStack; }
/// <summary> /// Replaces item in database based on form /// </summary> private void replaceItem() { ItemJSON item = formToJSON(); if (item != null) { ItemDatabaseJSON.Instance.ReplaceItem(item); } }
/// <summary> /// Inititializes a new instance of the Tool class from a JSON specification /// </summary> /// <param name="json">The JSON specification to initialize from.</param> public Tool(ItemJSON json) : base(json) { if (json.Tool == null) { throw new Exception("Invalid Tool JSON specification!"); } Rare = json.Tool.Rare; }
/// <summary> /// Data binding for Remove Item button click /// </summary> /// <param name="sender">The object initiating the event (unused)</param> /// <param name="e">The event args (unused)</param> private void onRemoveClicked(object sender, EventArgs e) { ItemJSON item = formToJSON(); if (item != null) { ItemDatabaseJSON.Instance.RemoveItem(item); refreshEntryList(); } }
/// <summary> /// Inititializes a new instance of the Unit class from a JSON specification /// </summary> /// <param name="json">The JSON specification to initialize from.</param> public Unit(ItemJSON json) : base(json) { if (json.Unit == null) { throw new Exception("Invalid Unit JSON specification!"); } EquipMask = json.Unit.EquipMask; setStatsToJSON(json.Unit.Stats); setResistancesToJSON(json.Unit.Resistances); }
/// <summary> /// Adds item to database based on current state of form /// </summary> private void addItem() { ItemJSON item = formToJSON(); if (item != null) { ItemDatabaseJSON.Instance.AddItem(item); //_nameText.Text = String.Empty; refreshEntryList(); } }
/// <summary> /// Inititializes a new instance of the Mag class from a JSON specification /// </summary> /// <param name="json">The JSON specification to initialize from.</param> public Mag(ItemJSON json) : base(json) { if (json.Mag == null) { throw new Exception("Invalid Mag JSON specification!"); } TriggerPercentage = json.Mag.TriggerPercentage; PhotonBlastTrigger = (TriggerType)Enum.Parse(typeof(TriggerType), json.Mag.PBTrigger); HPTrigger = (TriggerType)Enum.Parse(typeof(TriggerType), json.Mag.HPTrigger); BossTrigger = (TriggerType)Enum.Parse(typeof(TriggerType), json.Mag.BossTrigger); }
/// <summary> /// Inititializes a new instance of the DefenseItem class from a JSON specification /// </summary> /// <param name="json">The JSON specification to initialize from.</param> public DefenseItem(ItemJSON json) : base(json) { if (json.Defense == null) { throw new Exception("Invalid DefenseItem JSON specification!"); } EquipMask = json.Defense.EquipMask; setStatsToJSON(json.Defense.Stats); setResistancesToJSON(json.Defense.Resistances); RequirementLevel = json.Defense.RequirementLevel; MaxDFP = json.Defense.MaxDFP; MaxEVP = json.Defense.MaxEVP; Frame = Type == ItemType.Frame; }
/// <summary> /// Data binding for name text box on change /// </summary> /// <param name="sender">The object initiating the event (unused)</param> /// <param name="e">The event args (unused)</param> private void onNameTextChanged(object sender, EventArgs e) { if (_lock) { return; } _lock = true; ItemJSON item = null; foreach (KeyValuePair <string, ItemJSON> kvp in ItemDatabaseJSON.Instance.Database) { if (kvp.Key.ToLower() == _nameText.Text.ToLower()) { item = kvp.Value; _itemTypeCombo.SelectedIndex = (int)Enum.Parse(typeof(ItemType), item.Type) - 1; _nameText.Text = item.Name; for (int i = 0; i < _entryCombo.Items.Count; i++) { if (_entryCombo.Items[i].ToString().ToLower() == kvp.Key.ToLower()) { _entryCombo.SelectedIndex = i; break; } } break; } } if (item == null) { setAddItemMode(); _entryCombo.SelectedIndex = _entryCombo.Items.Count - 1; } else { setReplaceItemMode(); } setItemDefaults(); _lock = false; }
/// <summary> /// Inititializes a new instance of the Weapon class from a JSON specification /// </summary> /// <param name="json">The JSON specification to initialize from.</param> public Weapon(ItemJSON json) : base(json) { if (json.Weapon == null) { throw new Exception("Invalid Weapon JSON specification!"); } EquipMask = json.Weapon.EquipMask; setStatsToJSON(json.Weapon.Stats); setResistancesToJSON(json.Weapon.Resistances); WeaponType = (WeaponType)Enum.Parse(typeof(WeaponType), json.Weapon.WeaponType); Special = (SpecialType)Enum.Parse(typeof(SpecialType), json.Weapon.Special); Targets = json.Weapon.Targets; MaxGrind = json.Weapon.MaxGrind; MinATP = json.Weapon.MinATP; MaxATP = json.Weapon.MaxATP; RequirementATP = json.Weapon.RequirementATP; RequirementATA = json.Weapon.RequirementATA; RequirementMST = json.Weapon.RequirementMST; SRank = json.Weapon.SRank; }
public async Task <bool> UpdateItemAsync(Item item) { var newItem = new ItemJSON { _id = item.Id, Text = item.Text, Description = item.Description }; string jsonString = Newtonsoft.Json.JsonConvert.SerializeObject(newItem); var httpContent = new StringContent(jsonString, Encoding.UTF8, "application/json"); Uri uri = new Uri(string.Format(webService + "/save/" + newItem._id, newItem)); HttpClient client = new HttpClient(); var response = await client.PostAsync(uri, httpContent); // return(await Task.FromResult(true)); }
public async Task <bool> DeleteItemAsync(string id) { try { var ignore = new ItemJSON(); string jsonString = Newtonsoft.Json.JsonConvert.SerializeObject(ignore); var httpContent = new StringContent(jsonString, Encoding.UTF8, "application/json"); Uri uri = new Uri(string.Format(webService + "/delete/" + id, string.Empty)); HttpClient client = new HttpClient(); var response = await client.PostAsync(uri, httpContent); } catch (Exception ex) { Console.WriteLine("Error: " + ex.Message); } return(await Task.FromResult(true)); }
/// <summary> /// Inititializes a new instance of the EquippableItem class from a JSON specification /// </summary> /// <param name="json">The JSON specification to initialize from.</param> public EquippableItem(ItemJSON json) : base(json) { }
/// <summary> /// Sets the form values based on an ItemJSON object /// </summary> private void setFormToItemJSON() { ItemJSON item = null; foreach (KeyValuePair <string, ItemJSON> kvp in ItemDatabaseJSON.Instance.Database) { if (kvp.Key == _nameText.Text) { item = kvp.Value; break; } } if (item == null) { return; } try { _itemTypeCombo.SelectedIndex = (int)Enum.Parse(typeof(ItemType), item.Type) - 1; _nameText.Text = item.Name; _hexText.Text = item.Hex; _rarityText.Text = item.Rarity.ToString(); _maxStackText.Text = item.MaxStack.ToString(); if (item.Weapon != null) { _weaponTypeCombo.SelectedIndex = (int)Enum.Parse(typeof(WeaponType), item.Weapon.WeaponType); _specialCombo.SelectedIndex = (int)Enum.Parse(typeof(SpecialType), item.Weapon.Special); _targetsText.Text = item.Weapon.Targets.ToString(); _maxGrindText.Text = item.Weapon.MaxGrind.ToString(); _minATPText.Text = item.Weapon.MinATP.ToString(); _maxATPText.Text = item.Weapon.MaxATP.ToString(); _requirementATPText.Text = item.Weapon.RequirementATP.ToString(); _requirementATAText.Text = item.Weapon.RequirementATA.ToString(); _requirementMSTText.Text = item.Weapon.RequirementMST.ToString(); _sRankCheck.Checked = item.Weapon.SRank; setStatsToItemJSON(item.Weapon.Stats); setResistancesToItemJSON(item.Weapon.Resistances); setEquipsToItemJSON(item.Weapon.EquipMask); } else if (item.Defense != null) { _requirementLevelText.Text = item.Defense.RequirementLevel.ToString(); _maxDFPText.Text = item.Defense.MaxDFP.ToString(); _maxEVPText.Text = item.Defense.MaxEVP.ToString(); setStatsToItemJSON(item.Defense.Stats); setResistancesToItemJSON(item.Defense.Resistances); setEquipsToItemJSON(item.Defense.EquipMask); } else if (item.Unit != null) { setStatsToItemJSON(item.Unit.Stats); setResistancesToItemJSON(item.Unit.Resistances); setEquipsToItemJSON(item.Unit.EquipMask); } else if (item.Mag != null) { _pbTriggerCombo.SelectedIndex = (int)Enum.Parse(typeof(Mag.TriggerType), item.Mag.PBTrigger); _hpTriggerCombo.SelectedIndex = (int)Enum.Parse(typeof(Mag.TriggerType), item.Mag.HPTrigger); _bossTriggerCombo.SelectedIndex = (int)Enum.Parse(typeof(Mag.TriggerType), item.Mag.BossTrigger); _triggerPercentageText.Text = item.Mag.TriggerPercentage.ToString(); } else if (item.Technique != null) { _techTypeCombo.SelectedIndex = (int)Enum.Parse(typeof(TechniqueType), item.Technique.TechType) - 1; _techMSTRequired.Text = item.Technique.RequirementMST.ToString(); } else if (item.Tool != null) { _rareCheck.Checked = item.Tool.Rare; } } catch (Exception ex) { MessageBox.Show("Error! Ill-formatted data!\n\n" + ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// Converts the current state of the form to an ItemJSON object /// </summary> /// <returns>An ItemJSON object based on the current state of the form</returns> private ItemJSON formToJSON() { ItemJSON item = new ItemJSON(); ItemType itemType = (ItemType)(_itemTypeCombo.SelectedIndex + 1); try { ItemStatsJSON stats = null; ItemResistancesJSON resistances = null; item.Type = Enum.GetName(typeof(ItemType), _itemTypeCombo.SelectedIndex + 1); item.Name = _nameText.Text; item.Hex = _hexText.Text; item.Rarity = int.Parse(_rarityText.Text); item.MaxStack = int.Parse(_maxStackText.Text); if (itemType == ItemType.Weapon) { item.Weapon = new ItemWeaponJSON(); item.Weapon.WeaponType = Enum.GetName(typeof(WeaponType), _weaponTypeCombo.SelectedIndex); item.Weapon.Special = Enum.GetName(typeof(SpecialType), _specialCombo.SelectedIndex); item.Weapon.Targets = int.Parse(_targetsText.Text); item.Weapon.MaxGrind = int.Parse(_maxGrindText.Text); item.Weapon.MinATP = int.Parse(_minATPText.Text); item.Weapon.MaxATP = int.Parse(_maxATPText.Text); item.Weapon.RequirementATP = int.Parse(_requirementATPText.Text); item.Weapon.RequirementATA = int.Parse(_requirementATAText.Text); item.Weapon.RequirementMST = int.Parse(_requirementMSTText.Text); item.Weapon.SRank = _sRankCheck.Checked; stats = item.Weapon.Stats; resistances = item.Weapon.Resistances; item.Weapon.EquipMask = getEquipMask(); } else if (itemType == ItemType.Frame || itemType == ItemType.Barrier) { item.Defense = new ItemDefenseJSON(); item.Defense.RequirementLevel = int.Parse(_requirementLevelText.Text); item.Defense.MaxDFP = int.Parse(_maxDFPText.Text); item.Defense.MaxEVP = int.Parse(_maxEVPText.Text); stats = item.Defense.Stats; resistances = item.Defense.Resistances; item.Defense.EquipMask = getEquipMask(); } else if (itemType == ItemType.Unit) { item.Unit = new ItemUnitJSON(); stats = item.Unit.Stats; resistances = item.Unit.Resistances; item.Unit.EquipMask = getEquipMask(); } else if (itemType == ItemType.Mag) { item.Mag = new ItemMagJSON(); item.Mag.PBTrigger = Enum.GetName(typeof(Mag.TriggerType), _pbTriggerCombo.SelectedIndex); item.Mag.HPTrigger = Enum.GetName(typeof(Mag.TriggerType), _hpTriggerCombo.SelectedIndex); item.Mag.BossTrigger = Enum.GetName(typeof(Mag.TriggerType), _bossTriggerCombo.SelectedIndex); item.Mag.TriggerPercentage = int.Parse(_triggerPercentageText.Text); } else if (itemType == ItemType.Technique) { item.Technique = new ItemTechniqueJSON(); item.Technique.TechType = Enum.GetName(typeof(TechniqueType), _techTypeCombo.SelectedIndex + 1); item.Technique.RequirementMST = int.Parse(_techMSTRequired.Text); } else if (itemType == ItemType.Tool) { item.Tool = new ItemToolJSON(); item.Tool.Rare = _rareCheck.Checked; } if (stats != null) { stats.HP = int.Parse(_hpText.Text); stats.TP = int.Parse(_tpText.Text); stats.ATP = int.Parse(_atpText.Text); stats.DFP = int.Parse(_dfpText.Text); stats.MST = int.Parse(_mstText.Text); stats.ATA = double.Parse(_ataText.Text); stats.EVP = int.Parse(_evpText.Text); stats.LCK = int.Parse(_lckText.Text); } if (resistances != null) { resistances.EFR = int.Parse(_efrText.Text); resistances.EIC = int.Parse(_eicText.Text); resistances.ETH = int.Parse(_ethText.Text); resistances.ELT = int.Parse(_eltText.Text); resistances.EDK = int.Parse(_edkText.Text); } return(item); } catch (Exception ex) { MessageBox.Show("Error! One or more fields not formatted properly!\n\n" + ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return(null); } }
/// <summary> /// Inititializes a new instance of the Item class from a JSON specification /// </summary> /// <param name="json">The JSON specification to initialize from.</param> public UnknownItem(ItemJSON json) { }