예제 #1
0
    public async Task <string> Exec(
        BuildingEventArgs args,
        TokenCountDictionary tokens,
        GameState gameState
        )
    {
        if (!tokens.HasInvaders())
        {
            return("No invaders");
        }

        BuildingEventArgs.BuildType buildType = args.GetBuildType(tokens.Space);

        this.tokens    = tokens;
        this.buildType = buildType;
        this.gameState = gameState;

        if (await StopBuildWithDiseaseBehavior())
        {
            return(tokens.Space.Label + " build stopped by disease");
        }

        // Determine type to build
        int townCount = tokens.Sum(Invader.Town);
        int cityCount = tokens.Sum(Invader.City);
        HealthTokenClass invaderToAdd = townCount > cityCount ? Invader.City : Invader.Town;

        // check if we should
        bool shouldBuild = buildType switch {
            BuildingEventArgs.BuildType.CitiesOnly => invaderToAdd == Invader.City,
            BuildingEventArgs.BuildType.TownsOnly => invaderToAdd == Invader.Town,
            _ => true,
        };

        // build it
        if (shouldBuild)
        {
            await tokens.AddDefault(invaderToAdd, 1, AddReason.Build);
        }

        return(invaderToAdd.Label);
    }
예제 #2
0
 /// <summary> Adds a Dahan from the bag, or out of thin air. </summary>
 public Task Add(int count, AddReason reason = AddReason.Added)
 {
     return(_tokens.AddDefault(TokenType.Dahan, count, reason));
 }