public IActionResult Create(CharacterCreateRequest request) { try { bool response = _characterLogic.Create(request); if (!response) { return(BadRequest(new { message = "character couldnt be created" })); } return(Ok(response)); } catch (Exception e) { return(BadRequest(new { message = e.ToString() })); } }
private async Task HandleCharacterCreate(CharacterCreateRequest request) { try { await ShardSession.CreateCharacter(request); ForwardPacket(new CharacterCreateResponse() { Response = CharacterCreateResponseCode.Success }); } catch (CharacterAlreadyExistsException) { ForwardPacket(new CharacterCreateResponse() { Response = CharacterCreateResponseCode.NameTaken }); } }
public async Task CreateCharacter(CharacterCreateRequest request) { VerifyAuthenticated(); var characterList = GrainFactory.GetGrain <ICharacterList>(ShardName); var id = await characterList.AddCharacter(request.Name, AuthenticatedIdentity); try { var character = GrainFactory.GetGrain <ICharacter>(id); var entity = await character.Create(request.Name, AuthenticatedIdentity, ShardName, request.Race, request.Class, request.Sex, request.Skin, request.Face, request.HairStyle, request.HairColor, request.FacialHair); } catch (Exception) { // un-create the character in the character list if an error occurred, or it will crash the character list on reboot await characterList.RemoveCharacter(request.Name, AuthenticatedIdentity); // and re-throw the exception throw; } }
public void OnCharacterCreateRequest(MessageEventArgs args, CharacterCreateRequest request) { _characters[request.Slot] = request.Character; // init character request.Character.Status = new Status() { Health = 100, MaxHealth = 100, Mana = 100, MaxMana = 100, Endurance = 100, MaxEndurance = 100, Concentration = 100, MaxConcentration = 100 }; // everyone starts in cotswold request.Character.Region = 1; request.Character.Coordinates = new Coordinates(560467, 511652, 2344, 3398); // update the client with location, stats, level, starter gear, etc. OnCharacterOverviewRequest(args, new CharacterOverviewRequest(request.Character.Classification.Realm)); }
public async Task CharacterCreate(CharacterCreateRequest packet, IRakConnection connection) { var session = Server.SessionCache.GetSession(connection.EndPoint); uint shirtLot; uint pantsLot; await using (var ctx = new CdClientContext()) { // // Shirt // var shirtColor = await ctx.BrickColorsTable.FirstOrDefaultAsync(c => c.Id == packet.ShirtColor); var shirtName = $"{(shirtColor != null ? shirtColor.Description : "Bright Red")} Shirt {packet.ShirtStyle}"; var shirt = ctx.ObjectsTable.ToArray().FirstOrDefault(o => string.Equals(o.Name, shirtName, StringComparison.CurrentCultureIgnoreCase)); shirtLot = (uint)(shirt != null ? shirt.Id : 4049); // Select 'Bright Red Shirt 1' if not found. // // Pants // var pantsColor = await ctx.BrickColorsTable.FirstOrDefaultAsync(c => c.Id == packet.PantsColor); var pantsName = $"{(pantsColor != null ? pantsColor.Description : "Bright Red")} Pants"; var pants = ctx.ObjectsTable.ToArray().FirstOrDefault(o => string.Equals(o.Name, pantsName, StringComparison.CurrentCultureIgnoreCase)); pantsLot = (uint)(pants != null ? pants.Id : 2508); // Select 'Bright Red Pants' if not found. } var first = (await Server.Resources.ReadTextAsync("names/minifigname_first.txt")).Split('\n'); var middle = (await Server.Resources.ReadTextAsync("names/minifigname_middle.txt")).Split('\n'); var last = (await Server.Resources.ReadTextAsync("names/minifigname_last.txt")).Split('\n'); var name = ( first[packet.Predefined.First] + middle[packet.Predefined.Middle] + last[packet.Predefined.Last] ).Replace("\r", ""); await using (var ctx = new UchuContext()) { if (ctx.Characters.Any(c => c.Name == packet.CharacterName)) { Logger.Debug($"{connection} character create rejected due to duplicate name"); connection.Send(new CharacterCreateResponse { ResponseId = CharacterCreationResponse.CustomNameInUse } ); return; } if (ctx.Characters.Any(c => c.Name == name)) { Logger.Debug($"{connection} character create rejected due to duplicate pre-made name"); connection.Send(new CharacterCreateResponse { ResponseId = CharacterCreationResponse.PredefinedNameInUse } ); return; } var user = await ctx.Users.Include(u => u.Characters).SingleAsync(u => u.UserId == session.UserId); user.Characters.Add(new Character { CharacterId = IdUtilities.GenerateObjectId(), Name = name, CustomName = packet.CharacterName, ShirtColor = packet.ShirtColor, ShirtStyle = packet.ShirtStyle, PantsColor = packet.PantsColor, HairStyle = packet.HairStyle, HairColor = packet.HairColor, Lh = packet.Lh, Rh = packet.Rh, EyebrowStyle = packet.EyebrowStyle, EyeStyle = packet.EyeStyle, MouthStyle = packet.MouthStyle, LastZone = (int)ZoneId.VentureExplorerCinematic, LastInstance = 0, LastClone = 0, InventorySize = 20, LastActivity = DateTimeOffset.Now.ToUnixTimeSeconds(), Items = new List <InventoryItem> { new InventoryItem { InventoryItemId = IdUtilities.GenerateObjectId(), LOT = (int)shirtLot, Slot = 0, Count = 1, InventoryType = (int)InventoryType.Items, IsEquipped = true }, new InventoryItem { InventoryItemId = IdUtilities.GenerateObjectId(), LOT = (int)pantsLot, Slot = 1, Count = 1, InventoryType = (int)InventoryType.Items, IsEquipped = true } }, CurrentImagination = 0, MaximumImagination = 0 }); Logger.Debug( $"{user.Username} created character \"{packet.CharacterName}\" with the pre-made name of \"{name}\""); await ctx.SaveChangesAsync(); connection.Send(new CharacterCreateResponse { ResponseId = CharacterCreationResponse.Success } ); await SendCharacterList(connection, session.UserId); } }
public bool Create(CharacterCreateRequest request) { CharacterDataModel character = _converter.RequestToDataModel(request); return(_repository.Create(character)); }