Example #1
0
 async Task SacredSiteAtSouce_RestoreVirtualBeast(TokenMovedArgs args, TokenBinding srcBeasts)
 {
     if (2 <= CountOn(args.RemovedFrom))
     {
         await srcBeasts.Add(1);             // Beast token is virtual so maybe we don't want to trigger TokenAdded
     }
 }
    public async Task CheckForMove(TokenMovedArgs args)
    {
        if (args.Token.Class != tokenGroup)
        {
            return;
        }

        int maxThatCanMove = Math.Min(args.Count, spirit.Presence.CountOn(args.RemovedFrom));

        // 0 -> no action
        if (maxThatCanMove == 0)
        {
            return;
        }

        if (maxThatCanMove > 1)
        {
            throw new InvalidOperationException("Method is only designed to accept 1 move at a time.");
        }

        // Using 'Gather' here so user can click on existing Presence in Source
        // If we used 'Push', user would click on Destination instead of Source
        var source = await spirit.Action.Decision(Select.DeployedPresence.Gather("Move presence with " + args.Token.Class.Label + "?", args.AddedTo, new Space[] { args.RemovedFrom }));

        if (source != null)
        {
            spirit.Presence.Move(args.RemovedFrom, args.AddedTo, args.GameState);
        }
    }
Example #3
0
 void Move2Presence(GameState gs, TokenMovedArgs args)
 {
     // Move 2 of our presence
     for (int i = 0; i < 2; ++i)
     {
         base.RemoveFrom_NoCheck(args.RemovedFrom, gs);               // using base because we don't want to trigger anything
         base.PlaceOn(args.AddedTo, gs);
     }
 }
Example #4
0
 Task AddedVirtualBeastAtDestination_LimitTo1(GameState gs, TokenMovedArgs args)
 {
     // if destination/to now has 4 or more presence,
     // then there was already a virtual beast there and we need to remove 1 of the virtual beasts
     if (4 <= CountOn(args.AddedTo))
     {
         gs.Tokens[args.AddedTo].Beasts.Adjust(-1);             // don't trigger event
     }
     return(Task.CompletedTask);
 }
Example #5
0
    public async Task Publish_Moved(Token token, Space from, Space to)
    {
        var args = new TokenMovedArgs {
            Token       = token,
            RemovedFrom = from,
            AddedTo     = to,
            Count       = 1,
            GameState   = this.gameStateForEventArgs
        };

        await TokenMoved.InvokeAsync(args);

        // Also trigger the Added & Removed events
        await TokenAdded.InvokeAsync(args);

        await TokenRemoved.InvokeAsync(args);
    }
Example #6
0
    async Task InvadersMoved(TokenMovedArgs args)
    {
        if (!args.AddedTo.IsOcean)
        {
            return;
        }
        var gs  = args.GameState;
        var grp = args.Token.Class;

        if (grp == Invader.City || grp == Invader.Town || grp == Invader.Explorer)            // Could created an Invader subclass that is easier to test.
        // Drown Invaders for points
        {
            drownedCount += args.Token.FullHealth;
            await gs.Invaders.On(args.AddedTo).Destroy(1, (HealthToken)args.Token);

            int spiritCount = gs.Spirits.Length;
            while (spiritCount <= drownedCount)
            {
                ++Energy;
                drownedCount -= spiritCount;
            }
        }
    }
Example #7
0
    async Task TokenMoved(TokenMovedArgs args)
    {
        if (args.Token != TokenType.Beast)
        {
            return;                                       // not a beast
        }
        if (this.CountOn(args.RemovedFrom) < 2)
        {
            return;                                              // not our Sacred Site
        }
        var srcBeasts = args.GameState.Tokens[args.RemovedFrom].Beasts;

        if (srcBeasts.Count > 0 &&     // force moved our virtual beast
            await spirit.Action.Decision(Select.DeployedPresence.Gather("Move 2 presence with Beast?", args.AddedTo, new [] { args.RemovedFrom })) == null
            )
        {
            return;       // not moving presence
        }
        Move2Presence(args.GameState, args);

        await SacredSiteAtSouce_RestoreVirtualBeast(args, srcBeasts);

        await AddedVirtualBeastAtDestination_LimitTo1(args.GameState, args);
    }