Exemple #1
0
        public void Execute(List <string> extraWords, Character attackingCharacter)
        {
            var attackingCharacterLocation = GrainClusterClient.Universe.GetCharacterLocation(attackingCharacter.TrackingId).Result;
            var otherCharactersInLoc       = GrainClusterClient.Universe.GetCharactersInLocation(attackingCharacterLocation.TrackingId).Result
                                             .Where(c => c.TrackingId != attackingCharacter.TrackingId) // don't include the character doing the attacking
                                             .Select(c => new KeyValuePair <Character, string>(c, c.Name))
                                             .ToDictionary(kvp => kvp.Key, kvp => kvp.Value);

            if (otherCharactersInLoc.Count == 0)
            {
                attackingCharacter.SendDescriptiveTextDtoMessage("There are no characters to attack here.");
                attackingCharacter.GetLocation().SendDescriptiveTextDtoMessage($"{attackingCharacter.Name} is looking around for someone to attack!", attackingCharacter);
                return;
            }

            var wordCharacterMap = WordTranslator.WordsToCharacters(extraWords, otherCharactersInLoc.Keys.ToList());
            var foundCharacters  = wordCharacterMap
                                   .Where(i => i.Value != null)
                                   .Select(i => i.Value)
                                   .ToList();
            Character defendingCharacter;

            if (foundCharacters.Count == 0)
            {
                attackingCharacter.GetLocation().SendDescriptiveTextDtoMessage($"{attackingCharacter.Name} is acting dangerously!", attackingCharacter);
                return;
            }
            defendingCharacter = foundCharacters[0];
            defendingCharacter.Attack(attackingCharacter);
        }
Exemple #2
0
        public void Execute(List <string> extraWords, Character movingCharacter)
        {
            var movingCharacterStartLocation = GrainClusterClient.Universe.GetCharacterLocation(movingCharacter.TrackingId).Result;

            // Get a list of locations that can be moved to from here.
            var validLocations = GrainClusterClient.Universe.GetConnectedLocations(movingCharacterStartLocation.TrackingId).Result
                                 .ToDictionary(kvp => kvp, kvp => kvp.LocationName); // convert to Dictionary[{location}] = {locationName}

            var wordLocationMap = WordTranslator.WordsToLocations(extraWords, validLocations.Keys.ToList());
            var foundLocations  = wordLocationMap
                                  .Where(i => i.Value != null)
                                  .Select(i => i.Value)
                                  .ToList();

            if (foundLocations.Count > 0)
            {
                Location location = foundLocations[0];
                movingCharacter.GetLocation().SendDescriptiveTextDtoMessage($"{movingCharacter.Name} moves to the {location.LocationName}.", movingCharacter);
                GrainClusterClient.Universe.SetCharacterLocation(movingCharacter.TrackingId, location.TrackingId).Wait();
                movingCharacter.GetLocation().SendDescriptiveTextDtoMessage($"{movingCharacter.Name} has arrived in the area.", movingCharacter);

                // Make the player automatically look after they move to the new location
                CommandRunner.TryRunCommandFromCharacter("look", new List <string>(), movingCharacter);
            }
            else
            {
                movingCharacter.SendDescriptiveTextDtoMessage($"Unknown location.");
            }
        }
