예제 #1
0
        private static MobRenameInfo EnsureRegisterRenameInfo(Serial serial)
        {
            lock (renameHtLock)
            {
                if (renamedHt[serial] == null)
                {
                    renamedHt[serial] = new MobRenameInfo();
                    ((MobRenameInfo)renamedHt[serial]).Serial             = serial;
                    ((MobRenameInfo)renamedHt[serial]).Character          = new UOCharacter(serial);
                    ((MobRenameInfo)renamedHt[serial]).Character.Changed += RenameInfoCharacterChange;
                }
            }

            return((MobRenameInfo)renamedHt[serial]);
        }
예제 #2
0
        //---------------------------------------------------------------------------------------------

        private static void RenameInfoCharacterChange(object sender, ObjectChangedEventArgs e)
        {
            if (Game.Debug)
            {
                Game.PrintMessage("!RenameInfoCharacterChange");
            }

            UOCharacter ch = new UOCharacter(e.Serial);

            if (ch.Distance > 30 || ch.Distance < 0)
            {
                lock (renameHtLock)
                {
                    if (renamedHt[e.Serial] != null)
                    {
                        MobRenameInfo info = (MobRenameInfo)renamedHt[e.Serial];
                        info.Character.Changed -= RenameInfoCharacterChange;
                        renamedHt[e.Serial]     = info = null;
                    }
                }
            }
        }
예제 #3
0
        public static MobRenameInfo RenameCharacter(Serial serial, int maxTries)
        {
            UOCharacter   ch         = new UOCharacter(serial);
            MobRenameInfo renameInfo = EnsureRegisterRenameInfo(serial);//Game.renamedHt[serial] != null ? (MobRenameInfo)Game.renamedHt[serial] : new MobRenameInfo();

            if (renameInfo.Success || renameInfo.Tries >= maxTries)
            {
                return(renameInfo);
            }

            renameInfo.Tries++;

            bool check = false;

            check = !String.IsNullOrEmpty(ch.Name);

            if (!check)
            {
                if (Game.Debug)
                {
                    Game.PrintMessage("Rename Check - Name EMPTY");
                }
                check = ch.RequestStatus(250 + Core.CurrentLatency);
            }

            if (!check)
            {
                if (Game.Debug)
                {
                    Game.PrintMessage("Rename Check - !RequestStatus");
                }

                ch.Click();
                Game.Wait(150);
                check = !String.IsNullOrEmpty(ch.Name) && ch.RequestStatus(250);
            }

            renameInfo.OriginalName = ch.Name;

            if (check)
            {
                string playerCode = Rename.PlayerShortCode;

                if ((ch.Name + String.Empty).StartsWith(playerCode))
                {
                    renameInfo.NewName = ch.Name;
                    renameInfo.Success = true;
                }
                else if (ch.Renamable || Game.IsPossibleMob(ch) && ch.Distance <= 4)//Uvidime, ty klamaky nejak casti blbnou oproti summum
                {
                    var chars  = "abcdefghijklmnopqrstuvwxyz1234567890";
                    var random = new Random();
                    var result = new string(
                        Enumerable.Repeat(chars, 5)
                        .Select(s => s[random.Next(s.Length)])
                        .ToArray());

                    result = playerCode + result;
                    if (result.Length > 1)
                    {
                        result = result.Substring(0, result.Length - 2) + result[result.Length - 2].ToString().ToUpper() + result[result.Length - 1].ToString().ToUpper();
                    }
                    renameInfo.NewName = result;
                    renameInfo.Success = ch.Rename(result);


                    if (Game.Debug)
                    {
                        Game.PrintMessage("Rename : " + renameInfo.Success + " [" + result + "]/[" + renameInfo.OriginalName + "]");
                    }

                    Game.Wait(Core.CurrentLatency);

                    if (renameInfo.Success)
                    {
                        byte[] data = PacketBuilder.CharacterSpeechUnicode(ch.Serial, ch.Model, result, SpeechType.Regular,
                                                                           SpeechFont.Normal, Game.Val_PureWhite,
                                                                           "[ " + result + " ]");
                        Core.SendToClient(data, true);
                    }
                }
            }
            else if (Game.Debug)
            {
                Game.PrintMessage("!Rename Check");
            }

            if (renameInfo.Success)
            {
                new StatusBar().Show(ch.Serial);
            }

            return(renameInfo);
        }