void Update() { if (currentStatus == null) { return; } var nextStatus = currentStatus?.OnUpdate(); if (nextStatus != null && nextStatus != currentStatus?.GetType()) { SwitchStatus(nextStatus); } }
public void AddStatus(BaseStatus newStatus) { BaseStatus oldStatus = SearchStatusLike(newStatus.GetType()); if (oldStatus == null) { _statuses.Add(newStatus); } else { oldStatus.Update(newStatus); newStatus.DestroyStatusExecute(); } UpdateUI(); }
void ApplyToTile(int tile, Effect effect) { // Get list of valid tiles List <int> targetTiles; if (areaOfEffect) { targetTiles = Battleground.Instance.GetTilesFromShape(targetArea, tile); } else { targetTiles = new List <int> { tile } }; Debug.Log("tiles number: " + targetTiles.Count); switch (effect.effectType) { case EffectType.Miasma: // Spawn miasma on tiles foreach (int t in targetTiles) { MiasmaFieldEffect miasma = new MiasmaFieldEffect(effect.effectValue, effect.duration, owner, t); Battleground.Instance.AddFieldEffect(t, miasma); } break; case EffectType.Damage: float mult = 1.00f; for (int i = owner.Statuses.Count - 1; i >= 0; i--) { BaseStatus status = owner.Statuses[i]; if (status.GetType() == typeof(DamageMultiplierStatus)) { mult += status.Multiplier; // Remove multiplier status // TODO change if the status can have more than 1 use } } foreach (int t in targetTiles) { BaseUnit target = Battleground.Instance.GetUnitOnTile(t); if (target == null) { continue; } if (ParseTargetType(TargetType.Enemy, target.IsPlayer())) { int damage = (int)Math.Round(effect.effectValue * mult); target.DealDamage(damage, owner); owner.RemoveStatusOfType(typeof(DamageMultiplierStatus)); owner.UpdateUI(); // Add threat to player units if (owner.IsPlayer()) { PartyManager.Instance.ChangeThreat(owner, damage * 0.01f); } } } break; } } void ApplyToTargets(BaseUnit[] targets, Effect effect) { Debug.Log("Applying effects"); // Apply effects to specifically targeted units (dragged card onto or put AoE targeter on). switch (effect.effectType) { case EffectType.Damage: foreach (BaseUnit target in targets) { if (ParseTargetType(effect.targetType, target.IsPlayer())) { float mult = 1.00f; for (int i = owner.Statuses.Count - 1; i >= 0; i--) { BaseStatus status = owner.Statuses[i]; if (status.GetType() == typeof(DamageMultiplierStatus)) { mult += status.Multiplier; // Remove multiplier status // TODO change if the status can have more than 1 use owner.RemoveStatusOfType(status.GetType()); owner.UpdateUI(); } } int damage = (int)Math.Round(effect.effectValue * mult); target.DealDamage(damage, owner); // Add threat to player units if (owner.IsPlayer()) { PartyManager.Instance.ChangeThreat(owner, damage * 0.01f); } } } break; case EffectType.Block: foreach (BaseUnit target in targets) { if (ParseTargetType(effect.targetType, target.IsPlayer())) { BlockStatus blockStatus = new BlockStatus(effect.effectValue, effect.duration, owner, owner); target.AddStatus(blockStatus); } } break; case EffectType.Taunt: foreach (BaseUnit target in targets) { if (ParseTargetType(effect.targetType, target.IsPlayer())) { TauntStatus taunt = new TauntStatus(effect.duration, owner, target); target.AddStatus(taunt); } } break; case EffectType.Stun: foreach (BaseUnit target in targets) { if (ParseTargetType(effect.targetType, target.IsPlayer())) { StunStatus stun = new StunStatus(effect.duration, owner, target); target.AddStatus(stun); } } break; case EffectType.Push: foreach (BaseUnit target in targets) { if (ParseTargetType(effect.targetType, target.IsPlayer())) { // check if not on last col List <int> pushTiles = Battleground.Instance.FindEmptyTileNear(target.GetGridPosition()); if (pushTiles.Count < 1) { return; } int nextPos = pushTiles[UnityEngine.Random.Range(0, pushTiles.Count)]; target.MoveToTile(nextPos); if (owner.IsPlayer()) { PartyManager.Instance.ChangeThreat(owner, 0.05f); } } } break; case EffectType.SummonVoodoo: foreach (BaseUnit target in targets) { if (ParseTargetType(effect.targetType, target.IsPlayer())) { // Create voodoo unit GameObject voodooPrefab = Resources.Load <GameObject>("Prefabs/Units/Voodoo"); Debug.Log(voodooPrefab); BaseUnit voodoo = Instantiate(voodooPrefab).GetComponent <BaseUnit>(); List <int> voodooTiles = Battleground.Instance.FindEmptyTileNear(target.GetGridPosition()); int voodooPos = voodooTiles[UnityEngine.Random.Range(0, voodooTiles.Count)]; Battleground.Instance.PlaceUnitAt(voodoo, voodooPos); // Add status to transfer damage HealthLinkStatus healthLinkstatus = new HealthLinkStatus(1.0f, owner, target); voodoo.AddStatus(healthLinkstatus); } } break; case EffectType.Weakness: foreach (BaseUnit target in targets) { if (ParseTargetType(effect.targetType, target.IsPlayer())) { WeaknessStatus weaknessStatus = new WeaknessStatus(0.01f * effect.effectValue, effect.duration, owner, target); target.AddStatus(weaknessStatus); } } break; } }