Exemple #3
0
        protected async Task ProcessRecordAsync()
        {
            try
            {
                List <Word>          wordList = new List <Word>();
                IEnumerable <string> sourceWords;
                IWordLoader          wordLoader     = new WordLoader();
                IWordTranslator      wordTranslator = new WordTranslator();
                // Load word list from file
                WriteObject("Load word from the word file.");
                string fileType = _path.Substring(_path.LastIndexOf('.') + 1);
                if (fileType == "txt")
                {
                    sourceWords = await wordLoader.LoadWordFromFileAsync(_path);
                }
                else if (fileType == "xlsx")
                {
                    sourceWords = wordLoader.LoadWordFromExcelAsync(_path);
                }
                else
                {
                    throw new Exception($"{_path} is type invalid), Supported type includes xlsx, txt.");
                }

                var sortedSourceWord = from word in sourceWords
                                       orderby word ascending
                                       select word;
                // Translate word
                WriteObject("Translate word...");
                foreach (string word in sortedSourceWord)
                {
                    wordList.Add(await wordTranslator.TranslateAsync(word));
                }
                wordList.ForEach(item => item.LocalAudio = _storageFolder + $"\\audio\\" + item.EnglishLanguage + ".mp3");
                // Storage translated result to file.
                await wordLoader.StorageTranslatedWordAsync(wordList, Split, _storageFolder, Name);

                // Storage transfated result to excel file.
                if (IsExcel)
                {
                    await wordLoader.StorageTranslatedWordToExcelAsync(wordList, Split, _storageFolder + $@"\{Name}.xlsx", Name);
                }
                // Get andt storge mp3 file.

                if (IsAudio)
                {
                    WriteObject("Download mp3 file from web site.");
                    foreach (var item in wordList)
                    {
                        await wordLoader.GetWordMp3FileAsync(item);
                    }
                }
                WriteObject("Translated end");
            }
            catch
            {
                throw;
            }
        }
Exemple #4
0
 public void SimpleAtlWordUofTranslatorExport(string bstrSourcePath, string bstrDestPath)
 {
     try
     {
         //FileInfo fi = new FileInfo(bstrSourcePath);
         //IUOFTranslator trans = TranslatorFactory.CheckFileTypeAndInitialize(bstrSourcePath);
         IUOFTranslator trans = new WordTranslator();
         trans.OoxToUof(bstrSourcePath, bstrDestPath);
     }
     catch (Exception e)
     {
         System.Windows.Forms.MessageBox.Show(e.ToString());
     }
 }
Exemple #5
0
        public void SimpleAtlWordUofTranslatorImport(string bstrSourcePath, string bstrDestPath)
        {
            //openFileDialog1.Filter = "(办公文档*.pptx;*.xlsx;*.docx;*.uof;*.xml)|*.pptx;*.xlsx;*.docx;*.uof;*.xml";
            //openFileDialog1.ShowDialog();
            //FileInfo fi = new FileInfo(openFileDialog1.FileName);
            //string outputFileName = Path.GetFileNameWithoutExtension(openFileDialog1.FileName);
            //IUOFTranslator trans = TranslatorFactory.CheckFileTypeAndInitialize(openFileDialog1.FileName);
            //richTextBox1.Text = "";
            //if (fi.Extension.ToLower() == ".uof")
            //{
            //    switch (trans.GetType().Name)
            //    {
            //        case "PresentationTranslator": outputFileName += ".pptx"; break;
            //        case "WordTranslator": outputFileName += ".docx"; break;
            //        case "SpreadsheetTranslator": outputFileName += ".xlsx"; break;
            //        default: break;
            //    }
            //    trans.UofToOox(openFileDialog1.FileName, @"c:\" + outputFileName);
            //}
            //else
            //    trans.OoxToUof(openFileDialog1.FileName, @"c:\" + outputFileName + ".uof");
            //richTextBox1.Text += "转换完成,请在C盘根目录下查看转换后文件!\n";
            try
            {
                IUOFTranslator trans = new WordTranslator();
                trans.UofToOox(bstrSourcePath, bstrDestPath);



                //FileInfo fi = new FileInfo(bstrSourcePath);
                //IUOFTranslator trans = TranslatorFactory.CheckFileTypeAndInitialize(bstrSourcePath);
                //if (fi.Extension.ToLower() == ".uof")
                //{
                //    switch (trans.GetType().Name)
                //    {
                //        //case "PresentationTranslator": outputFileName += ".pptx"; break;
                //        case "WordTranslator":
                //            //outputFileName += ".docx";
                //            break;
                //        //case "SpreadsheetTranslator": outputFileName += ".xlsx"; break;
                //        default: break;
                //    }
                //    trans.UofToOox(bstrSourcePath, bstrDestPath);
                //}
            }
            catch (Exception e)
            {
                System.Windows.Forms.MessageBox.Show(e.ToString());
            }
        }
