// 取得疊字小名
        public static Verse.NameTriple GetStackNickName(Verse.NameTriple name, Gender gender = Gender.None)
        {
            string 小名 = "";

            if (Verse.Rand.Value >= 0.5f)
            {
                小名 = name.First.Substring(0, 1) + name.First.Substring(0, 1);
            }
            else
            {
                小名 = name.First.Substring(1, 1) + name.First.Substring(1, 1);
            }
            return(new Verse.NameTriple(name.First, 小名, name.Last));
        }
Пример #2
0
        public override bool ConfusinglySimilarTo(Name other)
        {
            NameSingle nameSingle = other as NameSingle;
            bool       result;

            if (nameSingle != null && nameSingle.nameInt == this.nameInt)
            {
                result = true;
            }
            else
            {
                NameTriple nameTriple = other as NameTriple;
                result = (nameTriple != null && nameTriple.Nick == this.nameInt);
            }
            return(result);
        }
 public static bool NameWordIsUsed(string singleName)
 {
     foreach (Name item in NameUseChecker.AllPawnsNamesEverUsed)
     {
         NameTriple nameTriple = item as NameTriple;
         if (nameTriple != null && (singleName == nameTriple.First || singleName == nameTriple.Nick || singleName == nameTriple.Last))
         {
             return(true);
         }
         NameSingle nameSingle = item as NameSingle;
         if (nameSingle != null && nameSingle.Name == singleName)
         {
             return(true);
         }
     }
     return(false);
 }
Пример #4
0
        public static NameTriple RandomPreferredName()
        {
            string     rawName;
            NameTriple result;

            if ((from name in Prefs.PreferredNames
                 where !name.NullOrEmpty()
                 select name).TryRandomElement(out rawName))
            {
                result = NameTriple.FromString(rawName);
            }
            else
            {
                result = null;
            }
            return(result);
        }
Пример #5
0
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return(false);
            }
            if (!(obj is NameTriple))
            {
                return(false);
            }
            NameTriple nameTriple = (NameTriple)obj;

            if (First == nameTriple.First && Last == nameTriple.Last)
            {
                return(Nick == nameTriple.Nick);
            }
            return(false);
        }
Пример #6
0
        public override bool ConfusinglySimilarTo(Name other)
        {
            NameTriple nameTriple = other as NameTriple;

            if (nameTriple != null)
            {
                if (this.Nick != null && this.Nick == nameTriple.Nick)
                {
                    return(true);
                }
                if (this.First == nameTriple.First && this.Last == nameTriple.Last)
                {
                    return(true);
                }
            }
            NameSingle nameSingle = other as NameSingle;

            return(nameSingle != null && nameSingle.Name == this.Nick);
        }
Пример #7
0
        public override bool Equals(object obj)
        {
            bool result;

            if (obj == null)
            {
                result = false;
            }
            else if (!(obj is NameTriple))
            {
                result = false;
            }
            else
            {
                NameTriple nameTriple = (NameTriple)obj;
                result = (this.First == nameTriple.First && this.Last == nameTriple.Last && this.Nick == nameTriple.Nick);
            }
            return(result);
        }
Пример #8
0
 public static bool NameWordIsUsed(string singleName)
 {
     foreach (Name current in NameUseChecker.AllPawnsNamesEverUsed)
     {
         NameTriple nameTriple = current as NameTriple;
         if (nameTriple != null && (singleName == nameTriple.First || singleName == nameTriple.Nick || singleName == nameTriple.Last))
         {
             bool result = true;
             return(result);
         }
         NameSingle nameSingle = current as NameSingle;
         if (nameSingle != null && nameSingle.Name == singleName)
         {
             bool result = true;
             return(result);
         }
     }
     return(false);
 }
