static async Task DefaultDestroyDahan(DahanGroupBinding dahan, int count, HealthToken token) { if (count <= 0) { return; } await dahan.Destroy(count, token); }
/// <returns># of dahan killed/destroyed</returns> public async Task DamageDefenders(int damageInflictedFromAttackers) { // Defend point have already been applied! // Start with Damage from attackers @event.defenderDamageFromAttackers = damageInflictedFromAttackers; if (damageInflictedFromAttackers == 0 || !cfg.ShouldDamageDahan) { return; } // Add Badlands damage @event.defenderDamageFromBadlands = BadLandsCount; int damageToApply = damageInflictedFromAttackers + BadLandsCount; // to defenders var defenders = @event.startingDefenders.Clone(); // Damage helping Invaders // When damaging defenders, it is ok to damage the explorers first. // https://querki.net/u/darker/spirit-island-faq/#!Voice+of+Command var participatingExplorers = defenders.Keys .OfType <HealthToken>() .Where(k => k.Class.Category == TokenCategory.Invader) .OrderByDescending(x => x.RemainingHealth) .ThenBy(x => x.StrifeCount) // non strifed first .ToArray(); if (participatingExplorers.Length > 0) { foreach (var token in participatingExplorers) { int tokensToDestroy = Math.Min(@event.startingDefenders[token], damageToApply / token.RemainingHealth); // destroy real tokens await grp.Destroy(tokensToDestroy, token); // update our defenders count defenders[token] -= tokensToDestroy; damageToApply -= tokensToDestroy * token.RemainingHealth; } } // !! if we had cities / towns helping with defend, we would want to apply partial damage to them here. // Dahan if (cfg.ShouldDamageDahan) { var participatingDahan = defenders.Keys .Cast <HealthToken>() .Where(k => k.Class.Category == TokenCategory.Dahan) .OrderBy(t => t.RemainingHealth) // kill damaged dahan first .ToArray(); var dahan = new DahanGroupBinding(Tokens, RemoveReason.DestroyedInBattle) { Frozen = Tokens.Dahan.Frozen }; foreach (var token in participatingDahan) { // 1st - Destroy weekest dahan first int tokensToDestroy = Math.Min(@event.startingDefenders[token], damageToApply / token.RemainingHealth); // rounds down if (tokensToDestroy > 0) { await cfg.DestroyDahan(dahan, tokensToDestroy, token); @event.dahanDestroyed += tokensToDestroy; defenders[token] -= tokensToDestroy; damageToApply -= tokensToDestroy * token.RemainingHealth; } // damage real tokens // 2nd - if we no longer have enougth to destroy this token, apply damage all the damage that remains if (0 < defenders[token] && 0 < damageToApply) { await dahan.ApplyDamageToToken(damageToApply, token); // update our defenders count ++defenders[token.AddDamage(damageToApply)]; --defenders[token]; damageToApply = 0; } } } }