public LavaTile() { name = "Lava"; passable = true; overlapType = TileOverlapType.Swim; sprite = GameAssets.Instance.sprites.GetSprite("Lava"); otDamage = new OverTimeDamage(TileType.Lava, 0.5f, 2); }
// Applies the given over time damage to this entity. public void AddOverTimeDamage(OverTimeDamage ot) { bool doApply = true; int cur = otDamage.IndexOf(ot); if (cur != -1) { otDamage[cur].active = true; doApply = false; } if (doApply) { ot.active = true; // Must make a new instance, otherwise entities will share a // single instance in the tile data and clash with each other. otDamage.Add(new OverTimeDamage(ot.type, ot.interval, ot.damage)); } }
// Applies damage to the entity based on the active // over time damage. public void ApplyOverTimeDamage() { for (int i = otDamage.Count - 1; i >= 0; --i) { OverTimeDamage ot = otDamage[i]; ot.timeLeft -= Time.deltaTime; if (ot.timeLeft <= 0.0f) { if (!ot.active) { otDamage.RemoveAt(i); continue; } Damage(ot.damage); ot.timeLeft = ot.interval; } // Set to inactive so that next time it runs out of time, // it will go away unless it was set to active before that. ot.active = false; } }