public static SkillErrorInfo GetSkillErrorInfo(GameObject sender, GameObject skillObject) { SkillErrorInfo skillErrorInfo = new SkillErrorInfo(); BaseBehavior baseBehaviorComponent = sender.GetComponent <BaseBehavior>(); List <SkillCondition> skillConditions = null; SkillInfo skillInfo = null; BaseSkillScript baseSkillScript = skillObject.GetComponent <BaseSkillScript>(); if (baseSkillScript != null) { skillConditions = baseSkillScript.skillConditions; skillInfo = baseSkillScript.skillInfo; } BaseBehavior senderBaseBehaviorComponent = skillObject.GetComponent <BaseBehavior>(); if (senderBaseBehaviorComponent != null) { skillConditions = senderBaseBehaviorComponent.skillConditions; skillInfo = senderBaseBehaviorComponent.skillInfo; } object[] errorInfo = GetSkillErrors( condList: skillConditions, team: baseBehaviorComponent.team, skillName: skillInfo.uniqueName, skillObject: skillObject, skillSender: sender); SkillCondition skillCondition = (SkillCondition)errorInfo[0]; string errorMessage = (string)errorInfo[1]; skillErrorInfo.errorMessage = errorMessage; if (errorMessage != "") { skillErrorInfo.isCanBeUsedAsSkill = false; } if (errorMessage != "" && skillCondition.notDisplayWhenFalse) { skillErrorInfo.isDisplayedAsSkill = false; } return(skillErrorInfo); }
public static object[] GetSkillErrors( List <SkillCondition> condList, GameObject skillObject = null, int team = -1, string skillName = "", GameObject skillSender = null) { object[] errorInfo = new object[] { null, "" }; SkillInfo skillInfo = null; if (skillObject.GetComponent <BaseBehavior>() != null) { skillInfo = skillObject.GetComponent <BaseBehavior>().skillInfo; } if (skillObject.GetComponent <BaseSkillScript>() != null) { skillInfo = skillObject.GetComponent <BaseSkillScript>().skillInfo; } CameraController cameraController = Camera.main.GetComponent <CameraController>(); if (cameraController.limit + skillInfo.takesLimit > cameraController.maxLimit) { errorInfo[0] = new SkillCondition(SkillConditionType._LimitCheck); errorInfo[1] = "You do not have enough population limit!"; return(errorInfo); } foreach (SkillCondition cond in condList) { if (cond.type == SkillConditionType.TearCheck) { bool hasUnitWithTear = false; if (skillObject.GetComponent <BaseBehavior>() != null) { hasUnitWithTear = BaseBehavior.IsHasUnitWithTear(cond.name, cond.minValue, cond.maxValue, skillSender); } if (skillObject.GetComponent <BaseSkillScript>() != null) { hasUnitWithTear = BaseSkillScript.IsHasUnitWithTear(cond.name, cond.minValue, cond.maxValue, skillSender, skillObject); } if (!hasUnitWithTear) { errorInfo[0] = cond; string[] TCErrors = new string[] { "first", "second", "third", "fourth" }; errorInfo[1] = String.Format("You need to have at least one {1} with {0} upgrade", TCErrors[cond.minValue], cond.readableName); return(errorInfo); } } if (cond.type == SkillConditionType.GlobalUpgradeCheck) { bool check = false; //if (skillObject.GetComponent<BaseBehavior>() != null) // hasUnitWithTear = BaseBehavior.IsHasUnitWithTear(cond.name, cond.minValue, cond.maxValue, team, skillSender); if (skillObject.GetComponent <BaseSkillScript>() != null) { check = CameraController.GlobalUpgradeCheck( cond.name, cond.minValue, cond.maxValue, upgradeType: skillObject.GetComponent <BaseSkillScript>().upgradeType, ownerId: skillSender.GetComponent <BaseBehavior>().ownerId); } if (!check) { errorInfo[0] = cond; errorInfo[1] = "You already has this upgrade"; return(errorInfo); } } if (cond.type == SkillConditionType.OnlyOneAtAQueue && IsQueueContain(skillSender, skillSender.GetComponent <BaseBehavior>().ownerId, skillName)) { errorInfo[0] = cond; errorInfo[1] = "This upgrade can be done in a single copy in one building"; return(errorInfo); } if (cond.type == SkillConditionType.OnlyOne && IsAnyQueueContain(skillSender.GetComponent <BaseBehavior>().ownerId, skillName)) { errorInfo[0] = cond; errorInfo[1] = "This upgrade can be done in a single copy"; return(errorInfo); } } return(errorInfo); }