Exemplo n.º 1
0
        public async Task <ServiceResponse <GetCharacter> > UpdateCharacter(UpdateCharacter updateCharacter)
        {
            ServiceResponse <GetCharacter> serviceResponse = new ServiceResponse <GetCharacter>();

            Character character = characters.FirstOrDefault(c => c.Id == updateCharacter.Id);


            try
            {
                character.Name         = updateCharacter.Name;
                character.Strength     = updateCharacter.Strength;
                character.Class        = updateCharacter.Class;
                character.Defence      = updateCharacter.Defence;
                character.HitPoints    = updateCharacter.HitPoints;
                character.Intelligence = updateCharacter.Intelligence;

                serviceResponse.Data = _mapper.Map <GetCharacter>(character);
            }
            catch (Exception ex)
            {
                serviceResponse.Success = false;
                serviceResponse.Message = ex.Message;
            }

            return(serviceResponse);
        }
Exemplo n.º 2
0
        public async Task <IActionResult> UpdateCharacter(UpdateCharacter updatedcharacter)
        {
            ServiceResponse <GetCharacter> response = await _characterService.UpdateCharacter(updatedcharacter);

            if (response.Data == null)
            {
                return(NotFound(response));
            }

            return(Ok(response));
        }
Exemplo n.º 3
0
        public ActionResult CharacterUpdateView(UpdateCharacter uModel)
        {
            try
            {
                Character character = characterClient.Find(uModel.Name);
                characterClient.Update(character);

                return(RedirectToAction("CharacterView"));
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                return(View("CharacterUpdateView"));
            }
        }
Exemplo n.º 4
0
    public void MasterUpdateCharacter(string gameRefId, string characterId, PlayerCharacter info, Hashtable model, string world, int exp)
    {
        UpdateCharacter op = new UpdateCharacter {
            Deleted     = false,
            CharacterId = characterId,
            GameRefId   = gameRefId,
            Model       = model,
            Race        = (byte)info.Race,
            Workshop    = (byte)info.Workshop,
            Exp         = exp,
            WorldId     = world
        };
        OperationRequest request = new OperationRequest((byte)ServerToServerOperationCode.UpdateCharacter, op);

        this.MasterPeer.SendOperationRequest(request, new SendParameters());
    }
Exemplo n.º 5
0
        public async Task <IActionResult> UpdateCharacter(int id, [FromBody] UpdateCharacter model)
        {
            try
            {
                if (model == null)
                {
                    _logger.LogError("Character object sent from client is null.");
                    return(BadRequest("Character object is null"));
                }

                if (!ModelState.IsValid)
                {
                    _logger.LogError("Invalid Character object sent from client.");
                    return(BadRequest("Invalid model object"));
                }

                Character entity = await _db.Characters.FirstOrDefaultAsync(x => x.Id == id);

                if (entity == null)
                {
                    _logger.LogError($"Character with id: {id}, hasn't been found in db.");
                    return(NotFound());
                }

                _mapper.Map(model, entity);
                _db.Characters.Update(entity);
                await _db.SaveChangesAsync();

                return(Ok());
            }
            catch (Exception ex)
            {
                _logger.LogError($"Something went wrong inside UpdateCharacter action: {ex.Message}");
                return(StatusCode(500, "Internal server error"));
            }
        }
Exemplo n.º 6
0
 public ActionResult CharacterUpdateView(string Name)
 {
     if (Name == null)
     {
         return(new HttpStatusCodeResult(HttpStatusCode.NotFound));
     }
     else
     {
         Character character = characterClient.Find(Name);
         if (character == null)
         {
             return(new HttpStatusCodeResult(HttpStatusCode.NotFound));
         }
         else
         {
             UpdateCharacter uModel = new UpdateCharacter();
             uModel.Name            = character.Name;
             uModel.Level           = character.Level;
             uModel.Class           = character.Class;
             uModel.BackGroundStory = character.BackGroundStory;
             return(View(uModel));
         }
     }
 }
Exemplo n.º 7
0
        protected override void OnOperationRequest(OperationRequest operationRequest, SendParameters sendParameters)
        {
            try {
                if (log.IsDebugEnabled)
                {
                    log.DebugFormat("OnOperationRequest: pid={0}, op={1}", this.ConnectionId, operationRequest.OperationCode);
                }
                OperationResponse response = null;
                switch ((ServerToServerOperationCode)operationRequest.OperationCode)
                {
                default:
                    response = new OperationResponse(operationRequest.OperationCode)
                    {
                        ReturnCode = -1, DebugMessage = "Unknown operation code"
                    };
                    break;

                case ServerToServerOperationCode.RegisterGameServer: {
                    response = this.ServerId.HasValue
                                ? new OperationResponse(operationRequest.OperationCode)
                    {
                        ReturnCode = -1, DebugMessage = "Already registered"
                    }
                                : this.HandleRegisterGameServerRequest(operationRequest);
                    break;
                }

                case ServerToServerOperationCode.UpdateShipModel:
                {
                    UpdateShipModel operation = new UpdateShipModel(this.Protocol, operationRequest);
                    if (!operation.IsValid)
                    {
                        response = new OperationResponse(operationRequest.OperationCode)
                        {
                            ReturnCode = (short)ReturnCode.InvalidOperationParameter, DebugMessage = "InvalidOperationParameter"
                        };
                    }
                    else
                    {
                        UpdateShipModelEvent evtData = new UpdateShipModelEvent {
                            CharacterId = operation.CharacterId,
                            GameRefId   = operation.GameRefId,
                            SlotType    = operation.SlotType,
                            TemplateId  = operation.TemplateId
                        };
                        EventData evt = new EventData((byte)S2SEventCode.UpdateShipModel, evtData);
                        application.GameServers.SendEvent(evt, new SendParameters(), ServerType.SelectCharacter);
                    }
                    break;
                }

                case ServerToServerOperationCode.UpdateCharacter:
                {
                    UpdateCharacter      operation = new UpdateCharacter(this.Protocol, operationRequest);
                    UpdateCharacterEvent evtData   = new UpdateCharacterEvent {
                        CharacterId = operation.CharacterId,
                        Deleted     = operation.Deleted,
                        GameRefId   = operation.GameRefId,
                        Model       = operation.Model,
                        Race        = operation.Race,
                        Workshop    = operation.Workshop,
                        Exp         = operation.Exp,
                        WorldId     = operation.WorldId
                    };
                    EventData evt = new EventData((byte)S2SEventCode.UpdateCharacter, evtData);
                    application.GameServers.SendEvent(evt, new SendParameters(), ServerType.SelectCharacter);
                    break;
                }
                }
                if (response != null)
                {
                    this.SendOperationResponse(response, sendParameters);
                }
            } catch (Exception ex) {
                log.Error(ex);
            }
        }
 public ICharacterModel Any(UpdateCharacter request)
 {
     return(workflow.Update(request));
 }