public override void OnVariableSet(DreamObject dreamObject, string variableName, DreamValue variableValue, DreamValue oldVariableValue) { base.OnVariableSet(dreamObject, variableName, variableValue, oldVariableValue); if (variableName == "key" || variableName == "ckey") { if (_playerManager.TryGetSessionByUsername(variableValue.GetValueAsString(), out var session)) { var connection = _dreamManager.GetConnectionBySession(session); connection.MobDreamObject = dreamObject; } } else if (variableName == "see_invisible") { //TODO } else if (variableName == "client" && variableValue != oldVariableValue) { var newClient = variableValue.GetValueAsDreamObject(); var oldClient = oldVariableValue.GetValueAsDreamObject(); if (newClient != null) { _dreamManager.GetConnectionFromClient(newClient).MobDreamObject = dreamObject; } else if (oldClient != null) { _dreamManager.GetConnectionFromClient(oldClient).MobDreamObject = null; } } }
public override void SetValue(DreamValue key, DreamValue value) { string varName = key.GetValueAsString(); if (_dreamObject.HasVariable(varName)) { _dreamObject.SetVariable(varName, value); } }
public static DreamValue NativeProc_Join(DreamObject instance, DreamObject usr, DreamProcArguments arguments) { DreamValue glue = arguments.GetArgument(0, "Glue"); int start = arguments.GetArgument(1, "Start").GetValueAsInteger(); //1-indexed int end = arguments.GetArgument(0, "End").GetValueAsInteger(); //1-indexed DreamList list = (DreamList)instance; string glueValue = (glue.Type == DreamValueType.String) ? glue.GetValueAsString() : ""; return(new DreamValue(list.Join(glueValue, start, end))); }
private void UpdateScreenLocation(DreamObject movable, DreamValue screenLocationValue) { ScreenLocation screenLocation; if (screenLocationValue.Value != null) { string screenLocationString = screenLocationValue.GetValueAsString(); screenLocation = new ScreenLocation(screenLocationString); } else { screenLocation = new ScreenLocation(); } Program.DreamStateManager.AddAtomScreenLocationDelta(movable, screenLocation); }
public static DreamValue NativeProc_Replace(DreamObject instance, DreamObject usr, DreamProcArguments arguments) { DreamRegex dreamRegex = DreamMetaObjectRegex.ObjectToDreamRegex[instance]; if (!dreamRegex.IsGlobal) { throw new NotImplementedException("Non-global regex replaces are not implemented"); } DreamValue haystack = arguments.GetArgument(0, "haystack"); DreamValue replace = arguments.GetArgument(1, "replacement"); int start = arguments.GetArgument(2, "Start").GetValueAsInteger(); int end = arguments.GetArgument(3, "End").GetValueAsInteger(); string haystackString = haystack.GetValueAsString(); if (end == 0) { end = haystackString.Length; } if (replace.TryGetValueAsProc(out DreamProc replaceProc)) { throw new NotImplementedException("Proc replacements are not implemented"); } else if (replace.TryGetValueAsString(out string replaceString)) { string replaced = dreamRegex.Regex.Replace(haystackString, replaceString, end - start, start - 1); instance.SetVariable("text", new DreamValue(replaced)); return(new DreamValue(replaced)); } else { throw new ArgumentException("Replacement argument must be a string"); } }
public override DreamValue GetValue(DreamValue key) { return(_dreamObject.GetVariable(key.GetValueAsString())); }
public override void OnVariableSet(DreamObject dreamObject, string variableName, DreamValue variableValue, DreamValue oldVariableValue) { base.OnVariableSet(dreamObject, variableName, variableValue, oldVariableValue); if (variableName == "key" || variableName == "ckey") { DreamConnection newClientConnection = Program.DreamServer.GetConnectionFromCKey(variableValue.GetValueAsString()); newClientConnection.MobDreamObject = dreamObject; } else if (variableName == "client" && variableValue != oldVariableValue) { DreamObject newClient = variableValue.GetValueAsDreamObject(); DreamObject oldClient = oldVariableValue.GetValueAsDreamObject(); if (newClient != null) { Program.ClientToConnection[newClient].MobDreamObject = dreamObject; } else if (oldClient != null) { Program.ClientToConnection[oldClient].MobDreamObject = null; } } }