コード例 #1
0
    public static async Task SingleInvaderWithExplorers(Spirit spirit, InvaderBinding grp, TokenClass oldInvader, int replaceCount)
    {
        var tokens   = grp.Tokens;
        var specific = (HealthToken)await spirit.Action.Decision(Select.Invader.ToReplace("disolve", grp.Space, tokens.OfType(oldInvader)));

        if (specific == null)
        {
            return;
        }

        tokens.Adjust(specific, -1);
        tokens.AdjustDefault(Invader.Explorer, replaceCount);

        // apply pre-existing damage
        int damage = System.Math.Min(replaceCount, specific.FullHealth - specific.RemainingHealth);      // !!! cleanup damage calculations
        await grp.Destroy(damage, Invader.Explorer);

        // !!! ??? pre-existing strife?
    }
コード例 #2
0
ファイル: RavageAction.cs プロジェクト: rettigcd/spiritisland
    /// <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;
                }
            }
        }
    }
コード例 #3
0
 static Task EachCityDestroys1Town(InvaderBinding grp)
 {
     return(grp.Destroy(grp.Tokens.Sum(Invader.City), Invader.Town));
 }
コード例 #4
0
    static Task Destroy_1ExplorerPerTownAnd2ExplorersPerCity(InvaderBinding grp)
    {
        int numToDestroy = grp.Tokens.Sum(Invader.Town) + grp.Tokens.Sum(Invader.City) * 2;

        return(grp.Destroy(numToDestroy, Invader.Explorer));
    }
コード例 #5
0
 static Task Destroy_1ExplorerPerTown(InvaderBinding grp)
 {
     return(grp.Destroy(grp.Tokens.Sum(Invader.Town), Invader.Explorer));
 }