public void RightButtonPush()
 {
     var asyncDelegation = new AsyncDelegation(restService);
     asyncDelegation.Post("add", new {Name="MonoTouch Name" })
         .WhenFinished(()=> {
             PullData();
         });
     asyncDelegation.Go();
 }
 private void AddGame(Guid gameId, string gameName)
 {
     var asyncDelegation = new AsyncDelegation(restService);
     asyncDelegation
         .Post("add", new { id = gameId.ToString(), name=gameName })
             .WhenFinished(() => FetchGames());
     asyncDelegation.Go();
 }
 void JoinGame(string gameId)
 {
     var asyncDelegation = new AsyncDelegation(restService);
     asyncDelegation.Post("joingame", new {gameId = gameId, playerId = Application.PlayerId, playerName = "Mono Touch"})
         .WhenFinished(()=> {
             var gameView = new GameViewController(gameId);
             this.NavigationController.PushViewController(gameView, true);
         });
     asyncDelegation.Go();
 }
 private void AddGame(string gameId, string gameName)
 {
     var asyncDelegation = new AsyncDelegation(restService);
     asyncDelegation
         .Post("add", new { id = gameId, name=gameName })
             .WhenFinished(()=>{JoinGame(gameId);})
             .Go();
 }
        /// <summary>
        /// Request from the view to hunt.
        /// </summary>
        public void Hunt()
        {
            //return if the current zombie pack id is 0
            if (_currentZombiePackId == Guid.Empty)
            {
                return;
            }

            if (_currentZombiePackInfo != null && _currentZombiePackInfo.CostPerHunt > _gameContext.UserEnergy.CurrentEnergy)
            {
                _notificationView.Notify("You do not have enough energy to hunt here.  Use an item to replenish your energy, equip armor to raise your maximum energy, or simply wait for your energy to replenish.  You will regain energy over time.");
                return;
            }

            AsyncDelegation ad = new AsyncDelegation();

            //perform hunt
            ad.Post(
              new
              {
                  controller = "ZombiePacks",
                  action = "Hunt",
                  userId = _gameContext.UserId,
                  zombiePackId = _currentZombiePackId
              })
                //when finished do nothing
              .WhenFinished(() => { })
              .ThenGet<UserInGameStats>(new { controller = "Users", action = "Stats", userId = _gameContext.UserId })
              .WhenFinished(
              (data) =>
              {
                  _gameContext.SetUserEnergy(data.EnergyResult);
                  _gameContext.SetUserInventory(data.Items);
                  _gameContext.SetUserAttackPower(data.AttackPower.Value);
                  _gameContext.SetMoney(data.Money.Value);
                  _gameContext.SetUserMaxItems(data.MaxItems.Value);
                  _gameContext.SetUserLevel(data.LevelResult);
              })
              //check to see if the zombie pack is cleared
              .ThenGet<BooleanResult>(
              new
              {
                  controller = "ZombiePacks",
                  action = "IsCleared",
                  userId = _gameContext.UserId,
                  zombiePackId = _currentZombiePackId
              })
                //when the zombie pack data is returned
              .WhenFinished(
              (booleanResult) =>
              {
                  //if the zombie pack has been destroyed
                  if (booleanResult.Value == true)
                  {
                      //find the zombie pack
                      Node node = _visibleZombiePacks.FirstOrDefault(c => c.Id == _currentZombiePackId);
                      if (node != null)
                      {
                          //remove the node from visible nodes
                          _visibleZombiePacks.Remove(node);

                          //notify to the game context that a zombie pack has been destroyed
                          List<Guid> nodes = new List<Guid>();
                          nodes.Add(node.Id);
                          _mapPresenterView.RemoveZombiePacks(nodes);

                          //set the zombie pack to guid.empty
                          _currentZombiePackId = Guid.Empty;

                          //if the zombie pack has been cleared, determine if the hotzone has been cleared and update the hunt status of the user
                          _gameContext.NotifyZombiePackDestroyed(node.Id);
                          UpdateHuntStatus();
                      }
                  }
                  else
                  {
                      //if the zombie pack hasn't been destroyed, update hunt status to reflect new destruction amounts.
                      UpdateHuntStatus();
                  }
              });

            ad.Go();
        }
        public void Buy(Item item)
        {
            if (item.Price > _gameContext.Money)
            {
                _notificationView.Notify("You don't have enough money to buy this item.  Go hunt for more zombies and come back when you do.");
                return;
            }

            if (_gameContext.UserInventory.Count >= _gameContext.UserMaxItems)
            {
                _notificationView.Notify("You can't carry any more items.  Go to the safe house and drop some items off, then come back.");
                return;
            }

            AsyncDelegation ad = new AsyncDelegation();

            ad.Post(
                new
                {
                    controller = "Users",
                    action = "BuyItem",
                    userId = _gameContext.UserId,
                    itemId = item.Id
                })
                .WhenFinished(() => { })
                .ThenGet<IntResult>(new { controller = "Users", action = "Money", userId = _gameContext.UserId })
                .WhenFinished(r =>
                {
                    _gameContext.SetMoney(r.Value);
                    GetUserMoney();
                    GetUserInventory();
                });

            ad.Go();

        }
        void SelectCard(string cardId)
        {
            var asyncDelegation = new AsyncDelegation (restService);

            if (_isCzar) {
                asyncDelegation.Post ("selectWinner", new {gameId = _gameId, cardId = cardId})
                .WhenFinished (() => {
                    FetchGame ();
                });
                asyncDelegation.Go ();
            } else {
                asyncDelegation.Post ("selectCard", new {gameId = _gameId, playerId = Application.PlayerId, whiteCardId = cardId})
                    .WhenFinished (() => {
                        FetchGame ();
                    });
                asyncDelegation.Go ();
            }
        }
 void ReadyForNextRound()
 {
     var asyncDelegation = new AsyncDelegation(restService);
     asyncDelegation.Post("readyForNextRound", new {gameId = _gameId, playerId = Application.PlayerId})
         .WhenFinished(()=> {
             shouldPool = true;
             PollGameData();
         });
     asyncDelegation.Go();
 }
        internal void TransferItemFromSafeHouseToUser(Guid itemId)
        {
            if (_gameContext.UserInventory.Count >= _gameContext.UserMaxItems)
            {
                _notificationView.Notify("You cannot equip any more items.  Move items to the safe house first to create more space.");
                return;
            }

            SafeHouseNode currentSafeHouse = GetCurrentSafeHouse();
            if (currentSafeHouse == null)
            {
                return;
            }

            AsyncDelegation ad = new AsyncDelegation();

            ad.Post(
                new
                {
                    controller = "SafeHouses",
                    action = "UserRetrieveItem",
                    userId = _gameContext.UserId,
                    safeHouseId = currentSafeHouse.Id,
                    itemId = itemId
                })
                .WhenFinished(() =>
                {
                    GetUserInventory();
                    GetSafeHouseInventory();
                });

            ad.Go();
        }
        internal void TransferItemFromUserToSafeHouse(Guid itemId)
        {
            SafeHouseNode currentSafeHouse = GetCurrentSafeHouse();
            if (currentSafeHouse == null)
            {
                return;
            }

            AsyncDelegation ad = new AsyncDelegation();

            ad.Post(
                new
                {
                    controller = "SafeHouses",
                    action = "StoreItem",
                    userId = _gameContext.UserId,
                    safeHouseId = currentSafeHouse.Id,
                    itemId = itemId
                })
                .WhenFinished(() =>
                {
                    GetUserInventory();
                    GetSafeHouseInventory();
                });

            ad.Go();
        }