public override void trigger() { int rollMax = Mathf.RoundToInt(strength); if (rollMax < 2) { Debug.LogWarning("<" + cardName + "> " + XMLName + " could not roll the die because it has less than 2 sides."); argument = null; } else { int roll = (UnityEngine.Random.Range(0, rollMax) + 1); //die roll argument = roll.ToString(); //store in argument //update the parent's propertyEffects, since they may have been cached before the roll was made PropertyEffects?curProps = parentData.propertyEffects; PropertyEffects newProps; if (curProps == null) { newProps = new PropertyEffects(); } else { newProps = curProps.Value; } newProps.dieRoll = roll; parentData.propertyEffects = newProps; } }
/// <summary> /// fires on each enemy in the given list, if possible /// </summary> /// <param name="targets">the enemies to attack</param> /// <returns>whether or not the attack was successful</returns> private bool fire(IEnumerable <EnemyScript> targets) { //only fire if we have valid targets if ((targets != null) && targets.Any()) { //reduce charge meter (if the gauge was overcharged, retain the excess) shotCharge -= 1.0f; //if we are operating on ammo, decrease that too if (effects != null) { if (effects.propertyEffects.limitedAmmo != null) { PropertyEffects temp = effects.propertyEffects; temp.limitedAmmo--; effects.propertyEffects = temp; updateLifespanText(); UpdateTooltipText(); } } //trigger attack effects if (effects != null) { foreach (IEffect effect in effects.effects) { if (effect.triggersAs(EffectType.attack)) { ((IEffectAttack)effect).towerAttack(this); } } } //create a struct and fill it with data about the attack DamageEventData ded = new DamageEventData(); ded.rawDamage = attackPower; ded.source = this; if (effects != null) { ded.effects = effects.clone(); } else { ded.effects = null; } //if overcharged and there are overcharge effects, try to apply them if ((shotCharge >= 1.0f) && (effects != null) && (effects.propertyEffects.maxOvercharge != null)) { int availableOvercharge = Mathf.FloorToInt(shotCharge); //calculate available points of overcharge int usedOvercharge = Mathf.Min(availableOvercharge, effects.propertyEffects.maxOvercharge.Value); //if there are more available than our max, still only use the max shotCharge -= usedOvercharge; //decrement gauge //trigger overcharge effects foreach (IEffect effect in effects.effects) { if (effect.triggersAs(EffectType.overcharge)) { ((IEffectOvercharge)effect).trigger(ref ded, usedOvercharge); } } } //determine projectile spawning by targeting effect if (effects != null) { switch (effects.lastUsedTargetingEffect) { case "targetOrthogonal": //if there is at least one target in range, fire directional shots in four different directions, each targeting enemies in that direction if (targets.Any()) { directionalShot(targets.Where(e => e.transform.position.x < this.transform.position.x).ToList(), ded, Vector2.left); directionalShot(targets.Where(e => e.transform.position.x > this.transform.position.x).ToList(), ded, Vector2.right); directionalShot(targets.Where(e => e.transform.position.y < this.transform.position.y).ToList(), ded, Vector2.up); directionalShot(targets.Where(e => e.transform.position.y > this.transform.position.y).ToList(), ded, Vector2.down); } break; case "targetBurst": burstFire(targets, ded); break; default: foreach (EnemyScript t in targets) { spawnBullet(t, ded); } break; } } else //no targeting effects present: use bullets { foreach (EnemyScript t in targets) { spawnBullet(t, ded); } } return(true); //success } else { return(false); //failure } }