public void UseExit(ExitWrapper exit) { WriteText("-------------------------------------------", null); var movementResult = new ScriptWrapper(CurrentGame.Settings.MovementScript).Execute(); foreach (var a in CurrentGame.ActiveStatusEffects) { a.RunOnMove(); } CheckStatusEffectsResolved(); bool result = true; foreach (var a in CurrentGame.EquippedItems.Select(a => a.Value).Where(a => a != null).Distinct()) { var res = new ScriptWrapper(a.item.EquipmentRef.OnMove).Execute(); if (res == false) { result = false; } } if ((movementResult == null || movementResult == true) && result) { CurrentGame.CurrentRoom = CurrentGame.Rooms[exit.ExitBase.RoomID]; } OutputCurrentRoomDescription(); MainViewModel.GetMainViewModelStatic().CurrentGame.RunActiveEvents(); GC.Collect(); }
// Use this for initialization void Start() { FindObjectOfType <Fading>().BeginFade(-1); tmMain = GameObject.Find("TextManager Main").GetComponent <TextManager>(); tmChoice = GameObject.Find("TextManager Choice").GetComponent <TextManager>(); tmInfo = GameObject.Find("TextManager Info").GetComponent <TextManager>(); tmBigTalk = GameObject.Find("TextManager BigTalk").GetComponent <TextManager>(); tmGold = GameObject.Find("TextManager Gold").GetComponent <TextManager>(); tmItem = GameObject.Find("TextManager Item").GetComponent <TextManager>(); tmInfoParent = tmInfo.transform.parent.parent.gameObject; tmBigTalk.SetTextQueue(new TextMessage[] { new TextMessage("[noskipatall][novoice]", false, true) }); utHeart = GameObject.Find("utHeart"); EnableBigText(false); if (scriptName == null) { throw new CYFException("You must give a valid script name to the function General.EnterShop()"); } script = new ScriptWrapper() { scriptname = scriptName }; string scriptText = ScriptRegistry.Get(ScriptRegistry.SHOP_PREFIX + scriptName); if (scriptText == null) { throw new CYFException("You must give a valid script name to the function General.EnterShop()"); } try { script.DoString(scriptText); script.SetVar("background", UserData.Create(new LuaSpriteController(GameObject.Find("Background").GetComponent <Image>()))); script.script.Globals["Interrupt"] = ((Action <DynValue, string>)Interrupt); script.script.Globals["CreateSprite"] = (Func <string, string, int, DynValue>)SpriteUtil.MakeIngameSprite; script.script.Globals["CreateLayer"] = (Action <string, string, bool>)SpriteUtil.CreateLayer; script.script.Globals["CreateText"] = (Func <Script, DynValue, DynValue, int, string, int, LuaTextManager>)LuaScriptBinder.CreateText; TryCall("Start"); tmMain.SetCaller(script); tmChoice.SetCaller(script); tmInfo.SetCaller(script); tmBigTalk.SetCaller(script); tmMain.SetTextQueue(new TextMessage[] { new TextMessage("[noskipatall][linespacing:11]" + script.GetVar("maintalk").String, true, false) }); tmChoice.SetTextQueue(new TextMessage[] { new TextMessage("[noskipatall][novoice][font:uidialoglilspace][linespacing:9] Buy\n Sell\n Talk\n Exit", false, true) }); tmGold.SetTextQueue(new TextMessage[] { new TextMessage("[noskipatall][novoice]" + PlayerCharacter.instance.Gold + "G", false, true) }); tmItem.SetTextQueue(new TextMessage[] { new TextMessage("[noskipatall][novoice]" + Inventory.inventory.Count + "/8", false, true) }); tmInfo.SetTextQueue(new TextMessage[] { new TextMessage("[noskipatall][novoice]", false, true) }); Camera.main.GetComponent <AudioSource>().clip = AudioClipRegistry.GetMusic(script.GetVar("music").String); Camera.main.GetComponent <AudioSource>().time = 0; Camera.main.GetComponent <AudioSource>().Play(); SetPlayerOnSelection(); } catch (InterpreterException ex) { UnitaleUtil.DisplayLuaError(scriptName, ex.DecoratedMessage != null ? UnitaleUtil.FormatErrorSource(ex.DecoratedMessage, ex.Message) + ex.Message : ex.Message); } catch (Exception ex) { UnitaleUtil.DisplayLuaError(scriptName, "Unknown error. Usually means you're missing a sprite.\nSee documentation for details.\nStacktrace below in case you wanna notify a dev.\n\nError: " + ex.Message + "\n\n" + ex.StackTrace); } }
public RemoteFilesystem(IProfile profile, ISynchronizeInvoke invoke) { _scriptWrapperBool = new ScriptWrapper <bool>(profile, invoke, d => bool.Parse(d.ToString())); _scriptWrapper = new ScriptWrapper <string>(profile, invoke, d => d.ToString()); _scriptWrapperDrive = new ScriptWrapper <Model.Fake.DriveInfo>(profile, invoke, Convert <Model.Fake.DriveInfo>); _scriptWrapperDirectory = new ScriptWrapper <Model.Fake.DirectoryInfo>(profile, invoke, Convert <Model.Fake.DirectoryInfo>); }
public PowershellBackupInfoExtractor(IProfile profile, ISynchronizeInvoke invoke) { _profile = profile; _invoke = invoke; _remoteScriptCopier = new RemoteScriptCopier(_profile, invoke); _scriptWrapper = new ScriptWrapper <string>(_profile, _invoke, d => d.ToString()); }
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); } }
// Use this for initialization void Start() { FindObjectOfType <Fading>().BeginFade(-1); tmMain = GameObject.Find("TextManager Main").GetComponent <TextManager>(); tmChoice = GameObject.Find("TextManager Choice").GetComponent <TextManager>(); tmInfo = GameObject.Find("TextManager Info").GetComponent <TextManager>(); tmBigTalk = GameObject.Find("TextManager BigTalk").GetComponent <TextManager>(); tmGold = GameObject.Find("TextManager Gold").GetComponent <TextManager>(); tmItem = GameObject.Find("TextManager Item").GetComponent <TextManager>(); tmInfoParent = tmInfo.transform.parent.parent.gameObject; tmBigTalk.SetTextQueue(new TextMessage[] { new TextMessage("[noskipatall][novoice]", false, true) }); utHeart = GameObject.Find("utHeart"); EnableBigText(false); if (scriptName == null) { UnitaleUtil.DisplayLuaError("Creating the shop menu", "You must give a valid script name to the function General.EnterShop()"); return; } script = new ScriptWrapper() { scriptname = scriptName }; string scriptText = ScriptRegistry.Get(ScriptRegistry.SHOP_PREFIX + scriptName); if (scriptText == null) { UnitaleUtil.DisplayLuaError("Creating the shop menu", "You must give a valid script name to the function General.EnterShop()"); return; } script.DoString(scriptText); script.SetVar("background", UserData.Create(new LuaSpriteController(GameObject.Find("Background").GetComponent <Image>()))); script.script.Globals["Interrupt"] = ((Action <DynValue, string>)Interrupt); script.script.Globals["CreateSprite"] = (Func <string, string, int, DynValue>)SpriteUtil.MakeIngameSprite; script.script.Globals["CreateLayer"] = (Action <string, string, bool>)SpriteUtil.CreateLayer; script.script.Globals["CreateText"] = (Func <Script, DynValue, DynValue, int, string, int, LuaTextManager>)LuaScriptBinder.CreateText; script.Call("Start"); tmMain.SetCaller(script); tmChoice.SetCaller(script); tmInfo.SetCaller(script); tmBigTalk.SetCaller(script); tmMain.SetTextQueue(new TextMessage[] { new TextMessage("[noskipatall][linespacing:11]" + script.GetVar("maintalk").String, true, false) }); tmChoice.SetTextQueue(new TextMessage[] { new TextMessage("[noskipatall][novoice][font:uidialoglilspace][linespacing:9] Buy\n Sell\n Talk\n Exit", false, true) }); tmGold.SetTextQueue(new TextMessage[] { new TextMessage("[noskipatall][novoice]" + PlayerCharacter.instance.Gold + "G", false, true) }); tmItem.SetTextQueue(new TextMessage[] { new TextMessage("[noskipatall][novoice]" + Inventory.inventory.Count + "/8", false, true) }); tmInfo.SetTextQueue(new TextMessage[] { new TextMessage("[noskipatall][novoice]", false, true) }); Camera.main.GetComponent <AudioSource>().clip = AudioClipRegistry.GetMusic(script.GetVar("music").String); Camera.main.GetComponent <AudioSource>().Play(); }
public void ActionDialogResult(TextMessage[] msg, UIState afterDialogState, ScriptWrapper caller = null) { stateAfterDialogs = afterDialogState; if (caller != null) { textmgr.setCaller(caller); } textmgr.setTextQueue(msg); SwitchState(UIState.DIALOGRESULT); }
private void PrepareWave() { DynValue nextWaves = script.GetVar("nextwaves"); waves = new ScriptWrapper[nextWaves.Table.Length]; waveNames = new string[waves.Length]; int currentWaveScript = 0; try { List <int> indexes = new List <int>(); for (int i = 0; i < waves.Length; i++) { currentWaveScript = i; DynValue ArenaStatus = UserData.Create(ArenaManager.luaStatus); waves[i] = new ScriptWrapper() { script = LuaScriptBinder.BoundScript() }; waves[i].script.Globals.Set("Arena", ArenaStatus); waves[i].script.Globals["EndWave"] = (Action)EndWaveTimer; waves[i].script.Globals["State"] = (Action <Script, string>)UIController.SwitchStateOnString; waves[i].script.Globals["CreateProjectile"] = (Func <Script, string, float, float, string, DynValue>)CreateProjectile; waves[i].script.Globals["CreateProjectileAbs"] = (Func <Script, string, float, float, string, DynValue>)CreateProjectileAbs; if (nextWaves.Table.Get(i + 1).Type != DataType.String) { UnitaleUtil.DisplayLuaError(StaticInits.ENCOUNTER, "Non-string value encountered in nextwaves table"); return; } else { waveNames[i] = nextWaves.Table.Get(i + 1).String; } waves[i].script.Globals["wavename"] = nextWaves.Table.Get(i + 1).String; try { waves[i].DoString(ScriptRegistry.Get(ScriptRegistry.WAVE_PREFIX + nextWaves.Table.Get(i + 1).String)); indexes.Add(i); } catch (InterpreterException ex) { UnitaleUtil.DisplayLuaError(nextWaves.Table.Get(i + 1).String + ".lua", ex.DecoratedMessage); } catch (Exception ex) { if (!GlobalControls.retroMode && !ScriptRegistry.dict.ContainsKey(ScriptRegistry.WAVE_PREFIX + nextWaves.Table.Get(i + 1).String)) { UnitaleUtil.DisplayLuaError(StaticInits.ENCOUNTER, "The wave " + nextWaves.Table.Get(i + 1).String + " doesn't exist."); } else { UnitaleUtil.DisplayLuaError("<UNKNOWN LOCATION>", ex.Message + "\n\n" + ex.StackTrace); } } } Table luaWaveTable = new Table(null); for (int i = 0; i < indexes.Count; i++) { luaWaveTable.Set(i + 1, UserData.Create(waves[indexes[i]])); } script.SetVar("Wave", DynValue.NewTable(luaWaveTable)); } catch (InterpreterException ex) { UnitaleUtil.DisplayLuaError(nextWaves.Table.Get(currentWaveScript + 1).String + ".lua", ex.DecoratedMessage); } }
public void RefreshPlayerDescription() { var wrapper = new ScriptWrapper(Settings.PlayerDescription); wrapper.Execute(); PlayerDescription.Clear(); foreach (var res in wrapper.TextResult) { PlayerDescription.Add(res); } }
public static void WriteImage(ImageRef line, ScriptWrapper script, bool includeBar = false) { if (includeBar) { WriteText("-------------------------------------------", null); } var mvm = (MainViewModel)Player.App.Current.Resources["MainViewModelStatic"]; mvm.FeedbackText.Add(line); }
public bool TryUnequipItem(ItemInstance i, bool force = false) { if (EquippedItems.Where(a => a.Value == i).Count() == 0) { MainViewModel.WriteText("ERROR: Item not equipped!", null); } if (!force) { foreach (var slot in i.item.EquipmentRef.OccupiesSlots) { foreach (var a in EquippedItems.Where(b => b.Value != null && b.Value != i).Select(b => b.Value).Distinct()) { var equip = a.item.EquipmentRef; if (equip.CoversSlots.Contains(slot)) { var result = new ScriptWrapper(equip.OnUnequip) { ItemBase = a }.Execute(); if (result == false) { MainViewModel.WriteText("Unable to unequip " + i.CurrentName + " because " + a.CurrentName + " is covering it and could not be removed!", null); return(false); } } } } { var result = new ScriptWrapper(i.item.EquipmentRef.OnUnequip) { ItemBase = i }.Execute(); if (result == false) { MainViewModel.WriteText("Unable to unequip " + i.CurrentName + " because it is currently unable to be removed!", null); return(false); } } } List <EquipmentSlot> slots = EquippedItems.Where(a => a.Value == i).Select(a => a.Key).ToList(); foreach (var a in slots) { EquippedItems[a] = null; } return(true); }
protected void OnModuleImported(PythonDataPlugin plugin, DataStore ds, ScriptWrapper sc) { try { //获取脚本方函数对象,函数的原型是请参考apple_apps.py里面的run var func = sc.GetScopeFunction <DataStore, bool, IDescriptiveProgress, CancellationToken, ParserResults>($"run"); if (func != null) { //运行此函数(建议在脚本里断点调试) var results = func(ds, true, plugin.Progress, plugin.CancellationToken); } } catch (Exception e) { TraceService.Trace(TraceLevel.Error, e.Message); } }
private async Task TestRemote(object sender, EventArgs <IRemoteSettings> e) { var profile = ProfilesService.CreateProfile(e.Value); _scriptWrapper = new ScriptWrapper <string>(profile, _view, d => d.ToString()); await _scriptWrapper.Run("dir"); if (_scriptWrapper.Results.Any()) { _displayMessage.ShowInfo("Success", "Your connection details are valid."); } if (_scriptWrapper.Errors.Any() && _scriptWrapper.Errors.First() is RemoteTimeoutException) { _displayMessage.ShowError("Connection Error", "Falied to connect to remote machine with specified parameters"); } _view.ToggleTestButton(true); }
/// <summary> /// Attempts to initialize the encounter's script file and bind encounter-specific functions to it. /// </summary> /// <returns>True if initialization succeeded, false if there was an error.</returns> private bool initScript() { script = new ScriptWrapper(); script.scriptname = StaticInits.ENCOUNTER; string scriptText = ScriptRegistry.Get(ScriptRegistry.ENCOUNTER_PREFIX + StaticInits.ENCOUNTER); try { script.DoString(scriptText); } catch (InterpreterException ex) { UnitaleUtil.displayLuaError(StaticInits.ENCOUNTER, ex.DecoratedMessage); return(false); } script.Bind("RandomEncounterText", (Func <string>)RandomEncounterText); script.Bind("CreateProjectile", (Func <Script, string, float, float, DynValue>)CreateProjectile); script.Bind("CreateProjectileAbs", (Func <Script, string, float, float, DynValue>)CreateProjectileAbs); script_ref = script; return(true); }
public override bool?Execute() { //Get the status effect StatusEffectWrapper statusEffect = null; ScriptWrapper parent = this.parent.GetTopParent(); statusEffect = parent.CurrentStatusEffect; var variable = this.parent.GetVarById(line.VariableRef.LinkedVarId); if (line.SelectedArgument.Value.IsNumber) { var numberArg = statusEffect.numberArguments.Where(a => a.Id == line.SelectedArgument.Ref).First(); variable.CurrentNumberValue = numberArg.NumberValue; } else { var numberArg = statusEffect.stringArguments.Where(a => a.Id == line.SelectedArgument.Ref).First(); variable.CurrentStringValue = numberArg.StringValue; } return(null); }
public static string FormatText(string line, ScriptWrapper script) { return(Regex.Replace(line, "\\{\\{(?<VarName>.*?)\\}\\}", a => { var mvm = MainViewModel.GetMainViewModelStatic(); var varName = a.Groups["VarName"].Value; string res = "INVALID VARIABLE NAME"; VariableWrapper v = null; if (script != null) { v = script.GetVarByName(varName); } else if (mvm.CurrentGame.VarByName.ContainsKey(varName)) { v = mvm.CurrentGame.VarByName[varName]; } if (v != null) { if (v.VariableBase.IsDateTime) { return v.CurrentDateTimeValue.ToString(); } if (v.VariableBase.IsNumber) { return v.CurrentNumberValue.ToString(); } if (v.VariableBase.IsString) { return v.CurrentStringValue.ToString(); } if (v.VariableBase.IsItem) { return (v.CurrentItemValue != null ? v.CurrentItemValue.CurrentName : "NULL ITEM"); } } return res; })); }
public static void WriteText(string line, ScriptWrapper script, bool includeBar = false) { if (includeBar) { WriteText("-------------------------------------------", null); } if (!string.IsNullOrWhiteSpace(line)) { var mvm = (MainViewModel)Player.App.Current.Resources["MainViewModelStatic"]; line = FormatText(line, script); mvm.FeedbackText.Add(line + "\n\n"); if (mvm.FeedbackText.Count() > 40) { while (mvm.FeedbackText.Count() > 40) { mvm.FeedbackText.Remove(mvm.FeedbackText.First()); } } } }
internal void RevertObject(ScriptWrapper obj) { string objectFileName = obj.FileName; bool delete = !File.Exists(SourceFolder + objectFileName); string Script = delete ? obj.ScriptText : File.ReadAllText(SourceFolder + objectFileName); using (SqlConnection conn = new SqlConnection(GetConnectionString())) { conn.Open(); var DelCmd = conn.CreateCommand(); if (Script.ToUpper().Contains("CREATE PROCEDURE".ToUpper())) { DelCmd.CommandText = $@"DROP PROCEDURE [{objectFileName.GetSchema()}].[{objectFileName.GetName()}]"; } if (Script.ToUpper().Contains("CREATE FUNCTION".ToUpper())) { DelCmd.CommandText = $@"DROP FUNCTION [{objectFileName.GetSchema()}].[{objectFileName.GetName()}]"; } if (Script.ToUpper().Contains("CREATE TRIGGER".ToUpper())) { DelCmd.CommandText = $@"DROP TRIGGER [{objectFileName.GetSchema()}].[{objectFileName.GetName()}]"; } DelCmd.ExecuteNonQuery(); if (!delete) { Server server = new Server(new ServerConnection(conn)); server.ConnectionContext.ExecuteNonQuery(Script); } } }
public ScriptWrapperTests() { _wrapper = new ScriptWrapper(); }
public static ScriptLineWrapper GetScriptLineWrapper(ScriptLine line, ScriptWrapper parent) { var lineType = line.GetType(); ScriptLineWrapper lineWrapper = null; if (lineType == typeof(Comment)) { lineWrapper = new CommentWrapper((Comment)line); //return comment; } if (lineType == typeof(Conditional)) { lineWrapper = new ConditionalWrapper((Conditional)line); } if (lineType == typeof(DisplayText)) { lineWrapper = new DisplayTextWrapper((DisplayText)line); } if (lineType == typeof(SetVariable)) { lineWrapper = new SetVariableWrapper((SetVariable)line); } if (lineType == typeof(ReturnTrue)) { lineWrapper = new ReturnTrueWrapper(); } if (lineType == typeof(ReturnFalse)) { lineWrapper = new ReturnFalseWrapper(); } if (lineType == typeof(StopGame)) { lineWrapper = new StopGameWrapper(); } if (lineType == typeof(AddText)) { lineWrapper = new AddTextWrapper((AddText)line); } if (lineType == typeof(AddItemToInventory)) { lineWrapper = new AddItemWrapper((AddItemToInventory)line); } if (lineType == typeof(SetItemProperty)) { lineWrapper = new SetItemPropertyWrapper((SetItemProperty)line); } if (lineType == typeof(GetItemProperty)) { lineWrapper = new GetItemPropertyWrapper((GetItemProperty)line); } if (lineType == typeof(GetCurrentItem)) { lineWrapper = new GetCurrentItemWrapper((GetCurrentItem)line); } if (lineType == typeof(RemoveItem)) { lineWrapper = new RemoveItemWrapper((RemoveItem)line); } if (lineType == typeof(RemoveThisItem)) { lineWrapper = new RemoveThisItemWrapper((RemoveThisItem)line); } if (lineType == typeof(RunCommonEvent)) { lineWrapper = new RunCommonEventWrapper((RunCommonEvent)line); } if (lineType == typeof(ReturnValue)) { lineWrapper = new ReturnValueWrapper((ReturnValue)line); } if (lineType == typeof(GetEquipmentSlot)) { lineWrapper = new GetEquipmentSlotWrapper((GetEquipmentSlot)line); } if (lineType == typeof(ForceEquip)) { lineWrapper = new ForceEquipWrapper((ForceEquip)line); } if (lineType == typeof(ForceUnequip)) { lineWrapper = new ForceUnequipWrapper((ForceUnequip)line); } if (lineType == typeof(StartConversation)) { lineWrapper = new StartConversationWrapper((StartConversation)line); } if (lineType == typeof(GoToStage)) { lineWrapper = new GoToStageWrapper((GoToStage)line); } if (lineType == typeof(ChangeRoom)) { lineWrapper = new ChangeRoomWrapper((ChangeRoom)line); } if (lineType == typeof(CreateEvent)) { lineWrapper = new CreateEventWrapper((CreateEvent)line); } if (lineType == typeof(AddToArray)) { lineWrapper = new AddToArrayWrapper((AddToArray)line); } if (lineType == typeof(ForEachInArray)) { lineWrapper = new ForEachInArrayWrapper((ForEachInArray)line); } if (lineType == typeof(ShowImage)) { lineWrapper = new ShowImageWrapper((ShowImage)line); } if (lineType == typeof(AddImage)) { lineWrapper = new AddImageWrapper((AddImage)line); } if (lineType == typeof(SetItemName)) { lineWrapper = new SetItemNameWrapper((SetItemName)line); } if (lineType == typeof(GetItemName)) { lineWrapper = new GetItemNameWrapper((GetItemName)line); } if (lineType == typeof(GetAllItems)) { lineWrapper = new GetAllItemsWrapper((GetAllItems)line); } if (lineType == typeof(GetAllItemsOfType)) { lineWrapper = new GetAllItemsOfTypeWrapper((GetAllItemsOfType)line); } if (lineType == typeof(ConcatenateArray)) { lineWrapper = new ConcatenateArrayWrapper((ConcatenateArray)line); } if (lineType == typeof(StopProcessing)) { lineWrapper = new StopProcessingWrapper(); } if (lineType == typeof(AddStatusEffect)) { lineWrapper = new AddStatusEffectWrapper((AddStatusEffect)line); } if (lineType == typeof(RemoveStatusEffect)) { lineWrapper = new RemoveStatusEffectWrapper((RemoveStatusEffect)line); } if (lineType == typeof(GetArgument)) { lineWrapper = new GetArgumentWrapper((GetArgument)line); } if (lineType == typeof(CheckIfEffectsResolved)) { lineWrapper = new CheckIfEffectsResolvedWrapper(); } if (lineWrapper != null) { lineWrapper.parent = parent; } return(lineWrapper); }
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); }
public List <ItemInstance> TryEquipItem(ItemInstance i, bool force = false) { List <ItemInstance> markedForRemoval = new List <ItemInstance>(); foreach (var a in EquippedItems.Where(b => b.Value != null).Select(b => b.Value).Distinct()) { var equip = a.item.EquipmentRef; foreach (var slot in i.item.EquipmentRef.OccupiesSlots) { if (equip.OccupiesSlots.Contains(slot)) { if (!force) { var result = new ScriptWrapper(equip.OnUnequip) { ItemBase = a }.Execute(); if (result != false) { markedForRemoval.Add(a); } else { MainViewModel.WriteText("Unable to equip " + i.CurrentName + " because " + a.CurrentName + " could not be removed!", null); return(new List <ItemInstance>()); } } else { markedForRemoval.Add(a); } } if (!force && equip.CoversSlots.Contains(slot)) { var result = new ScriptWrapper(equip.OnUnequip) { ItemBase = a }.Execute(); if (result == false) { MainViewModel.WriteText("Unable to equip " + i.CurrentName + " because " + a.CurrentName + " is covering it and could not be removed!", null); return(new List <ItemInstance>()); } } } } { var result = new ScriptWrapper(i.item.EquipmentRef.OnEquip) { ItemBase = i }.Execute(); if (result == false) { MainViewModel.WriteText("Unable to unequip " + i.CurrentName + " because it is currently unable to be equipped!", null); return(new List <ItemInstance>()); } } foreach (var a in markedForRemoval) { foreach (var slot in a.item.EquipmentRef.OccupiesSlots) { EquippedItems[slot] = null; } } foreach (var slot in i.item.EquipmentRef.OccupiesSlots) { EquippedItems[slot] = i; } if (PlayerInventory.Contains(i)) { PlayerInventory.Remove(i); } return(markedForRemoval); }
public void setCaller(ScriptWrapper s) { caller = s; }
internal PowerShellSiteProvider(IProfile profile, ISynchronizeInvoke invoke) { _scriptWrapperString = new ScriptWrapper <string>(profile, invoke, d => d.ToString()); _scriptWrapper = new ScriptWrapper <KeyValuePair <string, string> >(profile, invoke, Convert); }
public void ActionDialogResult(TextMessage msg, UIState afterDialogState, ScriptWrapper caller = null) { ActionDialogResult(new TextMessage[] { msg }, afterDialogState, caller); }
public override bool?Execute() { if ((line.SelectedEvent != null && line.SelectedEvent.LinkedCommonEvent != null) || (line.RunFromVariable && line.VarScript != null)) { try { var game = MainViewModel.GetMainViewModelStatic().CurrentGame; ScriptWrapper wrapper; string scriptType; CommonEventRef cRef = null; if (line.RunFromVariable) { if (parent.GetVarById(line.VarScript.LinkedVarId) != null) { CommonEventRef cer = parent.GetVarById(line.VarScript.LinkedVarId).CurrentCommonEventValue; if (cer != null && cer.LinkedCommonEvent != null) { wrapper = new ScriptWrapper(cer.LinkedCommonEvent.AssociatedScript); scriptType = cer.LinkedCommonEvent.EventType.Item1; cRef = cer; } else { MainViewModel.WriteText("Error: RunCommonEvent associated variable is null.", this.parent); return(false); } } else { MainViewModel.WriteText("Error: RunCommonEvent missing associated variable for script.", this.parent); return(false); } } else { wrapper = new ScriptWrapper(line.SelectedEvent.LinkedCommonEvent.AssociatedScript); scriptType = line.SelectedEvent.LinkedCommonEvent.EventType.Item1; cRef = line.SelectedEvent; } if (scriptType != CommonEvent.ScriptTypeOverwriteLocals) { wrapper.parent = this.parent; wrapper.DupeVars(this.parent); wrapper.IsRootScript = true; } else { wrapper.isSubscript = true; wrapper.parent = this.parent; } var result = wrapper.Execute(); if (wrapper.VariableResult != null && line.VarRef != null && parent.GetVarById(wrapper.VariableResult.LinkedVarId) != null && parent.GetVarById(line.VarRef.LinkedVarId) != null) { var source = wrapper.GetVarById(wrapper.VariableResult.LinkedVarId); var dest = parent.GetVarById(line.VarRef.LinkedVarId); dest.CurrentDateTimeValue = source.CurrentDateTimeValue; dest.CurrentItemValue = source.CurrentItemValue; dest.CurrentNumberValue = source.CurrentNumberValue; dest.CurrentStringValue = source.CurrentStringValue; dest.CurrentCommonEventValue = source.CurrentCommonEventValue; } if (cRef.LinkedCommonEvent.EventType.Item1 == CommonEvent.ScriptTypeTrueFalse) { return(result); } else { return(null); } } catch (Exception e) { MainViewModel.WriteText("Unhandled Exception in " + this.line.SelectedEvent.LinkedCommonEvent.Name + ":\n\n" + e.Message, null); } } MainViewModel.WriteText("Error: RunCommonEvent missing associated script.", this.parent); return(false); }
public RequestHelper(IProfile profile, ISynchronizeInvoke invoke) { _profile = profile; _scriptWrapper = new ScriptWrapper <string>(profile, invoke, d => d.ToString()); }