Пример #9
0
 public static object FromString(string str, Type itemType)
 {
     try
     {
         itemType = (Nullable.GetUnderlyingType(itemType) ?? itemType);
         if (itemType == typeof(string))
         {
             str = str.Replace("\\n", "\n");
             return(str);
         }
         if (itemType == typeof(int))
         {
             return(ParseIntPermissive(str));
         }
         if (itemType == typeof(float))
         {
             return(float.Parse(str, CultureInfo.InvariantCulture));
         }
         if (itemType == typeof(bool))
         {
             return(bool.Parse(str));
         }
         if (itemType == typeof(long))
         {
             return(long.Parse(str, CultureInfo.InvariantCulture));
         }
         if (itemType == typeof(double))
         {
             return(double.Parse(str, CultureInfo.InvariantCulture));
         }
         if (itemType == typeof(sbyte))
         {
             return(sbyte.Parse(str, CultureInfo.InvariantCulture));
         }
         if (itemType.IsEnum)
         {
             try
             {
                 object obj = BackCompatibility.BackCompatibleEnum(itemType, str);
                 if (obj != null)
                 {
                     return(obj);
                 }
                 return(Enum.Parse(itemType, str));
             }
             catch (ArgumentException innerException)
             {
                 string str2 = "'" + str + "' is not a valid value for " + itemType + ". Valid values are: \n";
                 str2 += GenText.StringFromEnumerable(Enum.GetValues(itemType));
                 ArgumentException ex = new ArgumentException(str2, innerException);
                 throw ex;
             }
         }
         if (itemType == typeof(Type))
         {
             if (str == "null" || str == "Null")
             {
                 return(null);
             }
             Type typeInAnyAssembly = GenTypes.GetTypeInAnyAssembly(str);
             if (typeInAnyAssembly == null)
             {
                 Log.Error("Could not find a type named " + str);
             }
             return(typeInAnyAssembly);
         }
         if (itemType == typeof(Action))
         {
             string[] array      = str.Split('.');
             string   methodName = array[array.Length - 1];
             string   empty      = string.Empty;
             empty = ((array.Length != 3) ? array[0] : (array[0] + "." + array[1]));
             Type       typeInAnyAssembly2 = GenTypes.GetTypeInAnyAssembly(empty);
             MethodInfo method             = typeInAnyAssembly2.GetMethods().First((MethodInfo m) => m.Name == methodName);
             return((Action)Delegate.CreateDelegate(typeof(Action), method));
         }
         if (itemType == typeof(Vector3))
         {
             return(FromStringVector3(str));
         }
         if (itemType == typeof(Vector2))
         {
             return(FromStringVector2(str));
         }
         if (itemType == typeof(Rect))
         {
             return(FromStringRect(str));
         }
         if (itemType == typeof(Color))
         {
             str = str.TrimStart('(', 'R', 'G', 'B', 'A');
             str = str.TrimEnd(')');
             string[] array2 = str.Split(',');
             float    num    = (float)FromString(array2[0], typeof(float));
             float    num2   = (float)FromString(array2[1], typeof(float));
             float    num3   = (float)FromString(array2[2], typeof(float));
             bool     flag   = num > 1f || num3 > 1f || num2 > 1f;
             float    num4   = (float)((!flag) ? 1 : 255);
             if (array2.Length == 4)
             {
                 num4 = (float)FromString(array2[3], typeof(float));
             }
             Color color = default(Color);
             if (!flag)
             {
                 color.r = num;
                 color.g = num2;
                 color.b = num3;
                 color.a = num4;
             }
             else
             {
                 color = GenColor.FromBytes(Mathf.RoundToInt(num), Mathf.RoundToInt(num2), Mathf.RoundToInt(num3), Mathf.RoundToInt(num4));
             }
             return(color);
         }
         if (itemType == typeof(PublishedFileId_t))
         {
             return(new PublishedFileId_t(ulong.Parse(str)));
         }
         if (itemType == typeof(IntVec2))
         {
             return(IntVec2.FromString(str));
         }
         if (itemType == typeof(IntVec3))
         {
             return(IntVec3.FromString(str));
         }
         if (itemType == typeof(Rot4))
         {
             return(Rot4.FromString(str));
         }
         if (itemType == typeof(CellRect))
         {
             return(CellRect.FromString(str));
         }
         if (itemType != typeof(CurvePoint))
         {
             if (itemType == typeof(NameTriple))
             {
                 NameTriple nameTriple = NameTriple.FromString(str);
                 nameTriple.ResolveMissingPieces();
             }
             else
             {
                 if (itemType == typeof(FloatRange))
                 {
                     return(FloatRange.FromString(str));
                 }
                 if (itemType == typeof(IntRange))
                 {
                     return(IntRange.FromString(str));
                 }
                 if (itemType == typeof(QualityRange))
                 {
                     return(QualityRange.FromString(str));
                 }
                 if (itemType == typeof(ColorInt))
                 {
                     str = str.TrimStart('(', 'R', 'G', 'B', 'A');
                     str = str.TrimEnd(')');
                     string[] array3   = str.Split(',');
                     ColorInt colorInt = new ColorInt(255, 255, 255, 255);
                     colorInt.r = (int)FromString(array3[0], typeof(int));
                     colorInt.g = (int)FromString(array3[1], typeof(int));
                     colorInt.b = (int)FromString(array3[2], typeof(int));
                     if (array3.Length == 4)
                     {
                         colorInt.a = (int)FromString(array3[3], typeof(int));
                     }
                     else
                     {
                         colorInt.a = 255;
                     }
                     return(colorInt);
                 }
             }
             throw new ArgumentException("Trying to parse to unknown data type " + itemType.Name + ". Content is '" + str + "'.");
         }
         return(CurvePoint.FromString(str));
     }
     catch (Exception innerException2)
     {
         ArgumentException ex2 = new ArgumentException("Exception parsing " + itemType + " from \"" + str + "\"", innerException2);
         throw ex2;
     }
 }
