コード例 #1
0
ファイル: Game1.cs プロジェクト: TheRioMiner/Rio-WoW-Radar
        protected override void Draw(GameTime gameTime)
        {
            float RadarZoom = settings.RadarZoom;

            Stopwatch drawTime = Stopwatch.StartNew();

            GraphicsDevice.Clear(Color.CornflowerBlue);
            spriteBatch.Begin();

            //Рисуем миникарту
            //spriteBatch.DrawMinimapOverlay(scanner.MyPlayer);

            //Отрисовываем гуи если в мире и мышка под меню
            if (!GUI.MouseOver | !(HasConnected & HasInWorld))
            {
                if (HasConnected)
                {
                    if (HasInWorld)
                    {
                        //Реинициализируем адресса, если что-то пошло не так
                        {
                            if (LastGameState != 3)
                            {
                                scanner.InitAddresses();
                            }

                            LastGameState = 3;
                        }



                        #region  Отрисовка руд, трав и объектов из базы данных!!
                        {
                            #region  Отрисовка руды из бд
                            {
                                if (settings.ores.Find)                                    //Если ищем с бд
                                {
                                    if (DB.database.Ores.ZoneExist(scanner.CurrentZoneID)) //Если есть хоть что-то в этой зоне
                                    {
                                        for (int i = 0; i < DB.database.Ores.OresDict[scanner.CurrentZoneID].Count; i++)
                                        {
                                            //Бережно берем из списка
                                            DataBase.cOres.Ore ore;
                                            try { ore = DB.database.Ores.OresDict[scanner.CurrentZoneID][i] as DataBase.cOres.Ore; }
                                            catch { continue; }


                                            //Если руда в радиусе прорисовки
                                            Vector2 orePos = new Vector2(ore.Position.X, ore.Position.Y);
                                            Vector2 imPos  = new Vector2(scanner.MyPlayer.XPos, scanner.MyPlayer.YPos);
                                            if (Tools.Vec.InRadius(orePos, imPos, (DB.database.Ores.MaxSeeDistance * 2)))
                                            {
                                                bool breaked = false;
                                                foreach (Radar.OtherObject obj in scanner.Objects)
                                                {
                                                    if (Enums.ObjDB.HasOre(obj.ObjectId))
                                                    {
                                                        if (Tools.Vec.InRadius(orePos, new Vector2(obj.XPos, obj.YPos), settings.nodes.RadiusCheck))
                                                        {
                                                            breaked = true;
                                                            break;
                                                        }
                                                    }
                                                }

                                                if (!breaked)
                                                {
                                                    int   XPos          = (int)((imPos.X - orePos.X) * RadarZoom + RadarWidth / 2);
                                                    int   YPos          = (int)((imPos.Y - orePos.Y) * RadarZoom + RadarHeight / 2);
                                                    float DistanceToOre = Vector2.Distance(orePos, imPos);

                                                    if (DistanceToOre < (ore.MaxSeeDistance / 1.5f))
                                                    {
                                                        float     Zoom          = RadarZoom / 4;
                                                        float     divide_factor = settings.nodes.NotExist_DivideFactor;
                                                        int       NodeSize      = (int)((settings.nodes.Size * Zoom) / divide_factor);
                                                        Color     textureColor  = Tools.GetOpacity(Color.Red, 96);
                                                        Color     textColor     = Tools.GetOpacity(Color.Red, 200);
                                                        Rectangle TextureDest   = new Rectangle(XPos, YPos, NodeSize, NodeSize);

                                                        spriteBatch.DrawTexture("other_notexist_node", TextureDest, textureColor);
                                                        spriteBatch.DrawText(ore.Name, new Vector2(XPos, YPos + NodeSize), (settings.ores.FontSize / divide_factor), textColor);
                                                    }
                                                    else
                                                    {
                                                        float     Zoom        = RadarZoom / 4;
                                                        int       NodeSize    = (int)(settings.nodes.Size * Zoom);
                                                        Rectangle TextureDest = new Rectangle(XPos, YPos, NodeSize, NodeSize);

                                                        spriteBatch.DrawTexture("other_notsee_node", TextureDest, Color.DarkRed);
                                                        spriteBatch.DrawText(ore.Name, new Vector2(XPos, YPos + NodeSize), settings.ores.FontSize, Color.DarkRed);
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            #endregion


                            #region  Отрисовка травы из бд
                            {
                                if (settings.herbs.Find)                                    //Если ищем с бд
                                {
                                    if (DB.database.Herbs.ZoneExist(scanner.CurrentZoneID)) //Если есть хоть что-то в этой зоне
                                    {
                                        for (int i = 0; i < DB.database.Herbs.HerbDict[scanner.CurrentZoneID].Count; i++)
                                        {
                                            //Бережно берем из списка
                                            DataBase.cHerbs.Herb herb;
                                            try { herb = DB.database.Herbs.HerbDict[scanner.CurrentZoneID][i] as DataBase.cHerbs.Herb; }
                                            catch { continue; }


                                            //Если трава в радиусе прорисовки
                                            Vector2 herbPos = new Vector2(herb.Position.X, herb.Position.Y);
                                            Vector2 imPos   = new Vector2(scanner.MyPlayer.XPos, scanner.MyPlayer.YPos);
                                            if (Tools.Vec.InRadius(herbPos, imPos, (DB.database.Herbs.MaxSeeDistance * 2)))
                                            {
                                                bool breaked = false;
                                                foreach (Radar.OtherObject obj in scanner.Objects)
                                                {
                                                    if (Enums.ObjDB.HasHerb(obj.ObjectId))
                                                    {
                                                        if (Tools.Vec.InRadius(herbPos, new Vector2(obj.XPos, obj.YPos), settings.nodes.RadiusCheck))
                                                        {
                                                            breaked = true;
                                                            break;
                                                        }
                                                    }
                                                }

                                                if (!breaked)
                                                {
                                                    int   XPos           = (int)((imPos.X - herbPos.X) * RadarZoom + RadarWidth / 2);
                                                    int   YPos           = (int)((imPos.Y - herbPos.Y) * RadarZoom + RadarHeight / 2);
                                                    float DistanceToHerb = Vector2.Distance(herbPos, imPos);

                                                    if (DistanceToHerb < 5)
                                                    {
                                                    }

                                                    if (DistanceToHerb < (herb.MaxSeeDistance / 1.5f))
                                                    {
                                                        float     Zoom          = RadarZoom / 4;
                                                        float     divide_factor = settings.nodes.NotExist_DivideFactor;
                                                        int       NodeSize      = (int)((settings.nodes.Size * Zoom) / divide_factor);
                                                        Color     textureColor  = Tools.GetOpacity(Color.Red, 96);
                                                        Color     textColor     = Tools.GetOpacity(Color.Red, 200);
                                                        Rectangle TextureDest   = new Rectangle(XPos, YPos, NodeSize, NodeSize);

                                                        spriteBatch.DrawTexture("other_notexist_node", TextureDest, textureColor);
                                                        spriteBatch.DrawText(herb.Name, new Vector2(XPos, YPos + NodeSize), (settings.herbs.FontSize / divide_factor), textColor);
                                                    }
                                                    else
                                                    {
                                                        float     Zoom        = RadarZoom / 4;
                                                        int       NodeSize    = (int)(settings.nodes.Size * Zoom);
                                                        Rectangle TextureDest = new Rectangle(XPos, YPos, NodeSize, NodeSize);

                                                        spriteBatch.DrawTexture("other_notsee_node", TextureDest, Color.DarkRed);
                                                        spriteBatch.DrawText(herb.Name, new Vector2(XPos, YPos + NodeSize), settings.herbs.FontSize, Color.DarkRed);
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            #endregion


                            #region Отрисовка редких объектов из бд
                            {
                                if (settings.rareobjects.Find | settings.otherobjects.Draw)   //Если ищем с бд
                                {
                                    if (DB.database.Objects.ZoneExist(scanner.CurrentZoneID)) ////Если есть хоть что-то в этой зоне
                                    {
                                        for (int i = 0; i < DB.database.Objects.ObjectsDict[scanner.CurrentZoneID].Count; i++)
                                        {
                                            //Бережно берем из списка
                                            DataBase.cObjects.Object abject;
                                            try { abject = DB.database.Objects.ObjectsDict[scanner.CurrentZoneID][i] as DataBase.cObjects.Object; }
                                            catch { continue; }


                                            //Если трава в радиусе прорисовки
                                            Vector2 objPos = new Vector2(abject.Position.X, abject.Position.Y);
                                            Vector2 imPos  = new Vector2(scanner.MyPlayer.XPos, scanner.MyPlayer.YPos);
                                            if (Tools.Vec.InRadius(objPos, imPos, (DB.database.Herbs.MaxSeeDistance * 2)))
                                            {
                                                bool breaked = false;
                                                foreach (Radar.OtherObject obj in scanner.Objects)
                                                {
                                                    if (Enums.ObjDB.HasRareObject(obj.ObjectId))
                                                    {
                                                        if (Tools.Vec.InRadius(objPos, new Vector2(obj.XPos, obj.YPos), settings.nodes.RadiusCheck))
                                                        {
                                                            breaked = true;
                                                            break;
                                                        }
                                                    }
                                                    else
                                                    {
                                                        bool hasOre       = Enums.ObjDB.HasOre(obj.ObjectId);
                                                        bool hasHerb      = Enums.ObjDB.HasHerb(obj.ObjectId);
                                                        bool hasRare      = Enums.ObjDB.HasRareObject(obj.ObjectId);
                                                        bool hasBlacklist = Enums.ObjDB.HasInBlackList(obj.ObjectId);

                                                        if (!hasOre & !hasHerb & !hasRare & !hasBlacklist) //Если это обычный объект
                                                        {
                                                            breaked = true;
                                                            break;
                                                        }
                                                    }
                                                }

                                                if (!breaked)
                                                {
                                                    Enums.Name_And_TextureName finded = new Enums.Name_And_TextureName();

                                                    //Если отрисовываемый объект не обычный, а редкий
                                                    if (Enums.ObjDB.GetRareObject(abject.ID, ref finded))
                                                    {
                                                        int   XPos             = (int)((imPos.X - objPos.X) * RadarZoom + RadarWidth / 2);
                                                        int   YPos             = (int)((imPos.Y - objPos.Y) * RadarZoom + RadarHeight / 2);
                                                        float DistanceToObject = Vector2.Distance(objPos, imPos);
                                                        Color randomColor      = Tools.GetRandomColor(random);

                                                        if (DistanceToObject < (abject.MaxSeeDistance / 1.5f))
                                                        {
                                                            float     Zoom          = RadarZoom / 4;
                                                            float     divide_factor = settings.nodes.NotExist_DivideFactor;
                                                            int       NodeSize      = (int)((settings.nodes.Size * Zoom) / divide_factor);
                                                            Color     textureColor  = Tools.GetOpacity(Color.Red, 96);
                                                            Color     textColor     = Tools.GetOpacity(Color.Red, 200);
                                                            Rectangle TextureDest   = new Rectangle(XPos, YPos, NodeSize, NodeSize);

                                                            spriteBatch.DrawTexture("other_notexist_node", TextureDest, textureColor);
                                                            spriteBatch.DrawText(finded.name, new Vector2(XPos, YPos + NodeSize), (settings.rareobjects.FontSize / divide_factor), textColor);
                                                        }
                                                        else
                                                        {
                                                            float     Zoom        = RadarZoom / 4;
                                                            int       NodeSize    = (int)(settings.nodes.Size * Zoom);
                                                            Rectangle TextureDest = new Rectangle(XPos, YPos, NodeSize, NodeSize);

                                                            spriteBatch.DrawTexture("other_notsee_node", TextureDest, randomColor);
                                                            spriteBatch.DrawText(finded.name, new Vector2(XPos, YPos + NodeSize), settings.rareobjects.FontSize, randomColor);
                                                        }
                                                    }
                                                    else  //Для обычных объектов
                                                    {
                                                        if (settings.otherobjects.Draw)
                                                        {
                                                            int    XPos             = (int)((imPos.X - objPos.X) * RadarZoom + RadarWidth / 2);
                                                            int    YPos             = (int)((imPos.Y - objPos.Y) * RadarZoom + RadarHeight / 2);
                                                            float  DistanceToObject = Vector2.Distance(objPos, imPos);
                                                            string id = abject.ID.ToString();

                                                            if (DistanceToObject < (abject.MaxSeeDistance / 1.5f))
                                                            {
                                                                float     Zoom          = RadarZoom / 4;
                                                                float     divide_factor = settings.nodes.NotExist_DivideFactor;
                                                                int       NodeSize      = (int)((settings.nodes.Size * Zoom) / divide_factor);
                                                                Color     textureColor  = Tools.GetOpacity(settings.otherobjects.Color, 96);
                                                                Color     textColor     = Tools.GetOpacity(settings.otherobjects.Color, 200);
                                                                Rectangle TextureDest   = new Rectangle(XPos, YPos, NodeSize, NodeSize);

                                                                spriteBatch.DrawTexture("other_notexist_node", TextureDest, textureColor);
                                                                spriteBatch.DrawText(id, new Vector2(XPos, YPos + NodeSize), (settings.otherobjects.FontSize / divide_factor), textColor);
                                                            }
                                                            else
                                                            {
                                                                float     Zoom        = RadarZoom / 4;
                                                                int       NodeSize    = (int)(settings.nodes.Size * Zoom);
                                                                Rectangle TextureDest = new Rectangle(XPos, YPos, NodeSize, NodeSize);

                                                                spriteBatch.DrawTexture("other_notsee_node", TextureDest, Color.DarkRed);
                                                                spriteBatch.DrawText(id, new Vector2(XPos, YPos + NodeSize), settings.otherobjects.FontSize, Color.DarkRed);
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            #endregion
                        }
                        #endregion



                        #region Отрисовка объектов которые видим
                        foreach (Radar.OtherObject obj in scanner.Objects)
                        {
                            Enums.Name_And_TextureName finded = new Enums.Name_And_TextureName();
                            if (Enums.ObjDB.GetHerb(obj.ObjectId, ref finded)) //Если это травка
                            {
                                if (settings.herbs.Draw)                       //Если отрисовываем травы, то рисуем уже
                                {
                                    float XPos = (scanner.MyPlayer.XPos - obj.XPos) * RadarZoom + RadarWidth / 2;
                                    float YPos = (scanner.MyPlayer.YPos - obj.YPos) * RadarZoom + RadarHeight / 2;

                                    int       Size        = settings.herbs.Size;
                                    Rectangle TextureDest = new Rectangle((int)XPos, (int)YPos, Size, Size);

                                    spriteBatch.DrawTexture(finded.textureName, TextureDest);
                                    spriteBatch.DrawText(finded.name, new Vector2(XPos, YPos + Size), settings.herbs.FontSize, settings.herbs.Color);
                                }
                            }
                            else if (Enums.ObjDB.GetOre(obj.ObjectId, ref finded)) //Если это руда
                            {
                                if (settings.ores.Draw)                            //Если отрисовываем травы, то рисуем уже
                                {
                                    float XPos = (scanner.MyPlayer.XPos - obj.XPos) * RadarZoom + RadarWidth / 2;
                                    float YPos = (scanner.MyPlayer.YPos - obj.YPos) * RadarZoom + RadarHeight / 2;

                                    int       Size        = settings.ores.Size;
                                    Rectangle TextureDest = new Rectangle((int)XPos, (int)YPos, Size, Size);

                                    spriteBatch.DrawTexture(finded.textureName, TextureDest);
                                    spriteBatch.DrawText(finded.name, new Vector2(XPos, YPos + Size), settings.ores.FontSize, settings.ores.Color);
                                }
                            }
                            else if (Enums.ObjDB.GetRareObject(obj.ObjectId, ref finded)) //Если это редкий объект
                            {
                                if (settings.rareobjects.Draw)                            //Если отрисовываем редкие объекты, то рисуем уже
                                {
                                    float XPos = (scanner.MyPlayer.XPos - obj.XPos) * RadarZoom + RadarWidth / 2;
                                    float YPos = (scanner.MyPlayer.YPos - obj.YPos) * RadarZoom + RadarHeight / 2;

                                    int       Size        = settings.rareobjects.Size;
                                    Rectangle TextureDest = new Rectangle((int)XPos, (int)YPos, Size, Size);
                                    Color     randomColor = Tools.GetRandomColor(random);

                                    spriteBatch.DrawLine(new Vector2(XPos, YPos), new Vector2(Drawing.RadarCenterXPos, Drawing.RadarCenterYPos), randomColor, 2);
                                    spriteBatch.DrawTexture(finded.textureName, TextureDest, GlobalRotating);
                                    spriteBatch.DrawText(finded.name, new Vector2(XPos, YPos + Size), settings.rareobjects.FontSize, randomColor);
                                }
                            }
                            else  //Просто объекты
                            {
                                if (settings.otherobjects.Draw) //Если отрисовываем обычные объекты, то рисуем уже
                                {
                                    float XPos = (scanner.MyPlayer.XPos - obj.XPos) * RadarZoom + RadarWidth / 2;
                                    float YPos = (scanner.MyPlayer.YPos - obj.YPos) * RadarZoom + RadarHeight / 2;

                                    if (settings.otherobjects.DrawLines)
                                    {
                                        if (!Enums.ObjDB.HasInBlackList(obj.ObjectId))
                                        {
                                            Vector2 radarCenter = new Vector2(Drawing.RadarCenterXPos, Drawing.RadarCenterYPos);
                                            Vector2 objPos      = new Vector2(XPos, YPos);
                                            spriteBatch.DrawLine(radarCenter, objPos, Color.AliceBlue, 1);
                                        }
                                    }

                                    int       Size        = settings.otherobjects.Size;
                                    Rectangle TextureDest = new Rectangle((int)XPos, (int)YPos, Size, Size);
                                    spriteBatch.DrawTexture("other_object", TextureDest);
                                    spriteBatch.DrawText(obj.ObjectId.ToString(), new Vector2(XPos, YPos + Size), settings.rareobjects.FontSize, settings.otherobjects.Color);
                                }
                            }
                        }
                        #endregion



                        //Отрисовываем игроков
                        foreach (Radar.PlayerObject player in scanner.Players)
                        {
                            spriteBatch.DrawPlayer(player, scanner.MyPlayer);
                        }



                        //Ищем объект?
                        //foreach (object obj in scanner.All)
                        //{
                        //    if (obj is Radar.OtherObject)
                        //    {
                        //        Radar.OtherObject otherObj = obj as Radar.OtherObject;


                        //    }
                        //    else if (obj is Radar.NpcObject)
                        //    {
                        //        Radar.NpcObject npc = obj as Radar.NpcObject;

                        //    }
                        //    else if (obj is Radar.PlayerObject)
                        //    {
                        //        Radar.PlayerObject player = obj as Radar.PlayerObject;

                        //    }
                        //}


                        //Отрисовываем цель
                        if (scanner.Target != null)
                        {
                            float     result     = Tools.Oscillate(0.32f, 1.5f, (float)(gameTime.TotalGameTime.TotalMilliseconds / 1000.0f));
                            Texture2D target_tex = Textures.GetTexture("other_target");

                            if (scanner.Target is Radar.PlayerObject)
                            {
                                Radar.PlayerObject player = scanner.Target as Radar.PlayerObject;

                                float XPos = (scanner.MyPlayer.XPos - player.XPos) * RadarZoom + RadarWidth / 2;
                                float YPos = (scanner.MyPlayer.YPos - player.YPos) * RadarZoom + RadarHeight / 2;

                                spriteBatch.DrawLine(new Vector2(Drawing.RadarCenterXPos, Drawing.RadarCenterYPos), new Vector2(XPos, YPos), Color.SlateBlue, 4);
                                spriteBatch.DrawTexture(target_tex, new Rectangle((int)XPos, (int)YPos, (int)(target_tex.Width * result), (int)(target_tex.Height * result)), GlobalRotating / 8, Color.Gold);
                            }
                            else if (scanner.Target is Radar.NpcObject)
                            {
                                Radar.NpcObject npc = scanner.Target as Radar.NpcObject;

                                float XPos = (scanner.MyPlayer.XPos - npc.XPos) * RadarZoom + RadarWidth / 2;
                                float YPos = (scanner.MyPlayer.YPos - npc.YPos) * RadarZoom + RadarHeight / 2;

                                spriteBatch.DrawLine(new Vector2(Drawing.RadarCenterXPos, Drawing.RadarCenterYPos), new Vector2(XPos, YPos), Color.SlateBlue, 4);
                                spriteBatch.DrawTexture(target_tex, new Rectangle((int)XPos, (int)YPos, (int)(target_tex.Width * result), (int)(target_tex.Height * result)), GlobalRotating / 8, Color.Gold);
                                spriteBatch.DrawText(npc.Name, new Vector2(XPos, YPos + target_tex.Height), 14.0f, Color.Gold);
                            }
                        }


                        //Рисуем себя по центру
                        spriteBatch.DrawMeAtCenter(scanner.MyPlayer);
                    }
                    else
                    {
                        Texture2D not_in_world_tex = Textures.GetTexture("other_not_in_world");
                        spriteBatch.DrawTextureFromLeft(not_in_world_tex, new Rectangle(0, 0, RadarWidth, RadarHeight));

                        LastGameState = 2;
                    }
                }
                else
                {
                    GraphicsDevice.Clear(Color.White);
                    spriteBatch.DrawText("Not connected!", new Vector2(RadarHeight / 2, RadarWidth / 2), 25.0f, Color.Black);

                    LastGameState = 1;
                }
            }
            else  //Иначе рисуем инфу
            {
                GraphicsDevice.Clear(Color.AntiqueWhite);
                spriteBatch.DrawInfo();
            }



            spriteBatch.End();

            drawTime.Stop();  //Устанавливаем таймер и обновляем значение
            DrawTime = drawTime.ElapsedTicks;

            base.Draw(gameTime);
        }