protected override bool Initialize(QuestBehaviour questBehaviour) { if (string.IsNullOrEmpty(this.ResourceName)) { string text; if (questBehaviour.TryGetQuestVariableValueByName <string>(this.ResourceNameVarName, out text)) { if (string.IsNullOrEmpty(text)) { Diagnostics.LogError("Resource name is null or empty, quest variable (varname: '{0}')", new object[] { this.ResourceNameVarName }); return(false); } this.ResourceName = text; } else { IDroppable droppable; if (!questBehaviour.TryGetQuestVariableValueByName <IDroppable>(this.ResourceNameVarName, out droppable)) { Diagnostics.LogError("Cannot retrieve quest variable (varname: '{0}')", new object[] { this.ResourceNameVarName }); return(false); } DroppableString droppableString = droppable as DroppableString; if (droppableString == null || string.IsNullOrEmpty(droppableString.Value)) { Diagnostics.LogError("Resource name is null or empty, quest variable (varname: '{0}')", new object[] { this.ResourceNameVarName }); return(false); } this.ResourceName = droppableString.Value; } } if (this.Amount == -1) { QuestRegisterVariable questRegisterVariable; IDroppable droppable2; if (questBehaviour.TryGetQuestVariableValueByName <QuestRegisterVariable>(this.AmountVarName, out questRegisterVariable)) { if (questRegisterVariable == null) { Diagnostics.LogError("QuestRegisterVariable is null, quest variable (varname: '{0}')", new object[] { this.ResourceNameVarName }); return(false); } this.Amount = questRegisterVariable.Value; } else if (questBehaviour.TryGetQuestVariableValueByName <IDroppable>(this.AmountVarName, out droppable2)) { if (droppable2 == null) { Diagnostics.LogError("QuestDropListVariableDefinition is null, quest variable (varname: '{0}')", new object[] { this.AmountVarName }); return(false); } DroppableInteger droppableInteger = droppable2 as DroppableInteger; if (droppableInteger == null) { Diagnostics.LogError("QuestDropListVariableDefinition does not contains a DroppableInteger (varname: '{0}')", new object[] { this.AmountVarName }); return(false); } this.Amount = droppableInteger.Value; } else { float f; if (!questBehaviour.TryGetQuestVariableValueByName <float>(this.AmountVarName, out f)) { Diagnostics.LogError("Cannot retrieve quest variable (varname: '{0}')", new object[] { this.AmountVarName }); return(false); } this.Amount = Mathf.RoundToInt(f); } } return(base.Initialize(questBehaviour)); }
bool IHeroManagementService.TryAllocateSkillPoints(Unit unit) { if (unit == null) { throw new ArgumentNullException("unit"); } UnitProfile unitProfile = unit.UnitDesign as UnitProfile; if (unitProfile == null || !unitProfile.IsHero) { return(false); } int num = (int)Math.Floor((double)(unit.GetPropertyValue(SimulationProperties.MaximumSkillPoints) - unit.GetPropertyValue(SimulationProperties.SkillPointsSpent))); if (num <= 0) { return(false); } if (unitProfile.UnitSkillAllocationSchemeReference == null || StaticString.IsNullOrEmpty(unitProfile.UnitSkillAllocationSchemeReference)) { return(false); } IDatabase <Droplist> database = Databases.GetDatabase <Droplist>(false); if (database == null) { return(false); } Droplist droplist; if (database.TryGetValue(unitProfile.UnitSkillAllocationSchemeReference, out droplist)) { UnitSkill[] availableUnitSkills = DepartmentOfEducation.GetAvailableUnitSkills(unit); for (int i = 0; i < num; i++) { Droplist droplist2; DroppableString droppableString = droplist.Pick(null, out droplist2, new object[0]) as DroppableString; if (droppableString != null) { if (!string.IsNullOrEmpty(droppableString.Value)) { StaticString subcategory = droppableString.Value; List <UnitSkill> list = (from iterator in availableUnitSkills where iterator.SubCategory == subcategory && DepartmentOfEducation.IsUnitSkillUnlockable(unit, iterator) select iterator).ToList <UnitSkill>(); if (list.Count > 0) { while (list.Count > 0) { int index = UnityEngine.Random.Range(0, list.Count); int num2 = 0; if (unit.IsSkillUnlocked(list[index].Name)) { num2 = unit.GetSkillLevel(list[index].Name) + 1; int num3 = 0; if (list[index].UnitSkillLevels != null) { num3 = list[index].UnitSkillLevels.Length - 1; } if (num2 > num3) { list.Remove(list[index]); continue; } } unit.UnlockSkill(list[index].Name, num2); num = (int)Math.Floor((double)(unit.GetPropertyValue(SimulationProperties.MaximumSkillPoints) - unit.GetPropertyValue(SimulationProperties.SkillPointsSpent))); break; } } } } } } return(true); }