Math Mode - Most of the code logic was copied from PlayerCharacter.getVariableValue included a treatment for math with attack routines (for example +6/+1 - 2 = +4/-1) @param aString The string to be converted @param aPC the PC being exported @return String
(String aString, PlayerCharacter aPC)
| 917 | * @return String |
| 918 | */ |
| 919 | private String mathMode(String aString, PlayerCharacter aPC) |
| 920 | { |
| 921 | String str = aString; |
| 922 | |
| 923 | // Deal with Knowledge () type tokens |
| 924 | str = processBracketedTokens(str, aPC); |
| 925 | |
| 926 | // Replace all square brackets with curved ones |
| 927 | str = str.replaceAll(Pattern.quote("["), "("); |
| 928 | str = str.replaceAll(Pattern.quote("]"), ")"); |
| 929 | |
| 930 | // A list of mathematical delimiters |
| 931 | final String delimiter = "+-/*"; |
| 932 | String valString = ""; |
| 933 | final int ADDITION_MODE = 0; |
| 934 | final int SUBTRACTION_MODE = 1; |
| 935 | final int MULTIPLICATION_MODE = 2; |
| 936 | final int DIVISION_MODE = 3; |
| 937 | // Mode is addition mode by default |
| 938 | int mode = ADDITION_MODE; |
| 939 | |
| 940 | int nextMode = 0; |
| 941 | final int REGULAR_MODE = 0; |
| 942 | final int INTVAL_MODE = 1; |
| 943 | final int SIGN_MODE = 2; |
| 944 | final int NO_ZERO_MODE = 3; |
| 945 | int endMode = REGULAR_MODE; |
| 946 | boolean attackRoutine = false; |
| 947 | String attackData = ""; |
| 948 | |
| 949 | float total = 0.0f; |
| 950 | for (int i = 0; i < str.length(); ++i) |
| 951 | { |
| 952 | valString += str.substring(i, i + 1); |
| 953 | |
| 954 | if ((i == (str.length() - 1)) |
| 955 | || ((delimiter.lastIndexOf(str.charAt(i)) > -1) && (i > 0) && (str.charAt(i - 1) != '.'))) |
| 956 | { |
| 957 | if (delimiter.lastIndexOf(str.charAt(i)) > -1) |
| 958 | { |
| 959 | valString = valString.substring(0, valString.length() - 1); |
| 960 | } |
| 961 | |
| 962 | { |
| 963 | // Deal with .TRUNC |
| 964 | if (valString.endsWith(".TRUNC")) |
| 965 | { |
| 966 | if (attackRoutine) |
| 967 | { |
| 968 | Logging.errorPrint("Math Mode Error: Not allowed to use .TRUNC in Attack Mode."); |
| 969 | } |
| 970 | else |
| 971 | { |
| 972 | valString = String.valueOf(Float |
| 973 | .valueOf(mathMode(valString.substring(0, valString.length() - 6), aPC)).intValue()); |
| 974 | } |
| 975 | } |
| 976 |
no test coverage detected