Example #1
0
 public void BeginResearch(Hero hero)
 {
     heroSelectedForResearch = hero;
     heroLevelOnResearchStart = hero.Level;
     researchPoints = CanResearchAtOnce;
     isResearching = true;
 }
Example #2
0
 internal void Order(string name, int time)
 {
     foreach (Hero hero in heroes)
     {
         if (hero.Name == name)
         {
             hero.Order(time);
             return;
         }
     }
     Hero h = new Hero(name);
     heroes.Add(h);
     buildOrders.Add(new OrderItem(name, time));
 }
Example #3
0
        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;
        }
Example #4
0
        public void EndResearch()
        {
            if (isResearching)
            {
                // calculate level required for the hero to research skills that he did research
                int researchPointsUsed = CanResearchAtOnce - researchPoints;
                int levelRequiredToResearch = heroLevelOnResearchStart + researchPointsUsed;

                // now specify that hero level in his last researched skills
                List<OrderItem> skillsResearched = heroSelectedForResearch.Abilities.BuildOrders;

                for (int i = skillsResearched.Count - researchPointsUsed;
                    i < skillsResearched.Count;
                    i++)
                {
                    skillsResearched[i].Tag = Math.Max(levelRequiredToResearch, skillsResearched[i].Tag);
                }
            }

            heroSelectedForResearch = null;
            researchPoints = 0;
            isResearching = false;
        }
