public ChatInfo(int time, Player from, TalkTo to, Player toPlayer, string message) { this.time = new TimeSpan(0, 0, 0, 0, time); this.from = from; this.to = to; this.toPlayer = toPlayer; this.message = message; }
public void AddSortedBySlot(Player p) { for(int i=0; i<players.Count; i++) if (p.SlotNo < players[i].SlotNo) { players.Insert(i, p); goto SETTYPE; } players.Add(p); SETTYPE: ; this.type = p.TeamType; }
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; }
bool PlayerCanBuyItem(Player p, string itemID, int time) { // only one shop can be selected at a time if (p.State.CurrentSelection.Count != 1) return false; Dictionary<string, int> dcItemsStockRegen; if (!dcShopItemsStockRegen.TryGetValue(p.State.CurrentSelection[0], out dcItemsStockRegen)) return true; int readyTime; if (!dcItemsStockRegen.TryGetValue(itemID, out readyTime)) return true; return time > readyTime; }
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; } }
private void CancelItem(Player player, uint itemId, int time) { if (itemId < 0x41000000 || itemId > 0x7a000000) return; string stringId = DHJassInt.int2id(itemId); //ParserUtility.StringFromUInt(itemId); switch (ParserUtility.ItemTypeFromId(stringId)) { case ItemType.None: break; case ItemType.Hero: player.Heroes.Cancel(stringId, time); break; case ItemType.Building: player.Buildings.Cancel(new OrderItem(stringId, time, true)); ; break; case ItemType.Research: player.Researches.Cancel(new OrderItem(stringId, time, true)); ; break; case ItemType.Unit: player.Units.Cancel(new OrderItem(stringId, time, true)); ; break; case ItemType.Upgrade: player.Upgrades.Cancel(new OrderItem(stringId, time, true)); ; break; } }
private void LoadPlayers(BinaryReader reader) { #region 4.0 [Decompressed data] #region doc // # | Size | Name //---+----------+-------------------------- // 1 | 4 byte | Unknown (0x00000110 - another record id?) // 2 | variable | PlayerRecord (see 4.1) // 3 | variable | GameName (null terminated string) (see 4.2) // 4 | 1 byte | Nullbyte // 5 | variable | Encoded String (null terminated) (see 4.3) // | | - GameSettings (see 4.4) // | | - Map&CreatorName (see 4.5) // 6 | 4 byte | PlayerCount (see 4.6) // 7 | 4 byte | GameType (see 4.7) // 8 | 4 byte | LanguageID (see 4.8) // 9 | variable | PlayerList (see 4.9) //10 | variable | GameStartRecord (see 4.11) #endregion //Unknown reader.ReadInt32(); host = new Player(); host.Load(reader); players.Add(host); type = host.GameType; name = ParserUtility.ReadString(reader); //nullbyte reader.ReadByte(); byte[] decoded = ParserUtility.GetDecodedBytes(reader); settings = new GameSettings(decoded); map = new MapInfo(ParserUtility.GetUInt(decoded, 9), ParserUtility.GetString(decoded, 13)); #endregion //playerCount, gameType, langId reader.ReadBytes(12); #region Player List while (reader.PeekChar() == 0x16) { #region doc //offset | size/type | Description //-------+-----------+----------------------------------------------------------- //0x0000 | 4/11 byte | PlayerRecord (see 4.1) //0x000? | 4 byte | unknown // | | (always 0x00000000 for patch version >= 1.07 // | | always 0x00000001 for patch version <= 1.06) #endregion Player p = new Player(); p.Load(reader); players.Add(p); reader.ReadBytes(4); } #endregion #region 4.10 [GameStartRecord] #region doc //offset | size/type | Description //-------+-----------+----------------------------------------------------------- //0x0000 | 1 byte | RecordID - always 0x19 //0x0001 | 1 word | number of data bytes following //0x0003 | 1 byte | nr of SlotRecords following (== nr of slots on startscreen) //0x0004 | n bytes | nr * SlotRecord (see 4.11) // n+4 | 1 dword | RandomSeed (see 4.12) // n+8 | 1 byte | SelectMode // | | 0x00 - team & race selectable (for standard custom games) // | | 0x01 - team not selectable // | | (map setting: fixed alliances in WorldEditor) // | | 0x03 - team & race not selectable // | | (map setting: fixed player properties in WorldEditor) // | | 0x04 - race fixed to random // | | (extended map options: random races selected) // | | 0xcc - Automated Match Making (ladder) // n+9 | 1 byte | StartSpotCount (nr. of start positions in map) #endregion //RecordId, number of data bytes following reader.ReadBytes(3); byte nSlots = reader.ReadByte(); for (byte i = 0; i < nSlots; i++) { #region 4.11 [SlotRecord] #region doc //offset | size/type | Description //-------+-----------+----------------------------------------------------------- //0x0000 | 1 byte | player id (0x00 for computer players) //0x0001 | 1 byte | map download percent: 0x64 in custom, 0xff in ladder //0x0002 | 1 byte | slotstatus: // | | 0x00 empty slot // | | 0x01 closed slot // | | 0x02 used slot //0x0003 | 1 byte | computer player flag: // | | 0x00 for human player // | | 0x01 for computer player //0x0004 | 1 byte | team number:0 - 11 // | | (team 12 == observer or referee) //0x0005 | 1 byte | color (0-11): // | | value+1 matches player colors in world editor: // | | (red, blue, cyan, purple, yellow, orange, green, // | | pink, gray, light blue, dark green, brown) // | | color 12 == observer or referee //0x0006 | 1 byte | player race flags (as selected on map screen): // | | 0x01=human // | | 0x02=orc // | | 0x04=nightelf // | | 0x08=undead // | | 0x20=random // | | 0x40=race selectable/fixed (see notes below) //0x0007 | 1 byte | computer AI strength: (only present in v1.03 or higher) // | | 0x00 for easy // | | 0x01 for normal // | | 0x02 for insane // | | for non-AI players this seems to be always 0x01 //0x0008 | 1 byte | player handicap in percent (as displayed on startscreen) // | | valid values: 0x32, 0x3C, 0x46, 0x50, 0x5A, 0x64 // | | (field only present in v1.07 or higher) #endregion #region byte playerId = reader.ReadByte(); reader.ReadByte(); byte slotStatus = reader.ReadByte(); byte computerFlag = reader.ReadByte(); byte teamNo = reader.ReadByte(); PlayerColor color = (PlayerColor)reader.ReadByte(); Race race = (Race)reader.ReadByte(); if ((uint)race > 0x40) race -= 0x40; AIStrength strength = (AIStrength)reader.ReadByte(); int handicap = reader.ReadByte(); #endregion #region if (slotStatus == 0x02) { Player player = GetPlayerById(playerId); if (playerId == 0 && /*player == null &&*/ computerFlag == 0x01) { player = new Player(); player.Race = race; player.Id = i; if (strength == AIStrength.Easy) player.Name = "Computer(Easy)"; else if (strength == AIStrength.Normal) player.Name = "Computer(Normal)"; else player.Name = "Computer(Insane)"; players.Add(player); } else if (player == null) { continue; } player.SlotNo = i; player.Color = color; player.Handicap = handicap; player.Id = playerId; player.IsComputer = computerFlag == 0x01; player.IsObserver = teamNo == 12; player.Race = race; player.TeamNo = teamNo; //+ 1; } #endregion #endregion } if (buildNo == 0 && nSlots == 0) { #region 6.1 Notes on official Blizzard Replays #region doc //o Since the lack of all slot records, one has to generate these data: //iterate slotNumber from 1 to number of PlayerRecords (see 4.1) // player id = slotNumber // slotstatus = 0x02 (used) // computerflag = 0x00 (human player) // team number = (slotNumber -1) mod 2 (team membership alternates in // PlayerRecord) // color = unknown (player gets random colors) // race = as in PlayerRecord // computerAI = 0x01 (non computer player) // handicap = 0x64 (100%) #endregion foreach (Player player in players) { player.SlotNo = player.Id; player.TeamNo = (player.SlotNo - 1) % 2; player.Handicap = 100; } #endregion } // sort players by their teams foreach (Player player in players) { // mark uninitialized players as Observers to avoid errors if (player.Race == 0 && player.TeamNo == 0) { Console.WriteLine("Warning: Player '" + player.Name + "' was not initialized and thus marked as Observer"); player.TeamNo = 12; player.IsObserver = true; } Team team = GetTeamByNo(player.TeamNo); team.AddSortedBySlot(player); } //random seed, select mode, startspotcount reader.ReadBytes(6); #endregion }
public HeroBuildView(Player p) : this() { DisplayHero(p); }
void displayHeroBuildOrder(Player p) { if (!openBuildsInForms) { foreach (TabPage page in replayTabControl.TabPages) if (page.Tag == p) { replayTabControl.SelectedTab = page; return; } replayTabControl.SuspendLayout(); TabPage tp = new TabPage(); HeroBuildView hbv = new HeroBuildView(p); tp.Controls.Add(hbv); tp.Text = p.Name; tp.Tag = p; tp.ToolTipText = p.Name + "'s Hero Build Order (Righ-Click to close)"; hbv.Dock = DockStyle.Fill; replayTabControl.TabPages.Add(tp); replayTabControl.SelectedTab = tp; replayTabControl.ResumeLayout(false); } else { Form buildForm = new Form(); buildForm.StartPosition = FormStartPosition.CenterScreen; buildForm.SuspendLayout(); HeroBuildView hbv = new HeroBuildView(p); buildForm.Controls.Add(hbv); buildForm.Text = p.Name + " - " + hbv.heroNameLabel.Text; buildForm.Tag = p; hbv.Dock = DockStyle.Fill; buildForm.Icon = Icon.FromHandle(((Bitmap)hbv.heroImagePanel.BackgroundImage).GetHicon()); buildForm.ClientSize = hbv.PreferredSize; buildForm.ResumeLayout(false); buildForm.Show(); } }
protected int[] getWardStatistics(Player p) { if (Current.map == null) return new int[] { 0 }; string result = string.Empty; int total = 0; int observer = 0; int sentry = 0; // get proper observer ward codeID string obsCodeID; if (DHLOOKUP.hpcItemProfiles.GetStringValue("sor7", "Name").Contains("Observer")) obsCodeID = "sor7"; else obsCodeID = "I05G"; // get proper sentry ward codeID string sentryCodeID; if (DHLOOKUP.hpcItemProfiles.GetStringValue("tgrh", "Name").Contains("Sentry")) sentryCodeID = "tgrh"; else sentryCodeID = "I05H"; int observerUses = DHFormatter.ToInt(DHLOOKUP.hpcItemData[obsCodeID, "uses"]); int sentryUses = DHFormatter.ToInt(DHLOOKUP.hpcItemData[sentryCodeID, "uses"]); foreach (OrderItem item in p.Items.BuildOrders) { switch (item.Name) { // observer ward case "sor7": case "h02C": // new version obs ward total += observerUses; observer += observerUses; break; case "tgrh": case "h02D": // new version sentry ward total += sentryUses; sentry += sentryUses; break; } } return new int[3] { total, observer, sentry }; }
private void OrderItem(Player player, uint itemId, int time) { if (itemId < 0x41000000 || itemId > 0x7a000000) return; string stringId = 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: player.Heroes.Train(stringId, time); break; case ItemType.Building: player.Buildings.Order(new OrderItem(stringId, time)); break; case ItemType.Item: 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; } }
public KillInfo(int time, Player killer, Player victim) { this.time = new TimeSpan(0, 0, 0, 0, time); this.killer = killer; this.victim = victim; }
public void Add(Player p) { players.Add(p); this.type = p.TeamType; }
bool BuyItemForPlayer(Player p, string itemID, int time) { // only one shop can be selected at a time if (p.State.CurrentSelection.Count != 1) return false; Dictionary<string, int> dcItemsStockRegen; if (!dcShopItemsStockRegen.TryGetValue(p.State.CurrentSelection[0], out dcItemsStockRegen)) { dcItemsStockRegen = new Dictionary<string, int>(); dcShopItemsStockRegen.Add(p.State.CurrentSelection[0], dcItemsStockRegen); } // ready_time = time + stock_regen + 300 (buy delay) dcItemsStockRegen[itemID] = time + ParserUtility.GetItemStockRegen(itemID) + 350; return true; }
public bool IsClone(int time, Player player, string message) { return this.rawTime + 250 >= time && this.from == player && this.message == message; }
void placePlayerOnTheMap(Player player, Image img) { if (player.LineUp == LineUp.JungleOrRoaming) { double realX = player.LineUpLocation.x - Jass.Native.Constants.map.minX; double realY = Jass.Native.Constants.map.maxY - player.LineUpLocation.y; double mapWidth = Jass.Native.Constants.map.maxX - Jass.Native.Constants.map.minX; double mapHeight = Jass.Native.Constants.map.maxY - Jass.Native.Constants.map.minY; double scaledX = ((double)mapPanel.Width) * (realX / mapWidth); double scaledY = ((double)mapPanel.Height) * (realY / mapHeight); ToolStrip ts = new ToolStrip(); ts.BackColor = Color.Transparent; ts.GripStyle = ToolStripGripStyle.Hidden; ts.ImageScalingSize = sentinelBottomLineUpTS.ImageScalingSize; ts.Renderer = UIRenderers.NoBorderRenderer; ts.CanOverflow = false; ts.Dock = DockStyle.None; ts.LayoutStyle = ToolStripLayoutStyle.Flow; ts.Padding = new Padding(0); ToolStripButton tsb = new ToolStripButton(); tsb.Image = img; tsb.ToolTipText = player.Name; tsb.Margin = new Padding(0, 0, 0, 0); tsb.Padding = new Padding(1, 1, 0, 0); tsb.BackColor = player.TeamType == TeamType.Sentinel ? Color.Red : Color.Lime; tsb.Tag = player; tsb.Click += new EventHandler(playerToolStripButton_Click); tsb.MouseDown += new MouseEventHandler(playerToolStripButton_MouseDown); ts.Items.Add(tsb); mapPanel.Controls.Add(ts); ts.Left = (int)scaledX - (tsb.Width / 2); ts.Top = (int)scaledY - (tsb.Height / 2); } else { switch (player.LineUp) { case LineUp.Top: addPlayerToMapLineUp(player, img, (player.TeamType == TeamType.Sentinel) ? sentinelTopLineUpTS : scourgeTopLineUpTS, false, (player.TeamType == TeamType.Scourge)); break; case LineUp.Middle: addPlayerToMapLineUp(player, img, (player.TeamType == TeamType.Sentinel) ? sentinelMiddleLineUpTS : scourgeMiddleLineUpTS, true, (player.TeamType == TeamType.Scourge)); break; case LineUp.Bottom: addPlayerToMapLineUp(player, img, (player.TeamType == TeamType.Sentinel) ? sentinelBottomLineUpTS : scourgeBottomLineUpTS, false, (player.TeamType == TeamType.Scourge)); 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; } }
void addPlayerToMapLineUp(Player p, Image img, ToolStrip ts, bool useAlternativeLayout, bool downToUpDirection) { ToolStripButton tsb = new ToolStripButton(); tsb.Image = img; tsb.ToolTipText = p.Name; tsb.Margin = new Padding(1, 0, 0, 0); tsb.Padding = new Padding(1, 1, 0, 0); tsb.BackColor = p.TeamType == TeamType.Sentinel ? Color.Red : Color.Lime; tsb.Tag = p; tsb.Click += new EventHandler(playerToolStripButton_Click); tsb.MouseDown += new MouseEventHandler(playerToolStripButton_MouseDown); if (useAlternativeLayout) { if (downToUpDirection) { switch (ts.Items.Count) { case 0: ts.Items.AddRange(new ToolStripItem[]{ GetLabel(tsb, true), GetLabel(tsb, true), GetLabel(tsb, false, 4), tsb, }); break; case 4: if (ts.Items[0].Image == null) { ts.Items.RemoveAt(0); ts.Items.Insert(0, tsb); break; } else if (ts.Items[1].Image == null) { ts.Items.RemoveAt(1); ts.Items.Insert(1, tsb); break; } else if (ts.Items[2] is ToolStripLabel) { ts.Items.RemoveAt(2); ts.Items.Insert(2, tsb); break; } ts.Items.Add(tsb); break; } } else switch (ts.Items.Count) { case 0: ts.Items.AddRange(new ToolStripItem[]{ GetLabel(tsb, true), tsb }); break; case 2: ts.Items.RemoveAt(0); ts.Items.Insert(0, GetLabel(tsb, false)); ts.Items.AddRange(new ToolStripItem[]{ GetLabel(tsb, true), tsb }); break; case 4: if (ts.Items[2].Image == null) ts.Items.RemoveAt(2); else if (ts.Items[0].Image == null) ts.Items.RemoveAt(0); ts.Items.Add(tsb); break; } } else if (downToUpDirection) { switch (ts.Items.Count) { case 0: ts.Items.AddRange(new ToolStripItem[]{ GetLabel(tsb, true), GetLabel(tsb, true), GetLabel(tsb, false, 4), tsb, }); break; case 4: if (ts.Items[2].Image == null) { ts.Items.RemoveAt(2); ts.Items.Add(tsb); break; } else if (ts.Items[1].Image == null) { ts.Items.RemoveAt(0); ts.Items.Insert(0, GetLabel(tsb, false, 4)); ts.Items.RemoveAt(1); ts.Items.Insert(1, tsb); break; } else if (ts.Items[0].Image == null) { ts.Items.RemoveAt(0); ts.Items.Insert(0, tsb); break; } ts.Items.Add(tsb); break; } } else switch (ts.Items.Count) { case 0: ts.Items.AddRange(new ToolStripItem[]{ GetLabel(tsb, false, 4), tsb }); break; case 2: if (ts.Items[0] is ToolStripLabel) ts.Items.RemoveAt(0); else ts.Items.Insert(0, GetLabel(tsb, false, 4)); ts.Items.Add(tsb); break; case 4: if (ts.Items[0] is ToolStripLabel) ts.Items.RemoveAt(0); ts.Items.Add(tsb); break; } }
void IncreaseHeroUseCount(Player player, Hero hero) { KeyValuePair<Hero,int> kvp; if (player.UsedHeroes.TryGetValue(hero.Name, out kvp)) player.UsedHeroes[hero.Name] = new KeyValuePair<Hero, int>(kvp.Key, kvp.Value + 1); else player.UsedHeroes.Add(hero.Name, new KeyValuePair<Hero, int>(hero, 1)); }
location GetAverageLocation(Player player, rect baseArea, List<int> alliedHeroes, int creepSpawnTime) { double x = 0; double y = 0; int count = 0; foreach (PlayerAction pa in player.Actions) { // if creeps were not spawned yet, then skip this action if (pa.Time < creepSpawnTime) continue; // if it's > than 3 minutes since creep spawn then stop if (pa.Time > creepSpawnTime + 180000) break; if (pa.IsValidObjects && !alliedHeroes.Contains(pa.Object1)) { // skip this action if it was performed on the base area if (baseArea.ContainsXY(pa.X, pa.Y, 800)) continue; if (x == 0 && y == 0) { x = pa.X; y = pa.Y; } else { x += pa.X; y += pa.Y; } count++; if (count > 50) break; } } x /= count; y /= count; return new location(x, y); }
public void Add(Player p) { players.Add(p); isObserver = p.IsObserver; }