Пример #1
0
 public CornerEntity(CornerModel corner)
 {
     Data = corner;
 }
        public void AddCorner(Client sender, string ids)
        {
            List <string> botIds = ids.Split(',').ToList();

            //Sprawdzamy czy gracz podał prawidłowe ID NPC
            if (!CornerBotHelper.TryGetCornerBotIds(botIds, out List <int> correctBotIds))
            {
                sender.SendError("Podano dane w nieprawidłowym formacie. Lub podany NPC nie istnieje.");
                return;
            }

            sender.SendInfo("Ustaw się w wybranej pozycji, a następnie wpisz \"tu\". użyj ctrl + shift + alt + d aby poznać swoją obecną pozycję.");

            FullPosition        position     = null;
            List <FullPosition> botPositions = new List <FullPosition>();

            void Handler(Client o, string message)
            {
                if (position == null && o == sender && message == "tu")
                {
                    position = new FullPosition
                    {
                        Position = new Vector3
                        {
                            X = sender.Position.X,
                            Y = sender.Position.Y,
                            Z = sender.Position.Z - 0.5f
                        },

                        Rotation = new Vector3
                        {
                            X = sender.Rotation.X,
                            Y = sender.Rotation.Y,
                            Z = sender.Rotation.Z
                        }
                    };

                    sender.SendInfo("Wyznacz trasę npc na rogu. Ustaw się w danym punkcie i wpisz \"poz\".");
                    sender.SendInfo("Aby zacząć od nowa wpisz \"reset\"");
                    sender.SendInfo("Aby usunąć ostatnią pozycję wpisz \"usun\"");
                }
                else if (position != null && o == sender && message == "/poz")
                {
                    botPositions.Add(new FullPosition
                    {
                        Position = new Vector3
                        {
                            X = sender.Position.X,
                            Y = sender.Position.Y,
                            Z = sender.Position.Z
                        },

                        Rotation = new Vector3
                        {
                            X = sender.Rotation.X,
                            Y = sender.Rotation.Y,
                            Z = sender.Rotation.Z
                        }
                    });

                    sender.SendInfo($"Obecna liczba punktów: {botPositions.Count}. Aby zakończyć wpisz \"zakoncz\"");
                    sender.SendInfo("Aby zacząć od nowa wpisz /reset");
                }
                else if (position != null && botPositions.Count != 0 && o == sender && message == "zakoncz")
                {
                    CornerModel data = new CornerModel
                    {
                        CreatorForumName = o.GetAccountEntity().DbModel.Name,
                        Position         = position,
                        CornerBots       = XmlHelper.GetXmlObjects <CornerBotModel>(Path.Combine(Utils.XmlDirectory, "CornerBots"))
                                           .Where(bot => correctBotIds.Contains(bot.BotId)).ToList(),
                        BotPositions = botPositions
                    };
                    //Dodajemy nowy plik .xml
                    XmlHelper.AddXmlObject(data, Path.Combine(Utils.XmlDirectory, "Corners"));
                    CornerEntity corner = new CornerEntity(data);
                    Corners.Add(corner);

                    sender.SendInfo("Dodawanie rogu zakończyło się pomyślnie.");
                }
                else if (botPositions.Count != 0 && position != null && o == sender && message == "usun")
                {
                    botPositions.RemoveAt(botPositions.Count);
                }
                else if (botPositions.Count != 0 && position != null && o == sender && message == "reset")
                {
                    position     = null;
                    botPositions = new List <FullPosition>();
                    sender.SendInfo("Ustaw się w wybranej pozycji, a następnie wpisz \"tu\".");
                    sender.SendInfo("...użyj /diag aby poznać swoją obecną pozycję.");
                }
            };
        }