private void itemsDGrV_CellValueNeeded(object sender, DataGridViewCellValueEventArgs e) { OrderItem item = player.Items.BuildOrders[e.RowIndex]; switch (e.ColumnIndex) { case 0: // Time e.Value = timeToString(item.Time); break; case 1: // Item Image if (DHHELPER.IsNewVersionItem(item.Name)) { e.Value = DHRC.GetImage(DHFormatter.ToString(DHLOOKUP.hpcUnitProfiles[item.Name, "Art"])); } else { e.Value = DHRC.GetImage(DHFormatter.ToString(DHLOOKUP.hpcItemProfiles[item.Name, "Art"])); } break; case 2: // Item Name if (DHHELPER.IsNewVersionItem(item.Name)) { e.Value = DHFormatter.ToString(DHLOOKUP.hpcUnitProfiles[item.Name, "Name"]); } else { e.Value = DHFormatter.ToString(DHLOOKUP.hpcItemProfiles[item.Name, "Name"]); } break; } }
internal item SellItemNormal(unit shop, HabProperties hpsItem) { string ID = hpsItem.name; IRecord item = Items.GetByUnit("codeID", ID); bool isNewVersionItem = DHHELPER.IsNewVersionItem(ID); if (!(item is item) && !(item is unit)) { item = isNewVersionItem ? (IRecord) new unit(hpsItem.name) : (IRecord) new item(hpsItem.name); Items.Add(item); } item = item.Clone(); if (isNewVersionItem) { (item as unit).DoSummon = true; (item as unit).set_owningPlayer(Current.unit.get_owningPlayer()); //! shop.OnSell(item as unit); // sell item as unit } else { shop.OnSellItem(item as item, Current.unit); } // pay the gold for this item int goldCost = isNewVersionItem ? (item as unit).goldCost : (item as item).goldCost; Current.player.Gold = Current.player.Gold - goldCost; return(item as item); }
internal static ItemType ItemTypeFromId(string stringId) { if (DHLOOKUP.hpcAbilityData == null) { return(ItemType.None); } //if (skillHeroes.ContainsValue(stringId)) if (DHLOOKUP.dcHeroesTaverns.ContainsKey(stringId)) { return(ItemType.Hero); } //if (skillHeroes.ContainsKey(stringId)) if (DHLOOKUP.dcAbilitiesHeroes.ContainsKey(stringId)) { return(ItemType.HeroAbility); } if (DHLOOKUP.hpcAbilityData.ContainsKey(stringId)) { return(ItemType.Ability); } //if (units.Contains(stringId)) if (DHLOOKUP.hpcUnitProfiles.ContainsKey(stringId)) { if (DHHELPER.IsNewVersionItem(stringId)) { return(ItemType.Item); } else { return(ItemType.Unit); } } if (buildingUpgrades.Contains(stringId)) { return(ItemType.Upgrade); } if (buildings.Contains(stringId)) { return(ItemType.Building); } //if (items.Contains(stringId)) if (DHLOOKUP.hpcItemProfiles.ContainsKey(stringId)) { return(ItemType.Item); } if (researches.Contains(stringId)) { return(ItemType.Research); } return(ItemType.None); }
internal void InitListByShop(unit shop) { HabPropertiesCollection hpcListItems = new HabPropertiesCollection(); if (shop == null) { InitList(DHLOOKUP.shops); } else { DBSTRINGCOLLECTION itemList; HabPropertiesCollection hpcItemProfiles; if (DHHELPER.IsNewVersionItemShop(shop)) { itemList = shop.sellunits; hpcItemProfiles = DHLOOKUP.hpcUnitProfiles; } else { itemList = shop.sellitems; hpcItemProfiles = DHLOOKUP.hpcItemProfiles; } foreach (string itemID in itemList) { HabProperties hps = hpcItemProfiles[itemID]; hpcListItems.Add(hps); } InitList(hpcListItems); } }
internal void InitList(List <unit> shops) { this.Width = this.width + 4; itemsLV.BeginUpdate(); // init list itemsLV.Items.Clear(); itemsLV.Groups.Clear(); foreach (unit s in shops) { ListViewGroup Group = new ListViewGroup(s.codeID, s.ID); Group.Tag = s; itemsLV.Groups.Add(Group); DBSTRINGCOLLECTION itemList; HabPropertiesCollection hpcItemProfiles; if (DHHELPER.IsNewVersionItemShop(s)) { itemList = s.sellunits; hpcItemProfiles = DHLOOKUP.hpcUnitProfiles; } else { itemList = s.sellitems; hpcItemProfiles = DHLOOKUP.hpcItemProfiles; } foreach (string itemID in itemList) { HabProperties hpsItem = hpcItemProfiles[itemID]; string iconName = hpsItem.GetStringValue("Art"); if (String.IsNullOrEmpty(iconName)) { continue; } ListViewItem lvi_Item = new ListViewItem(); lvi_Item.ImageKey = iconName; lvi_Item.Tag = hpsItem; lvi_Item.Group = Group; itemsLV.Items.Add(lvi_Item); } } itemsLV.EndUpdate(); DisplayCaption(); }
public bool Train(string ability, int time, int maxAllowedLevelForResearch) { if (time - possibleRetrainedTime < retrainTimeDelayAfterUsingTome) { if (lastRetrainTime != possibleRetrainedTime) { lastRetrainTime = possibleRetrainedTime; level = 0; dcAbilities = new Dictionary <string, int>(); abilitySets.Add(dcAbilities); } if (dcAbilities.ContainsKey(ability)) { dcAbilities[ability]++; } else { dcAbilities.Add(ability, 1); } level++; abilities.Order(new OrderItem(ability, time)); return(true); } else if (time - lastTrainTime > trainSkillDelay) { int abilityLevel; if (dcAbilities.TryGetValue(ability, out abilityLevel)) { abilityLevel++; } else { abilityLevel = 1; } int requriedHeroLevel = DHHELPER.GetRequiredHeroLevelForAbility(ability, abilityLevel); if (maxAllowedLevelForResearch < requriedHeroLevel) { return(false); } dcAbilities[ability] = abilityLevel; level++; lastTrainTime = time; abilities.Order(new OrderItem(ability, time, requriedHeroLevel)); return(true); } return(false); }
internal static string GetBestMatchAbilityForHero(Hero hero, string abilityId, ItemType type) { switch (type) { case ItemType.HeroAbility: return(abilityId); case ItemType.Ability: string similarAbilityId = DHHELPER.GetSimilarAbilityFromHero(hero.Name, abilityId); return((similarAbilityId == null) ? abilityId : similarAbilityId); default: return(abilityId); } }
public void showItemToolTip(HabProperties hpsItem, bool inventory) { UIRichTextEx.Default.ClearText(); if (hpsItem == null) { return; } UIRichTextEx.Default.AddTaggedText(DHFormatter.ToString(hpsItem.GetValue("Tip")), UIFonts.boldArial8, Color.White);//item.ID, UIFonts.boldArial8, Color.White); string gold = null; string mana = null; HabProperties hpsItemData; if (DHHELPER.IsNewVersionItem(hpsItem.name)) { hpsItemData = DHMpqDatabase.UnitSlkDatabase["UnitBalance"][hpsItem.name]; } else { hpsItemData = DHMpqDatabase.ItemSlkDatabase["ItemData"][hpsItem.name]; } bool pawnable = DHFormatter.ToBool(hpsItemData.GetValue("pawnable")); DBINT goldcost = new DBINT(hpsItemData.GetValue("goldcost")); //int goldcost = DHFormatter.ToInt(hpsItemData.GetValue("goldcost")); if ((inventory && !pawnable) == false) { gold = inventory ? (goldcost / 2) + "" : goldcost.Text; } ShowPrices(mana, gold); tipRTB.Rtf = UIRichTextEx.Default.CloseRtf(); UIRichTextEx.Default.ClearText(); UIRichTextEx.Default.AddTaggedText(DHFormatter.ToString(hpsItem.GetValue("UberTip")), UIFonts.boldArial8, Color.White);//item.description.Text, UIFonts.boldArial8, Color.White); ubertipRTB.Rtf = UIRichTextEx.Default.CloseRtf(); }
internal int GetGoldCost(item item) { string originalCodeID; if (ComplexItems == null) { if (MorphingItems.TryGetValue(item.codeID, out originalCodeID)) { if (DHHELPER.IsNewVersionItem(originalCodeID)) { return(DHMpqDatabase.UnitSlkDatabase["UnitBalance"][originalCodeID].GetIntValue("GoldCost")); } else { return(DHLOOKUP.hpcItemData[originalCodeID].GetIntValue("GoldCost")); } } else { return(item.goldCost); } } if (ComplexItemCosts == null) { ComplexItemCosts = new Dictionary <string, int>(ComplexItems.Count); } int result = 0; if (ComplexItemCosts.TryGetValue(item.codeID, out result)) { return(result); } List <List <string> > componentsList; if (!ComplexItems.TryGetValue(item.codeID, out componentsList)) { if (MorphingItems.TryGetValue(item.codeID, out originalCodeID)) { return(DHLOOKUP.hpcItemData[originalCodeID].GetIntValue("GoldCost")); } else { return(item.goldCost); } } List <string> components = componentsList[0]; foreach (string codeID in components) { if (!MorphingItems.TryGetValue(codeID, out originalCodeID)) { originalCodeID = codeID; } HabProperties hpsComponent = DHLOOKUP.hpcItemData[originalCodeID]; result += hpsComponent.GetIntValue("GoldCost"); } ComplexItemCosts.Add(item.codeID, result); return(result); }
public void CollectItemCombiningData() { if (MorphingItems != null) { return; } sameLookingComplexItems = null; Current.player.AcceptMessages = false; Dictionary <string, widget> dcItems = new Dictionary <string, widget>(); foreach (unit shop in DHLOOKUP.shops) { if (DHHELPER.IsNewVersionItemShop(shop)) { foreach (string unitID in shop.sellunits) { if (!dcItems.ContainsKey(unitID)) { unit u = new unit(unitID); u.DoSummon = true; u.set_owningPlayer(Current.player); dcItems.Add(unitID, u); } } } else { foreach (string itemID in shop.sellitems) { if (!dcItems.ContainsKey(itemID)) { dcItems.Add(itemID, new item(itemID)); } } } } unit test_unit = new unit(); test_unit.codeID = "test"; test_unit.Inventory.init(0, 10); test_unit.set_owningPlayer(Current.player); DHJassExecutor.CaughtReferences.Clear(); DHJassExecutor.CatchArrayReference = true; DBINVENTORY inventory = test_unit.Inventory; List <widget> itemList = new List <widget>(dcItems.Values); MorphingItems = new Dictionary <string, string>(itemList.Count); SplashScreen splashScreen = new SplashScreen(); splashScreen.Show(); splashScreen.ShowText("Collecting item combining data..."); for (int i = 0; i < itemList.Count; i++) { widget item = itemList[i]; if (DHHELPER.IsNewVersionItem(item.codeID)) { test_unit.OnSell(item as unit); Thread.Sleep(2); // to pass control to item handling script thread } else { test_unit.OnSellItem(item as item, test_unit); inventory.put_item(item as item); } item result = inventory[0].Item; if (result != null) { if (result.codeID != item.codeID) { MorphingItems.Add(result.codeID, item.codeID); } inventory[0].drop_item(); } splashScreen.ShowProgress((double)i, (double)itemList.Count); } Current.player.remove_unit(test_unit); test_unit.destroy(); List <string> arrays = DHJassExecutor.CaughtReferences; if (arrays.Count == 6) { Dictionary <int, DHJassValue> dcA = (DHJassExecutor.Globals[arrays[0]] as DHJassArray).Array; Dictionary <int, DHJassValue> dcB = (DHJassExecutor.Globals[arrays[1]] as DHJassArray).Array; Dictionary <int, DHJassValue> dcC = (DHJassExecutor.Globals[arrays[2]] as DHJassArray).Array; Dictionary <int, DHJassValue> dcD = (DHJassExecutor.Globals[arrays[3]] as DHJassArray).Array; Dictionary <int, DHJassValue> dcCombined = (DHJassExecutor.Globals[arrays[4]] as DHJassArray).Array; ComplexItems = new Dictionary <string, List <List <string> > >(dcA.Count); int value; foreach (int key in dcA.Keys) { List <string> components = new List <string>(4); value = dcA[key].IntValue; if (value != 0) { components.Add(DHJassInt.int2id(value)); } value = dcB[key].IntValue; if (value != 0) { components.Add(DHJassInt.int2id(value)); } value = dcC[key].IntValue; if (value != 0) { components.Add(DHJassInt.int2id(value)); } value = dcD[key].IntValue; if (value != 0) { components.Add(DHJassInt.int2id(value)); } value = dcCombined[key].IntValue; if (value != 0) { string strValue = DHJassInt.int2id(value); List <List <string> > componentsList; if (!ComplexItems.TryGetValue(strValue, out componentsList)) { componentsList = new List <List <string> >(1); ComplexItems.Add(strValue, componentsList); } componentsList.Add(components); } } } splashScreen.Close(); Current.player.AcceptMessages = true; }