public void Execute(SchemeExecutor executor) { ObjectVariable objectVariable = executor.GetVariableByName(characterName); ObjectVariable numberVariable = executor.FindValueByString(numberName); if (objectVariable == null) { throw SchemeExecutor.CreateException($"Character '{characterName}' not found"); } if (numberVariable.Type != VariableTypes.Number) { throw SchemeExecutor.CreateException($"Number is expected to be of type number"); } int requiredNumber = (int)numberVariable.Value; if (!(objectVariable.Value is Character)) { throw SchemeExecutor.CreateException("Items can only be added to characters"); } Character character = (Character)(objectVariable.Value); ObjectVariable itemVariable = executor.GetVariableByName(itemName); if (!executor.CheckTypeCompatibility(VariableTypes.Object, itemVariable.Type)) { throw SchemeExecutor.CreateException($"Type '{itemVariable.Type}' is not an object type"); } character.AddItem(executor.Game, (Object)itemVariable.Value, requiredNumber); }
public void Execute(SchemeExecutor executor) { ObjectVariable objectVariable = executor.GetVariableByName(characterName); if (objectVariable == null) { throw SchemeExecutor.CreateException($"Character '{characterName}' not found"); } if (!(objectVariable.Value is Character)) { throw SchemeExecutor.CreateException("Spells can only be added to characters"); } Character character = (Character)(objectVariable.Value); ObjectVariable spellVariable = executor.GetVariableByName(spellName); if (!executor.CheckTypeCompatibility(VariableTypes.Object, spellVariable.Type)) { throw SchemeExecutor.CreateException($"Type '{spellVariable.Type}' is not an object type"); } character.AddSpell((Object)spellVariable.Value); }
public void Execute(SchemeExecutor executor) { ObjectVariable @object = executor.GetVariableByName(objectName); ObjectVariable numberVariable = executor.FindValueByString(numberName); if (@object == null) { throw SchemeExecutor.CreateException($"Object '{objectName}' not found"); } if (numberVariable.Type != VariableTypes.Number) { throw SchemeExecutor.CreateException($"Number is expected to be of type number"); } int requiredNumber = (int)numberVariable.Value; if (!(@object.Value is Character)) { throw new SchemeExecutionException($"Object '{objectName}' is not a character"); } Character character = (Character)(@object.Value); int ownedNumber = character.CountItem(itemName); bool owns = ownedNumber >= requiredNumber; executor.SetVariable(targetName, new ObjectVariable(VariableTypes.Logical, "", owns)); }
protected override bool GetResult(ObjectVariable variable1, ObjectVariable variable2) { //In case of numbers and logicals we compare values if (variable1.Type == VariableTypes.Number) { if (variable2.Type != VariableTypes.Number) { throw SchemeExecutor.CreateException("Cannot compare number and non-number"); } int value1_int = (int)variable1.Value; int value2_int = (int)variable2.Value; return(value1_int == value2_int); } if (variable1.Type == VariableTypes.Logical) { if (variable2.Type != VariableTypes.Logical) { throw SchemeExecutor.CreateException("Cannot compare logical and non-logical"); } bool value1_bool = (bool)variable1.Value; bool value2_bool = (bool)variable2.Value; return(value1_bool == value2_bool); } //In case of other types, we compare if they are the same object return(variable1.Value == variable2.Value); }
protected override bool GetResult(ObjectVariable variable1, ObjectVariable variable2) { if (variable1.Type != VariableTypes.Number || variable2.Type != VariableTypes.Number) { throw SchemeExecutor.CreateException("Cannot compare non-numbers"); } int value1_int = (int)variable1.Value; int value2_int = (int)variable2.Value; return(value1_int < value2_int); }
public void Execute(SchemeExecutor executor) { ObjectVariable objectVariable = executor.GetVariableByName(objectName); if (!executor.CheckTypeCompatibility(VariableTypes.Object, objectVariable.Type)) { throw SchemeExecutor.CreateException($"Object has to be compatible with 'object' (actual type: '{objectVariable.Type}')"); } Object @object = (Object)objectVariable.Value; @object.ForbidAttribute(attributeName); }
protected override bool Evaluate(SchemeExecutor executor) { ObjectVariable variable = executor.FindValueByString(value); if (variable.Type != VariableTypes.Logical) { throw SchemeExecutor.CreateException("Cannot use non-logical value in JF"); } bool value_bool = (bool)variable.Value; return(!value_bool); }
public void Execute(SchemeExecutor executor) { ObjectVariable variable = executor.FindValueByString(value); if (variable.Type != VariableTypes.Logical) { throw SchemeExecutor.CreateException("Cannot invert non-logical"); } bool value_bool = (bool)variable.Value; executor.SetVariable(target, new ObjectVariable(VariableTypes.Logical, "", (!value_bool))); }
public void Execute(SchemeExecutor executor) { ObjectVariable objectVariable = executor.GetVariableByName(objectName); // ObjectVariable property = executor //Uses of 'is': // object has attribute actor is forest_wanderer // class var race of actor is dwarf // -> OF(race, actor, _0) EQUALS(_0, dwarf, _0) // item/spell is the same as... some_item is sword_1 //some_item.Name == "sword_1" /* * 1. Check if object's name equals to propertyName * 2. Check if object has attribute named propertyName */ bool value = false; //If we check class variable if (executor.Game.Config.IsClassType(objectVariable.Type)) { //we search for the required class var c = executor.FindValueByString(propertyName); //then we compare it to the classvar value = objectVariable.Value == c.Value; } else { if (!executor.CheckTypeCompatibility(VariableTypes.Object, objectVariable.Type)) { throw SchemeExecutor.CreateException("Object has to be compatible with 'object'"); } Object @object = (Object)objectVariable.Value; if (@object.Name == propertyName) { value = true; } else if (@object.HasAttribute(propertyName)) { value = true; } } executor.SetVariable(target, new ObjectVariable(VariableTypes.Logical, "", value)); }
public void Execute(SchemeExecutor executor) { ObjectVariable @object = executor.GetVariableByName(objectName); if (@object == null) { throw SchemeExecutor.CreateException($"Object '{objectName}' not found"); } if (!(@object.Value is Character)) { throw new SchemeExecutionException($"Object '{objectName}' is not a character"); } Character character = (Character)(@object.Value); bool owns = character.KnowsSpell(spellName); executor.SetVariable(targetName, new ObjectVariable(VariableTypes.Logical, "", owns)); }
protected override bool GetResult(ObjectVariable variable1, ObjectVariable variable2) { if (variable1.Type != VariableTypes.Number || variable2.Type != VariableTypes.Number) { throw SchemeExecutor.CreateException("Cannot compare non-numbers"); } int value1_int = (int)variable1.Value; int value2_int = (int)variable2.Value; if (op == ">") { return(value1_int > value2_int); } if (op == "<") { return(value1_int < value2_int); } if (op == ">=") { return(value1_int >= value2_int); } if (op == "<=") { return(value1_int <= value2_int); } if (op == "!=") { return(value1_int != value2_int); } if (op == "=") { return(value1_int == value2_int); } return(false); }