Ejemplo n.º 1
0
        public async Task EntityActionHandler(DeepTalk hub, string package, UserDB user, string tcpId, IMongoCollection <UserDB> manager, DeepTalkService talkService)
        {
            var characterGame = Storage.Instance.GetCharacter(user.Accounts.Find(c => c.TcpId == tcpId).CurrentCharacter.Key);
            var cliId         = user.CliConnectionId;
            var apiKey        = user.ApiKey;

            string[] splittedData = package.Substring(2).Split(';');
            int      actionId     = int.Parse(splittedData[1]);

            if (actionId > 0)
            {
                int entityId = int.Parse(splittedData[2]);
                switch (actionId)
                {
                case 1:     // Entity Move on map
                    int startCell = Hash.GetCellNum(splittedData[3].Substring(1, 2));
                    int cellId    = Hash.GetCellNum(splittedData[3].Substring(splittedData[3].Length - 2));
                    if (entityId == characterGame.Key)
                    {
                        var gttMovementType = splittedData[0];
                        var path            = PathFinder.Instance.GetPath(characterGame.Map, characterGame.CellId, cellId, true);
                        var timeNeed        = PathFinderUtils.Instance.GetDeplacementTime(characterGame.Map, path);
                        List <IHubClientAction> pathAction = new List <IHubClientAction>();
                        pathAction.Add(new HubNodeAction(path, (newCell) =>
                        {
                            characterGame.CellId = newCell;
                            characterGame.Map.Entities[entityId].CellId = newCell;
                        }, new HubClientAction(new MapMessage(characterGame.Map, tcpId)
                                               )));
                        talkService.AddTask(tcpId, cliId, apiKey.Key.ToString(), pathAction, 0);
                        List <IHubClientAction> TaskRequest = new List <IHubClientAction>();
                        TaskRequest.Add(new HubPackageAction($"GKK{gttMovementType}"));
                        talkService.AddTask(tcpId, cliId, apiKey.Key.ToString(), TaskRequest, timeNeed);
                    }
                    else
                    {
                        var path = PathFinder.Instance.GetPath(characterGame.Map, startCell, cellId, true);
                        List <IHubClientAction> TaskRequest = new List <IHubClientAction>();
                        TaskRequest.Add(new HubNodeAction(path, (newCell) =>
                        {
                            if (characterGame.Map.Entities.ContainsKey(entityId))
                            {
                                characterGame.Map.Entities[entityId].CellId = newCell;
                            }
                        }, new HubClientAction(new MapMessage(characterGame.Map, tcpId))));
                        talkService.AddTask(tcpId, cliId, apiKey.Key.ToString(), TaskRequest, 0);
                        //characterGame.Map.Entities[entityId].CellId = cellId;
                        //hub.DispatchToClient(new MapMessage(characterGame.Map, tcpId), tcpId);
                    }
                    break;
                }
            }
        }
        public async Task SelectedCharacterPackageHandle(DeepTalk hub, string package, UserDB user, string tcpId, IMongoCollection <UserDB> manager, DeepTalkService talkService)
        {
            var characterGame = Storage.Instance.GetCharacter(user.Accounts.Find(c => c.TcpId == tcpId).CurrentCharacter.Key);
            var inventory     = Database.Inventories.Find(i => i.Key == characterGame.Fk_Inventory).First();

            string[] splittedData = package.Substring(4).Split('|');

            characterGame.Key     = int.Parse(splittedData[0]);
            characterGame.Name    = splittedData[1];
            characterGame.Level   = byte.Parse(splittedData[2]);
            characterGame.BreedId = byte.Parse(splittedData[3]);
            characterGame.Sex     = byte.Parse(splittedData[4]);
            inventory.Items.DeserializeItems(splittedData[9]);

            characterGame.State = CharacterStateEnum.IDLE;

            List <IHubClientAction> Actions = new List <IHubClientAction>();

            Actions.Add(new HubPackageAction("GC1"));
            Actions.Add(new HubMethodAction(() => Database.Inventories.ReplaceOneAsync(i => i.Key == characterGame.Fk_Inventory, inventory).Wait()));
            Actions.Add(new HubClientAction(new LogMessage(LogType.SYSTEM_INFORMATION, "Personnage en ligne", tcpId)));
            talkService.AddTask(tcpId, user.CliConnectionId, user.ApiKey.Key.ToString(), Actions, new Random().Next(150, 450));
        }