public static string GenerateMiniKey(CharacterPool type = CharacterPool.AlphanumericMixedCase) { RandomNumberGenerator random = System.Security.Cryptography.RandomNumberGenerator.Create(); var pool = Encoders.GetCharacterPool(type); while (true) { var bytes = new byte[29]; random.GetNonZeroBytes(bytes); var minikey = "S" + new String(bytes.Select <byte, char>(x => pool[x % pool.Length]).ToArray()); try { ValidateMiniKey(minikey); return(minikey); } catch (Exception e) { if (e.Message != "Failed to pass typo check") { var aa = minikey.Length; Console.WriteLine(aa); } } } }
private static LinkedList <string> FindSentencesWithWordLengths(ReadOnlyCollection <int> requiredWordLengths, CharacterPool initialCharacters, ReadOnlyDictionary <int, string[]> allowedWordsGroupedByLength) { var foundSentences = new LinkedList <string>(); string seedSentence = String.Empty; const int IndexOfFirstWord = 0; int lengthOfFirstWord = requiredWordLengths[IndexOfFirstWord]; string[] candidatesForFirstWord; bool candidatesExistForFirstWord = allowedWordsGroupedByLength.TryGetValue(lengthOfFirstWord, out candidatesForFirstWord); if (candidatesExistForFirstWord) { foreach (string wordCandidate in candidatesForFirstWord) { FindSentencesBeginningWith(wordCandidate, seedSentence, requiredWordLengths, IndexOfFirstWord, initialCharacters, allowedWordsGroupedByLength, foundSentences); } } return(foundSentences); }
private void EnsureChar(ref TestCharacter chr, CharacterPool pool) { chr = pool.Create(); chr.SetMoney(100000); chr.GodMode = true; chr.EnsureInWorldAndLiving(); }
public override void Load(string json) { var data = JsonUtility.FromJson <CharacterData>(json); CharacterPool.Register(data.characterId, player); player.data = data; player.characterController.enabled = false; transform.position = data.position; player.graphic.rotation = data.rotation; for (int i = 0; i < player.inventory.slots; i++) { player.inventory.DestroyItem(i); } for (int i = 0; i < data.items.Count; i++) { for (int j = 0; j < data.quantities[i]; j++) { player.inventory.AddItem(data.items[i]); } player.inventory.items[i].Equipped = data.equipped[i]; } player.GetComponent <CharacterEquipment>().CheckEquipment(); player.characterController.enabled = true; }
protected void Awake() { if (SaveGameManager.newGame) { data.characterId = CharacterPool.Register(this).ToString(); } equipment = GetComponent <CharacterEquipment>(); }
public void UpdateData(CharacterData data) { this.data = data; SetHealth(data.health); transform.position = data.position; transform.rotation = data.rotation; CharacterPool.Register(data.characterId, this); ActivateRoutine(data.routine, true, true); }
private List <GameObject> _PooledGreenEnemy; // Green's pool list. #endregion #region Methods #region Unity Callback Methods private void Awake() { if (Instance == null) { Instance = this; } Init(); }
private static bool TryFindSecretPhrase(int numWordsInSentence, int numCharactersInAnagram, ReadOnlyDictionary <char, int> anagramCharCounts, ReadOnlyDictionary <int, string[]> wordCandidatesGroupedByLength, string secretPhraseMd5Hash, out string secretPhrase) { ReadOnlyCollection <ReadOnlyCollection <int> > wordLengthCombinations = GenerateWordLengthCombinations(numCharactersInAnagram, numWordsInSentence); string foundPhrase = null; // Alas, closures don't allow out parameters... Action <ReadOnlyCollection <int>, ParallelLoopState> TryFindPhrase = (wordLengthCombination, state) => { if (wordLengthCombination.Any(wordLength => !wordCandidatesGroupedByLength.ContainsKey(wordLength))) { return; // Failure } var initialCharacters = new CharacterPool(anagramCharCounts); LinkedList <string> sentences = FindSentencesWithWordLengths(wordLengthCombination, initialCharacters, wordCandidatesGroupedByLength); if (sentences.Any()) { foreach (string sentence in sentences) { IEnumerable <IEnumerable <string> > permutationsOfSentence = Math.FindPermutations(sentence.Split(), numWordsInSentence); // Lazily traverse through all permutations of the sentence and exit immediately if we find the secret phrase. foreach (IEnumerable <string> permutation in permutationsOfSentence) { if (state.IsStopped) { return; // Another task found the secret phrase } string permutationString = String.Join(" ", permutation.ToArray()); string candidateMd5Hash = permutationString.ComputeMD5Hash().ConvertToHexString(useLowerCase: true); if (candidateMd5Hash == secretPhraseMd5Hash) { foundPhrase = permutationString; state.Stop(); return; // Success } } } } }; Parallel.ForEach(wordLengthCombinations, TryFindPhrase); secretPhrase = foundPhrase; return(secretPhrase != null); }
void EnsureChar(ref TestCharacter chr, CharacterPool pool) { //if (chr == null || chr.IsInWorld) { chr = pool.Create(); chr.SetMoney(100000); chr.GodMode = true; chr.EnsureInWorldAndLiving(); } }
public void AppendPool(CPool newPool) { if (CharacterPool == null) { CharacterPool = newPool; } else { CharacterPool.AppendCharacters(newPool.Characters.ToArray()); } }
public static ICharacter Create(Character prefab, CharacterPool pool = null) { ICharacter character = GameObject.Instantiate(prefab); CharacteristicController characteristicController = new CharacteristicController(character); character.Construct(characteristicController); if (pool != null) { pool.AddToPool(character); } return(character); }
private void OnDamaged(Damage damage) { if (!string.IsNullOrEmpty(damage.source)) { data.currentTarget = damage.source; if (currentRoutine != NPCRoutine.Combat) { ActivateRoutine(NPCRoutine.Combat); } } if (data.health - damage.amount <= 0) // Dying { OnDeath?.Invoke(); CharacterPool.GetCharacter(damage.source)?.Killed(gameObject.name); } }
private static void FindSentencesBeginningWith(string word, string sentenceSoFar, ReadOnlyCollection <int> lengthsOfWordsInSentence, int currentWordIndexInSentence, CharacterPool remainingCharacters, ReadOnlyDictionary <int, string[]> allowedWordsGroupedByLength, LinkedList <string> allFoundSentences) { string updatedSentence = null; if (remainingCharacters.TryRemoveAllCharacters(word)) { updatedSentence = sentenceSoFar == String.Empty ? word : sentenceSoFar + " " + word; if (remainingCharacters.NumCharsLeft == 0) { allFoundSentences.AddLast(updatedSentence); } else { int nextWordIndexInSentence = currentWordIndexInSentence + 1; int lengthOfNextWord = lengthsOfWordsInSentence[nextWordIndexInSentence]; string[] candidatesForNextWord; bool candidatesExistForNextWord = allowedWordsGroupedByLength.TryGetValue(lengthOfNextWord, out candidatesForNextWord); if (candidatesExistForNextWord) { foreach (string wordCandidate in candidatesForNextWord) { FindSentencesBeginningWith(wordCandidate, updatedSentence, lengthsOfWordsInSentence, nextWordIndexInSentence, remainingCharacters, allowedWordsGroupedByLength, allFoundSentences); } } } remainingCharacters.AddCharacters(word); } }
public static string BaseEncode(byte[] bytes, CharacterPool characterPool, bool preserveLeadingZeros) { var pool = GetCharacterPool(characterPool); var intData = new BigInteger(bytes.Reverse().Concat(new byte[] { 0x00 }).ToArray()); string result = ""; while (intData > 0) { int remainder = (int)(intData % pool.Length); intData /= pool.Length; result = pool[remainder] + result; } if (preserveLeadingZeros) { for (int i = 0; i < bytes.Length && bytes[i] == 0; i++) { result = '1' + result; } } return(result); }
private CharacterBase GetTarget() { return(CharacterPool.GetCharacter(data.currentTarget)); }
public static string GetCharacterPool(CharacterPool type = CharacterPool.AlphanumericMixedCase) { return(CharacterPoolValues[(int)type]); }
public void SetPool(CharacterPool pool) { this.characterPool = pool; }
public Shop() { pool = new CharacterPool(); }