/// <summary> /// Method for loading an ability from the name of that ability /// Returns an ability loaded based on its type. /// Used to load abilities after a save or in combat mode as entire abilities can /// not be easily serialized. /// </summary> /// <param name="pstrAbilityName"></param> /// <returns></returns> public static Ability LoadAbilityFromName(string pstrAbilityName) { Ability musLoadedAbility = null; string strFormattedAbilityName = pstrAbilityName.ToLower().Replace(" ", string.Empty); if (SingleTargetAbilities.Contains(strFormattedAbilityName)) { musLoadedAbility = new SingleTargetAbility(pstrAbilityName); } else if (MultiTargetAbilities.Contains(strFormattedAbilityName)) { musLoadedAbility = new MultiTargetAbility(pstrAbilityName); } else if (BuffAbilities.Contains(strFormattedAbilityName)) { musLoadedAbility = new BuffAbility(pstrAbilityName); } else if (DebuffAbilities.Contains(strFormattedAbilityName)) { musLoadedAbility = new DebuffAbility(pstrAbilityName); } return(musLoadedAbility); }
public void OnMouseOver() { //If the animation is done if (inPlace && MapMan.Selected != null) { //Init our lists of targets targets = new List <Unit>(); //If it's single target we're just target the one tile if (ability.AbiltyType == Ability.ABILITYTYPE.SingleTarget) { //Check who we're targeting if (BoardMan.playerUnits.Contains(MapMan.Selected.GetComponent <UnitObjectScript>().getUnit())) { targets = BoardMan.enemyUnits; } else { targets = BoardMan.playerUnits; } //Check if we're a valid tile foreach (Unit u in targets) { if (pos.x == u.getPos().x&& pos.y == u.getPos().y) { valid = true; } } //If we're valid, change material when moused over if (valid) { GetComponent <MeshRenderer>().material = mousedOverValid; } else { GetComponent <MeshRenderer>().material = mousedOverInvalid; } } //If it's multi target, we gotta worry about shapes else if (ability.AbiltyType == Ability.ABILITYTYPE.MultiTarget) { MultiTargetAbility aMi = (MultiTargetAbility)MultiTargetAbility.LoadAbilityFromName(ability.AbilityName); if (AOEShape == null) { //Cone is actually a sphere (just didn't change the name elsewhere yet) if (aMi.AbilityShape == Ability.MultiTargetShape.Cone) { AOEShape = Instantiate(SphereAOEPrefab); AOEShape.transform.localScale *= aMi.Length; AOEShape.gameObject.layer = 2; AOEShape.transform.position = transform.position; } else if (aMi.AbilityShape == Ability.MultiTargetShape.Line) { AOEShape = Instantiate(CubeAOEPrefab); AOEShape.gameObject.layer = 2; AOEShape.transform.localScale = new Vector3(AOEShape.transform.localScale.x * aMi.Length, AOEShape.transform.localScale.y, AOEShape.transform.localScale.z); AOEShape.transform.position = new Vector3(transform.position.x + aMi.Length / 2, transform.position.y, transform.position.z); } else if (aMi.AbilityShape == Ability.MultiTargetShape.Square) { AOEShape = Instantiate(CubeAOEPrefab); AOEShape.transform.localScale *= aMi.Length; AOEShape.gameObject.layer = 2; AOEShape.transform.position = transform.position; } } //Get the line offset and facing the right way if (aMi.AbilityShape == Ability.MultiTargetShape.Line) { if (BoardMan.abilityDirection == 0) { AOEShape.transform.eulerAngles = new Vector3(0, 0, 0); AOEShape.transform.position = new Vector3(transform.position.x + aMi.Length / 2, transform.position.y, transform.position.z); } else if (BoardMan.abilityDirection == 1) { AOEShape.transform.eulerAngles = new Vector3(0, 270, 0); AOEShape.transform.position = new Vector3(transform.position.x, transform.position.y, transform.position.z + aMi.Length / 2); } else if (BoardMan.abilityDirection == 2) { AOEShape.transform.eulerAngles = new Vector3(0, 180, 0); AOEShape.transform.position = new Vector3(transform.position.x - aMi.Length / 2, transform.position.y, transform.position.z); } else if (BoardMan.abilityDirection == 3) { AOEShape.transform.eulerAngles = new Vector3(0, 90, 0); AOEShape.transform.position = new Vector3(transform.position.x, transform.position.y, transform.position.z - aMi.Length / 2); } } //Check what units we should be targeting. if (ability.AbiltyType != Ability.ABILITYTYPE.Buff) { if (BoardMan.playerUnits.Contains(MapMan.Selected.GetComponent <UnitObjectScript>().getUnit())) { targets = AOEShape.GetComponent <AOE>().getTargets(true); } else { targets = AOEShape.GetComponent <AOE>().getTargets(false); } } else { if (BoardMan.playerUnits.Contains(MapMan.Selected.GetComponent <UnitObjectScript>().getUnit())) { targets = AOEShape.GetComponent <AOE>().getTargets(false); } else { targets = AOEShape.GetComponent <AOE>().getTargets(true); } } if (targets != new List <Unit>()) { valid = true; } else { valid = false; } if (valid) { GetComponent <MeshRenderer>().material = mousedOverValid; AOEShape.GetComponent <MeshRenderer>().material = mousedOverValid; } else { GetComponent <MeshRenderer>().material = mousedOverInvalid; AOEShape.GetComponent <MeshRenderer>().material = mousedOverInvalid; } } else if (ability.AbiltyType == Ability.ABILITYTYPE.Buff) { //If we're a buff, we target friendly units if (BoardMan.playerUnits.Contains(MapMan.Selected.GetComponent <UnitObjectScript>().getUnit())) { targets = BoardMan.playerUnits; } else { targets = BoardMan.enemyUnits; } foreach (Unit u in targets) { if (pos.x == u.getPos().x&& pos.y == u.getPos().y) { valid = true; } } if (valid) { GetComponent <MeshRenderer>().material = mousedOverValid; } else { GetComponent <MeshRenderer>().material = mousedOverInvalid; } } else if (ability.AbiltyType == Ability.ABILITYTYPE.Debuff) { //Debuff targets enemy units if (BoardMan.playerUnits.Contains(MapMan.Selected.GetComponent <UnitObjectScript>().getUnit())) { targets = BoardMan.enemyUnits; } else { targets = BoardMan.playerUnits; } foreach (Unit u in targets) { if (pos.x == u.getPos().x&& pos.y == u.getPos().y) { valid = true; } } if (valid) { GetComponent <MeshRenderer>().material = mousedOverValid; } else { GetComponent <MeshRenderer>().material = mousedOverInvalid; } } //Actually clicking (using the ability) if ((Input.GetMouseButtonDown(0) || autoClick) && !buttonSwitch) { buttonSwitch = true; //Grab gameInfo for scaling GameObject GameInfoObject = GameObject.Find("GameInfo"); GameInfo gameInfo = GameInfoObject.GetComponent <GameInfo>(); //Subtract faith cost and then update the ui (MapMan.Selected.GetComponent <UnitObjectScript>().getUnit() as God).faith -= ability.FaithCost; UIMan.updateFaithLabels(); //Just damage the one unit if single target if (ability.AbiltyType == Ability.ABILITYTYPE.SingleTarget) { SingleTargetAbility aSi = (SingleTargetAbility)SingleTargetAbility.LoadAbilityFromName(ability.AbilityName); Unit target = new Unit(); foreach (Unit u in targets) { if (pos.x == u.getPos().x&& pos.y == u.getPos().y) { target = u; } } if (BoardMan.playerUnits.Contains(target)) { target.dealDamage((int)((aSi.AbilityDamage + (gameInfo.PlayerFaction.WorshipperCount / 100)) * gameInfo.GodAttackMultiplier)); } else { target.dealDamage((int)((aSi.AbilityDamage + (gameInfo.PlayerFaction.WorshipperCount / 100)) * (gameInfo.EnemyFaction.GodTier + 1))); } //Kill target if it died if (target.WorshiperCount <= 0) { BoardMan.killUnit(target); } } // Damage all the target within the AOE if it's multi else if (ability.AbiltyType == Ability.ABILITYTYPE.MultiTarget) { MultiTargetAbility aMi = (MultiTargetAbility)MultiTargetAbility.LoadAbilityFromName(ability.AbilityName); foreach (Unit u in targets) { if (BoardMan.playerUnits.Contains(u)) { u.dealDamage((int)((aMi.AbilityDamage + (gameInfo.PlayerFaction.WorshipperCount / 100)) * gameInfo.GodAttackMultiplier)); } else { u.dealDamage((int)((aMi.AbilityDamage + (gameInfo.PlayerFaction.WorshipperCount / 100)) * (gameInfo.EnemyFaction.GodTier + 1))); } if (u.WorshiperCount <= 0) { BoardMan.killUnit(u); } } GameObject[] AOEShapes = GameObject.FindGameObjectsWithTag("AOEShapes"); foreach (GameObject g in AOEShapes) { Destroy(g); } } else if (ability.AbiltyType == Ability.ABILITYTYPE.Buff) { Unit target = new Unit(); foreach (Unit u in targets) { if (pos.x == u.getPos().x&& pos.y == u.getPos().y) { target = u; } } //Add the new status effect when used target.addNewStatusEffect(ability, true); } else if (ability.AbiltyType == Ability.ABILITYTYPE.Debuff) { Unit target = new Unit(); foreach (Unit u in targets) { if (pos.x == u.getPos().x&& pos.y == u.getPos().y) { target = u; } } //Add the new status effect when used target.addNewStatusEffect(ability, false); } //End turn once we used an ability MapMan.Selected.GetComponent <UnitObjectScript>().getUnit().EndTurnButton(); //Unslecting //MapMan.Selected = null; //Clean up Tiles MapMan.ClearSelection(); } if (Input.GetMouseButtonUp(0) && buttonSwitch) { buttonSwitch = false; } //Udating direction for the line AOE if (Input.GetMouseButtonDown(1)) { if (BoardMan.abilityDirection < 3) { BoardMan.abilityDirection++; } else { BoardMan.abilityDirection = 0; } } } }