public void DisplayHero(Player p) { if (p.Heroes.Count == 0) { playerNameLabel.Text = p.Name; return; } player = p; hero = p.GetMostUsedHero(); string imagePath = DHLOOKUP.hpcUnitProfiles[hero.Name, "Art"] as string; if (imagePath == null) return; heroImagePanel.BackgroundImage = DHRC.GetImage(imagePath); playerNameLabel.Text = p.Name; heroNameLabel.Text = DHFormatter.ToString(DHLOOKUP.hpcUnitProfiles[hero.Name, "Name"]); skillsDGrV.RowCount = hero.Abilities.BuildOrders.Count; itemsDGrV.RowCount = player.Items.BuildOrders.Count; }
private void OrderItem(Player player, uint itemId, int time, double x, double y, int objectID1, int objectID2) { // if this is orderID (not an objectID) if ((itemId >> 16) == 0x000D) { switch ((short)itemId) { case 0x0003: // rightclick player.Actions.Add(new PlayerAction( PlayerActionType.RightClick, x,y, time, objectID1, objectID2)); break; case 0x000F: // attack player.Actions.Add(new PlayerAction( PlayerActionType.Attack, x, y, time, objectID1, objectID2)); break; } return; } string stringId = DHJassInt.int2id(itemId);//ParserUtility.StringFromUInt(itemId); switch (ParserUtility.ItemTypeFromId(stringId)) { case ItemType.None: if ((itemId >> 16) == 0x00000233) player.Units.Order(new OrderItem("ubsp", time)); break; case ItemType.Hero: player.Heroes.Order(stringId, time); break; case ItemType.HeroAbility: Hero hero; if (player.State.IsResearching && (TryFindHeroByCache(player.State.CurrentSelection, out hero) || (hero = player.GetMostUsedHero())!=null) && hero.Train(stringId, time, player.State.MaxAllowedLevelForResearch))// player.Heroes.Train(stringId, time)) { player.State.CompleteResearch(); } break; case ItemType.Ability: if (player.State.IsResearching && (TryFindHeroByCache(player.State.CurrentSelection, out hero) || (hero = player.GetMostUsedHero()) != null) && hero.Train(ParserUtility.GetBestMatchAbilityForHero(hero, stringId, ItemType.Ability), time, player.State.MaxAllowedLevelForResearch)) { player.State.CompleteResearch(); } break; case ItemType.Building: player.Buildings.Order(new OrderItem(stringId, time)); break; case ItemType.Item: if (PlayerCanBuyItem(player, stringId, time)) { BuyItemForPlayer(player, stringId, time); player.Items.Order(new OrderItem(stringId, time)); } if (stringId == "tret") player.Heroes.PossibleRetrained(time); break; case ItemType.Unit: player.Units.Order(new OrderItem(stringId, time)); break; case ItemType.Upgrade: player.Upgrades.Order(new OrderItem(stringId, time)); ; break; case ItemType.Research: player.Researches.Order(new OrderItem(stringId, time)); ; break; } }
bool MakeSureHeroExists(Player player, int time, out Hero hero) { // check if the list of currently selected units contains objectId // that references hero in dcHeroCache int objectId1; if (TryFindHeroByCache(player.State.CurrentSelection, out hero, out objectId1)) { // if the hero object value is empty (which means this hero hasn't been used by anyone yet) if (hero.ObjectId == -1) { // get name of currently selected hero string heroName = hero.Name; // find hero that is owned by this player // and has same name as the hero currently selected Hero playerHero = player.Heroes[heroName]; // if this player does not own hero with specified name if (playerHero == null) { // then use the selected hero playerHero = hero; // add this hero to current player // (the player will own this hero from now on) player.Heroes.Order(playerHero, time); } else // if this player does have a hero with same name as the selected hero, // then use the player's own hero hero = playerHero; // assign object id to this hero hero.ObjectId = objectId1; // update hero-cache // this ensures that objectId contained in current selection // will reference the hero object that this player owns. dcHeroCache[objectId1] = hero; } else // if this hero has been already used by someone, // check if this player doesnt have any hero, // in which case add this hero to him (players probably used -swap command) if (player.Heroes.Count == 0) player.Heroes.Order(hero, time); IncreaseHeroUseCount(player, hero); return true; } else { // if hero cannot be found, just try to get most used hero hero = player.GetMostUsedHero(); return hero != null; } }