Пример #1
0
        public static DynamicElement Clone(DynamicElement element)
        {
            DynamicElement newElement = new DynamicElement
            {
                elementName         = element.elementName,
                x_left              = element.x_left,
                x_right             = element.x_right,
                y                   = element.y,
                rotateDegreeCurrent = element.rotateDegreeCurrent,
                startDegree         = element.startDegree,
                mirror              = element.mirror,
                background          = element.background,
                slowRotation        = element.slowRotation,
                backSide            = element.backSide,
                currentSide         = element.currentSide,
                movingType          = element.movingType,
                oneWay              = element.oneWay,
                positiveDirection   = element.positiveDirection
            };

            return(newElement);
        }
Пример #2
0
        public void Launch(double?startX = null, double?startY        = null, FlightDirectionType?startDirection = null,
                           bool dead     = false, bool transformation = false, bool suspended = false, bool swarm = false)
        {
            if (!transformation && (!Shilka.training || !cloud))
            {
                allAircraftsInGame += 1;
            }

            Application.Current.Dispatcher.BeginInvoke(new ThreadStart(delegate
            {
                FirePlace main = (FirePlace)Application.Current.MainWindow;

                zIndexType?zIndex = null;

                Image newAircraftImage = new Image
                {
                    Width  = size[0],
                    Height = size[1]
                };

                Aircraft newAircraft = Clone();

                newAircraft.dead = dead;

                newAircraft.suspendedTarget = suspended;

                newAircraft.y = startY ?? rand.Next(maxAltitudeGlobal, Aircrafts.minAltitudeGlobal);

                if ((newAircraft.minAltitude != -1) && (newAircraft.y > newAircraft.minAltitude))
                {
                    newAircraft.y = newAircraft.minAltitude;
                }

                FlightDirectionType newDirection = startDirection ?? (Functions.TossACoin() ? FlightDirectionType.Right : FlightDirectionType.Left);

                if ((Weather.currentWeather == Weather.WeatherTypes.storm) && cloud)
                {
                    newDirection = Weather.stormDirection;
                }

                if ((Shilka.currentScript == Scripts.ScriptsNames.Belgrad) && !cloud)
                {
                    if (friend)
                    {
                        newDirection = FlightDirectionType.Right;
                    }
                    else
                    {
                        newDirection = FlightDirectionType.Left;
                    }
                }

                newAircraft.flightDirection = newDirection;

                int swarmDistance = (swarm ? rand.Next(20, Constants.UAV_SWARM_DISTANCE) : 0);

                if (newDirection == FlightDirectionType.Right)
                {
                    newAircraft.x = -1 * newAircraftImage.Width - swarmDistance;
                }
                else
                {
                    newAircraft.x = Application.Current.MainWindow.Width + swarmDistance;
                }

                newAircraft.x = startX ?? newAircraft.x;

                newAircraftImage.Source = Functions.ImageFromResources(
                    imageName: aircraftType,
                    type: (newAircraft.cloud ? ImageType.Other : ImageType.Aircraft)
                    );

                bool flightLeftAndNotCloud = (newAircraft.flightDirection == FlightDirectionType.Left) && !cloud;
                bool flightRightAndCloud   = Functions.TossACoin() && cloud;

                if (flightLeftAndNotCloud || flightRightAndCloud)
                {
                    newAircraftImage.FlowDirection = FlowDirection.RightToLeft;
                }

                newAircraftImage.Margin = new Thickness(newAircraft.x, newAircraft.y, 0, 0);

                if ((elements != null) && (elements.Count > 0))
                {
                    zIndex = (rand.Next(2) > 0 ? zIndexType.inFront : zIndexType.Behind);

                    foreach (DynamicElement d in elements)
                    {
                        DynamicElement tmp = DynamicElement.Clone(d);
                        tmp.element        = new Image
                        {
                            Margin = new Thickness(newAircraft.x, newAircraft.y, 0, 0),
                            Source = Functions.ImageFromResources(d.elementName, ImageType.DynamicElement)
                        };
                        tmp.rotateDegreeCurrent = d.startDegree;

                        if ((newAircraft.flightDirection == FlightDirectionType.Right) && !d.mirror)
                        {
                            tmp.element.FlowDirection = FlowDirection.RightToLeft;
                        }
                        else if ((newAircraft.flightDirection == FlightDirectionType.Left) && d.mirror)
                        {
                            tmp.element.FlowDirection = FlowDirection.RightToLeft;
                        }

                        newAircraft.dynamicElemets.Add(tmp);

                        bool flightRightAndZRotate = (
                            (newAircraft.flightDirection == FlightDirectionType.Right)
                            &&
                            (d.movingType == DynamicElement.MovingType.zRotate)
                            );

                        int newZIndex = 0;
                        bool inFront  = (zIndex == zIndexType.inFront);

                        if (d.background || flightRightAndZRotate)
                        {
                            newZIndex = (inFront ? 65 : 25);
                        }
                        else if (newAircraft.flightDirection == FlightDirectionType.Right)
                        {
                            newZIndex = (inFront ? 85 : 45);
                        }
                        else
                        {
                            newZIndex = (inFront ? 75 : 35);
                        }

                        Canvas.SetZIndex(tmp.element, newZIndex);

                        main.firePlace.Children.Add(tmp.element);
                    }
                }

                int randomSpeed = (cloud ? 0 : rand.Next(3));

                newAircraft.speed = (speed < 1 ? Constants.STANDART_SPEED : speed) + randomSpeed;

                if ((Shilka.currentScript == Scripts.ScriptsNames.Khmeimim) && !friend && !airliner && !cloud)
                {
                    speed = Constants.UAC_SWARM_SPEED;
                }

                if (newAircraft.minAltitude == -1)
                {
                    newAircraft.minAltitude = Aircrafts.minAltitudeGlobal;
                }

                if (((!friend && !airliner) || (Shilka.training && !cloud && friend)) && !transformation)
                {
                    Statistic.NewAircraftAdd(this);
                }

                if (suspended)
                {
                    Canvas.SetZIndex(newAircraftImage, 101);
                }
                else if (zIndex != null)
                {
                    int newZIndex = 0;
                    bool inFront  = (zIndex == zIndexType.inFront);

                    if (newAircraft.flightDirection == FlightDirectionType.Right)
                    {
                        newZIndex = (inFront ? 80 : 40);
                    }
                    else
                    {
                        newZIndex = (inFront ? 70 : 30);
                    }

                    Canvas.SetZIndex(newAircraftImage, newZIndex);
                }
                else
                {
                    Canvas.SetZIndex(newAircraftImage, (cloud ? 100 : 50));
                }

                if (Shilka.school || !cloud)
                {
                    Label aircraftLabelName = new Label
                    {
                        Content = newAircraft.GetAircraftFullName()
                    };
                    newAircraft.aircraftSchoolName = aircraftLabelName;

                    Brush labelNameColor = null;

                    if (airliner)
                    {
                        labelNameColor = Brushes.Blue;
                    }
                    else if (friend)
                    {
                        labelNameColor = Brushes.Green;
                    }
                    else
                    {
                        labelNameColor = Brushes.Red;
                    }

                    newAircraft.aircraftSchoolName.Foreground = labelNameColor;

                    Canvas.SetZIndex(aircraftLabelName, Canvas.GetZIndex(newAircraftImage));
                    main.firePlace.Children.Add(aircraftLabelName);

                    if (!airliner && !friend)
                    {
                        Label aircraftLabelPrice = new Label
                        {
                            Content = GetAircraftPriceLine()
                        };
                        newAircraft.aircraftSchoolPrice            = aircraftLabelPrice;
                        newAircraft.aircraftSchoolPrice.Foreground = Brushes.Gray;
                        Canvas.SetZIndex(aircraftLabelPrice, Canvas.GetZIndex(newAircraftImage));
                        main.firePlace.Children.Add(aircraftLabelPrice);
                    }
                }

                if (Shilka.school && !newAircraft.cloud)
                {
                    newAircraft.MessagesForSchool(main);
                }

                if (Shilka.training)
                {
                    newAircraft.MessageForTraining(main);
                }

                newAircraft.aircraftImage = newAircraftImage;
                main.firePlace.Children.Add(newAircraftImage);
                aircrafts.Add(newAircraft);
            }));
        }