Пример #10
0
        /// <summary>
        /// 前後綴點綴產生暱稱
        /// </summary>
        /// <param name="name">角色原名</param>
        /// <param name="gender">角色性別</param>
        /// <returns></returns>
        public static Verse.NameTriple GetNormalNickName(Verse.NameTriple name, Gender gender = Gender.None, Pawn pawn = null)
        {
            string 小名 = "";
            string 前綴 = "";
            string 後綴 = "";

            #region  稱產生
            // 前後規則
            // 前綴稱號 小、阿、大
            // 後綴稱號 哥or姐 弟or妹
            // 寵物就直接用前綴了
            if (Verse.Rand.Value >= 0.5f || pawn.RaceProps.Animal)
            {
                if (Verse.Rand.Value >= 0.66f)
                {
                    前綴 = "小";
                }
                else if (Verse.Rand.Value >= 0.33f)
                {
                    前綴 = "阿";
                }
                else
                {
                    前綴 = "大";
                }
            }
            else
            {
                if (gender == Gender.Female)
                {
                    if (Verse.Rand.Value >= 0.5f)
                    {
                        後綴 = "姐";
                    }
                    else
                    {
                        後綴 = "妹";
                    }
                }
                else
                {
                    if (Verse.Rand.Value >= 0.5f)
                    {
                        後綴 = "哥";
                    }
                    else if (Verse.Rand.Value >= 0.3f)
                    {
                        後綴 = "弟";
                    }
                    else
                    {
                        後綴 = "狗";
                    }
                }
            }
            // 取姓取名則一
            // 取姓
            // 取名
            if (Verse.Rand.Value >= 0.5f)
            {
                小名 = 前綴 + name.Last + 後綴;
            }
            else
            {
                Random rand = new Random();
                int    cut  = rand.Next(0, 2);
                小名 = 前綴 + name.First.Substring(cut, 1) + 後綴;
            }
            #endregion

            return(new Verse.NameTriple(name.First, 小名, name.Last));
        }
Пример #11
0
        //=======================以下尚開發中=====================
        // 取得諧音小名 不穩定 暫不使用
        // To Get homophonic NickName (But It's Proformace is not good), It's bad to foreach an unsort data.
        public static Verse.NameTriple GetHomophonicNickName(Verse.NameTriple name, Gender gender = Gender.None)
        {
            string        小名   = "";
            List <string> 男單詞庫 = new List <string> {
                "菊花", "博起", "華哥兒", "番薯", "芭樂",
                "小熊維尼", "鎖鏈殺手", "滷肉飯", "師傅", "屌炸天", "小淫蟲", "淫魔", "送飯的", "節節八八"
            };

            List <string> 女單詞庫 = new List <string> {
                "番薯", "芭樂", "辣台妹", "罡妹", "正咩", "北妻", "水餃", "冰淇淋", "滷肉飯", "隨意包盧肌考尻", "夏天妹", "和平使者", "便宜"
            };

            if (gender == Gender.Female)
            {
                女單詞庫.Shuffle();
                bool ok = false;
                女單詞庫.ForEach(word =>
                {
                    if (ok == false)
                    {
                        小名 = "";

                        // 單字中所有字詞
                        List <string> wordWords = new List <string>();
                        for (int i = 0; i < word.Length; i++)
                        {
                            wordWords.Add(word.Substring(i, 1));
                        }
                        // 諧音轉換器
                        wordWords.ForEach(w =>
                        {
                            if (findWord(w, name.First.Substring(0, 1)))
                            {
                                小名 = 小名 + name.First.Substring(0, 1);
                                ok = true;
                                Log.Message(小名);
                            }
                            else if (findWord(w, name.First.Substring(1, 1)))
                            {
                                小名 = 小名 + name.First.Substring(1, 1);
                                ok = true;
                                Log.Message(小名);
                            }
                            else
                            {
                                小名 = 小名 + w;
                            }
                        });
                    }
                });


                return(ok ? new Verse.NameTriple(name.First, 小名, name.Last) : new Verse.NameTriple(name.First, "", name.Last));
            }
            else
            {
                男單詞庫.Shuffle();
                bool ok = false;
                男單詞庫.ForEach(word =>
                {
                    if (ok == false)
                    {
                        小名 = "";

                        // 單字中所有字詞
                        List <string> wordWords = new List <string>();
                        for (int i = 0; i < word.Length; i++)
                        {
                            wordWords.Add(word.Substring(i, 1));
                        }
                        // 諧音轉換器
                        wordWords.ForEach(w =>
                        {
                            if (findWord(w, name.First.Substring(0, 1)))
                            {
                                小名 = 小名 + name.First.Substring(0, 1);
                                ok = true;
                                Log.Message(小名);
                            }
                            else if (findWord(w, name.First.Substring(1, 1)))
                            {
                                小名 = 小名 + name.First.Substring(1, 1);
                                ok = true;
                                Log.Message(小名);
                            }
                            else
                            {
                                小名 = 小名 + w;
                            }
                        });
                    }
                });
                return(ok ? new Verse.NameTriple(name.First, 小名, name.Last) : new Verse.NameTriple(name.First, "", name.Last));
            }
        }
