public void SetPerkValue(PerkObject perk, bool enable) { HeroAdminCharacterPerk result = this.Perks.FirstOrDefault(cp => cp.StringId.Equals(perk.StringId)); if (null != result) { result.Enable = enable; } else { this.Perks.Add(new HeroAdminCharacterPerk(perk.StringId, perk.Skill.StringId, enable)); } /* CharacterPerks heroPerks = ReflectUtils.ReflectField<CharacterPerks>("_heroPerks", this._hero); * if (null != heroPerks) * { * heroPerks.SetPropertyValue(perk, selected ? 1 : 0); * }*/ }
public void ToHero(Hero hero) { /// hero.HeroDeveloper.ClearHero(); BodyProperties bodyProperties = BodyProperties.Default; hero.Level = this.Level; BodyProperties.FromString(this.BodyPropertiesString, out bodyProperties); HeroUtils.UpdateHeroCharacterBodyProperties(hero.CharacterObject, bodyProperties, this.IsFemale); HeroAdminCharacterAttribute attr; hero.ClearAttributes(); for (int i = 0; i < 6; i++) { attr = this.Attributes.FirstOrDefault((obj) => obj.AttributeName == Enum.GetName(typeof(CharacterAttributesEnum), i)); if (null != attr) { hero.SetAttributeValue((CharacterAttributesEnum)i, attr.AttributeValue); // hero.HeroDeveloper.AddAttribute((CharacterAttributesEnum)i, attr.AttributeValue, false); } } HeroAdminCharacterSkill adminCharacterSkill; hero.ClearSkills(); foreach (SkillObject current in SkillObject.All) { adminCharacterSkill = Skills.FirstOrDefault((obj) => obj.StringId.Equals(current.StringId)); if (null != adminCharacterSkill) { // hero.SetSkillValue(current, adminCharacterSkill.SkillValue); int xpRequiredForSkillLevel = Campaign.Current.Models.CharacterDevelopmentModel.GetXpRequiredForSkillLevel(adminCharacterSkill.SkillValue); hero.HeroDeveloper.SetPropertyValue(current, (float)xpRequiredForSkillLevel); hero.SetSkillValue(current, adminCharacterSkill.SkillValue); ReflectUtils.ReflectMethodAndInvoke("SetFocus", hero.HeroDeveloper, new object[] { current, adminCharacterSkill.SkillFocus }); ///hero.HeroDeveloper.AddFocus(current, adminCharacterSkill.SkillFocus, false); } } hero.ClearPerks(); foreach (PerkObject perk in PerkObject.All) { HeroAdminCharacterPerk result = this.Perks.FirstOrDefault(cp => cp.StringId.Equals(perk.StringId)); if (null != result) { // hero.SetPerkValue(current, true); // 直接修改数据,因为上面方法会发送事件 CharacterPerks heroPerks = ReflectUtils.ReflectField <CharacterPerks>("_heroPerks", hero); if (null != heroPerks) { heroPerks.SetPropertyValue(perk, result.Enable ? 1: 0); } } } hero.ClearTraits(); foreach (TraitObject trait in TraitObject.All) { HeroAdminCharacterTrait characterTrait = Traits.FirstOrDefault((obj) => obj.StringId.Equals(trait.StringId)); if (null != characterTrait) { hero.SetTraitLevel(trait, characterTrait.Level); } } }