private static ReturnTypes ConditionThirsty(CharacterInstance ch, int conditionValue) { ReturnTypes retcode = ReturnTypes.None; if (ch.Level < LevelConstants.AvatarLevel && ch.CurrentClass != ClassTypes.Vampire) { color.set_char_color(ATTypes.AT_THIRSTY, ch); DescriptorAttribute attrib = ConditionTypes.Thirsty.GetAttribute <DescriptorAttribute>(); color.send_to_char(attrib.Messages[conditionValue * 2], ch); if (conditionValue < 2) { comm.act(ATTypes.AT_THIRSTY, attrib.Messages[(conditionValue * 2) + 1], ch, null, null, ToTypes.Room); if (conditionValue == 0) { ch.WorsenMentalState(ch.IsPKill() ? 1 : 2); retcode = ch.CauseDamageTo(ch, 2, (int)SkillNumberTypes.Undefined); } else { ch.WorsenMentalState(1); } } } return(retcode); }
private static ReturnTypes ConditionBloodthirsty(CharacterInstance ch, int conditionValue) { ReturnTypes retcode = ReturnTypes.None; if (ch.Level < LevelConstants.AvatarLevel) { color.set_char_color(ATTypes.AT_BLOOD, ch); DescriptorAttribute attrib = ConditionTypes.Bloodthirsty.GetAttribute <DescriptorAttribute>(); color.send_to_char(attrib.Messages[conditionValue * 2], ch); if (conditionValue < 2) { comm.act(ATTypes.AT_HUNGRY, attrib.Messages[(conditionValue * 2) + 1], ch, null, null, ToTypes.Room); if (conditionValue == 0) { ch.WorsenMentalState(2); retcode = ch.CauseDamageTo(ch, ch.MaximumHealth / 20, (int)SkillNumberTypes.Undefined); } else { ch.WorsenMentalState(1); } } } return(retcode); }
private static string GetStandingDescriptor(CharacterInstance ch, CharacterInstance victim, DescriptorAttribute attrib) { if (victim.IsImmortal()) { return(attrib.Messages.First()); } if (((victim.CurrentRoom.SectorType == SectorTypes.Underwater) || (victim.CurrentRoom.SectorType == SectorTypes.OceanFloor)) && !victim.IsAffected(AffectedByTypes.AquaBreath) && !victim.IsNpc()) { return(attrib.Messages.ToList()[1]); } if ((victim.CurrentRoom.SectorType == SectorTypes.Underwater) || (victim.CurrentRoom.SectorType == SectorTypes.OceanFloor)) { return(attrib.Messages.ToList()[2]); } if (victim.IsAffected(AffectedByTypes.Floating) || victim.IsAffected(AffectedByTypes.Flying)) { return(attrib.Messages.ToList()[3]); } return(attrib.Messages.ToList()[4]); }
private static string CreateInvalidLengthCfString(DescriptorAttribute descriptorAttribute) { return(StringCreation.CreateRandomCfString( descriptorAttribute.MaxLength + 1, false, CharacterType.Letters)); }
/// <summary> /// Adds the keyboard actuator to the list of actuators. This /// actuator is bundled with the SDK. /// </summary> private void addKeyboardActuatorToCache() { var attr = DescriptorAttribute.GetDescriptor(typeof(InputActuators.KeyboardActuator)); if (attr != null) { addActuatorToCache(attr.Id, typeof(InputActuators.KeyboardActuator)); } }
private static string GetSleepingDescriptor(CharacterInstance ch, CharacterInstance victim, DescriptorAttribute attrib) { if (ch.CurrentPosition == PositionTypes.Sitting || ch.CurrentPosition == PositionTypes.Resting) { return(attrib.Messages.First()); } return(attrib.Messages.ToList()[1]); }
/// <summary> /// Gets the ACAT descriptor guid for the specifed Type /// </summary> /// <param name="type">Scanner class Type</param> /// <returns>The descirptor guid</returns> internal static Guid GetFormId(Type type) { var descAttribute = DescriptorAttribute.GetDescriptor(type); Guid retVal = Guid.Empty; if (descAttribute != null) { retVal = descAttribute.Id; } return(retVal); }
private static ReturnTypes ConditionDrunk(CharacterInstance ch, int conditionValue) { if (conditionValue == 0 || conditionValue == 1) { color.set_char_color(ATTypes.AT_SOBER, ch); DescriptorAttribute attrib = ConditionTypes.Drunk.GetAttribute <DescriptorAttribute>(); color.send_to_char(attrib.Messages[conditionValue], ch); } return(ReturnTypes.None); }
private static string CreateRandomValidValue(DescriptorAttribute descriptorAttribute) { // Return random enum value if enumType is defined if (null != descriptorAttribute.EnumType) { var methodInfo = typeof(StringUtils).GetMethod("PickRandomEnumValue"); var genericMethod = methodInfo.MakeGenericMethod(descriptorAttribute.EnumType); var enumValue = genericMethod.Invoke(null, null); return(enumValue.ToString()); } // Return random member of array if it is defined. if (null != descriptorAttribute.Array) { return(descriptorAttribute.Array[Random.Next(descriptorAttribute.Array.Length - 1)]); } // Return value generated from Regex if it is defined. if (null != descriptorAttribute.Regex) { return(RegexGenerator.GenerateMatch(descriptorAttribute.Regex)); } // Return value generated from PropertyType switch (descriptorAttribute.PropertyType) { case PropertyType.String: var characterType = descriptorAttribute.CharacterType == CharacterType.NotAssigned ? CharacterType.Anything : descriptorAttribute.CharacterType; var maxLength = descriptorAttribute.MaxLength > 0 ? descriptorAttribute.MaxLength : DefaultStringLength; return(StringCreation.CreateRandomCfString(maxLength, false, characterType)); case PropertyType.Int: return(Random.Next().ToString(CultureInfo.InvariantCulture)); case PropertyType.Decimal: var decimalPoints = descriptorAttribute.DecimalPoints >= 0 ? descriptorAttribute.DecimalPoints : DefaultDecimalPoints; return(Math.Round(Random.NextDouble() * 100, decimalPoints).ToString(CultureInfo.InvariantCulture)); case PropertyType.Bool: return(CreateRandomBool()); case PropertyType.Date: return(CreateRandomDate()); case PropertyType.Email: return(CreateRandomEmailAddress()); default: throw new ArgumentOutOfRangeException(); } }
public static ReturnTypes SpringTheTrap(this CharacterInstance ch, ObjectInstance obj) { var level = obj.Value.ToList()[2]; var txt = string.Empty; var trapType = TrapTypes.None; DescriptorAttribute attrib = null; try { trapType = EnumerationExtensions.GetEnum <TrapTypes>(obj.Value.ToList()[1]); attrib = trapType.GetAttribute <DescriptorAttribute>(); txt = attrib.Messages.FirstOrDefault(); } catch (ArgumentException) { txt = TrapTypeLookupDefault; } var dam = SmaugRandom.Between(obj.Value.ToList()[2], obj.Value.ToList()[2] * 2); comm.act(ATTypes.AT_HITME, $"You are {txt}!", ch, null, null, ToTypes.Character); comm.act(ATTypes.AT_ACTION, $"$n is {txt}.", ch, null, null, ToTypes.Room); --obj.Value.ToList()[0]; if (obj.Value.ToList()[0] <= 0) { obj.Extract(); } var returnCode = ReturnTypes.None; if (!string.IsNullOrEmpty(attrib?.Messages.ToList()[1])) { var skill = RepositoryManager.Instance.GetEntity <SkillData>(attrib.Messages.ToList()[1]); returnCode = ch.ObjectCastSpell((int)skill.ID, level, ch); } if (trapType == TrapTypes.Blade || trapType == TrapTypes.ElectricShock) { returnCode = ch.CauseDamageTo(ch, dam, Program.TYPE_UNDEFINED); } if ((trapType == TrapTypes.PoisonArrow || trapType == TrapTypes.PoisonDagger || trapType == TrapTypes.PoisonDart || trapType == TrapTypes.PoisonNeedle) && returnCode == ReturnTypes.None) { returnCode = ch.CauseDamageTo(ch, dam, Program.TYPE_UNDEFINED); } return(returnCode); }
private static string GetSittingDescriptor(CharacterInstance ch, CharacterInstance victim, DescriptorAttribute attrib) { switch (ch.CurrentPosition) { case PositionTypes.Sitting: return(attrib.Messages.First()); case PositionTypes.Resting: return(attrib.Messages.ToList()[1]); } return(attrib.Messages.ToList()[2]); }
/// <summary> /// Finds engine by the specified name /// </summary> /// <param name="name">name of the engine</param> /// <returns>The engine</returns> public Guid GetByName(String name) { foreach (var type in Collection) { IDescriptor descriptor = DescriptorAttribute.GetDescriptor(type); if (String.Compare(descriptor.Name, name, true) == 0) { return(descriptor.Id); } } return(Guid.Empty); }
/// <summary> /// Looks up the cache for the specified GUID and returns the Type /// </summary> /// <param name="guid"></param> /// <returns></returns> public Type Lookup(Guid guid) { foreach (Type type in _wordPredictorsTypeCache.Values) { IDescriptor descriptor = DescriptorAttribute.GetDescriptor(type); if (descriptor != null && Equals(guid, descriptor.Id)) { Log.Debug("Found word predictor of type " + type); return(type); } } Log.Debug("Could not find word predictor for id " + guid.ToString()); return(null); }
/// <summary> /// Returns the ID of the WordPredictor with the /// specified name /// </summary> /// <param name="name">name of the word predictor</param> /// <returns>ID of the word predictor</returns> public Guid GetByName(String name) { foreach (Type type in _wordPredictorsTypeCache.Values) { IDescriptor descriptor = DescriptorAttribute.GetDescriptor(type); if (descriptor != null && String.Compare(descriptor.Name, name, true) == 0) { Log.Debug("Found word predictor [" + name + "]"); return(descriptor.Id); } } Log.Debug("Could not find word predictor for [" + name + "]"); return(Guid.Empty); }
/// <summary> /// Returns the ID of the spellchecker by looking /// up the spellCheckerName of the spellchecker /// </summary> /// <param spellCheckerName="spellCheckerName">name to check</param> /// <returns>the spellchecker id, Empty if not found</returns> public Guid GetByName(String spellCheckerName) { foreach (var type in _spellCheckersTypeCache.Values) { var descriptor = DescriptorAttribute.GetDescriptor(type); if (descriptor != null && String.Compare(descriptor.Name, spellCheckerName, true) == 0) { Log.Debug("Found spellchecker [" + spellCheckerName + "]"); return(descriptor.Id); } } Log.Debug("Could not find spellchecker for [" + spellCheckerName + "]"); return(Guid.Empty); }
private static string GetMountedDescriptor(CharacterInstance ch, CharacterInstance victim, DescriptorAttribute attrib) { if (victim.CurrentMount == null) { return(attrib.Messages.First()); } if (victim.CurrentMount == ch) { return(attrib.Messages.ToList()[1]); } return(victim.CurrentRoom == victim.CurrentMount.CurrentRoom ? string.Format(attrib.Messages.ToList()[2], Macros.PERS(victim.CurrentMount, ch)) : attrib.Messages.ToList()[3]); }
private static string GetFightingDescriptor(CharacterInstance ch, CharacterInstance victim, DescriptorAttribute attrib) { if (victim.CurrentFighting != null) { return(attrib.Messages.First()); } if (victim.GetMyTarget() == ch) { return(attrib.Messages.ToList()[2]); } return(victim.CurrentRoom == victim.CurrentFighting.Who.CurrentRoom ? string.Format(attrib.Messages.ToList()[2], Macros.PERS(victim.CurrentFighting.Who, ch)) : attrib.Messages.ToList()[3]); }
/// <summary> /// Gets the TTSEngine class Type correspoding to the guid /// </summary> /// <param name="guid"></param> /// <returns></returns> public Type this[Guid guid] { get { foreach (var type in Collection) { IDescriptor descriptor = DescriptorAttribute.GetDescriptor(type); if (descriptor != null && Guid.Equals(guid, descriptor.Id)) { Log.Debug("Found TTS engine of type " + type); return(type); } } Log.Debug("Could not find TTS engine for id " + guid.ToString()); return(null); } }
/// <summary> /// Looks up the cache for the specified GUID and returns the Type /// </summary> /// <param name="guid"></param> /// <returns></returns> public Type Lookup(Guid guid) { if (Equals(guid, NullWordPredictor.Descriptor.Id)) { return(typeof(NullWordPredictor)); } foreach (Type type in Collection) { IDescriptor descriptor = DescriptorAttribute.GetDescriptor(type); if (descriptor != null && Equals(guid, descriptor.Id)) { Log.Debug("Found word predictor of type " + type); return(type); } } Log.Debug("Could not find word predictor for id " + guid.ToString()); return(null); }
/// <summary> /// Looks up the cache for the specified GUID and returns the Type /// </summary> /// <param name="guid"></param> /// <returns></returns> public Type Lookup(Guid guid) { if (Equals(guid, NullTTSEngine.Descriptor.Id)) { return(typeof(NullTTSEngine)); } foreach (Type type in Collection) { IDescriptor descriptor = DescriptorAttribute.GetDescriptor(type); if (descriptor != null && Equals(guid, descriptor.Id)) { Log.Debug("Found TTS Engine of type " + type); return(type); } } Log.Debug("Could not find TTS Engine for id " + guid); return(null); }
/// <summary> /// Call back function for when it finds a DLL. Load the dll and /// look for TTS Engine types in there. If found, add them to the cache /// </summary> /// <param name="dllName">name of the dll found</param> private void onFileFound(String dllName) { try { Assembly ttsEngineAssembly = Assembly.LoadFile(dllName); foreach (Type type in ttsEngineAssembly.GetTypes()) { if (typeof(ITTSEngine).IsAssignableFrom(type)) { DescriptorAttribute attr = DescriptorAttribute.GetDescriptor(type); if (attr != null && attr.Id != Guid.Empty) { Add(attr.Id, _dirWalkCurrentCulture, type); } } } } catch (Exception ex) { Log.Debug("Could get types from assembly " + dllName + ". Exception : " + ex.ToString()); } }
/// <summary> /// Call back function for when it finds a DLL. Load the dll and /// look for spell checker types in there. If found, add them to the cache /// </summary> /// <param name="dllName">Full path to the dll</param> private void onFileFound(String dllName) { try { var wordPredictorAssembly = Assembly.LoadFile(dllName); foreach (var type in wordPredictorAssembly.GetTypes()) { if (typeof(ISpellChecker).IsAssignableFrom(type)) { var attr = DescriptorAttribute.GetDescriptor(type); if (attr != null && attr.Id != Guid.Empty) { Add(attr.Id, _dirWalkCurrentCulture, type); } } } } catch (Exception ex) { Log.Debug("Could get types from assembly " + dllName + ". Exception : " + ex); } }
/// <summary> /// Callback function for the directory walker. called whenever /// it finds a DLL /// </summary> /// <param name="dllName"></param> private void onFileFound(String dllName) { try { var inputActuatorsAssembly = Assembly.LoadFrom(dllName); foreach (Type type in inputActuatorsAssembly.GetTypes()) { if (typeof(ActuatorBase).IsAssignableFrom(type)) { var attr = DescriptorAttribute.GetDescriptor(type); if (attr != null && attr.Id != Guid.Empty) { addActuatorToCache(attr.Id, type); } } } } catch (Exception ex) { Log.Debug("Could not get types from assembly " + dllName + ". Exception : " + ex.ToString()); } }
/// <summary> /// Call back function for when it finds a DLL. Load the dll and /// look for word predictor types in there. If found, add them to the cache /// </summary> /// <param name="dllName"></param> private void onFileFound(String dllName) { try { Assembly wordPredictorAssembly = Assembly.LoadFile(dllName); foreach (Type type in wordPredictorAssembly.GetTypes()) { if (typeof(IWordPredictor).IsAssignableFrom(type)) { DescriptorAttribute attr = DescriptorAttribute.GetDescriptor(type); if (attr != null && attr.Id != Guid.Empty) { Add(attr.Id, type); } } } } catch (Exception ex) { Log.Debug("Could get types from assembly " + dllName + ". Exception : " + ex.ToString()); } }
/// <summary> /// Callback function for the directory walker. When a DLL is found, /// looks for all the TTSEngine types in the DLL and caches the GUID and /// the class type for the engine /// </summary> /// <param name="dllName">name of the DLL to load</param> private void onFileFound(String dllName) { try { var ttsEngineAssembly = Assembly.LoadFile(dllName); foreach (var type in ttsEngineAssembly.GetTypes()) { if (typeof(ITTSEngine).IsAssignableFrom(type)) { var attr = DescriptorAttribute.GetDescriptor(type); if (attr != null && attr.Id != Guid.Empty) { addEngineTypeToCache(attr.Id, type); } } } } catch (Exception ex) { Log.Debug("Could get types from assembly " + dllName + ". Exception : " + ex); } }
/// <summary> /// Returns the ID of the TTS Engine that supports the /// specified culture info. If no culture-specific /// TTS Engine is found, Guid.Empty is returned /// </summary> /// <param name="ci">culture info</param> /// <returns>ID of the TTS Engine</returns> public Guid GetDefaultByCulture(CultureInfo ci) { Tuple <String, Type> foundTuple = null; // first look for culture-specific TTS Engines foreach (var tuple in _ttsEnginesTypeCache.Values) { if (ci == null) { if (String.IsNullOrEmpty(tuple.Item1)) { foundTuple = tuple; break; } } else if (!String.IsNullOrEmpty(tuple.Item1) && (String.Compare(tuple.Item1, ci.Name, true) == 0) || String.Compare(tuple.Item1, ci.TwoLetterISOLanguageName, true) == 0) { foundTuple = tuple; break; } } if (foundTuple != null) { IDescriptor descriptor = DescriptorAttribute.GetDescriptor(foundTuple.Item2); if (descriptor != null) { Log.Debug("Found TTS Engine for culture " + (ci != null ? ci.Name : "Neutral") + "[" + descriptor.Name + "]"); return(descriptor.Id); } } return(Guid.Empty); }
/// <summary> /// Loads actuator settigns from the settings file. /// Walks through the extensions dirs, looks for actuators in there /// and caches the Types of the actuators. /// Configures the actuators with the settings from the settings file. /// Also if any acutators were discovered that are not in the settings file, /// adds them to the settings file and saves it. /// </summary> /// <param name="extensionDirs">directories to walk through</param> /// <param name="configFile">name of the actuators settings file</param> /// <param name="loadAll">whether to load even the disabled actuators</param> /// <returns>true on success</returns> public bool Load(IEnumerable <String> extensionDirs, String configFile, bool loadAll = false) { addKeyboardActuatorToCache(); foreach (string dir in extensionDirs) { String extensionDir = dir + "\\" + ActuatorManager.ActuatorsRootDir; loadActuatorTypesIntoCache(extensionDir); } if (!File.Exists(configFile)) { return(false); } ActuatorConfig.ActuatorSettingsFileName = configFile; Config = ActuatorConfig.Load(); // walk through the settings file create and configure // actuators foreach (var actuatorSetting in Config.ActuatorSettings) { try { bool enabled = (loadAll) || actuatorSetting.Enabled; if (enabled && (actuatorSetting.Id != Guid.Empty)) { if (!_actuatorsTypeCache.ContainsKey(actuatorSetting.Id)) { continue; } var type = _actuatorsTypeCache[actuatorSetting.Id]; if (type != null) { var assembly = Assembly.LoadFrom(type.Assembly.Location); var actuator = (IActuator)assembly.CreateInstance(type.FullName); if (actuator != null) { actuator.OnRegisterSwitches(); actuator.Load(actuatorSetting.SwitchSettings); actuator.Enabled = actuatorSetting.Enabled; var actuatorEx = new ActuatorEx(actuator); _actuatorsEx.Add(actuatorEx); _actuators.Add(actuator); } } } } catch (Exception ex) { Log.Exception(ex); } } // now go through all the actuators that are not in the // settings file and add them to the settings file bool isDirty = false; foreach (var actuatorType in _actuatorsTypeCache.Values) { var attr = DescriptorAttribute.GetDescriptor(actuatorType); if (attr != null && attr.Id != Guid.Empty) { var actuatorSetting = Config.Find(attr.Id); if (actuatorSetting != null) { continue; } try { var assembly = Assembly.LoadFrom(actuatorType.Assembly.Location); var actuator = (IActuator)assembly.CreateInstance(actuatorType.FullName); if (actuator != null) { var actuatorEx = new ActuatorEx(actuator); _actuatorsEx.Add(actuatorEx); _actuators.Add(actuator); actuatorSetting = new ActuatorSetting(attr.Name, attr.Id); Config.ActuatorSettings.Add(actuatorSetting); actuator.OnRegisterSwitches(); actuator.Load(actuatorSetting.SwitchSettings); isDirty = true; } } catch (Exception ex) { Log.Exception(ex); } } } if (isDirty) { Config.Save(); } return(true); }
/// <summary> /// Initializes a new instance of the class. /// </summary> public VolumeSettingsAgent() { Name = DescriptorAttribute.GetDescriptor(GetType()).Name; }
/// <summary> /// Initializes a new instance of the class. /// </summary> public SwitchWindowsAgent() { Name = DescriptorAttribute.GetDescriptor(GetType()).Name; }
/// <summary> /// Initializes a new instance of the class. /// </summary> public SwitchWindowsAgent() { Name = DescriptorAttribute.GetDescriptor(GetType()).Name; initProperties(); }