Пример #12
0
        public static NameTriple FromString(string rawName)
        {
            if (rawName.Trim().Length == 0)
            {
                Log.Error("Tried to parse PawnName from empty or whitespace string.");
                return(NameTriple.Invalid);
            }
            NameTriple nameTriple = new NameTriple();
            int        num        = -1;
            int        num2       = -1;

            for (int i = 0; i < rawName.Length - 1; i++)
            {
                if (rawName[i] == ' ' && rawName[i + 1] == '\'' && num == -1)
                {
                    num = i;
                }
                if (rawName[i] == '\'' && rawName[i + 1] == ' ')
                {
                    num2 = i;
                }
            }
            if (num == -1 || num2 == -1)
            {
                if (!rawName.Contains(' '))
                {
                    nameTriple.nickInt = rawName.Trim();
                }
                else
                {
                    string[] array = rawName.Split(' ');
                    if (array.Length == 1)
                    {
                        nameTriple.nickInt = array[0].Trim();
                    }
                    else if (array.Length == 2)
                    {
                        nameTriple.firstInt = array[0].Trim();
                        nameTriple.lastInt  = array[1].Trim();
                    }
                    else
                    {
                        nameTriple.firstInt = array[0].Trim();
                        nameTriple.lastInt  = string.Empty;
                        for (int j = 1; j < array.Length; j++)
                        {
                            NameTriple nameTriple2 = nameTriple;
                            nameTriple2.lastInt += array[j];
                            if (j < array.Length - 1)
                            {
                                NameTriple nameTriple3 = nameTriple;
                                nameTriple3.lastInt += " ";
                            }
                        }
                    }
                }
            }
            else
            {
                nameTriple.firstInt = rawName.Substring(0, num).Trim();
                nameTriple.nickInt  = rawName.Substring(num + 2, num2 - num - 2).Trim();
                nameTriple.lastInt  = ((num2 >= rawName.Length - 2) ? string.Empty : rawName.Substring(num2 + 2).Trim());
            }
            return(nameTriple);
        }