Exemple #6
0
        public void when_jumbledUpLetters_and_possibleWords_are_passed_in_theAnswer_should_pass_the_test()
        {
            //ARRANGE
            var jumbledUpLetters = "ortsp";

            string[] possibleWords = { "sport", "parrot", "ports", "matey" };
            string[] theAnswer     = { "sport", "ports" };
            var      compiler      = new WordTranslator();

            //ACT
            var result = compiler.WordFinder(jumbledUpLetters, possibleWords);

            //ASSERT

            CollectionAssert.AreEquivalent(theAnswer, result);
        }
Exemple #7
0
        static async Task Main(string[] args)
        {
            //string subFolder = "level4-05";
            IWordLoader          wordLoader      = new WordLoader();
            IWordTranslator      wordTranslator  = new WordTranslator();
            List <Word>          wordList        = new List <Word>();
            string               storageFolder   = @"D:\Lucas\EnglishVocabulary\level4";
            IEnumerable <string> engWordTemplate = wordLoader.LoadWordFromExcelAsync(@"C:\Users\v-diya\Desktop\EnglishLevel4.xlsx");//(await wordLoader.LoadWordFromFileAsync(@$"D:\Lucas\git\EnglishVocabulary\resources\Level4Vocabulary\{subFolder}.txt")).ToList();

            var engWord = from word in engWordTemplate
                          orderby word ascending
                          select word;


            //int skipDebug = 0;
            foreach (string word in engWord)
            {
                //if (skipDebug > 57) break;
                wordList.Add(await wordTranslator.TranslateAsync(word));
                //skipDebug++;
            }

            wordList.ForEach(item => item.LocalAudio = storageFolder + $"\\audio\\" + item.EnglishLanguage + ".mp3");

            await wordLoader.StorageTranslatedWordAsync(wordList, 100, storageFolder, "level4");

            await wordLoader.StorageTranslatedWordToExcelAsync(wordList, 100, storageFolder + @"\level4.xlsx", "level4");

            try
            {
                foreach (var item in wordList)
                {
                    await wordLoader.GetWordMp3FileAsync(item);
                }
            }
            catch (HttpRequestException ex)
            {
                Console.WriteLine(ex.Message);
            }
            Console.ReadKey();
        }
Exemple #8
0
        public void Execute(List <string> extraWords, Character grabbingCharacter)
        {
            var grabbingCharacterLocation = GrainClusterClient.Universe.GetCharacterLocation(grabbingCharacter.TrackingId).Result;
            var locationItems             = GrainClusterClient.Universe.GetLocationItems(grabbingCharacterLocation.TrackingId).Result;

            if (locationItems == null || locationItems.Count == 0)
            {
                grabbingCharacter.SendDescriptiveTextDtoMessage("There is nothing to grab.");
                grabbingCharacter.GetLocation().SendDescriptiveTextDtoMessage($"{grabbingCharacter.Name} is looking around for something.", grabbingCharacter);
                return;
            }

            var availableItems = locationItems
                                 .Where(i => !i.Key.IsBound && i.Key.IsVisible) // Filter out bound and invisible items because these cannot be picked up
                                 .Select(i => new KeyValuePair <Item, string>(
                                             i.Key,
                                             i.Key.GetDescription(i.Value).UppercaseFirstChar()
                                             ))
                                 .ToDictionary(i => i.Key, i => i.Value);

            if (!availableItems.Any())
            {
                grabbingCharacter.SendDescriptiveTextDtoMessage("There is nothing that can be grabbed.");
                grabbingCharacter.GetLocation().SendDescriptiveTextDtoMessage($"{grabbingCharacter.Name} is looking around for something.", grabbingCharacter);
                return;
            }

            // Try to auto-determine what the player is trying to grab
            var wordItemMap = WordTranslator.WordsToItems(extraWords, availableItems.Keys.ToList());
            var foundItems  = wordItemMap
                              .Where(i => i.Value != null)
                              .Select(i => i.Value)
                              .ToList();
            Item itemToGrab;

            if (foundItems.Count == 0)
            {
                grabbingCharacter.SendDescriptiveTextDtoMessage("There is nothing like that here.");
                grabbingCharacter.GetLocation().SendDescriptiveTextDtoMessage($"{grabbingCharacter.Name} is looking around for something.", grabbingCharacter);
                return;
            }
            itemToGrab = foundItems[0];

            var itemAmountToGrab = locationItems[itemToGrab];

            if (itemAmountToGrab > 1)
            {
                var leftWords     = wordItemMap.Where(i => i.Value == null).Select(i => i.Key).ToList();
                var wordNumberMap = WordTranslator.WordsToNumbers(leftWords);
                var foundNumbers  = wordNumberMap.Where(i => i.Value.HasValue).Select(i => i.Value.Value).ToList();
                if (foundNumbers.Count > 0)
                {
                    itemAmountToGrab = foundNumbers[0];
                }

                if (itemAmountToGrab <= 0)
                {
                    return;
                }
                if (itemAmountToGrab > locationItems[itemToGrab])
                {
                    itemAmountToGrab = locationItems[itemToGrab];
                }
            }

            itemToGrab.Grab(itemAmountToGrab, grabbingCharacter);
        }
