public async Task <int> RequestAccountUpgrade(string type, string user) { var users = _ctx.UserBase.AsQueryable().Where(u => u.Email == user).Select(u => u).FirstOrDefault(); UpgradeRequest request = new UpgradeRequest() { Organization = users.Organization, role = type, UserId = users.Id }; //var result = _ctx.UpgradeRequest.Add(request); try { //int response = await _ctx.SaveChangesAsync(); //return response; await _ctx.UpgradeRequest.InsertOneAsync(request); return(1); } catch (DbUpdateException) { throw; } }
/// <summary> /// Players upgrade request processing /// </summary> /// <param name="clientID"></param> /// <param name="request"></param> public void ProcessUpgradeRequest(int clientID, UpgradeRequest request) { Player player = PlayersManager.GetPlayer(clientID); if (player == null) { Console.WriteLine($"Can't find player {clientID}"); return; } if (player.CurrentMatch == null) { Console.WriteLine($"Player {player.ClientID} is not in the game"); return; } GameMatch match = player.CurrentMatch; Field playerField = match.Player1 == player ? match.Field1 : match.Field2; Field enemyField = match.Player1 == player ? match.Field2 : match.Field1; Player enemy = match.Player1 == player ? match.Player2 : match.Player1; FieldManager.RefreshDurationEffects(playerField); FieldManager.RefreshDurationEffects(enemyField); FieldManager.RefreshGlobalEffects(playerField, player); FieldManager.RefreshGlobalEffects(enemyField, enemy); UpgradeRequestResponse upgradeResponse = UpgradeManager.ProcessUpgradeRequest(match, player, request.UpgradeBlockType); switch (upgradeResponse) { case UpgradeRequestResponse.Ok: break; case UpgradeRequestResponse.NotEnoughMana: SendError(player, ErrorType.NotEnoughMana); return; default: throw new ArgumentOutOfRangeException(); } GameStateResponse response = new GameStateResponse { GameState = GetPlayer1MatchStateData(match), Effects = new EffectData[0], }; Server.SendDataToClient(match.Player1.ClientID, (int)DataTypes.GameStateResponse, response); if (match.GameMode == GameMode.Practice) { return; } response = new GameStateResponse { GameState = GetPlayer2MatchStateData(match), Effects = new EffectData[0] }; Server.SendDataToClient(match.Player2.ClientID, (int)DataTypes.GameStateResponse, response); }
/// <summary> /// Request to upgrade block type /// </summary> /// <param name="blockType"></param> public void OnPlayerUpgrade(BlockTypes blockType) { UpgradeRequest request = new UpgradeRequest(); request.UpgradeBlockType = blockType; NetworkManager.Instance.SendUpgradeData(request); }
public JsonResult Upgrade(UpgradeRequest request) { var response = new JResult() { Status = false }; //当前上下文 var context = CustomerContext.Context; if (context == null) { response.Message = "用户已超时、请重新登录﹗"; return(Json(response, JsonRequestBehavior.AllowGet)); } var customer = CustomerApp.Instance.Get(context.SysNo); if (customer == null) { response.Message = "扩展会员不存在﹗"; return(Json(response, JsonRequestBehavior.AllowGet)); } var upgradeGrade = customer.Grade + Step.步长.GetHashCode(); var code = CodeApp.Instance.GetByType(EC.Entity.Enum.CodeEnum.CodeTypeEnum.会员等级信息.GetHashCode()); if (code != null) { var grades = code.Value.ToObject <List <Grade> >(); var grade = grades.FirstOrDefault(p => p.Type == upgradeGrade); if (grade != null) { //验证升级基金 if (customer.UpgradeFundAmount < grade.Amount) { response.StatusCode = ErrorEnum.余额不足.GetHashCode().ToString(); response.Message = "升级基金不足!"; return(Json(response, JsonRequestBehavior.AllowGet)); } } } response = NewCustomerApp.Instance.NewUpgrade(new EC.Entity.Parameter.Request.NewCRM.NewUpgradeRequest() { CustomerSysNo = customer.SysNo }); return(Json(response, JsonRequestBehavior.AllowGet)); }
/// <summary> /// Posts a new upgrade request to a confirmation validator requesting that it upgrade to a Primary Validator. /// Requesting bank will pass a <see cref="UpgradeRequest"/> /// </summary> /// <param name="upgradeRequest"></param> /// <returns><see cref="HttpResponseMessage"/>NOTE: 200: Ok - Validator has accepted the upgrade request, 400: Bad Request - Validator has rejected the upgrade</returns> public async Task <HttpResponseMessage> PostUpgradeRequestAsync(UpgradeRequest upgradeRequest) { if (upgradeRequest is null) { // TODO: Create specific exception throw new Exception(); } var httpContent = new StringContent(JsonConvert.SerializeObject(upgradeRequest), Encoding.UTF8, "application/json"); var jsonString = await httpContent.ReadAsStringAsync(); if (string.IsNullOrEmpty(jsonString)) { // TODO: Create specific exception throw new Exception(); } var response = await _requestSender.PostAsync("/upgrade_request/", httpContent); return(response); }
public ResultBase Execute([FromBody] UpgradeRequest request) { ResultBase result = new ResultBase(); User user = this.userDao.GetUser(request.UserID); UpgradeData upgradeInfo = null; if ("Health".Equals(request.UpgradeType)) { upgradeInfo = this.upgradeDao.GetUpgradeInfo(request.UpgradeType, user.HealthLevel); } else if ("Damage".Equals(request.UpgradeType)) { upgradeInfo = this.upgradeDao.GetUpgradeInfo(request.UpgradeType, user.HealthLevel); } else if ("Defense".Equals(request.UpgradeType)) { upgradeInfo = this.upgradeDao.GetUpgradeInfo(request.UpgradeType, user.HealthLevel); } else if ("Speed".Equals(request.UpgradeType)) { upgradeInfo = this.upgradeDao.GetUpgradeInfo(request.UpgradeType, user.HealthLevel); } else { // 유효하지 않은 업그레이드 타입입니다. } // 다이아몬드가 있는지? if (user.Diamond < upgradeInfo.UpgradeCost) { // TODO: 돈이 없어서 업그레이드 못해줌 result.ResultCode = 5; result.Message = "Not Enough Diamond"; return(result); } if (upgradeInfo == null) { // 최대 레벨에 도달했습니다. result.ResultCode = 4; result.Message = "Upgrade Fail : Max Level"; return(result); } if ("Health".Equals(request.UpgradeType)) { user.HealthLevel = user.HealthLevel + 1; user.Health = user.Health + upgradeInfo.UpgradeAmount; user.Diamond = user.Diamond - upgradeInfo.UpgradeCost; } else if ("Damage".Equals(request.UpgradeType)) { user.DamageLevel = user.DamageLevel + 1; user.Damage = user.Damage + upgradeInfo.UpgradeAmount; user.Diamond = user.Diamond - upgradeInfo.UpgradeCost; } else if ("Defense".Equals(request.UpgradeType)) { user.DefenseLevel = user.DefenseLevel + 1; user.Defense = user.Defense + upgradeInfo.UpgradeAmount; user.Diamond = user.Diamond - upgradeInfo.UpgradeCost; } else if ("Speed".Equals(request.UpgradeType)) { user.SpeedLevel = user.SpeedLevel + 1; user.Speed = user.Speed + upgradeInfo.UpgradeAmount; user.Diamond = user.Diamond - upgradeInfo.UpgradeCost; } this.userDao.UpdateUser(user); result.ResultCode = 1; result.Message = "Success"; return(result); }
public void SendUpgradeData(UpgradeRequest request) { client.SendData((int)DataTypes.UpgradeRequest, request); }