diff --git a/game_config.py b/game_config.py index e04bf08..c76a6cc 100644 --- a/game_config.py +++ b/game_config.py @@ -7,8 +7,9 @@ MAX_STUNNED_ROUNDS = 10 # Max amount of rounds a player can be stunned ## ## Spells config ## -CHANCE_HEAL_PARTLY = 25 # Percentage chance a player is healed with 5% of max health when using a defensive spell -CHANCE_HEAL_FULLY = 5 # Percentage chance a player is fully healed when using a defensive spell +CHANCE_HEAL_PARTLY = 25 # Percentage chance a player is healed with 5% of max health when using a defensive spell +CHANCE_HEAL_FULLY = 5 # Percentage chance a player is fully healed when using a defensive spell +MAX_LEVENSHTEIN_DISTANCE = 3 # Max Levenshtein distance (max amount of typos a user can make) before considering a spell fails. Setting this to 0 disables it (and in that case also doesn't require the levenshtein package) ## ## Misc diff --git a/spells.py b/spells.py index 5422e95..e8dffd1 100644 --- a/spells.py +++ b/spells.py @@ -1,5 +1,8 @@ import random -from game_config import CHANCE_HEAL_PARTLY, CHANCE_HEAL_FULLY, DEBUG_MODE +from game_config import CHANCE_HEAL_PARTLY, CHANCE_HEAL_FULLY, DEBUG_MODE, MAX_LEVENSHTEIN_DISTANCE + +if MAX_LEVENSHTEIN_DISTANCE > 0: + from Levenshtein import distance SPELL_TYPE_NONE = -1 SPELL_TYPE_USELESS = 0 @@ -8,15 +11,6 @@ SPELL_TYPE_COMMON = 2 SPELL_TYPE_POWERFUL = 3 SPELL_TYPE_UNFORGIVABLE = 4 - - -#Maximum Levenshtein distance. Eg if a user casts 'Pritrgo' instead of 'Protego', distance would be 2 and Protego would still be cast if MAX_LEVENSHTEIN_DISTANCE is at least 2 -#Set to 0 to disable -MAX_LEVENSHTEIN_DISTANCE = 0 - -if MAX_LEVENSHTEIN_DISTANCE > 0: - from Levenshtein import distance - _INVALID_SPELL = ".@wizardduel@__spell_invalid__" #Internal usage only ##