Exemple #9
0
 public DocsController(WordTranslator translator)
 {
     _translator = translator;
 }
Exemple #10
0
        public void Execute(List <string> extraWords, Character interactingCharacter)
        {
            var useableLocationItems = interactingCharacter.GetLocation().GetUseableItems()
                                       .Select(i => new KeyValuePair <Item, string>(
                                                   i.Key,
                                                   i.Key.GetDescription(i.Value).UppercaseFirstChar()
                                                   ));

            var useableCharacterItems = interactingCharacter.GetUseableInventoryItems()
                                        .Select(i => new KeyValuePair <Item, string>(
                                                    i.Key,
                                                    i.Key.GetDescription(i.Value).UppercaseFirstChar()
                                                    ));

            // This represents all items that can be used (either directory or indirectly)
            var allUseableItems = useableLocationItems
                                  .Union(useableCharacterItems)
                                  .ToDictionary(i => i.Key, i => i.Value); // This also removes duplicates

            // This represnts only primary interaction items
            var allPrimaryItems = allUseableItems
                                  .Where(i => i.Key.IsInteractionPrimary)
                                  .ToDictionary(i => i.Key, i => i.Value); // This also removes duplicates

            // The end goal of interact is to interact with a primary item,
            // so if none of those exist here, we are done.
            if (!allPrimaryItems.Any())
            {
                interactingCharacter.SendDescriptiveTextDtoMessage("There is nothing available to interact with.");
                interactingCharacter.GetLocation().SendDescriptiveTextDtoMessage($"{interactingCharacter.Name} is looking around for something.", interactingCharacter);
                return;
            }

            Item primaryItem   = null;
            Item secondaryItem = null;

            // If there were extra words typed in, then attempt to auto-map them
            if (extraWords.Count > 0)
            {
                // Try to auto-determine the choices if extra words are typed in
                var wordItemMap = WordTranslator.WordsToItems(extraWords, allUseableItems.Keys.ToList());
                var foundItems  = wordItemMap
                                  .Where(i => i.Value != null)
                                  .Select(i => i.Value)
                                  .ToList();

                // The primary item is considered the last item in the sentence that is a primary interaction item
                primaryItem = foundItems.LastOrDefault(i => i.IsInteractionPrimary);

                // This example contains only 1 item that has its primary property set (keyhole)
                // Considering that a player could type sentences like this
                //     use key on keyhole       - This syntax works also when there are 2 primaries involved
                //     use keyhole with key     - This syntax won't work with 2 primaries, it will get them backwards
                //                                For this reason, we disable this pattern all-together to avoid confusion
                // In cases where we are working with 2 primary items, the code can't really determine if the first
                // or the second is the primary. It works fine with 1 primary only both ways, but then messes up when there
                // are two primaries. Therefore to make it so sentences always produce a dependable result we make the
                // rule that a secondary item MUST come before the primary item in the sentence.
                // We only set secondary if a primary item was found though
                if (primaryItem != null)
                {
                    foreach (var foundItem in foundItems)
                    {
                        // We reached the primary item, stop looking as it is invalid
                        // for the secondary item to exist past the primary
                        if (foundItem.TrackingId == primaryItem.TrackingId)
                        {
                            break;
                        }
                        secondaryItem = foundItem;
                        break;
                    }
                }

                if (
                    primaryItem == null ||                                                    // extra words were typed, but no primary found
                    (primaryItem != null && secondaryItem == null && foundItems.Count > 1) || // the extra words looked like more items than what we could map to
                    (primaryItem != null && secondaryItem != null && foundItems.Count > 2)    // the extra words looked like more items than what we could map to
                    )
                {
                    interactingCharacter.SendDescriptiveTextDtoMessage("I don't quite understand, make sure the target item you want to use is last in the sentence.");
                    return;
                }

                // Otherwise the extra words seem to have translated into the items to use properly
                primaryItem.Interact(secondaryItem, interactingCharacter);
            }
        }
