Example #1
0
        public override int WriteTo(byte[] Buffer, int StartIndex = 0)
        {
            int cursor = StartIndex;

            cursor += base.WriteTo(Buffer, cursor);

            cursor += CharCreationInfo.WriteTo(Buffer, cursor);

            return(cursor - StartIndex);
        }
Example #2
0
        public override int ReadFrom(byte[] Buffer, int StartIndex = 0)
        {
            int cursor = StartIndex;

            cursor += base.ReadFrom(Buffer, cursor);

            CharCreationInfo = new CharCreationInfo(Buffer, cursor);
            cursor          += CharCreationInfo.ByteLength;

            return(cursor - StartIndex);
        }
        public override int ReadFrom(byte[] Buffer, int StartIndex = 0)
        {
            int cursor = StartIndex;

            cursor += base.ReadFrom(Buffer, cursor);

            CharCreationInfo = new CharCreationInfo(Buffer, cursor);
            cursor += CharCreationInfo.ByteLength;

            return cursor - StartIndex;
        }      
Example #4
0
        public void StartCharacterCreation(CharCreationInfo creationInfo)
        {
            if (creationInfo == null)
            {
                throw new ArgumentNullException(nameof(creationInfo));
            }

            var writer = _WriterFactory.Create(ScriptMessages.CreateCharacter);

            creationInfo.Write(writer);
            _MessageSender.SendScriptMessage(writer, NetPriority.Medium, NetReliability.Reliable);
        }
Example #5
0
        public async void HandleMessage(Client.Client sender, PacketReader stream)
        {
            if (sender == null)
            {
                throw new ArgumentNullException(nameof(sender));
            }

            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream));
            }

            try
            {
                CharCreationInfo creationInfo = new CharCreationInfo();
                creationInfo.Read(stream);

                //Get the account session of the client.
                if (_AuthenticationService.TryGetSession(sender, out Session session))
                {
                    //Lets first check if the account can have an additional account(limit is taken from the rp config).
                    int charOwnershipsCount = await _CharacterService.GetCharacterOwnershipsCountAsync(session.Account);


                    if (charOwnershipsCount >= _RpConfig.MaxCharacterPerAccount)
                    {
                        using (var packet = _PacketWriterPool.GetScriptMessageStream(ScriptMessages.CharacterCreationResult))
                        {
                            packet.Write(false);
                            packet.Write((byte)CharacterCreationFailure.CharacterLimitReached);
                            sender.SendScriptMessage(packet, NetPriority.Medium, NetReliability.Reliable);
                        }
                        return;
                    }


                    //Create the new character.
                    CharacterCreationResult result =
                        await _CharacterService.CreateHumanPlayerCharacterAsync(creationInfo);



                    if (result is CharacterCreationFailed failed)
                    {
                        using (var packet = _PacketWriterPool.GetScriptMessageStream(ScriptMessages.CharacterCreationResult))
                        {
                            //Failure
                            packet.Write(false);
                            packet.Write((byte)failed.Reason);
                            sender.SendScriptMessage(packet, NetPriority.Medium, NetReliability.Reliable);
                        }
                    }
                    else if (result is CharacterCreationSuccess success)
                    {
                        //The character was created. Add an ownership entity and set the active character for account of the message sender.
                        await Task.WhenAll(new List <Task>
                        {
                            _CharacterService.AddCharacterOwnershipAsync(session.Account, success.Character),
                            _CharacterService.SetAccountActiveCharacterAsync(session.Account, success.Character)
                        });


                        using (var packet = _PacketWriterPool.GetScriptMessageStream(ScriptMessages.CharacterCreationResult))
                        {
                            //Success
                            packet.Write(true);
                            sender.SendScriptMessage(packet, NetPriority.Medium, NetReliability.Reliable);
                        }
                    }
                }
                else
                {
                    //This should not even be possible. Disconnect the client.
                    _Log.Error($"The client '{sender.SystemAddress}' tried to create a character while not being logged in(should never be possible)");
                    sender.Disconnect();
                }
            }
            catch (Exception e)
            {
                _Log.Error($"Something went wrong while handling a '{SupportedMessage}' message from the client '{sender.SystemAddress}'. Exception: {e}");
                sender.Disconnect();
            }
        }
