//Casts from an enemy position: calls processCast on results public void enemyCast(SpellDictionary dict, SpellData s, int position, int target) { field.breakThirdEye(); field.Pause = true; // parent.pause battle for attack AudioPlayer.main.playSFX("sfx_enemy_cast"); AnimationPlayer.main.playAnimation("anim_spell_empower", field.enemy_arr[position].Transform.position, 2f); Pair <bool[], bool[]> targetPattern = spellDict.getTargetPattern(s, field.player_arr, target, field.enemy_arr, position); preCastEffects(targetPattern, field.enemy_arr[position], s, chat.getLine(field.enemy_arr[position].Stats.ChatDatabaseID)); BattleEffects.main.setDim(true, field.enemy_arr[position].enemy_sprite); StartCoroutine(enemy_pause_cast(dict, s, position, target)); }
private IEnumerator enemy_pause_cast(SpellDictionary dict, SpellData s, int position, int target) { uiManager.setEnabledGauges(false); BattleEffects.main.setDim(true, field.enemy_arr[position].enemy_sprite); yield return(new WaitForSeconds(1f)); field.enemy_arr[position].startSwell(); List <Transform> noTargetPositions; List <CastData> data = dict.cast(s, field.player_arr, target, field.enemy_arr, position, out noTargetPositions); processCast(data, s, noTargetPositions, (BattleField.FieldPosition)position); yield return(new WaitForSeconds(1f)); uiManager.setEnabledGauges(true); postCastEffects(); field.enemy_arr[position].attack_in_progress = false; field.lastCaster = (BattleField.FieldPosition)position; field.update(); }
/// <summary> /// Try to insert a character from TryCharacters into an every position. /// </summary> /// <param name="word">source word</param> /// <param name="suggestedWords">generated suggested words will be placed here</param> /// <param name="dic"></param> public override void Apply(string word, Dictionary <string, SpellSuggestion> suggestedWords, SpellDictionary dic) { int wordLen = word.Length; string tryChars = dic.TryCharacters; int tryCharsNum = tryChars.Length; for (int i = 0; i <= wordLen; ++i) { for (int k = 0; k < tryCharsNum; ++k) { string newWord = word.Insert(i, tryChars[k].ToString()); if (dic.IsWordCorrect(newWord)) { if (!suggestedWords.ContainsKey(newWord)) { suggestedWords.Add(newWord, new SpellSuggestion(newWord, spellChecker.EditDistanceWeights.InsertCharWeight)); } } } } }
/// <summary> /// /// </summary> /// <param name="word">source word</param> /// <param name="suggestedWords">generated suggested words will be placed here</param> /// <param name="dic"></param> public abstract void Apply(string word, Dictionary <string, SpellSuggestion> suggestedWords, SpellDictionary dic);
/// <summary> /// Tries to replace every char of the passed word to chars from the TryCharacters of the dictionary. /// </summary> /// <param name="word">source word</param> /// <param name="suggestedWords">generated suggested words will be placed here</param> /// <param name="dic"></param> public override void Apply(string word, Dictionary <string, SpellSuggestion> suggestedWords, SpellDictionary dic) { int srcWordLen = word.Length; string tryChars = dic.TryCharacters; int tryCharsNum = tryChars.Length; for (int i = 0; i < srcWordLen; ++i) { StringBuilder s = new StringBuilder(word); for (int k = 0; k < tryCharsNum; ++k) { char ch = tryChars[k]; if (s[i] == ch) { continue; } s[i] = ch; string newWord = s.ToString(); if (dic.IsWordCorrect(newWord)) { if (!suggestedWords.ContainsKey(newWord)) { suggestedWords.Add(newWord, new SpellSuggestion(newWord, spellChecker.EditDistanceWeights.ReplaceCharWeight)); } } } } }
/// <summary> /// Applies replace patterns of the passed dictionary. /// </summary> /// <param name="word">source word</param> /// <param name="suggestedWords">generated suggested words will be placed here</param> /// <param name="dic"></param> public override void Apply(string word, Dictionary <string, SpellSuggestion> suggestedWords, SpellDictionary dic) { var replacePatterns = dic.ReplacePatterns; int n = replacePatterns.Count; int p; for (int i = 0; i < n; ++i) { var replacePattern = replacePatterns[i]; string searchChars = replacePattern.SearchChars; string replaceChars = replacePattern.ReplaceChars; int editDistance = 0; string newWord = word; p = 0; while ((p = newWord.IndexOf(searchChars, p)) != -1) { newWord = newWord.Substring(0, p) + replaceChars + newWord.Substring(p + searchChars.Length); p += replaceChars.Length; editDistance += spellChecker.EditDistanceWeights.ReplaceCharWeight * Math.Max(searchChars.Length, replaceChars.Length); if (dic.IsWordCorrect(newWord)) { if (!suggestedWords.ContainsKey(newWord)) { suggestedWords.Add(newWord, new SpellSuggestion(newWord, editDistance)); } } } } }
/// <summary> /// Try to split the passed word onto 2 words. /// </summary> /// <param name="word">source word</param> /// <param name="suggestedWords">generated suggested words will be placed here</param> /// <param name="dic"></param> public override void Apply(string word, Dictionary <string, SpellSuggestion> suggestedWords, SpellDictionary dic) { int wordLen = word.Length; if (wordLen < 2) { return; } for (int i = 1; i < wordLen; ++i) { string word1 = word.Substring(0, i); string word2 = word.Substring(i); if (dic.IsWordCorrect(word1) && dic.IsWordCorrect(word2)) { string newText = word1 + ' ' + word2; if (!suggestedWords.ContainsKey(newText)) { suggestedWords.Add(newText, new SpellSuggestion(newText, spellChecker.EditDistanceWeights.InsertCharWeight)); } } } }
/// <summary> /// Tries to omit one by one char. /// </summary> /// <param name="word">source word</param> /// <param name="suggestedWords">generated suggested words will be placed here</param> /// <param name="dic"></param> public override void Apply(string word, Dictionary <string, SpellSuggestion> suggestedWords, SpellDictionary dic) { int wordLen = word.Length; if (wordLen <= 1) { return; } for (int i = 0; i < wordLen; ++i) { string newWord = word.Remove(i, 1); if (dic.IsWordCorrect(newWord)) { if (!suggestedWords.ContainsKey(newWord)) { suggestedWords.Add(newWord, new SpellSuggestion(newWord, spellChecker.EditDistanceWeights.DeleteCharWeight)); } } } }
/// <summary> /// Tries to swap every pair of adjacent chars. /// </summary> /// <param name="word">source word</param> /// <param name="suggestedWords">generated suggested words will be placed here</param> /// <param name="dic"></param> public override void Apply(string word, Dictionary <string, SpellSuggestion> suggestedWords, SpellDictionary dic) { int wordLen = word.Length; for (int i = 0; i < wordLen - 1; ++i) { // swapping... StringBuilder s = new StringBuilder(word); char t = s[i]; s[i] = s[i + 1]; s[i + 1] = t; string newWord = s.ToString(); if (dic.IsWordCorrect(newWord)) { if (!suggestedWords.ContainsKey(newWord)) { suggestedWords.Add(newWord, new SpellSuggestion(newWord, spellChecker.EditDistanceWeights.SwapCharWeight)); } } } }