Exemple #11
0
        public void Execute(List <string> extraWords, Character droppingCharacter)
        {
            var droppingCharacterLocation = GrainClusterClient.Universe.GetCharacterLocation(droppingCharacter.TrackingId).Result;
            var droppingCharacterItems    = GrainClusterClient.Universe.GetCharacterItems(droppingCharacter.TrackingId).Result;

            if (droppingCharacterItems == null || droppingCharacterItems.Count == 0)
            {
                droppingCharacter.SendDescriptiveTextDtoMessage("You have no items.");
                droppingCharacter.GetLocation().SendDescriptiveTextDtoMessage($"{droppingCharacter.Name} is happy that they have no items.", droppingCharacter);
                return;
            }

            var availableItems = droppingCharacterItems
                                 .Where(i => !i.Key.IsBound && i.Key.IsVisible) // Filter out bound and invisible items because these cannot be dropped
                                 .Select(i => new KeyValuePair <Item, string>(
                                             i.Key,
                                             i.Key.GetDescription(i.Value).UppercaseFirstChar()
                                             ))
                                 .ToDictionary(i => i.Key, i => i.Value);

            if (!availableItems.Any())
            {
                droppingCharacter.SendDescriptiveTextDtoMessage("You have nothing that can be dropped.");
                droppingCharacter.GetLocation().SendDescriptiveTextDtoMessage($"{droppingCharacter.Name} is digging around in their inventory looking for something.", droppingCharacter); // TODO: he/she/pronoun ?
                return;
            }

            // Try to auto-determine what the character is trying to drop
            var wordItemMap = WordTranslator.WordsToItems(extraWords, availableItems.Keys.ToList());
            var foundItems  = wordItemMap
                              .Where(i => i.Value != null)
                              .Select(i => i.Value)
                              .ToList();
            Item itemToDrop;

            if (foundItems.Count == 0)
            {
                droppingCharacter.SendDescriptiveTextDtoMessage("You don't have anything like that.");
                droppingCharacter.GetLocation().SendDescriptiveTextDtoMessage($"{droppingCharacter.Name} is digging around in their inventory looking for something.", droppingCharacter); // TODO: he/she/pronoun ?
                return;
            }
            itemToDrop = foundItems[0];

            var itemAmountToDrop = droppingCharacterItems[itemToDrop];

            if (itemAmountToDrop > 1)
            {
                var leftWords     = wordItemMap.Where(i => i.Value == null).Select(i => i.Key).ToList();
                var wordNumberMap = WordTranslator.WordsToNumbers(leftWords);
                var foundNumbers  = wordNumberMap.Where(i => i.Value.HasValue).Select(i => i.Value.Value).ToList();
                if (foundNumbers.Count > 0)
                {
                    itemAmountToDrop = foundNumbers[0];
                }

                if (itemAmountToDrop <= 0)
                {
                    return;
                }
                if (itemAmountToDrop > droppingCharacterItems[itemToDrop])
                {
                    itemAmountToDrop = droppingCharacterItems[itemToDrop];
                }
            }

            itemToDrop.Drop(itemAmountToDrop, droppingCharacter);
        }