Example #6
0
 public Task <CharacterCreationResult> CreateHumanPlayerCharacterAsync(CharCreationInfo creationInfo) =>
 CreateHumanPlayerCharacterTransaction.CreateHumanPlayerCharacterAsync(creationInfo);
        /// <summary>
        /// Constructor
        /// </summary>
        public DataController()
        {          
            // create lists
            roomObjects = new RoomObjectList(300);
            roomObjectsFiltered = new RoomObjectListFiltered(roomObjects);
            projectiles = new ProjectileList(50);
            onlinePlayers = new OnlinePlayerList(200);
            inventoryObjects = new InventoryObjectList(100);
            avatarCondition = new StatNumericList(5);
            avatarAttributes = new StatNumericList(10);
            avatarSkills = new SkillList(100);
            avatarSpells = new SkillList(100);
            avatarQuests = new SkillList(100);
            roomBuffs = new ObjectBaseList<ObjectBase>(30);
            avatarBuffs = new ObjectBaseList<ObjectBase>(30);
            spellObjects = new SpellObjectList(100);
            backgroundOverlays = new BackgroundOverlayList(5);
            playerOverlays = new ObjectBaseList<PlayerOverlay>(10);            
            chatMessages = new BaseList<ServerString>(101);
            gameMessageLog = new BaseList<GameMessage>(100);
            visitedTargets = new List<RoomObject>(50);
            clickedTargets = new List<uint>(50);
            actionButtons = new ActionButtonList();
            ignoreList = new List<string>(20);
            chatCommandHistory = new List<string>(20);

            // attach some listeners
            RoomObjects.ListChanged += OnRoomObjectsListChanged;
            Projectiles.ListChanged += OnProjectilesListChanged;
            ChatMessages.ListChanged += OnChatMessagesListChanged;

            // make some lists sorted
            OnlinePlayers.SortByName();
            AvatarSkills.SortByResourceName();
            AvatarSpells.SortByResourceName();
            SpellObjects.SortByName();
            
            // create single data objects
            roomInformation = new RoomInfo();
            lightShading = new LightShading(0, new SpherePosition(0, 0));
            backgroundMusic = new PlayMusic();
            guildInfo = new GuildInfo();
            guildShieldInfo = new GuildShieldInfo();
            guildAskData = new GuildAskData();
            diplomacyInfo = new DiplomacyInfo();
            adminInfo = new AdminInfo();
            tradeInfo = new TradeInfo();
            buyInfo = new BuyInfo();
            welcomeInfo = new WelcomeInfo();
            charCreationInfo = new CharCreationInfo();
            statChangeInfo = new StatChangeInfo();
            newsGroup = new NewsGroup();
            objectContents = new ObjectContents();
            effects = new Effects();
            lookPlayer = new PlayerInfo();
            lookObject = new ObjectInfo();
            clientPreferences = new PreferencesFlags();

            // some values
            ChatMessagesMaximum = 100;
            ChatCommandHistoryMaximum = 20;
            ChatCommandHistoryIndex = -1;
            AvatarObject = null;
            IsResting = false;
            SelfTarget = false;
            IsNextAttackApplyCastOnHighlightedObject = false;
            AvatarID = UInt32.MaxValue;
            TargetID = UInt32.MaxValue;
            ViewerPosition = V3.ZERO;
            UIMode = UIMode.None;
        }
Example #8
0
 public CharInfoMessage(CharCreationInfo CharCreationInfo)
     : base(MessageTypeGameMode.CharInfo)
 {
     this.CharCreationInfo = CharCreationInfo;
 }
