Пример #1
0
        private static void HandleCommands()
        {
            DeleteMenu(GetSystemMenu(GetConsoleWindow(), false), SC_CLOSE, MF_BYCOMMAND);

            string command;

            do
            {
                command = Console.ReadLine();
                if (!string.IsNullOrEmpty(command))
                {
                    string[] pCom = command.Split(' ');
                    switch (pCom[0])
                    {
                    case "maintenance":
                    {
                        if (pCom.Length < 2)
                        {
                            continue;
                        }

                        int nTime = 0;

                        if (!int.TryParse(pCom[1], out nTime))
                        {
                            continue;
                        }

                        bool bRestart = true;

                        if (pCom.Length > 2)
                        {
                            var nRestart = 0;
                            if (!int.TryParse(pCom[2], out nRestart))
                            {
                                continue;
                            }
                            bRestart = nRestart > 0;
                        }

                        ThreadHandler.SetMaintenance(nTime, bRestart);
                        break;
                    }

                    case "cancelmaintenance":
                    {
                        ThreadHandler.CancelMaintenance();
                        break;
                    }

                    case "count_gen":
                    {
                        int    nCount = 0;
                        string szMap  = "undefined";
                        break;
                    }

                    case "cls":
                    case "clear":
                        Console.Clear();
                        break;

                    case "syninscribeall":
                    {
                        foreach (var syn in ServerKernel.Syndicates.Values)
                        {
                            foreach (var synMember in syn.Members.Values)
                            {
                                var dbUser = Database.Characters.SearchByIdentity(synMember.Identity);
                                if (dbUser == null)
                                {
                                    continue;
                                }
                                var allItems = Database.Items.FetchByUser(synMember.Identity);
                                if (allItems == null)
                                {
                                    continue;
                                }
                                foreach (var item in allItems)
                                {
                                    Item         pItem = new Item(null, item);
                                    ItemPosition pos   = Calculations.GetItemPosition(pItem.Type);
                                    switch (pos)
                                    {
                                    case ItemPosition.HEADWEAR:
                                    case ItemPosition.NECKLACE:
                                    case ItemPosition.RING:
                                    case ItemPosition.RIGHT_HAND:
                                    case ItemPosition.LEFT_HAND:
                                    case ItemPosition.ARMOR:
                                    case ItemPosition.BOOTS:
                                    case ItemPosition.ATTACK_TALISMAN:
                                    case ItemPosition.DEFENCE_TALISMAN:
                                    {
                                        if (!syn.Arsenal.Poles.ContainsKey(Arsenal.GetArsenalType(pos)))
                                        {
                                            continue;
                                        }
                                        Totem totem = new Totem(new DbSyntotem
                                                {
                                                    Itemid   = pItem.Identity,
                                                    Synid    = syn.Identity,
                                                    Userid   = synMember.Identity,
                                                    Username = dbUser.Name
                                                }, pItem);
                                        totem.Save();
                                        if (syn.Arsenal.AddItem(pItem, totem))
                                        {
                                            Console.WriteLine("{0} has inscribed gear {1} on syndicate {2}.",
                                                              dbUser.Name, pItem.Itemtype.Name, syn.Name);
                                        }
                                        continue;
                                    }

                                    default:
                                        continue;
                                    }
                                }
                            }
                        }
                        break;
                    }

                    case "fixpointallot":
                    {
                        var allUser = new CharacterRepository().FetchAll();
                        foreach (var user in allUser)
                        {
                            if (user.Metempsychosis < 1 || user.Level < 15)
                            {
                                continue;
                            }

                            int prof = (int)(user.Profession >= 100 ? 10 : ((user.Profession - (user.Profession % 10)) / 10));
                            if (prof > 10)
                            {
                                prof = 10;
                            }
                            var pData = ServerKernel.PointAllot.Values.FirstOrDefault(x => x.Profession == prof && x.Level == 1);
                            if (pData == null)
                            {
                                Console.WriteLine("Could not fetch attribute points data. ResetAttrPoints for user {0}", user.Identity);
                                continue;
                            }

                            user.Strength = pData.Strength;
                            user.Agility  = pData.Agility;
                            user.Vitality = pData.Vitality;
                            user.Spirit   = pData.Spirit;

                            ushort usAdd = 0;
                            if (user.Metempsychosis == 1)
                            {
                                usAdd  = (ushort)(30 + Math.Min((1 + (130 - 120)) * (130 - 120) / 2, 55));
                                usAdd += (ushort)((user.Level - 15) * 3);
                            }
                            else if (user.Metempsychosis == 2)
                            {
                                //byte firstMetempsychosisLev = (byte)((user.MeteLevel - (user.MeteLevel % 10000)) / 10000);
                                usAdd  = (ushort)(30 + Math.Min((1 + (130 - 120)) * (130 - 120) / 2, 55));
                                usAdd += (ushort)(52 + Math.Min((1 + (130 - 120)) * (130 - 120) / 2, 55));
                                usAdd += (ushort)((user.Level - 15) * 3);
                            }
                            user.AdditionalPoints = (ushort)(usAdd - 10);
                            Database.Characters.SaveOrUpdate(user);
                            Console.WriteLine(
                                "User(prof:{9}, id:{0}, name:{1}, str:{2}, agi:{3}, vit:{4}, spi:{5}, add:{8}, metem:{6}, level: {7}) updated",
                                user.Identity, user.Name, user.Strength, user.Agility, user.Vitality, user.Spirit,
                                user.Metempsychosis, user.Level, user.AdditionalPoints, prof);
                        }
                        Console.WriteLine("Finished...");
                        break;
                    }
                    }
                }
            } while (command != "close");
        }