Пример #13
0
        } // NAME ANIMALS END

        static private void nameOther()
        {
            Pawn               colonist       = null;
            Faction            local_faction  = null;
            IEnumerable <Pawn> colonist_pawns = from p in Verse.Find.CurrentMap.mapPawns.FreeColonistsAndPrisoners
                                                where !p.RaceProps.Animal && p.Name != null && !p.Name.Numerical
                                                select p;

            for (int i = 0; i < colonist_pawns.Count(); i++)
            {
                //Verse.Log.Message("COLONIST: " + colonist_pawns.ElementAt(i).Name);
                //info = colonist_pawns.ElementAt(i).attack()
                colonist = colonist_pawns.ElementAt(i);

                local_faction = colonist.Faction;
                if (local_faction != null)
                {
                    //Verse.Log.Message("FACTION " + local_faction.ToString());
                    break;
                }
            }

            if (local_faction == null)
            {
                Verse.Log.Message("FACTION null");
            }


            IList <string> usedOtherNames = new List <string>();

            //get a list of already used pawn names
            IEnumerable <Pawn> others_pawns = from p in Verse.Find.CurrentMap.mapPawns.AllPawnsSpawned
                                              where !p.RaceProps.Animal && p.Name != null && !p.Name.Numerical
                                              select p;

            for (int i = 0; i < others_pawns.Count(); i++)
            {
                try {
                    if (others_pawns.ElementAt(i).Faction != local_faction &&
                        ((Verse.NameTriple)others_pawns.ElementAt(i).Name).First == "Twitch")
                    {
                        //Verse.Log.Message("OTHER: " + others_pawns.ElementAt(i).Name);
                        usedOtherNames.Add(((Verse.NameTriple)others_pawns.ElementAt(i).Name).Nick);
                    }
                }
                catch (System.Exception) {
                    Verse.Log.Message("RENAME EXCEPTION ");
                }
            }


            //rename other pawns
            for (int i = 0; i < others_pawns.Count(); i++)
            {
                try {
                    if (others_pawns.ElementAt(i).Faction != local_faction &&
                        ((Verse.NameTriple)others_pawns.ElementAt(i).Name).First != "Twitch")
                    {
                        string one_name_str = "";
                        bool   found_name   = false;
                        for (int f = 0; f < namePool.Count(); f++)
                        {
                            one_name_str = namePool.ElementAt(f);

                            if (usedOtherNames.IndexOf(one_name_str) == -1)
                            {
                                found_name = true;
                                break;
                            }
                        }

                        if (!found_name)
                        {
                            Verse.Log.Message("NO UNIQUE NAME FOR OTHERS");
                            break;
                        }
                        usedOtherNames.Add(one_name_str);

                        string last = "";

                        /*if (one_name_str == "BonjwaRedpanda") {
                         * others_pawns.ElementAt(i).skills.Learn(RimWorld.SkillDefOf.Shooting, 999999);
                         * last = "The Shooter";
                         *
                         * others_pawns.ElementAt(i).story.traits.allTraits.Clear();
                         *
                         * RimWorld.Trait shooter = new RimWorld.Trait(RimWorld.TraitDefOf.ShootingAccuracy, 1);
                         * others_pawns.ElementAt(i).story.traits.GainTrait(shooter);
                         *
                         * RimWorld.Trait bloodlust = new RimWorld.Trait(RimWorld.TraitDefOf.Bloodlust);
                         * others_pawns.ElementAt(i).story.traits.GainTrait(bloodlust);
                         *
                         * RimWorld.Trait beauty = new RimWorld.Trait(RimWorld.TraitDefOf.Beauty, 1);
                         * others_pawns.ElementAt(i).story.traits.GainTrait(beauty);
                         *
                         * RimWorld.Trait sens = new RimWorld.Trait(RimWorld.TraitDefOf.PsychicSensitivity, 1);
                         * others_pawns.ElementAt(i).story.traits.GainTrait(sens);
                         * }
                         *
                         * if (one_name_str == "Moobot") {
                         * others_pawns.ElementAt(i).skills.Learn(RimWorld.SkillDefOf.Melee, 999999);
                         * last = "will kill you with bare hands";
                         *
                         * //strip to drop all weapons and meele fight
                         * others_pawns.ElementAt(i).Strip();
                         *
                         * //give traits
                         * others_pawns.ElementAt(i).story.traits.allTraits.Clear();
                         *
                         * RimWorld.Trait bloodlust = new RimWorld.Trait(RimWorld.TraitDefOf.Bloodlust);
                         * others_pawns.ElementAt(i).story.traits.GainTrait(bloodlust);
                         *
                         * RimWorld.Trait tough = new RimWorld.Trait(RimWorld.TraitDefOf.Tough);
                         * others_pawns.ElementAt(i).story.traits.GainTrait(tough);
                         *
                         * RimWorld.Trait brawler = new RimWorld.Trait(RimWorld.TraitDefOf.Brawler);
                         * others_pawns.ElementAt(i).story.traits.GainTrait(brawler);
                         *
                         * RimWorld.Trait sens = new RimWorld.Trait(RimWorld.TraitDefOf.PsychicSensitivity, 1);
                         * others_pawns.ElementAt(i).story.traits.GainTrait(sens);
                         * }
                         *
                         * if (one_name_str == "Kerrag") {
                         * others_pawns.ElementAt(i).skills.Learn(RimWorld.SkillDefOf.Cooking, 999999);
                         * last = "The Cook";
                         *
                         *
                         * //give traits
                         * others_pawns.ElementAt(i).story.traits.allTraits.Clear();
                         *
                         * RimWorld.Trait sensitive = new RimWorld.Trait(RimWorld.TraitDefOf.PsychicSensitivity, 1);
                         * others_pawns.ElementAt(i).story.traits.GainTrait(sensitive);
                         *
                         * RimWorld.Trait trans = new RimWorld.Trait(RimWorld.TraitDefOf.Transhumanist);
                         * others_pawns.ElementAt(i).story.traits.GainTrait(trans);
                         *
                         * RimWorld.Trait indu = new RimWorld.Trait(RimWorld.TraitDefOf.Industriousness, 1);
                         * others_pawns.ElementAt(i).story.traits.GainTrait(indu);
                         * }
                         *
                         *
                         * if (one_name_str == "bonjwahonor") {
                         * others_pawns.ElementAt(i).skills.Learn(RimWorld.SkillDefOf.Social, 999999);
                         * last = "The Nice Guy";
                         *
                         * //give traits
                         * others_pawns.ElementAt(i).story.traits.allTraits.Clear();
                         *
                         * RimWorld.Trait greed = new RimWorld.Trait(RimWorld.TraitDefOf.Greedy);
                         * others_pawns.ElementAt(i).story.traits.GainTrait(greed);
                         *
                         * RimWorld.Trait memory = new RimWorld.Trait(RimWorld.TraitDefOf.GreatMemory);
                         * others_pawns.ElementAt(i).story.traits.GainTrait(memory);
                         *
                         * RimWorld.Trait kind = new RimWorld.Trait(RimWorld.TraitDefOf.Kind);
                         * others_pawns.ElementAt(i).story.traits.GainTrait(kind);
                         *
                         * RimWorld.Trait pyro = new RimWorld.Trait(RimWorld.TraitDefOf.Pyromaniac);
                         * others_pawns.ElementAt(i).story.traits.GainTrait(pyro);
                         * }
                         *
                         * if (one_name_str == "Neandi") {
                         * others_pawns.ElementAt(i).skills.Learn(RimWorld.SkillDefOf.Artistic, 999999);
                         * last = "The Artist";
                         *
                         * //give traits
                         * others_pawns.ElementAt(i).story.traits.allTraits.Clear();
                         *
                         * RimWorld.Trait drug = new RimWorld.Trait(RimWorld.TraitDefOf.DrugDesire, 1);
                         * others_pawns.ElementAt(i).story.traits.GainTrait(drug);
                         *
                         * RimWorld.Trait ascet = new RimWorld.Trait(RimWorld.TraitDefOf.Ascetic);
                         * others_pawns.ElementAt(i).story.traits.GainTrait(ascet);
                         *
                         * RimWorld.Trait nudist = new RimWorld.Trait(RimWorld.TraitDefOf.Nudist);
                         * others_pawns.ElementAt(i).story.traits.GainTrait(nudist);
                         *
                         * RimWorld.Trait psycho = new RimWorld.Trait(RimWorld.TraitDefOf.Psychopath);
                         * others_pawns.ElementAt(i).story.traits.GainTrait(psycho);
                         * }*/


                        Verse.Log.Message("GIVE NAME (OTHER): " + one_name_str);
                        Verse.NameTriple nametriple = new Verse.NameTriple("Twitch", one_name_str, last);
                        others_pawns.ElementAt(i).Name = nametriple;
                    }
                }
                catch (System.Exception) {
                    Verse.Log.Message("RENAME EXCEPTION ");
                }
            }
        }
