public override bool?Execute() { if (line.LinkedArray != null && line.LinkedVar != null && line.LinkedArray.Value != null && line.LinkedVar.LinkedVariable != null) { var game = MainViewModel.GetMainViewModelStatic().CurrentGame; var linkedArray = game.ArraysById[line.LinkedArray.Ref]; List <object> copiedArray = new List <object>(); foreach (var a in linkedArray) { copiedArray.Add(a); } if (line.ClearArray) { linkedArray.Clear(); } foreach (var a in copiedArray) { //First copy the value ScriptWrapper sw = new ScriptWrapper(line.ExecutingScript); sw.parent = this.parent; var variable = sw.GetVarById(line.LinkedVar.LinkedVarId); if (line.LinkedArray.Value.IsCommonEvent) { variable.CurrentCommonEventValue = (CommonEventRef)a; } if (line.LinkedArray.Value.IsString) { variable.CurrentStringValue = a.ToString(); } if (line.LinkedArray.Value.IsNumber) { variable.CurrentNumberValue = (int)a; } if (line.LinkedArray.Value.IsItem) { variable.CurrentItemValue = (ItemInstance)a; } //Then execute the child script var res = sw.Execute(); //If a true or false value was returned, finish the script immediately. if (res != null) { return(res); } } return(null); } else { MainViewModel.WriteText("Error in Iterate through Array script.", this.parent); return(false); } }
public void RefreshPlayerDescription() { var wrapper = new ScriptWrapper(Settings.PlayerDescription); wrapper.Execute(); PlayerDescription.Clear(); foreach (var res in wrapper.TextResult) { PlayerDescription.Add(res); } }
public override bool?Execute() { bool?conditionResult = null; if (line.IsComparison) { conditionResult = ComparisonCheck(); } if (line.ItemIsNotNull) { if (line.SelectedVariable != null) { var v = parent.GetVarById(line.SelectedVariable.LinkedVarId); if (v != null) { conditionResult = v.CurrentItemValue != null; } } } if (line.ItemIsClass) { if (line.SelectedVariable == null) { conditionResult = false; } else { var variable = parent.GetVarById(line.SelectedVariable.LinkedVarId); if (variable.CurrentItemValue == null) { conditionResult = false; } else { conditionResult = false; var parentClass = variable.CurrentItemValue.item.ItemClassParent; while (parentClass != null && conditionResult == false) { if (parentClass.Name == line.SelectedClassName) { conditionResult = true; } parentClass = parentClass.ParentClass; } } } } if (line.PlayerHasItem) { if (line.SelectedItem != null && line.SelectedItem.LinkedItemId != null) { if (MainViewModel.GetMainViewModelStatic().CurrentGame.PlayerInventory.Where(a => a.item.ItemID == line.SelectedItem.LinkedItemId).Count() > 0) { conditionResult = true; } else { conditionResult = false; } } else { return(false); } } if (conditionResult == null) { return(false); } bool?result = null; if (conditionResult == true) { ScriptWrapper s = new ScriptWrapper(line.ThenStatement); s.parent = parent; result = s.Execute(); } else if (conditionResult == false) { ScriptWrapper s = new ScriptWrapper(line.ElseStatement); s.parent = parent; result = s.Execute(); } return(result); }