예제 #1
0
        public H3Map LoadMap()
        {
            mapObject = new H3Map();

            using (FileStream file = new FileStream(h3mFileFullPath, FileMode.Open, FileAccess.Read))
            {
                using (BinaryReader reader = new BinaryReader(file))
                {
                    ReadHeader(reader);

                    ReadDisposedHeroes(reader);

                    ReadAllowedArtifacts(reader);

                    ReadAllowedSpellsAbilities(reader);

                    ReadRumors(reader);

                    ReadPredefinedHeroes(reader);

                    ReadTerrain(reader);

                    ReadObjectTemplates(reader);

                    ReadObjects(reader);

                    ReadEvents(reader);

                    ConsolidateAndAdjustData();
                }
            }

            return(mapObject);
        }
예제 #2
0
        public static void LoadArtifactsOfHero(BinaryReader reader, H3Map map, HeroInstance hero)
        {
            hero.Data.Artifacts = new ArtifactSet();
            bool artSet = reader.ReadBoolean();

            if (artSet)
            {
                Console.WriteLine("Artifact is set.");

                if (false)
                {
                    // Already set the pack
                }

                for (int pom = 0; pom < 16; pom++)
                {
                    LoadArtifactToSlot(reader, map, hero, pom);
                }

                // misc5 art 17
                if (map.Header.Version >= EMapFormat.SOD)
                {
                    if (!LoadArtifactToSlot(reader, map, hero, (int)EArtifactPosition.MACH4))   //catapult
                    {
                        hero.Data.Artifacts.PutAt(EArtifactId.CATAPULT, EArtifactPosition.MACH4);
                    }
                }

                LoadArtifactToSlot(reader, map, hero, (int)EArtifactPosition.SPELLBOOK);   //SpellBook


                // Misc5 possibly
                if (map.Header.Version > EMapFormat.ROE)
                {
                    LoadArtifactToSlot(reader, map, hero, (int)EArtifactPosition.MISC5);   //Misc
                }
                else
                {
                    reader.Skip(1);
                }

                // Backpack items
                int amount = reader.ReadUInt16();
                Console.WriteLine("Backpack item amount:" + amount);
                for (int ss = 0; ss < amount; ++ss)
                {
                    LoadArtifactToSlot(reader, map, hero, 19 + ss);
                }
            }
        }
예제 #3
0
        public static bool LoadArtifactToSlot(BinaryReader reader, H3Map map, HeroInstance hero, int slotIndex)
        {
            int artmask = 0xffff;

            if (map.Header.Version == EMapFormat.ROE)
            {
                artmask = 0xff;
            }

            int aid = reader.ReadUInt16();

            bool isArt = (aid != artmask);

            if (isArt)
            {
                Console.WriteLine("loadArtifactToSlot: id={0}, slot={1}", aid, slotIndex);

                ArtifactSet artifactSet = hero.Data.Artifacts;

                EArtifactId artifactId = (EArtifactId)aid;
                H3Artifact  artifact   = new H3Artifact(artifactId);

                if (artifact.IsBig() && slotIndex > 19)
                {
                    return(false);
                }

                EArtifactPosition slot = (EArtifactPosition)slotIndex;
                if (aid == 0 && slot == EArtifactPosition.MISC5)
                {
                    //TODO: check how H3 handles it -> art 0 in slot 18 in AB map
                    slot = EArtifactPosition.SPELLBOOK;
                }

                // this is needed, because some H3M maps (last scenario of ROE map) contain invalid data like misplaced artifacts
                //// auto artifact = CArtifactInstance::createArtifact(map, aid);
                //// auto artifactPos = ArtifactPosition(slot);

                if (artifactSet.CanPutAt(artifactId, slot))
                {
                    artifactSet.PutAt(artifactId, slot);
                }


                return(true);
            }

            return(false);
        }