public Creature(string _name, Vector3Int _pos, creatureType _type = creatureType.neutral, CreatureModel _model = CreatureModel.human, CreatureSex _sex = CreatureSex.none, creatureSize _size = creatureSize.medium) { name = _name; type = _type; model = _model; sex = _sex; size = _size; worldSpacePosition = _pos; }
private void btnGenerateUniqueName_Click(object sender, EventArgs e) { if (speciesIndex < 0 || speciesIndex > Values.V.species.Count - 1) { return; } // collect creatures of the same species var sameSpecies = (_females ?? new List <Creature> { }).Concat((_males ?? new List <Creature> { })).ToList(); var names = sameSpecies.Select(x => x.name).ToArray(); // replace tokens in user configurated pattern string var tokendict = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase) { { "species", Values.V.species[speciesIndex].name }, { "sex", CreatureSex.ToString() }, { "sex_short", CreatureSex.ToString().Substring(0, 1) } }; var r = new Regex("\\{(?<key>" + string.Join("|", tokendict.Keys.Select(x => Regex.Escape(x))) + ")\\}", RegexOptions.IgnoreCase | RegexOptions.Singleline | RegexOptions.ExplicitCapture); var pattern = r.Replace(Properties.Settings.Default.sequentialUniqueNamePattern, (m) => { string replacement = null; return(tokendict.TryGetValue(m.Groups["key"].Value, out replacement) ? replacement : m.Value); }); // find the sequence token, and if not, return because the configurated pattern string is invalid without it var index = pattern.IndexOf("{n}", StringComparison.OrdinalIgnoreCase); if (index == -1) { return; } var patternStart = pattern.Substring(0, index); var patternEnd = pattern.Substring(index + 3); // loop until we find a unique name in the sequence which is not taken string name = null; var n = 1; do { name = string.Concat(patternStart, n, patternEnd); n++; } while (names.Contains(name, StringComparer.OrdinalIgnoreCase)); // set the creature name CreatureName = name; }
/// <summary> /// This method creates the token dictionary for the dynamic creature name generation. /// </summary> /// <param name="creature">Creature with the data</param> /// <param name="creatureNames">A list of all name of the currently stored creatures</param> /// <returns>A dictionary containing all tokens and their replacements</returns> private Dictionary <string, string> createTokenDictionary(Creature creature, string[] creatureNames) { var date_short = DateTime.Now.ToString("yy-MM-dd"); var date_compressed = date_short.Replace("-", ""); var time_short = DateTime.Now.ToString("hh:mm:ss"); var time_compressed = time_short.Replace(":", ""); string hp = creature.levelsWild[0].ToString().PadLeft(2, '0'); string stam = creature.levelsWild[1].ToString().PadLeft(2, '0'); string oxy = creature.levelsWild[2].ToString().PadLeft(2, '0'); string food = creature.levelsWild[3].ToString().PadLeft(2, '0'); string weight = creature.levelsWild[4].ToString().PadLeft(2, '0'); string dmg = creature.levelsWild[5].ToString().PadLeft(2, '0'); string spd = creature.levelsWild[6].ToString().PadLeft(2, '0'); string trp = creature.levelsWild[7].ToString().PadLeft(2, '0'); double imp = creature.imprintingBonus * 100; double eff = creature.tamingEff * 100; var rand = new Random(DateTime.Now.Millisecond); var randStr = rand.Next(100000, 999999).ToString(); string effImp = "Z"; string prefix = ""; if (imp > 0) { prefix = "I"; effImp = Math.Round(imp).ToString(); } else if (eff > 1) { prefix = "E"; effImp = Math.Round(eff).ToString(); } while (effImp.Length < 3 && effImp != "Z") { effImp = "0" + effImp; } effImp = prefix + effImp; int generation = 0; if (mother != null) { generation = mother.generation + 1; } if (father != null && father.generation + 1 > generation) { generation = father.generation + 1; } var precompressed = CreatureSex.ToString().Substring(0, 1) + date_compressed + hp + stam + oxy + food + weight + dmg + effImp; var spcShort = Values.V.species[speciesIndex].name.Replace(" ", ""); var speciesShort = spcShort; var vowels = new string[] { "a", "e", "i", "o", "u" }; while (spcShort.Length > 4 && spcShort.LastIndexOfAny(new char[] { 'a', 'e', 'i', 'o', 'u' }) > 0) { spcShort = spcShort.Remove(spcShort.LastIndexOfAny(new char[] { 'a', 'e', 'i', 'o', 'u' }), 1); // remove last vowel (not the first letter) } spcShort = spcShort.Substring(0, Math.Min(4, spcShort.Length)); speciesShort = speciesShort.Substring(0, Math.Min(4, speciesShort.Length)); // replace tokens in user configurated pattern string return(new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase) { { "species", Values.V.species[speciesIndex].name }, { "spcs_short", spcShort }, { "spcs_shortu", spcShort.ToUpper() }, { "species_short", speciesShort }, { "species_shortu", speciesShort.ToUpper() }, { "sex", CreatureSex.ToString() }, { "sex_short", CreatureSex.ToString().Substring(0, 1) }, { "cpr", precompressed }, { "date_short", date_short }, { "date_compressed", date_compressed }, { "times_short", time_short }, { "times_compressed", time_compressed }, { "time_short", time_short.Substring(0, 5) }, { "time_compressed", time_compressed.Substring(0, 4) }, { "hp", hp }, { "stam", stam }, { "oxy", oxy }, { "food", food }, { "weight", weight }, { "dmg", dmg }, { "spd", spd }, { "trp", trp }, { "effImp", effImp }, { "muta", numericUpDownMutations.Value.ToString().PadLeft(3, '0') }, { "gen", generation.ToString().PadLeft(3, '0') }, { "gena", dec2hexvig(generation).PadLeft(2, '-') }, { "rnd", randStr }, { "tn", (creatureNames.Length + 1).ToString() } }); }
public static T SetSex <T>(this T entity, CreatureSex value) where T : CharacterTemplateDefinition { entity.SetField("sex", value); return(entity); }
public SexRec(CreatureSex value, string sign, int nameRS) { Value = value; Sign = sign; NameRS = nameRS; }
public override void LoadXML(XmlNode element, FileVersion version) { try { base.LoadXML(element, version); Race = (RaceID)Enum.Parse(typeof(RaceID), ReadElement(element, "Race")); Gfx = ReadElement(element, "gfx"); Sfx = ReadElement(element, "sfx"); string signs = ReadElement(element, "Signs"); Flags = new CreatureFlags(signs); if (!signs.Equals(Flags.Signature)) { throw new Exception("CreatureSigns not equals " + Convert.ToString(GUID)); } MinHP = Convert.ToInt16(ReadElement(element, "minHP")); MaxHP = Convert.ToInt16(ReadElement(element, "maxHP")); AC = Convert.ToInt16(ReadElement(element, "AC")); Speed = Convert.ToSByte(ReadElement(element, "Speed")); ToHit = Convert.ToInt16(ReadElement(element, "ToHit")); Attacks = Convert.ToSByte(ReadElement(element, "Attacks")); Constitution = Convert.ToInt16(ReadElement(element, "Constitution")); Strength = Convert.ToInt16(ReadElement(element, "Strength")); MinDB = Convert.ToInt16(ReadElement(element, "minDB")); MaxDB = Convert.ToInt16(ReadElement(element, "maxDB")); Survey = Convert.ToByte(ReadElement(element, "Survey")); Level = Convert.ToSByte(ReadElement(element, "Level")); Alignment = (Alignment)Enum.Parse(typeof(Alignment), ReadElement(element, "Alignment")); Weight = (float)ConvertHelper.ParseFloat(ReadElement(element, "Weight"), 0.0f, true); Sex = StaticData.GetSexBySign(ReadElement(element, "Sex")); FleshEffect = Convert.ToInt32(ReadElement(element, "FleshEffect")); FleshSatiety = Convert.ToInt16(ReadElement(element, "FleshSatiety")); string sym = ReadElement(element, "Symbol"); Symbol = (string.IsNullOrEmpty(sym) ? '?' : sym[0]); Extinctable = Convert.ToBoolean(ReadElement(element, "Extinctable")); Dexterity = Convert.ToUInt16(ReadElement(element, "Dexterity")); Hear = Convert.ToByte(ReadElement(element, "Hear")); Smell = Convert.ToByte(ReadElement(element, "Smell")); FramesCount = Convert.ToByte(ReadElement(element, "FramesCount")); XmlNodeList nl = element.SelectSingleNode("Lands").ChildNodes; Lands = new string[nl.Count]; for (int i = 0; i < nl.Count; i++) { XmlNode n = nl[i]; Lands[i] = n.Attributes["ID"].InnerText; } nl = element.SelectSingleNode("Abilities").ChildNodes; for (int i = 0; i < nl.Count; i++) { XmlNode n = nl[i]; AbilityID ab = (AbilityID)Enum.Parse(typeof(AbilityID), n.Attributes["ID"].InnerText); int val = Convert.ToInt32(n.Attributes["Value"].InnerText); Abilities.Add((int)ab, val); } nl = element.SelectSingleNode("Skills").ChildNodes; for (int i = 0; i < nl.Count; i++) { XmlNode n = nl[i]; SkillID sk = (SkillID)Enum.Parse(typeof(SkillID), n.Attributes["ID"].InnerText); int val = Convert.ToInt32(n.Attributes["Value"].InnerText); Skills.Add((int)sk, val); } nl = element.SelectSingleNode("Inventory").ChildNodes; Inventory = new InventoryEntry[nl.Count]; for (int i = 0; i < nl.Count; i++) { XmlNode n = nl[i]; InventoryEntry invEntry = new InventoryEntry(); Inventory[i] = invEntry; invEntry.ItemSign = n.Attributes["ID"].InnerText; invEntry.CountMin = Convert.ToInt32(n.Attributes["CountMin"].InnerText); invEntry.CountMax = Convert.ToInt32(n.Attributes["CountMax"].InnerText); XmlAttribute stat = n.Attributes["Status"]; if (stat != null) { ParseStatus(invEntry, stat.InnerText); } } XmlNodeList dnl = element.SelectNodes("Dialog"); if (dnl.Count > 0) { XmlNode dialogXmlNode = (XmlNode)dnl[0]; Dialog.LoadXML(dialogXmlNode, version, true); } } catch (Exception ex) { Logger.Write("CreatureEntry.loadXML(): " + ex.Message); throw ex; } }
public static T SetSex <T>(this T entity, CreatureSex value) where T : MonsterPresentationDefinition { entity.SetField("sex", value); return(entity); }