Пример #14
0
        public static object FromString(string str, Type itemType)
        {
            object result;

            try
            {
                itemType = (Nullable.GetUnderlyingType(itemType) ?? itemType);
                if (itemType == typeof(string))
                {
                    str    = str.Replace("\\n", "\n");
                    result = str;
                }
                else if (itemType == typeof(int))
                {
                    result = int.Parse(str, CultureInfo.InvariantCulture);
                }
                else if (itemType == typeof(float))
                {
                    result = float.Parse(str, CultureInfo.InvariantCulture);
                }
                else if (itemType == typeof(bool))
                {
                    result = bool.Parse(str);
                }
                else if (itemType == typeof(long))
                {
                    result = long.Parse(str, CultureInfo.InvariantCulture);
                }
                else if (itemType == typeof(double))
                {
                    result = double.Parse(str, CultureInfo.InvariantCulture);
                }
                else if (itemType == typeof(sbyte))
                {
                    result = sbyte.Parse(str, CultureInfo.InvariantCulture);
                }
                else
                {
                    if (itemType.IsEnum)
                    {
                        try
                        {
                            result = Enum.Parse(itemType, str);
                            return(result);
                        }
                        catch (ArgumentException innerException)
                        {
                            string text = string.Concat(new object[]
                            {
                                "'",
                                str,
                                "' is not a valid value for ",
                                itemType,
                                ". Valid values are: \n"
                            });
                            text += GenText.StringFromEnumerable(Enum.GetValues(itemType));
                            ArgumentException ex = new ArgumentException(text, innerException);
                            throw ex;
                        }
                    }
                    if (itemType == typeof(Type))
                    {
                        if (str == "null" || str == "Null")
                        {
                            result = null;
                        }
                        else
                        {
                            Type typeInAnyAssembly = GenTypes.GetTypeInAnyAssembly(str);
                            if (typeInAnyAssembly == null)
                            {
                                Log.Error("Could not find a type named " + str);
                            }
                            result = typeInAnyAssembly;
                        }
                    }
                    else if (itemType == typeof(Action))
                    {
                        string[] array = str.Split(new char[]
                        {
                            '.'
                        });
                        string methodName = array[array.Length - 1];
                        string typeName   = string.Empty;
                        if (array.Length == 3)
                        {
                            typeName = array[0] + "." + array[1];
                        }
                        else
                        {
                            typeName = array[0];
                        }
                        Type       typeInAnyAssembly2 = GenTypes.GetTypeInAnyAssembly(typeName);
                        MethodInfo method             = typeInAnyAssembly2.GetMethods().First((MethodInfo m) => m.Name == methodName);
                        result = (Action)Delegate.CreateDelegate(typeof(Action), method);
                    }
                    else if (itemType == typeof(Vector3))
                    {
                        result = ParseHelper.FromStringVector3(str);
                    }
                    else if (itemType == typeof(Vector2))
                    {
                        result = ParseHelper.FromStringVector2(str);
                    }
                    else if (itemType == typeof(Rect))
                    {
                        result = ParseHelper.FromStringRect(str);
                    }
                    else if (itemType == typeof(Color))
                    {
                        str = str.TrimStart(new char[]
                        {
                            '(',
                            'R',
                            'G',
                            'B',
                            'A'
                        });
                        str = str.TrimEnd(new char[]
                        {
                            ')'
                        });
                        string[] array2 = str.Split(new char[]
                        {
                            ','
                        });
                        float num  = (float)ParseHelper.FromString(array2[0], typeof(float));
                        float num2 = (float)ParseHelper.FromString(array2[1], typeof(float));
                        float num3 = (float)ParseHelper.FromString(array2[2], typeof(float));
                        bool  flag = num > 1f || num3 > 1f || num2 > 1f;
                        float num4 = (float)((!flag) ? 1 : 255);
                        if (array2.Length == 4)
                        {
                            num4 = (float)ParseHelper.FromString(array2[3], typeof(float));
                        }
                        Color color;
                        if (!flag)
                        {
                            color.r = num;
                            color.g = num2;
                            color.b = num3;
                            color.a = num4;
                        }
                        else
                        {
                            color = GenColor.FromBytes(Mathf.RoundToInt(num), Mathf.RoundToInt(num2), Mathf.RoundToInt(num3), Mathf.RoundToInt(num4));
                        }
                        result = color;
                    }
                    else if (itemType == typeof(PublishedFileId_t))
                    {
                        result = new PublishedFileId_t(ulong.Parse(str));
                    }
                    else if (itemType == typeof(IntVec2))
                    {
                        result = IntVec2.FromString(str);
                    }
                    else if (itemType == typeof(IntVec3))
                    {
                        result = IntVec3.FromString(str);
                    }
                    else if (itemType == typeof(Rot4))
                    {
                        result = Rot4.FromString(str);
                    }
                    else if (itemType == typeof(CellRect))
                    {
                        result = CellRect.FromString(str);
                    }
                    else
                    {
                        if (itemType != typeof(CurvePoint))
                        {
                            if (itemType == typeof(NameTriple))
                            {
                                NameTriple nameTriple = NameTriple.FromString(str);
                                nameTriple.ResolveMissingPieces(null);
                            }
                            else
                            {
                                if (itemType == typeof(FloatRange))
                                {
                                    result = FloatRange.FromString(str);
                                    return(result);
                                }
                                if (itemType == typeof(IntRange))
                                {
                                    result = IntRange.FromString(str);
                                    return(result);
                                }
                                if (itemType == typeof(QualityRange))
                                {
                                    result = QualityRange.FromString(str);
                                    return(result);
                                }
                                if (itemType == typeof(ColorInt))
                                {
                                    str = str.TrimStart(new char[]
                                    {
                                        '(',
                                        'R',
                                        'G',
                                        'B',
                                        'A'
                                    });
                                    str = str.TrimEnd(new char[]
                                    {
                                        ')'
                                    });
                                    string[] array3 = str.Split(new char[]
                                    {
                                        ','
                                    });
                                    ColorInt colorInt = new ColorInt(255, 255, 255, 255);
                                    colorInt.r = (int)ParseHelper.FromString(array3[0], typeof(int));
                                    colorInt.g = (int)ParseHelper.FromString(array3[1], typeof(int));
                                    colorInt.b = (int)ParseHelper.FromString(array3[2], typeof(int));
                                    if (array3.Length == 4)
                                    {
                                        colorInt.a = (int)ParseHelper.FromString(array3[3], typeof(int));
                                    }
                                    else
                                    {
                                        colorInt.a = 255;
                                    }
                                    result = colorInt;
                                    return(result);
                                }
                            }
                            throw new ArgumentException(string.Concat(new string[]
                            {
                                "Trying to parse to unknown data type ",
                                itemType.Name,
                                ". Content is '",
                                str,
                                "'."
                            }));
                        }
                        result = CurvePoint.FromString(str);
                    }
                }
            }
            catch (Exception innerException2)
            {
                ArgumentException ex2 = new ArgumentException(string.Concat(new object[]
                {
                    "Exception parsing ",
                    itemType,
                    " from \"",
                    str,
                    "\""
                }), innerException2);
                throw ex2;
            }
            return(result);
        }