Example #9
0
        public Task <CharacterCreationResult> CreateHumanPlayerCharacterAsync(CharCreationInfo creationInfo)
        {
            if (creationInfo == null)
            {
                throw new ArgumentNullException(nameof(creationInfo));
            }

            return(_CharacterService.CheckCharacterExistsAsync(creationInfo.Name).ContinueWith <CharacterCreationResult>(task =>
            {
                //Validate the creation info because it comes directly from the client(we do not trust the client).
                if (!creationInfo.Validate(out string invalidProperty, out object value))
                {
                    _Log.Warn($"Character creation failed due to invalid {nameof(CharCreationInfo)}, invalid attribute is '{invalidProperty}' with value '{value}'");
                    return new CharacterCreationFailed(CharacterCreationFailure.InvalidCreationInfo);
                }

                //Check whether the name can be used for a character.
                if (!_NameValidator.IsValid(creationInfo.Name))
                {
                    return (CharacterCreationResult) new CharacterCreationFailed(CharacterCreationFailure.NameIsInvalid);
                }

                //The character does already exist.
                if (task.Result)
                {
                    return (CharacterCreationResult) new CharacterCreationFailed(CharacterCreationFailure
                                                                                 .AlreadyExists);
                }

                //Create the new character
                try
                {
                    using (CharacterManagementContext db = _ContextFactory.Create())
                    {
                        SpawnPoint spawn = _SpawnPointProvider.GetSpawnPoint();

                        //Add the character
                        var characterEntity = new CharacterEntity
                        {
                            CharacterName = creationInfo.Name,
                            PositionX = spawn.Point.X,
                            PositionY = spawn.Point.Y,
                            PositionZ = spawn.Point.Z,
                            Rotation = spawn.Rotation.Yaw,
                            WorldName = spawn.World.Path,
                            TemplateName = _CharacterTemplateSelector.GetTemplate(creationInfo)
                        };
                        db.Characters.Add(characterEntity);

                        //Add the visuals of the character.
                        var customVisuals = new CharacterCustomVisualsEntity
                        {
                            OwnerCharacter = characterEntity,
                            BodyMesh = creationInfo.BodyMesh,
                            BodyTex = creationInfo.BodyTex,
                            HeadMesh = creationInfo.HeadMesh,
                            HeadTex = creationInfo.HeadTex,
                            Voice = creationInfo.Voice,
                            Fatness = creationInfo.Fatness,
                            BodyWidth = creationInfo.BodyWidth
                        };
                        db.CustomVisuals.Add(customVisuals);

                        //Save the changes.
                        db.SaveChanges();


                        Character character = _CharacterBuilder.HumanCharacterFromEntities(characterEntity, customVisuals);

                        //Invoke the character creation event(later so we can inform the client first)
                        _Dispatcher.EnqueueAction(() =>
                        {
                            _CharacterService.OnCharacterCreated(new CharacterCreatedArgs(character));
                        });

                        //Return information about successful character creation.
                        return new CharacterCreationSuccess(character);
                    }
                }
                catch (Exception e)
                {
                    throw new DatabaseRequestException("Something went wrong while adding the new character to the database.", e);
                }
            }));
        }
Example #10
0
 public string GetTemplate(CharCreationInfo charInfo)
 {
     return(charInfo.BodyMesh == HumBodyMeshs.HUM_BODY_NAKED0 ? "maleplayer" : "femaleplayer");
 }
Example #11
0
 public CharacterCreationCompletedArgs(CharCreationInfo charCreationInfo)
 {
     CharCreationInfo = charCreationInfo ?? throw new ArgumentNullException(nameof(charCreationInfo));
 }
 public CharInfoMessage(CharCreationInfo CharCreationInfo) 
     : base(MessageTypeGameMode.CharInfo)
 {           
     this.CharCreationInfo = CharCreationInfo;
 }
Example #13
0
        protected NPCInst CreateNPC(NPCClass def, int teamID, CharCreationInfo cInfo = null)
        {
            if (def == null)
            {
                return(null);
            }

            NPCInst npc;

            if (def.Definition == null)
            {
                if (cInfo == null)
                {
                    npc = new NPCInst(NPCDef.Get("maleplayer"));
                    npc.RandomizeCustomVisuals(def.Name, true);
                }
                else
                {
                    npc = new NPCInst(NPCDef.Get(cInfo.BodyMesh == HumBodyMeshs.HUM_BODY_NAKED0 ? "maleplayer" : "femaleplayer"))
                    {
                        UseCustoms     = true,
                        CustomBodyTex  = cInfo.BodyTex,
                        CustomHeadMesh = cInfo.HeadMesh,
                        CustomHeadTex  = cInfo.HeadTex,
                        CustomVoice    = cInfo.Voice,
                        CustomFatness  = cInfo.Fatness,
                        CustomScale    = new Vec3f(cInfo.BodyWidth, 1.0f, cInfo.BodyWidth),
                        CustomName     = cInfo.Name
                    };
                }
            }
            else
            {
                npc = new NPCInst(NPCDef.Get(def.Definition));
            }

            // add inventory items
            if (def.ItemDefs != null)
            {
                foreach (var invItem in def.ItemDefs)
                {
                    var item = new ItemInst(ItemDef.Get(invItem.DefName));
                    item.SetAmount(invItem.Amount);
                    npc.Inventory.AddItem(item);
                    npc.EffectHandler.TryEquipItem(item);
                }
            }

            // add overlays
            if (def.Overlays != null)
            {
                foreach (var overlay in def.Overlays)
                {
                    if (npc.ModelDef.TryGetOverlay(overlay, out ScriptOverlay ov))
                    {
                        npc.ModelInst.ApplyOverlay(ov);
                    }
                }
            }

            npc.TeamID = teamID;

            npc.Protection = def.Protection;
            npc.Damage     = def.Damage;
            npc.SetHealth(def.HP, def.HP);
            npc.Guild = def.Guild;
            return(npc);
        }