public void SaveToDisk() { DateTime stamp = DateTime.Now; string backupFolder = Path.Combine(Directory.GetParent(Executable.Path).ToString(), "HeroesResourceManagerBackups", stamp.ToString("yyyy-MM-dd-HHmmss")); Directory.CreateDirectory(backupFolder); SaveHeroExeData(backupFolder); if (CreatureManager.AnyChanges) { CreatureManager.SaveLocalChanges(this); } if (HeroesManager.AnyChanges) { HeroesManager.SaveLocalChanges(this); } if (HeroClass.AnyChanges) { HeroClass.SaveLocalChanges(this); } if (Spell.AnyChanges) { Spell.SaveLocalChanges(this); } foreach (var lodFile in ResourceFiles) { lodFile.SaveToDiskBackupAndSwap(backupFolder); } }
private void cbCreatures_SelectedIndexChanged(object sender, EventArgs e) { if (Heroes3Master.Master != null && CreatureManager.Loaded) { var creature = CreatureManager.Get(cbCastles.SelectedIndex, cbCreatures.SelectedIndex); LoadCreatureInfo(creature); string allCreatures = Properties.Resources.creatures; string defName = allCreatures.Split(new[] { "\r\n" }, StringSplitOptions.None)[creature.CreatureIndex].Split(';')[2] + ".def"; var lodFile = Heroes3Master.Master.Resolve(defName); if (creatureAnimation != null) { pbCreature.Image = null; creatureAnimation.Dispose(); } var def = lodFile[defName].GetDefFile(); if (def != null) { creatureAnimation = new CreatureAnimationLoop(creature.CreatureIndex, def); creatureAnimation.TimerTick += creatureAnimation_TimerTick; creatureAnimation.Enabled = true; } } }
private static string GetCreatureSiblingsText(Creature creature) { if (creature.TownIndex <= 8) { return(creature.Plural1.ChangeFirstCharCase() + " or " + CreatureManager.GetByCreatureIndex(creature.CreatureIndex + 1).Plural1.ChangeFirstCharCase()); } return(creature.Plural1.ChangeFirstCharCase()); }
// private static Bitmap GetImageForPropertyType(ProfilePropertyType propertyType, int index, bool forceAllCreatures) { if (index >= 0) { if (propertyType == ProfilePropertyType.Creature) { int realIndex = CreatureManager.OnlyActiveCreatures[index].CreatureIndex; return(CreatureManager.GetImage(Heroes3Master.Master, realIndex)); } if (propertyType == ProfilePropertyType.SecondarySkill) { return(SecondarySkill.AllSkills[index / 3].GetImage(Heroes3Master.Master, 1 + index % 3)); } if (propertyType == ProfilePropertyType.Spell) { return(Spell.AllSpells[index].GetImage(Heroes3Master.Master)); } if (propertyType == ProfilePropertyType.SpecCreature || propertyType == ProfilePropertyType.SpecCreatureStatic) { return(CreatureManager.GetImage(Heroes3Master.Master, CreatureManager.IndexesOfFirstLevelCreatures[index])); } if (propertyType == ProfilePropertyType.SpecCreatureUpgrade) { if (!forceAllCreatures) { return(CreatureManager.GetImage(Heroes3Master.Master, CreatureManager.IndexesOfFirstLevelCreatures[index])); } int realIndex = CreatureManager.OnlyActiveCreatures[index].CreatureIndex; return(CreatureManager.GetImage(Heroes3Master.Master, realIndex)); } if (propertyType == ProfilePropertyType.SpecSpell) { return(Spell.GetSpellByIndex(Spell.SpecSpellIndexes[index]).GetImage(Heroes3Master.Master)); } if (propertyType == ProfilePropertyType.SpecSecondarySkill) { return(SecondarySkill.GetImage(Heroes3Master.Master, SecondarySkill.IndexesOfAllSpecSkills[index], 1)); } if (propertyType == ProfilePropertyType.SpecResource) { return(Resource.GetImage(Heroes3Master.Master, index)); } } return(null); }
private static Bitmap GetBackgroundImageForPropertyType(ProfilePropertyType propertyType, bool forceAllCreatures) { if (Heroes3Master.Master != null) { if (propertyType == ProfilePropertyType.Creature) { return(new Bitmap(CreatureManager.GetAllCreaturesBitmapParallel(Heroes3Master.Master))); } if (propertyType == ProfilePropertyType.SecondarySkill) { return(new Bitmap(SecondarySkill.GetSkillTree(Heroes3Master.Master))); } if (propertyType == ProfilePropertyType.Spell) { return(new Bitmap(Spell.GetAllSpells(Heroes3Master.Master))); } if (propertyType == ProfilePropertyType.SpecCreature || propertyType == ProfilePropertyType.SpecCreatureStatic) { return(CreatureManager.GetAllBasicCreatures(Heroes3Master.Master)); } if (propertyType == ProfilePropertyType.SpecCreatureUpgrade) { if (forceAllCreatures) { return(new Bitmap(CreatureManager.GetAllCreaturesBitmapParallel(Heroes3Master.Master))); } return(CreatureManager.GetAllBasicCreatures(Heroes3Master.Master)); } if (propertyType == ProfilePropertyType.SpecSecondarySkill) { return(SecondarySkill.GetSkillsForSpeciality(Heroes3Master.Master)); } if (propertyType == ProfilePropertyType.SpecSpell) { return(Spell.GetAvailableSpellsForSpeciality(Heroes3Master.Master)); } if (propertyType == ProfilePropertyType.SpecResource) { return(Resource.GetAllResources(Heroes3Master.Master)); } } return(null); }
private void gridImages_ItemSelected(int value) { if (PropertyType == ProfilePropertyType.SpecCreatureStatic) { btnSave.Focus(); } else if (PropertyType == ProfilePropertyType.SpecCreatureUpgrade) { if (selectedBoxIndex == 0) { Box1Creature = CreatureManager.IndexesOfFirstLevelCreatures[value]; pbCreature1.Image = CreatureManager.GetImage(Heroes3Master.Master, Box1Creature); } else if (selectedBoxIndex == 1) { Box2Creature = CreatureManager.IndexesOfFirstLevelCreatures[value]; pbCreature2.Image = CreatureManager.GetImage(Heroes3Master.Master, Box2Creature); } else if (selectedBoxIndex == 2) { Box3Creature = CreatureManager.OnlyActiveCreatures[value].CreatureIndex; pbCreature3.Image = CreatureManager.GetImage(Heroes3Master.Master, Box3Creature); } } else { int objId = value; if (PropertyType == ProfilePropertyType.SpecCreature) { objId = CreatureManager.IndexesOfFirstLevelCreatures[value]; } else if (PropertyType == ProfilePropertyType.SpecSpell) { objId = Spell.SpecSpellIndexes[value]; } else if (PropertyType == ProfilePropertyType.SpecSecondarySkill) { objId = SecondarySkill.IndexesOfAllSpecSkills[value]; } if (this.ItemSelected != null) { this.ItemSelected(objId, 0, 0, 0); Close(); } } }
private void UpdateCreatureBoxes() { if (Box1Creature >= 0) { pbCreature1.Image = CreatureManager.GetImage(Heroes3Master.Master, Box1Creature); } if (Box2Creature >= 0) { pbCreature2.Image = CreatureManager.GetImage(Heroes3Master.Master, Box2Creature); } if (Box3Creature >= 0) { pbCreature3.Image = CreatureManager.GetImage(Heroes3Master.Master, Box3Creature); } }
private void cbCreatures_DrawItem(object sender, DrawItemEventArgs e) { if (Heroes3Master.Master != null && e.Index >= 0) { int castleIndex = selectedCastle; var clr = Town.AllColors[castleIndex]; if (!cacheOther) { e.Graphics.FillRectangle(new SolidBrush(clr), e.Bounds); var creature = CreatureManager.Get(castleIndex, e.Index); e.Graphics.DrawImage(CreatureManager.GetSmallImage(Heroes3Master.Master, creature.CreatureIndex), e.Bounds.X, e.Bounds.Y); e.Graphics.DrawString(creature.Name, e.Font, Brushes.Black, e.Bounds.X + 46, e.Bounds.Y + 9); } else { if (BitmapCache.DrawItemCreaturesOtherComboBox == null) { otherCreatures = CreatureManager.OnlyActiveCreatures.Where(c => c.TownIndex == 9 && c.CreatureIndex != 149).ToArray(); BitmapCache.DrawItemCreaturesOtherComboBox = new Bitmap[otherCreatures.Length]; } Bitmap cached; if (BitmapCache.DrawItemCreaturesOtherComboBox[e.Index] == null) { cached = new Bitmap(e.Bounds.Width, e.Bounds.Height); using (var g = Graphics.FromImage(cached)) { g.FillRectangle(new SolidBrush(clr), new Rectangle(Point.Empty, e.Bounds.Size)); var creature = CreatureManager.Get(castleIndex, e.Index); g.DrawImage(CreatureManager.GetSmallImage(Heroes3Master.Master, creature.CreatureIndex), Point.Empty); g.DrawString(creature.Name.ToString(), e.Font, Brushes.Black, 46, 9); } BitmapCache.DrawItemCreaturesOtherComboBox[e.Index] = cached; } else { cached = BitmapCache.DrawItemCreaturesOtherComboBox[e.Index]; } e.Graphics.DrawImage(cached, e.Bounds.Location); } } }
public void RefreshData() { routingCache = new Dictionary <string, LodFile>(); BackupManager = new BackupManager(); Resource.Unload(); CreatureAnimationLoop.Unload(); BitmapCache.UnloadCachedDrawItems(); HeroesManager.LoadInfo(this); HeroClass.LoadInfo(this); CreatureManager.LoadInfo(this); Spell.LoadInfo(this); SecondarySkill.LoadInfo(this); StringsData.LoadInfo(this); Speciality.LoadInfo(this); Town.LoadInfo(this); HeroExeData.LoadInfo(this); BackupManager.LoadData(this); }
//331 288 public void LoadHero(int heroIndex, Heroes3Master master) { HeroIndex = heroIndex; Hero = null; if (heroIndex > -1 && heroIndex < HeroesManager.HeroesOrder.Length && master != null) { var hs = HeroesManager.AllHeroes[heroIndex]; var bckgImage = HeroesManager.GetBackground(master); var canvas = new Bitmap(bckgImage); var g = Graphics.FromImage(canvas); /* g.InterpolationMode = InterpolationMode.High; * g.SmoothingMode = SmoothingMode.HighQuality; * g.TextRenderingHint = TextRenderingHint.AntiAliasGridFit; * g.CompositingQuality = CompositingQuality.HighQuality;*/ g.DrawImage(bckgImage, Point.Empty); var portrait = master.ResolveWith(HeroesManager.HeroesOrder[hs.ImageIndex]).GetBitmap(); g.DrawImage(portrait, new Point(4, 3)); var heroData = HeroExeData.Data[heroIndex]; var z = Speciality.GetImage(master, heroData.Index); g.DrawImage(z, new Point(4, 166)); Hero = heroData; if (heroData.Skill1 != null) { g.DrawImage(heroData.Skill1.GetImage(master, heroData.FirstSkillLevel), new Point(5, 213)); } if (heroData.Skill2 != null) { g.DrawImage(heroData.Skill2.GetImage(master, heroData.SecondSkillLevel), new Point(148, 213)); } var img1 = CreatureManager.GetImage(master, heroData.Unit1Index); g.DrawImage(img1, new Point(5, 262)); var img2 = CreatureManager.GetImage(master, heroData.Unit2Index); g.DrawImage(img2, new Point(68, 262)); var img3 = CreatureManager.GetImage(master, heroData.Unit3Index); g.DrawImage(img3, new Point(129, 262)); if (heroData.Spell != null) { g.DrawImage(heroData.Spell.GetImage(master), 192, 262); } DrawData(g, heroData); //heroData.Class.Stats /* * g.DrawImage(ps.GetSprite(0), new Point(18, 97)); * g.DrawImage(ps.GetSprite(1), new Point(88, 97)); * g.DrawImage(ps.GetSprite(2), new Point(158, 97)); * g.DrawImage(ps.GetSprite(5), new Point(228, 97)); */ g.Dispose(); PictureBox.Image = canvas; CalculateRatio(); } }
private static string GenerateCustomSpecText(HeroExeData hero) { string title = "", shortDescription = "", longDescription = ""; var spec = hero.Spec; // if spec is secondary skill, it would be found in original data; if (spec.Type == SpecialityType.CreatureLevelBonus) { var creature = CreatureManager.GetByCreatureIndex(spec.ObjectId); title = creature.Plural1.ChangeFirstCharCase(); shortDescription = "Creature Bonus: " + creature.Plural1.ChangeFirstCharCase(); if (creature.TownIndex <= 8) { longDescription = string.Format("Increases Speed of any {0} by 1 and their Attack and Defense skills by 5% for every {1} (rounded up)." , GetCreatureSiblingsText(creature), creature.CreatureTownLevel == 1 ? "level" : (creature.CreatureTownLevel + " levels")); } else { longDescription = string.Format("Increases Speed of any {0} by 1 and their Attack and Defense skills by 5% for every 4 levels (rounded up).", creature.Plural1.ChangeFirstCharCase()); } } else if (spec.Type == SpecialityType.Resource) { int d = 1; if (spec.ObjectId == (int)ResourceSpeciality.Gold350) { d = 350; } string resourceType = Enum.GetName(typeof(ResourceSpeciality), spec.ObjectId); title = "+ " + d + " " + resourceType; shortDescription = title + " each day."; longDescription = "Increases kingdom's " + resourceType.ChangeFirstCharCase(false) + " production by " + d + " per day."; } else if (spec.Type == SpecialityType.Spell) { var spell = Spell.GetSpellByIndex(spec.ObjectId); title = spell.Name; shortDescription = "Spell Bonus: " + spell.Name; longDescription = "Casts " + spell.Name + "with effect increased by 3% for every n hero levels, where n is the level of the targeted creature."; } else if (spec.Type == SpecialityType.CreatureStaticBonus) { var creature = CreatureManager.GetByCreatureIndex(spec.ObjectId); int attack, defense, damage; spec.TryGetCreatureStaticBonuses(out attack, out defense, out damage); title = creature.Plural1.ChangeFirstCharCase(); shortDescription = "Creature Bonus: " + title; longDescription = GetCreatureSiblingsText(creature); longDescription += " receive "; if (attack != 0) { longDescription += " +" + attack + " Attack"; } if (defense != 0) { longDescription += " +" + defense + " Attack"; } if (damage != 0) { longDescription += " +" + damage + " Damage"; } } else if (spec.Type == SpecialityType.CreaturesUpgrade) { int crFrom2 = BitConverter.ToInt32(spec.Data, 12); int crTo = BitConverter.ToInt32(spec.Data, 16); title = CreatureManager.GetByCreatureIndex(crTo).Plural1.ChangeFirstCharCase(); shortDescription = "Creature Bonus: " + title; if (crFrom2 >= 0 || spec.ObjectId >= 0) { longDescription = "Can upgrade "; if (spec.ObjectId >= 0) { longDescription += GetCreatureSiblingsText(CreatureManager.GetByCreatureIndex(spec.ObjectId)); } if (crFrom2 >= 0 && spec.ObjectId >= 0) { longDescription += " and "; } if (crFrom2 >= 0) { longDescription += GetCreatureSiblingsText(CreatureManager.GetByCreatureIndex(crFrom2)); } longDescription += " to " + title; } else { longDescription = shortDescription; } } return(string.Format("{0}\t{1}\t{2}", title, shortDescription, longDescription)); }
public string GetDescription() { string s = Type + " | "; if (TypeId == 0) { s += SecondarySkill.AllSkills[ObjectId]; } else if (TypeId == 1) { s += CreatureManager.GetByCreatureIndex(ObjectId); } else if (TypeId == 2) { if (Enum.IsDefined(typeof(ResourceSpeciality), ObjectId)) { s += Enum.GetName(typeof(ResourceSpeciality), ObjectId); } } else if (TypeId == 3) { s += Spell.GetSpellByIndex(ObjectId); } else if (TypeId == 4) { s += CreatureManager.GetByCreatureIndex(ObjectId); int attack, defense, damage; TryGetCreatureStaticBonuses(out attack, out defense, out damage); if (attack != 0) { s += " A: +" + attack; } if (defense != 0) { s += " D: +" + defense; } if (damage != 0) { s += " DMG: +" + damage; } } else if (TypeId == 5) { s += "+2 Speed"; } else if (TypeId == 6) { int crFrom2 = BitConverter.ToInt32(Data, 12); int crTo = BitConverter.ToInt32(Data, 16); s += "Creature Upgrade: From ("; s += CreatureManager.GetByCreatureIndex(ObjectId); s += " AND "; s += CreatureManager.GetByCreatureIndex(crFrom2); s += ") To"; s += CreatureManager.GetByCreatureIndex(crTo); } else if (TypeId == 7 || TypeId == -1) { s += Enum.GetName(typeof(SpecialityType), ObjectId); } return(s); }