Example #5
0
        private void LoadTimeSlot(BinaryReader reader, short rest, int time, ref bool isPaused)
        {
            bool wasDeselect = false;

//#pragma warning disable TooWideLocalVariableScope
            short flag;
            uint itemId;
            float x;
            float y;
            int objectId1;
            int objectId2;
            uint itemId1;
            uint itemId2;
            float x2;
            float y2;
            short unitCount;
            byte groupNo;
            byte slotNo;
            int len;
            string gamecache;
            string missonKey;
            string key;
            int value;
            List<int> units;            
//#pragma warning restore TooWideLocalVariableScope

            while (rest > 0)
            {
                byte playerId = reader.ReadByte();
                Player player = GetPlayerById(playerId);
                player.Time = time;
                short playerBlockRest = reader.ReadInt16();                
                rest -= 3;
                short prest = playerBlockRest;

                while (prest > 0)
                {
                    #region
                    byte actionId = reader.ReadByte();
                    switch (actionId)
                    {
                        //pause game
                        case 0x01:
                            isPaused = true;                            
                            chats.Add(new ChatInfo(time, player, TalkTo.System, null, "pause"));                            
                            prest--;                            
                            break;
                        //resume game
                        case 0x02:
                            isPaused = false;                            
                            chats.Add(new ChatInfo(time, player, TalkTo.System, null, "resume"));
                            prest--;
                            break;
                        //set game speed
                        case 0x03:
                            prest -= 2;
                            break;
                        //icrease, decrease game speed
                        case 0x04:
                        case 0x05:
                            prest--;
                            break;
                        //save game
                        case 0x06:
                            len = 0;
                            while (reader.ReadByte() != 0)
                                len++;
                            chats.Add(new ChatInfo(time, player, TalkTo.System, null, "save"));
                            prest -= (short)(len + 2);
                            break;
                        //game saved
                        case 0x07:
                            reader.ReadInt32();
                            prest -= 5;
                            break;
                        //unit ability without target
                        case 0x10:
                            flag = reader.ReadInt16();
                            itemId = reader.ReadUInt32();
                            //unknownA, unknownB
                            reader.ReadInt64();

                            player.ActionsCount++;
#if !SUPRESS_HASH_CALCULATION 
                            hashWriter.Write(time);
                            hashWriter.Write(actionId);
                            hashWriter.Write(flag);
                            hashWriter.Write(itemId);
#endif

                            //if (string.Compare(DHJassInt.int2id(itemId),"A00S", true)==0)

                            OrderItem(player, itemId, time, 0,0, -1, -1);
                            prest -= 15;
                            break;
                        //unit ability with target position
                        case 0x11:
                            flag = reader.ReadInt16();
                            itemId = reader.ReadUInt32();
                            //unknownA, unknownB
                            reader.ReadInt64();
                            x = reader.ReadSingle();
                            y = reader.ReadSingle();

                            player.ActionsCount++;
#if !SUPRESS_HASH_CALCULATION 
                            hashWriter.Write(time);
                            hashWriter.Write(actionId);
                            hashWriter.Write(flag);
                            hashWriter.Write(itemId);
                            hashWriter.Write(x);
                            hashWriter.Write(y);
#endif

                            OrderItem(player, itemId, time, x, y, -1, -1);
                            prest -= 23;
                            break;
                        //unit ability with target position and target object
                        case 0x12:
                            flag = reader.ReadInt16();
                            itemId = reader.ReadUInt32();
                            //unknownA, unknownB
                            reader.ReadInt64();
                            x = reader.ReadSingle();
                            y = reader.ReadSingle();
                            objectId1 = reader.ReadInt32();
                            objectId2 = reader.ReadInt32();

                            player.ActionsCount++;
#if !SUPRESS_HASH_CALCULATION 
                            hashWriter.Write(time);
                            hashWriter.Write(actionId);
                            hashWriter.Write(flag);
                            hashWriter.Write(itemId);
                            hashWriter.Write(x);
                            hashWriter.Write(y);
                            hashWriter.Write(objectId1);
                            hashWriter.Write(objectId2);
#endif
                            OrderItem(player, itemId, time, x, y, objectId1, objectId2);
                            prest -= 31;
                            break;
                        //unit ability with target position, target object, and target item (give item action)
                        case 0x13:
                            flag = reader.ReadInt16();
                            itemId = reader.ReadUInt32();
                            //unknownA, unknownB
                            reader.ReadInt64();
                            x = reader.ReadSingle();
                            y = reader.ReadSingle();
                            objectId1 = reader.ReadInt32();
                            objectId2 = reader.ReadInt32();
                            itemId1 = reader.ReadUInt32();
                            itemId2 = reader.ReadUInt32();

                            player.ActionsCount++;
#if !SUPRESS_HASH_CALCULATION 
                            hashWriter.Write(time);
                            hashWriter.Write(actionId);
                            hashWriter.Write(flag);
                            hashWriter.Write(itemId);
                            hashWriter.Write(x);
                            hashWriter.Write(y);
                            hashWriter.Write(objectId1);
                            hashWriter.Write(objectId2);
                            hashWriter.Write(itemId1);
                            hashWriter.Write(itemId2);
#endif
                            prest -= 39;
                            break;
                        //unit ability with two target positions and two item IDs
                        case 0x14:
                            flag = reader.ReadInt16();
                            itemId = reader.ReadUInt32();
                            //unknownA, unknownB
                            reader.ReadInt64();
                            x = reader.ReadSingle();
                            y = reader.ReadSingle();
                            itemId1 = reader.ReadUInt32();
                            reader.ReadBytes(9);
                            x2 = reader.ReadSingle();
                            y2 = reader.ReadSingle();

                            player.ActionsCount++;
#if !SUPRESS_HASH_CALCULATION 
                            hashWriter.Write(time);
                            hashWriter.Write(actionId);
                            hashWriter.Write(flag);
                            hashWriter.Write(itemId);
                            hashWriter.Write(x);
                            hashWriter.Write(y);
                            hashWriter.Write(itemId1);
                            hashWriter.Write(x2);
                            hashWriter.Write(y2);
#endif
                            prest -= 44;
                            break;
                        //change selection
                        case 0x16:
                            byte selectMode = reader.ReadByte();
                            unitCount = reader.ReadInt16();
                            //object ids
                            //reader.ReadBytes(unitCount * 8);
                            for (int i = 0; i < unitCount; i++)
                            {
                                objectId1 = reader.ReadInt32();
                                objectId2 = reader.ReadInt32();

                                if (selectMode!=2)
                                    player.State.CurrentSelection.Add(objectId1);
                                else
                                    player.State.CurrentSelection.Remove(objectId1);
                            }

                            //if is deselect
                            if (selectMode == 2)
                            {
                                wasDeselect = true;
                                player.ActionsCount++;
                            }
                            else
                            {
                                if (!wasDeselect)
                                    player.ActionsCount++;
                                wasDeselect = false;
                            }
                            player.Units.Multiplier = unitCount;
#if !SUPRESS_HASH_CALCULATION 
                            hashWriter.Write(time);
                            hashWriter.Write(actionId);
                            hashWriter.Write(selectMode);
                            hashWriter.Write(unitCount);
#endif
                            prest -= (short)(unitCount * 8 + 4);
                            break;
                        //create group
                        case 0x17:
                            groupNo = reader.ReadByte();
                            unitCount = reader.ReadInt16();
                            //unit ids
                            //reader.ReadBytes(unitCount * 8);
                            units = new List<int>(unitCount);
                            for (int i = 0; i < unitCount; i++)
                            {
                                objectId1 = reader.ReadInt32();
                                objectId2 = reader.ReadInt32();

                                units.Add(objectId1);
                            }

                            player.ActionsCount++;
                            player.Groups.SetGroup(groupNo, units);
#if !SUPRESS_HASH_CALCULATION 
                            hashWriter.Write(time);
                            hashWriter.Write(actionId);
                            hashWriter.Write(groupNo);
                            hashWriter.Write(unitCount);
#endif
                            prest -= (short)(unitCount * 8 + 4);
                            break;
                        //select group
                        case 0x18:
                            groupNo = reader.ReadByte();
                            //unknown
                            reader.ReadByte();

                            player.State.CurrentSelection = new List<int>(player.Groups[groupNo]);

                            player.ActionsCount++;
                            player.Units.Multiplier = (short)player.Groups[groupNo].Count;
#if !SUPRESS_HASH_CALCULATION 
                            hashWriter.Write(time);
                            hashWriter.Write(actionId);
                            hashWriter.Write(groupNo);
#endif
                            prest -= 3;
                            break;
                        //select sub group
                        case 0x19:
                            //itemId, objectId1, objectId2
                            itemId = reader.ReadUInt32();
                            objectId1 = reader.ReadInt32();
                            reader.ReadInt32();

                            string codeID = DHJassInt.int2id(itemId);

                            // write this objectID-codeID pair to cache
                            if (!dcObjectsCodeIDs.ContainsKey(objectId1) || dcObjectsCodeIDs[objectId1]!=codeID)
                            {                                
                                dcObjectsCodeIDs[objectId1] = codeID;

                                if (DHLOOKUP.dcHeroesTaverns.ContainsKey(codeID))
                                {
                                    Hero cachedHero;
                                    if (!dcHeroCache.TryGetValue(objectId1, out cachedHero) || cachedHero.Name != codeID)
                                        dcHeroCache[objectId1] = new Hero(codeID);                                
                                }
                            }

                            // update current selection for player
                            //player.State.CurrentSelection = objectId1;

                            //no way to find how many buildings is in a subgroup..
                            player.Units.Multiplier = 1;
                            prest -= 13;
                            break;
                        //pre select sub group
                        case 0x1A:
                            prest--;
                            break;
                        //unknown
                        case 0x1B:
                            //unknown, objectid1, objectid2
                            reader.ReadByte();
                            reader.ReadInt64();
                            prest -= 10;
                            break;
                        //select ground item
                        case 0x1C:
                            //unknown, objectid1, objectid2
                            reader.ReadByte();
                            reader.ReadInt64();

                            player.ActionsCount++;
                            prest -= 10;
                            break;
                        //cancel hero revival
                        case 0x1D:
                            reader.ReadInt64();
                            player.ActionsCount++;
                            prest -= 9;
                            break;
                        //remove unit from order queue
                        case 0x1E:
                            slotNo = reader.ReadByte();
                            itemId = reader.ReadUInt32();

                            player.ActionsCount++;
#if !SUPRESS_HASH_CALCULATION 
                            hashWriter.Write(time);
                            hashWriter.Write(actionId);
                            hashWriter.Write(slotNo);
                            hashWriter.Write(itemId);
#endif
                            CancelItem(player, itemId, time);
                            prest -= 6;
                            break;
                        //unknown
                        case 0x21:
                            reader.ReadInt64();
                            prest -= 9;
                            break;
                        //cheats
                        case 0x20:
                        case 0x22:
                        case 0x23:
                        case 0x24:
                        case 0x25:
                        case 0x26:
                        case 0x29:
                        case 0x2A:
                        case 0x2B:
                        case 0x2C:
                        case 0x2F:
                        case 0x30:
                        case 0x31:
                        case 0x32:
                            prest--;
                            break;
                        //cheats
                        case 0x27:
                        case 0x28:
                        case 0x2D:
                            reader.ReadByte();
                            reader.ReadInt32();
                            prest -= 6;
                            break;
                        //cheats
                        case 0x2E:
                            reader.ReadInt32();
                            prest -= 5;
                            break;
                        //change ally option
                        case 0x50:
                            reader.ReadByte();
                            reader.ReadInt32();
                            prest -= 6;
                            break;
                        //transfer resource
                        case 0x51:
                            slotNo = reader.ReadByte();
                            int gold = reader.ReadInt32();
                            int lumber = reader.ReadInt32();

#if !SUPRESS_HASH_CALCULATION 
                            hashWriter.Write(time);
                            hashWriter.Write(actionId);
                            hashWriter.Write(slotNo);
                            hashWriter.Write(gold);
                            hashWriter.Write(lumber);
#endif
                            prest -= 10;
                            break;
                        //trigger chat
                        case 0x60:
                            //unknownA, unknownB
                            reader.ReadInt64();
                            len = 0;
                            while (reader.ReadByte() != 0)
                                len++;

                            prest -= (short)(10 + len);
                            break;
                        //esc pressed
                        case 0x61:
                            // exit research mode for this player
                            if (player.State.IsResearching)
                                player.State.EndResearch();
                            player.ActionsCount++;
                            prest--;
                            break;
                        //Scenario Trigger
                        case 0x62:
                            //unknownABC
                            reader.ReadInt32();
                            reader.ReadInt64();

                            prest -= 13;
                            break;
                        //begin choose hero skill
                        case 0x66:
                            // end any previous research session
                            player.State.EndResearch();
                            // make sure that there is a hero in player's current selection
                            Hero hero;                            
                            if (!MakeSureHeroExists(player, time, out hero)) 
                                Console.WriteLine("No hero selected for choose skill action!");
                            else
                                player.State.BeginResearch(hero);
                            player.ActionsCount++;
                            prest--;
                            break;
                        //begin choose building
                        case 0x67:
                            player.ActionsCount++;
                            prest--;
                            break;
                        //ping mini map
                        case 0x68:
                            //x, y
                            reader.ReadInt64();
                            //unknown
                            reader.ReadInt32();

                            prest -= 13;
                            break;
                        //continue game
                        case 0x69:
                        case 0x6A:
                            reader.ReadInt64();
                            reader.ReadInt64();
                            prest -= 17;
                            break;
                        // SyncStoredInteger actions
                        case 0x6B:
                            gamecache = ParserUtility.ReadString(reader);
                            missonKey = ParserUtility.ReadString(reader);
                            key = ParserUtility.ReadString(reader);
                            value = reader.ReadInt32();
                            //Console.WriteLine("Sync: [" + gamecache + "][" + missonKey + "][" + key + "]=" + value);
                            prest -= (short)((gamecache.Length + 1) + (missonKey.Length + 1) + (key.Length + 1) + 4 + 1);

                            switch (missonKey)
                            {
                                //case "0":
                                case "1":
                                case "2":
                                case "3":
                                case "4":
                                case "5":                                    
                                    int slot = int.Parse(missonKey);
                                    Player p = GetPlayerBySlot(slot - 1);
                                    if (p!=null) p.gameCacheValues[key] = value;                                    
                                    break;                                
                                case "7":
                                case "8":
                                case "9":
                                case "10":
                                case "11":
                                    slot = int.Parse(missonKey);
                                    p = GetPlayerBySlot(slot - 2);                                    
                                    if (p!= null) p.gameCacheValues[key] = value;                                    
                                    break;
                                case "Global":
                                    if (key == "Winner")                                                                            
                                        this.GetTeamByType((TeamType)value).IsWinner = true;                                    
                                    break;
                                case "Data":
                                    // hero death
                                    if (key.StartsWith("Hero"))
                                    {
                                        int deadId = int.Parse(key.Substring(4));
                                        Player victim = GetPlayerBySpecialSlot(deadId);
                                        Player killer = GetPlayerBySpecialSlot(value);

                                        int gcValue;
                                        victim.gameCacheValues.TryGetValue("deaths", out gcValue);
                                        victim.gameCacheValues["deaths"] = gcValue + 1;

                                        // if killer is a player
                                        if (killer != null)
                                        {
                                            killer.gameCacheValues.TryGetValue("kills", out gcValue);
                                            killer.gameCacheValues["kills"] = gcValue + 1;
                                        }

                                        kills.Add(new KillInfo(time, killer, victim));
                                    }
                                    else
                                        // player disconnected
                                        if (key.StartsWith("CK"))
                                        {
                                            int deniesIndex = key.IndexOf('D');
                                            int neutralsIndex = key.IndexOf('N');

                                            int creepKills = int.Parse(key.Substring(2, deniesIndex - 2));
                                            int creepDenies = int.Parse(key.Substring(deniesIndex + 1, neutralsIndex - deniesIndex - 1));

                                            Player leavingPlayer = GetPlayerBySpecialSlot(value);
                                            if (leavingPlayer != null)
                                            {
                                                leavingPlayer.gameCacheValues["creeps"] = creepKills;
                                                leavingPlayer.gameCacheValues["denies"] = creepDenies;
                                            }
                                        }                                        
                                    break;
                            }
                            break;
                        case 0x70:
                            gamecache = ParserUtility.ReadString(reader);
                            missonKey = ParserUtility.ReadString(reader);
                            key = ParserUtility.ReadString(reader);
                            prest -= (short)((gamecache.Length + 1) + (missonKey.Length + 1) + (key.Length + 1) + 1);
                            break;
                        case 0x75:
                            reader.ReadByte();
                            prest -= 2;
                            break;
                        default:
                            if (actionId == 0)
                            {
                                prest--;
                                byte[] bskipped = reader.ReadBytes(prest);
                                prest = 0;
                                Console.WriteLine("Warning: ActionID==0 found. Skipping remaining " + bskipped.Length + " bytes in the timeslot...");
                            }
                            else
                                throw new W3gParserException("Unknown ActionID:" + actionId);
                            break;
                    }
                    #endregion
                }
                rest -= playerBlockRest;
            }
        }
Example #6
0
 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));            
 }
Example #7
0
        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;
            }
        }
Example #8
0
        bool TryFindHeroByCache(List<int> unitList, out Hero hero, out int heroObjectID)
        {
            foreach (int objectID in unitList)
                if (dcHeroCache.TryGetValue(objectID, out hero))
                {
                    heroObjectID = objectID;
                    return true;
                }

            heroObjectID = 0;
            hero = null;
            return false;
        }
Example #9
0
 internal void Order(Hero h, int time)
 {
     heroes.Add(h);
     buildOrders.Add(new OrderItem(h.Name, time));
 }
Example #10
0
        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;
            }
        }