public void CalculateModifiers() { strengthModifier = ObjectParser.Divide(strength - 10, 2); dexterityModifier = ObjectParser.Divide(dexterity - 10, 2); constitutionModifier = ObjectParser.Divide(constitution - 10, 2); intelligenceModifier = ObjectParser.Divide(intelligence - 10, 2); wisdomModifier = ObjectParser.Divide(wisdom - 10, 2); charismaModifier = ObjectParser.Divide(charisma - 10, 2); }
/// <summary> /// For Condition, Note, Remove /// </summary> private static void Parse_Info_Text(ConsoleKeyInfo keyInfo) { switch (keyInfo.Key) { case Confirm: if (Program.data.idList.Count > 0) { var actor = Program.data.GetActor(Program.data.idList[Program.outputData.Info_GetSelected()]); switch (Program.outputData.info_opMode) { case Info_OpMode.Condition: if (actor != null) { // Add Condition var condition = Program.outputData.Info_GetArgument().GetCondition(); if (condition.HasValue) { if (actor.AddCondition(condition.Value)) { Program.outputData.Info_Argument_Clear(); } } } break; case Info_OpMode.Note: if (actor != null) { // Add Note actor.AddNote(Program.outputData.Info_GetArgument()); } break; case Info_OpMode.Remove: if (actor != null) { if (Program.outputData.Info_GetArgument().Length == 0) { // Remove Actor Program.data.RemoveActor(actor.id); Program.outputData.Info_UpdateArgumentInfo(); } else { var condition = Program.outputData.Info_GetArgument().GetCondition(); if (condition.HasValue) { // Remove Condition actor.RemoveCondition(condition.Value); Program.outputData.Info_UpdateArgumentInfo(); } else { // Remove Note var index = ObjectParser.GetInt10(Program.outputData.Info_GetArgument()); if (index.HasValue) { actor.RemoveNote(index.Value); Program.outputData.Info_UpdateArgumentInfo(); } } } } break; default: throw new ArgumentOutOfRangeException(nameof(Program.outputData.info_opMode)); } } break; default: // Parse Char as Input ObjectParser.FormatChar(keyInfo.KeyChar, Program.outputData.Info_Argument_Add); break; } }
/// <summary> /// For LoseHealth, GainHealth, GainTemp /// </summary> private static void Parse_Info_HealthChange(ConsoleKeyInfo keyInfo) { switch (keyInfo.Key) { case Confirm: // Evaluate Tokens if (Program.data.idList.Count > 0) { var tokens = ObjectParser.GetTokens(Program.outputData.Info_GetArgument()); if (tokens.HasValue) { var result = tokens.Value.Evaluate(); if (result.HasValue) { switch (Program.outputData.info_opMode) { case Info_OpMode.LoseHealth: Program.data.LoseHealth(Program.data.idList[Program.outputData.Info_GetSelected()], result.Value); break; case Info_OpMode.GainHealth: Program.data.GainHealth(Program.data.idList[Program.outputData.Info_GetSelected()], result.Value); break; case Info_OpMode.GainTemp: Program.data.GainTemporary(Program.data.idList[Program.outputData.Info_GetSelected()], result.Value); break; default: throw new ArgumentOutOfRangeException(nameof(Program.outputData.info_opMode)); } } } } break; case GainHealth: // Gain Health if (Program.data.idList.Count > 0) { if ((keyInfo.Modifiers & ConsoleModifiers.Alt) != 0) { Program.data.GainHealth(Program.data.idList[Program.outputData.Info_GetSelected()], AltAmount); } else if ((keyInfo.Modifiers & ConsoleModifiers.Control) != 0) { Program.data.GainHealth(Program.data.idList[Program.outputData.Info_GetSelected()], CtrlAmount); } else if ((keyInfo.Modifiers & ConsoleModifiers.Shift) != 0) { Program.data.GainHealth(Program.data.idList[Program.outputData.Info_GetSelected()], ShiftAmount); } else { Program.data.GainHealth(Program.data.idList[Program.outputData.Info_GetSelected()], DefAmount); } } break; case LoseHealth: // Lose Health if (Program.data.idList.Count > 0) { if ((keyInfo.Modifiers & ConsoleModifiers.Alt) != 0) { Program.data.LoseHealth(Program.data.idList[Program.outputData.Info_GetSelected()], AltAmount); } else if ((keyInfo.Modifiers & ConsoleModifiers.Control) != 0) { Program.data.LoseHealth(Program.data.idList[Program.outputData.Info_GetSelected()], CtrlAmount); } else if ((keyInfo.Modifiers & ConsoleModifiers.Shift) != 0) { Program.data.LoseHealth(Program.data.idList[Program.outputData.Info_GetSelected()], ShiftAmount); } else { Program.data.LoseHealth(Program.data.idList[Program.outputData.Info_GetSelected()], DefAmount); } } break; default: // Add Character to Argument ObjectParser.FormatExpressionChar(keyInfo.KeyChar, Program.outputData.Info_Argument_Add); break; } }
public void Info_UpdateArgumentInfo() { Actor actor; if (Program.data.idList.Count == 0) { actor = null; } else { actor = Program.data.GetActor(Program.data.idList[info_selected]); } if (actor == null) { info_argument_valid = false; info_argument_condition = Option <Condition> .Null; } else { switch (info_opMode) { case Info_OpMode.LoseHealth: case Info_OpMode.GainHealth: case Info_OpMode.GainTemp: var tokens = ObjectParser.GetTokens(info_argumentString); info_argument_valid = tokens.HasValue && tokens.Value.Validate(); info_argument_condition = Option <Condition> .Null; return; case Info_OpMode.Remove: if (info_argumentString.Length == 0) { // Remove Creature info_argument_valid = true; info_argument_condition = Option <Condition> .Null; } else { var condition = info_argumentString.GetCondition(); if (condition.HasValue) { // Conditon info_argument_valid = actor.conditions.Contains(condition.Value); info_argument_condition = condition.Value; } else { // Note (indexed by Number) var index = ObjectParser.GetInt10(info_argumentString); info_argument_valid = index.HasValue && actor.HasNote(index.Value); info_argument_condition = Option <Condition> .Null; } } return; case Info_OpMode.Condition: { var condition = info_argumentString.GetCondition(); info_argument_valid = condition.HasValue && !actor.conditions.Contains(condition.Value); info_argument_condition = condition; } return; case Info_OpMode.Note: // Parse Integer info_argument_valid = true; return; } } }
// === Parse Integer Expression === public static Option <List <Token> > GetTokens(string text) { Stack <int> bracketStarts = new Stack <int>(); List <Token> tokens = new List <Token>(); int intStart = int.MinValue; for (int index = 0; index < text.Length; ++index) { switch (text[index]) { case '+': if (intStart >= 0) { tokens.Add(new Token(TokenType.Integer, ObjectParser.GetInt10_Unsafe(text, intStart, index))); intStart = int.MinValue; } tokens.Add(new Token(TokenType.Add)); break; case '-': if (intStart >= 0) { tokens.Add(new Token(TokenType.Integer, ObjectParser.GetInt10_Unsafe(text, intStart, index))); intStart = int.MinValue; } tokens.Add(new Token(TokenType.Subtract)); break; case '*': if (intStart >= 0) { tokens.Add(new Token(TokenType.Integer, ObjectParser.GetInt10_Unsafe(text, intStart, index))); intStart = int.MinValue; } tokens.Add(new Token(TokenType.Multiply)); break; case '/': if (intStart >= 0) { tokens.Add(new Token(TokenType.Integer, ObjectParser.GetInt10_Unsafe(text, intStart, index))); intStart = int.MinValue; } tokens.Add(new Token(TokenType.Divide)); break; case 'd': case 'D': if (intStart >= 0) { tokens.Add(new Token(TokenType.Integer, ObjectParser.GetInt10_Unsafe(text, intStart, index))); intStart = int.MinValue; } tokens.Add(new Token(TokenType.Dice)); break; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': if (intStart < 0) { intStart = index; } break; case '(': if (intStart >= 0) { tokens.Add(new Token(TokenType.Integer, ObjectParser.GetInt10_Unsafe(text, intStart, index))); intStart = int.MinValue; } bracketStarts.Push(tokens.Count); tokens.Add(new Token(TokenType.Bracket)); break; case ')': if (intStart >= 0) { tokens.Add(new Token(TokenType.Integer, ObjectParser.GetInt10_Unsafe(text, intStart, index))); intStart = int.MinValue; } if (bracketStarts.Count == 0) { return(Option <List <Token> > .Null); } else { tokens[bracketStarts.Peek()].value = tokens.Count; bracketStarts.Pop(); break; } default: return(Option <List <Token> > .Null); } } if (intStart >= 0) { tokens.Add(new Token(TokenType.Integer, ObjectParser.GetInt10_Unsafe(text, intStart, text.Length))); } if (bracketStarts.Count == 0) { return(tokens); } else { return(Option <List <Token> > .Null); } }
public Actor CreateInstance(List <ColoringType> coloringTypes, List <string> errors) { Actor actor = new Actor(); // Get Name actor.name = name; // Get HP Values var eval_HP = HP.Evaluate(); if (!eval_HP.HasValue) { errors.Add("[Actor, name='" + name + "'] Unable to Compute: hp"); } else { actor.currentHP = eval_HP.Value; actor.maximumHP = eval_HP.Value; } if (temporary.HasValue) { var eval_temporary = temporary.Value.Evaluate(); if (!eval_temporary.HasValue) { errors.Add("[Actor, name='" + name + "'] Unable to Compute: temp"); } else { actor.temporaryHP = eval_temporary.Value; } } // Get Color Values if (coloring.HasValue) { if (coloringType.HasValue) { errors.Add("[Actor, name='" + name + "'] Ambiguity: Coloring is defined twice"); } else { actor.base_text = coloring.Value.base_text; actor.base_bg = coloring.Value.base_bg; actor.active_text = coloring.Value.active_text; actor.active_bg = coloring.Value.active_bg; } } else { string targetColoringType; if (coloringType.HasValue) { targetColoringType = coloringType.Value; } else { targetColoringType = Program.settings.defaultColoringType; } bool found = false; for (int index = 0; index < coloringTypes.Count; ++index) { if (coloringTypes[index].name == targetColoringType) { actor.base_text = coloringTypes[index].base_text; actor.base_bg = coloringTypes[index].base_bg; actor.active_text = coloringTypes[index].active_text; actor.active_bg = coloringTypes[index].active_bg; found = true; break; } } if (!found) { errors.Add("[Actor, name='" + name + "'] Coloring not found: " + targetColoringType); } } // Get Armor Class if (armorClass.HasValue) { var eval_armorClass = armorClass.Value.Evaluate(); if (!eval_armorClass.HasValue) { errors.Add("[Actor, name='" + name + "'] Unable to Compute: ac"); } else { actor.armorClass = eval_armorClass.Value; } } // Get Speed actor.speed = speed; // Get Scores if (scores.HasValue) { void AddScoresError(string error) { errors.Add("[Actor, name='" + name + "']" + error); }; int errorCount = errors.Count; var eval_scores = scores.Value.GetScores(AddScoresError); if (errors.Count == errorCount) { actor.scores = eval_scores; } } // Get Intiative if (initiative.HasValue) { var eval_initiative = initiative.Value.Evaluate(); if (!eval_initiative.HasValue) { errors.Add("[Actor, name='" + name + "'] Unable to Compute: ini"); } else { actor.initiative = eval_initiative.Value; } } else { if (!actor.scores.HasValue) { errors.Add("[Actor, name='" + name + "'] Unable to Determine Value: ini"); } else { actor.initiative = ObjectParser.Roll(1, 20) + actor.scores.Value.dexterityModifier; } } // Get Attacks, Description, Conditions actor.attacks = attacks; actor.description = description; if (conditions == null) { actor.conditions = new Conditions(); } else { actor.conditions = conditions.Clone(); } // Get Notes for (int index = 0; index < notes.Count; ++index) { actor.notes.Add(new Note(actor.nextNoteIndex, notes[index])); ++actor.nextNoteIndex; } // Get Remove actor.remove = remove; return(actor); }