Пример #15
0
        static private void nameOther()
        {
            Faction local_faction = localFaction();

            if (local_faction == null)
            {
                Verse.Log.Message("FACTION null");
                return;
            }


            IEnumerable <Pawn> others_pawns = from p in Verse.Find.CurrentMap.mapPawns.AllPawnsSpawned
                                              where !p.RaceProps.Animal && p.Name != null && !p.Name.Numerical
                                              select p;

            for (int i = 0; i < others_pawns.Count(); i++)
            {
                try {
                    if (others_pawns.ElementAt(i).Faction != local_faction &&
                        ((Verse.NameTriple)others_pawns.ElementAt(i).Name).First != "Twitch")
                    {
                        string name = getNameFromList();
                        if (name == null || name.Length == 0)
                        {
                            Verse.Log.Message("NO NAMES FOR OTHERS");
                            return;
                        }

                        Verse.NameTriple nametriple = new Verse.NameTriple("Twitch", name, "#" + name);
                        Verse.Log.Message("GIVE NAME (OTHER): " + nametriple.ToString());
                        others_pawns.ElementAt(i).Name = nametriple;
                        //Verse.Log.Message("TITLE: " + others_pawns.ElementAt(i).story.adul);
                    }
                }
                catch (System.Exception e) {
                    Verse.Log.Message("RENAME EXCEPTION " + e.ToString());
                }
            }

            //rename other pawns

            /*for (int i = 0; i < others_pawns.Count(); i++) {
             *
             * try {
             *    if (others_pawns.ElementAt(i).Faction != local_faction
             *    && ((Verse.NameTriple)others_pawns.ElementAt(i).Name).First != "Twitch") {
             *
             *       string one_name_str = "";
             *       bool found_name = false;
             *       for (int f = 0; f < namePool.Count(); f++) {
             *          one_name_str = namePool.ElementAt(f);
             *
             *          if (usedOtherNames.IndexOf(one_name_str) == -1) {
             *             found_name = true;
             *             break;
             *          }
             *       }
             *
             *       if (!found_name) {
             *          Verse.Log.Message("NO UNIQUE NAME FOR OTHERS");
             *          break;
             *       }
             *       usedOtherNames.Add(one_name_str);
             *
             *       string last = "";
             *       /*if (one_name_str == "BonjwaRedpanda") {
             *          others_pawns.ElementAt(i).skills.Learn(RimWorld.SkillDefOf.Shooting, 999999);
             *          last = "The Shooter";
             *
             *          others_pawns.ElementAt(i).story.traits.allTraits.Clear();
             *
             *          RimWorld.Trait shooter = new RimWorld.Trait(RimWorld.TraitDefOf.ShootingAccuracy, 1);
             *          others_pawns.ElementAt(i).story.traits.GainTrait(shooter);
             *
             *          RimWorld.Trait bloodlust = new RimWorld.Trait(RimWorld.TraitDefOf.Bloodlust);
             *          others_pawns.ElementAt(i).story.traits.GainTrait(bloodlust);
             *
             *          RimWorld.Trait beauty = new RimWorld.Trait(RimWorld.TraitDefOf.Beauty, 1);
             *          others_pawns.ElementAt(i).story.traits.GainTrait(beauty);
             *
             *          RimWorld.Trait sens = new RimWorld.Trait(RimWorld.TraitDefOf.PsychicSensitivity, 1);
             *          others_pawns.ElementAt(i).story.traits.GainTrait(sens);
             *       }
             *
             *       if (one_name_str == "Moobot") {
             *          others_pawns.ElementAt(i).skills.Learn(RimWorld.SkillDefOf.Melee, 999999);
             *          last = "will kill you with bare hands";
             *
             *          //strip to drop all weapons and meele fight
             *          others_pawns.ElementAt(i).Strip();
             *
             *          //give traits
             *          others_pawns.ElementAt(i).story.traits.allTraits.Clear();
             *
             *          RimWorld.Trait bloodlust = new RimWorld.Trait(RimWorld.TraitDefOf.Bloodlust);
             *          others_pawns.ElementAt(i).story.traits.GainTrait(bloodlust);
             *
             *          RimWorld.Trait tough = new RimWorld.Trait(RimWorld.TraitDefOf.Tough);
             *          others_pawns.ElementAt(i).story.traits.GainTrait(tough);
             *
             *          RimWorld.Trait brawler = new RimWorld.Trait(RimWorld.TraitDefOf.Brawler);
             *          others_pawns.ElementAt(i).story.traits.GainTrait(brawler);
             *
             *          RimWorld.Trait sens = new RimWorld.Trait(RimWorld.TraitDefOf.PsychicSensitivity, 1);
             *          others_pawns.ElementAt(i).story.traits.GainTrait(sens);
             *       }
             *
             *       if (one_name_str == "Kerrag") {
             *          others_pawns.ElementAt(i).skills.Learn(RimWorld.SkillDefOf.Cooking, 999999);
             *          last = "The Cook";
             *
             *
             *          //give traits
             *          others_pawns.ElementAt(i).story.traits.allTraits.Clear();
             *
             *          RimWorld.Trait sensitive = new RimWorld.Trait(RimWorld.TraitDefOf.PsychicSensitivity, 1);
             *          others_pawns.ElementAt(i).story.traits.GainTrait(sensitive);
             *
             *          RimWorld.Trait trans = new RimWorld.Trait(RimWorld.TraitDefOf.Transhumanist);
             *          others_pawns.ElementAt(i).story.traits.GainTrait(trans);
             *
             *          RimWorld.Trait indu = new RimWorld.Trait(RimWorld.TraitDefOf.Industriousness, 1);
             *          others_pawns.ElementAt(i).story.traits.GainTrait(indu);
             *       }
             *
             *
             *       if (one_name_str == "bonjwahonor") {
             *          others_pawns.ElementAt(i).skills.Learn(RimWorld.SkillDefOf.Social, 999999);
             *          last = "The Nice Guy";
             *
             *          //give traits
             *          others_pawns.ElementAt(i).story.traits.allTraits.Clear();
             *
             *          RimWorld.Trait greed = new RimWorld.Trait(RimWorld.TraitDefOf.Greedy);
             *          others_pawns.ElementAt(i).story.traits.GainTrait(greed);
             *
             *          RimWorld.Trait memory = new RimWorld.Trait(RimWorld.TraitDefOf.GreatMemory);
             *          others_pawns.ElementAt(i).story.traits.GainTrait(memory);
             *
             *          RimWorld.Trait kind = new RimWorld.Trait(RimWorld.TraitDefOf.Kind);
             *          others_pawns.ElementAt(i).story.traits.GainTrait(kind);
             *
             *          RimWorld.Trait pyro = new RimWorld.Trait(RimWorld.TraitDefOf.Pyromaniac);
             *          others_pawns.ElementAt(i).story.traits.GainTrait(pyro);
             *       }
             *
             *       if (one_name_str == "Neandi") {
             *          others_pawns.ElementAt(i).skills.Learn(RimWorld.SkillDefOf.Artistic, 999999);
             *          last = "The Artist";
             *
             *          //give traits
             *          others_pawns.ElementAt(i).story.traits.allTraits.Clear();
             *
             *          RimWorld.Trait drug = new RimWorld.Trait(RimWorld.TraitDefOf.DrugDesire, 1);
             *          others_pawns.ElementAt(i).story.traits.GainTrait(drug);
             *
             *          RimWorld.Trait ascet = new RimWorld.Trait(RimWorld.TraitDefOf.Ascetic);
             *          others_pawns.ElementAt(i).story.traits.GainTrait(ascet);
             *
             *          RimWorld.Trait nudist = new RimWorld.Trait(RimWorld.TraitDefOf.Nudist);
             *          others_pawns.ElementAt(i).story.traits.GainTrait(nudist);
             *
             *          RimWorld.Trait psycho = new RimWorld.Trait(RimWorld.TraitDefOf.Psychopath);
             *          others_pawns.ElementAt(i).story.traits.GainTrait(psycho);
             *       }*
             *
             *
             *       Verse.Log.Message("GIVE NAME (OTHER): " + one_name_str);
             *       Verse.NameTriple nametriple = new Verse.NameTriple("Twitch", one_name_str, last);
             *       others_pawns.ElementAt(i).Name = nametriple;
             *    }
             * }
             * catch (System.Exception) {
             *    Verse.Log.Message("RENAME EXCEPTION ");
             * }
             * }*/
        }