public async Task KreirajMec(int id1, int id2, string lokacija, [FromBody] Mec m)
        {
            var igrac1 = await Context.Igraci.FindAsync(id1);

            var igrac2 = await Context.Igraci.FindAsync(id2);

            var mec = new Mec();
            var rez = new Rezultat();

            rez.Igrac1             = igrac1;
            rez.Igrac2             = igrac2;
            rez.BrSet1             = 0;
            rez.BrSet2             = 0;
            rez.BrPoenaSeta1prvog  = 0;
            rez.BrPoenaSeta1drugog = 0;
            rez.BrPoenaSeta2prvog  = 0;
            rez.BrPoenaSeta2drugog = 0;
            rez.TrenutniSet        = 1;
            rez.KrajMeca           = false;
            mec.Rezultat           = rez;
            mec.Lokacija           = lokacija;
            mec.VremeOdrzavanja    = m.VremeOdrzavanja;
            Context.Rezultati.Add(rez);
            Context.Mecevi.Add(mec);
            await Context.SaveChangesAsync();
        }
Exemple #2
0
        public Mec Update([FromForm] int id, [FromForm] int idIgraca)
        {
            Mec mec = this.context.Mecevi.FirstOrDefault(x => x.Id == id);

            if (mec.Igrac1Id == idIgraca)
            {
                if (mec.Rezultat11 == 6 || mec.Rezultat21 == 6)
                {
                    mec.Rezultat12++;
                }
                else
                {
                    mec.Rezultat11++;
                }
            }
            else
            {
                if (mec.Rezultat11 == 6 || mec.Rezultat21 == 6)
                {
                    mec.Rezultat22++;
                }
                else
                {
                    mec.Rezultat21++;
                }
            }

            this.context.SaveChanges();

            return(mec);
        }
        public async Task UpisiMec([FromBody] Mec mec, int idRez)
        {
            var rez = await Context.Rezultati.FindAsync(idRez);

            mec.Rezultat = rez;
            Context.Mecevi.Add(mec);
            await Context.SaveChangesAsync();
        }
        public async Task IzmeniMec(int idMeca, [FromBody] Mec mec)
        {
            var stariMec = await Context.Mecevi.FindAsync(idMeca);

            stariMec.Lokacija        = mec.Lokacija;
            stariMec.VremeOdrzavanja = mec.VremeOdrzavanja;
            Context.Update <Mec>(mec);
            await Context.SaveChangesAsync();
        }
Exemple #5
0
        public static PredictionOutput GetCirclePrediction(PredictionInput input)
        {
            var mainTargetPrediction = Prediction.Instance.GetPrediction(input, false, true);
            var posibleTargets       = new List <PossibleTarget>
            {
                new PossibleTarget {
                    Position = (Vector2)mainTargetPrediction.UnitPosition, Unit = input.Unit
                }
            };

            if (mainTargetPrediction.HitChance >= HitChance.Medium)
            {
                posibleTargets.AddRange(AoePrediction.GetPossibleTargets(input));
            }

            while (posibleTargets.Count > 1)
            {
                var mecCircle = Mec.GetMec(posibleTargets.Select(h => h.Position).ToList());

                if (mecCircle.Radius <= input.RealRadius - 10 && mecCircle.Center.DistanceSquared(input.RangeCheckFrom)
                    < input.Range * input.Range)
                {
                    return(new PredictionOutput
                    {
                        AoeTargetsHit = posibleTargets.Select(h => (Obj_AI_Hero)h.Unit).ToList(),
                        CastPosition = (Vector3)mecCircle.Center,
                        UnitPosition = mainTargetPrediction.UnitPosition,
                        HitChance = mainTargetPrediction.HitChance,
                        Input = input,
                        AoeHitCount = posibleTargets.Count
                    });
                }

                float maxdist      = -1;
                var   maxdistindex = 1;

                for (var i = 1; i < posibleTargets.Count; i++)
                {
                    var distance = posibleTargets[i].Position.DistanceSquared(posibleTargets[0].Position);

                    if (!(distance > maxdist) && maxdist.CompareTo(-1) != 0)
                    {
                        continue;
                    }

                    maxdistindex = i;
                    maxdist      = distance;
                }

                posibleTargets.RemoveAt(maxdistindex);
            }

            return(mainTargetPrediction);
        }
 private void btnBrisiMec_Click(object sender, EventArgs e)
 {
     if (MessageBox.Show("Obrisati čete meč. Želite li nastaviti?", "Upozorenje", MessageBoxButtons.OKCancel) == DialogResult.OK)
     {
         Mec mecZaObrisati = mecBindingSource.Current as Mec;
         mecBindingSource.Remove(mecZaObrisati);
         tennisTrackEntities.Mec.Remove(mecZaObrisati);
         tennisTrackEntities.SaveChanges();
         OsvjeziMeceve();
     }
 }
Exemple #7
0
 private bool ProvjeraValjanostiRezultataMeca(Mec mec)
 {
     foreach (var item in mec.Sets)
     {
         if (((item.Rezultat_prvi_clan == 6 && item.Rezultat_drugi_clan < 5) || (item.Rezultat_prvi_clan == 7 && (item.Rezultat_drugi_clan == 6 || item.Rezultat_drugi_clan == 5)) ||
              (item.Rezultat_drugi_clan == 6 && item.Rezultat_prvi_clan < 5) || (item.Rezultat_drugi_clan == 7 && (item.Rezultat_prvi_clan == 6 || item.Rezultat_prvi_clan == 5))) == false)
         {
             return(false);
         }
     }
     return(true);
 }
Exemple #8
0
            public static PredictionOutput GetPrediction(PredictionInput input)
            {
                PredictionOutput prediction = Prediction.GetPrediction(input, false, true);
                List <AoePrediction.PossibleTarget> list = new List <AoePrediction.PossibleTarget>
                {
                    new AoePrediction.PossibleTarget
                    {
                        Position = prediction.UnitPosition.ToVector2(),
                        Unit     = input.Unit
                    }
                };

                if (prediction.Hitchance >= HitChance.Medium)
                {
                    list.AddRange(AoePrediction.GetPossibleTargets(input));
                }
                while (list.Count > 1)
                {
                    var mec = Mec.GetMec((from h in list
                                          select h.Position).ToList <Vector2>());
                    if (mec.Radius <= input.RealRadius - 10f && Vector2.DistanceSquared(mec.Center, input.RangeCheckFrom.ToVector2()) < input.Range * input.Range)
                    {
                        PredictionOutput predictionOutput = new PredictionOutput();
                        predictionOutput.AoeTargetsHit = (from hero in list
                                                          select hero.Unit).ToList <AIBaseClient>();
                        predictionOutput.CastPosition        = mec.Center.ToVector3();
                        predictionOutput.UnitPosition        = prediction.UnitPosition;
                        predictionOutput.Hitchance           = prediction.Hitchance;
                        predictionOutput.Input               = input;
                        predictionOutput._aoeTargetsHitCount = list.Count;
                        return(predictionOutput);
                    }
                    float num   = -1f;
                    int   index = 1;
                    for (int i = 1; i < list.Count; i++)
                    {
                        float num2 = Vector2.DistanceSquared(list[i].Position, list[0].Position);
                        if (num2 > num || num.CompareTo(-1f) == 0)
                        {
                            index = i;
                            num   = num2;
                        }
                    }
                    list.RemoveAt(index);
                }
                return(prediction);
            }
Exemple #9
0
        public static Vector3?GetCircularClearLocation(SpellWrapper spell)
        {
            List <Obj_AI_Base> minions = ObjectManager.Get <Obj_AI_Base>()
                                         .Where(x => x.IsValidTarget(spell.Range) && x.IsValidSpellTarget()).ToList();
            List <Vector2> positions = minions.Select(x => x.ServerPosition.To2D()).ToList();

            Vector3?bestAimPosition    = null;
            int     highestMinionCount = MinimumMinions;

            if (minions.Count >= MinimumMinions)
            {
                foreach (Vector2 minionCoordinate in positions)
                {
                    int count = minions.Count(m => m.Distance(minionCoordinate) <= spell.Width && spell.CanKill(m));
                    if (count >= highestMinionCount)
                    {
                        bestAimPosition    = minionCoordinate.To3D();
                        highestMinionCount = count;
                    }
                }

                foreach (Vector2 p1 in positions)
                {
                    foreach (Vector2 p2 in positions)
                    {
                        if (!p1.Equals(p2))
                        {
                            Vector2        center;
                            float          radius;
                            List <Vector2> combination = new List <Vector2>(new Vector2[] { p1, p2 });

                            Mec.FindMinimalBoundingCircle(combination, out center, out radius);

                            int count = minions.Count(m => m.Distance(center) <= spell.Width && spell.CanKill(m));
                            if (count >= highestMinionCount)
                            {
                                bestAimPosition    = center.To3D();
                                highestMinionCount = count;
                            }
                        }
                    }
                }
            }

            return(bestAimPosition);
        }
Exemple #10
0
        private bool ProvjeravaIzjednacenRezultat(Mec mec)
        {
            int setoviIgraca1 = 0, setoviIgraca2 = 0;

            foreach (var item in mec.Sets)
            {
                if (item.Rezultat_prvi_clan > item.Rezultat_drugi_clan)
                {
                    setoviIgraca1++;
                }
                else
                {
                    setoviIgraca2++;
                }
            }
            if (setoviIgraca1 != setoviIgraca2)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemple #11
0
        public static LaneclearResult GetCircularClearLocation(float range, float width, int minHit)
        {
            var minions = ObjectManager.Get <Obj_AI_Base>().Where(x => x.IsValidSpellTarget(range));

            var allPositions = minions.Select(x => x.ServerPosition.To2D()).ToList();

            if (minHit == 1 && allPositions.Any())
            {
                return(new LaneclearResult(1, allPositions.FirstOrDefault().To3D()));
            }

            var positionCount = allPositions.Count;

            var lcount = Math.Min(positionCount, 5);

            HashSet <LaneclearResult> results = new HashSet <LaneclearResult>();

            void CheckResult(Vector3 c)
            {
                var hitMinions = allPositions.Where(x => x.Distance(c) <= 0.95f * width);

                var count = hitMinions.Count();

                if (count >= minHit)
                {
                    var result = new LaneclearResult(count, c);
                    results.Add(result);
                }
            }

            if (allPositions.Count >= minHit)
            {
                Vector2 center;

                float radius;

                Mec.FindMinimalBoundingCircle(allPositions, out center, out radius);

                if (center.IsZero)
                {
                    return(new LaneclearResult(0, Vector3.Zero));
                }

                CheckResult(center.To3D());

                for (int i = 0; i < lcount; i++)
                {
                    for (int j = 0; j < lcount; j++)
                    {
                        var positions = new List <Vector2> {
                            allPositions[i], allPositions[j]
                        };

                        Mec.FindMinimalBoundingCircle(positions, out center, out radius);

                        CheckResult(center.To3D());
                    }
                }

                return(results.MaxBy(x => x.numberOfMinionsHit));
            }

            return(null);
        }
Exemple #12
0
        public static Result GetCircleAoePrediction(this Spell spell, Obj_AI_Hero target, HitChance hitChance,
                                                    bool boundingRadius = true, bool extended = true, Vector3?sourcePosition = null)
        {
            try
            {
                if (spell == null || target == null)
                {
                    return(new Result(Vector3.Zero, new List <Obj_AI_Hero>()));
                }
                var fromPosition = sourcePosition ?? ObjectManager.GetLocalPlayer().ServerPosition;
                var hits         = new List <Obj_AI_Hero>();
                var center       = Vector3.Zero;
                var radius       = float.MaxValue;
                var range        = spell.Range + (extended ? spell.Width * 0.85f : 0) +
                                   (boundingRadius ? target.BoundingRadius * BoundingRadiusMultiplicator : 0);
                var positions = (from t in GameObjects.EnemyHeroes
                                 where t.IsValidTarget(range * 1.5f, false, false, fromPosition)
                                 let prediction = spell.GetPrediction(t)
                                                  where prediction.HitChance >= hitChance
                                                  select new Position(t, prediction.UnitPosition)).ToList();
                var spellWidth = spell.Width;
                if (positions.Any())
                {
                    var mainTarget    = positions.FirstOrDefault(p => p.Hero.NetworkId == target.NetworkId);
                    var possibilities =
                        ProduceEnumeration(
                            positions.Where(
                                p => p.UnitPosition.Distance(mainTarget.UnitPosition) <= spell.Width * 0.85f).ToList())
                        .Where(p => p.Count > 0 && p.Any(t => t.Hero.NetworkId == mainTarget.Hero.NetworkId))
                        .ToList();
                    foreach (var possibility in possibilities)
                    {
                        var mec      = Mec.GetMec(possibility.Select(p => p.UnitPosition.To2D()).ToList());
                        var distance = spell.From.Distance(mec.Center.To3D());
                        if (mec.Radius < spellWidth && distance < range)
                        {
                            var lHits  = new List <Obj_AI_Hero>();
                            var circle =
                                new MyPolygon.Circle(
                                    spell.From.Extend(
                                        mec.Center.To3D(), spell.Range > distance ? distance : spell.Range), spell.Width);

                            if (boundingRadius)
                            {
                                lHits.AddRange(
                                    from position in positions
                                    where
                                    new MyPolygon.Circle(
                                        position.UnitPosition,
                                        position.Hero.BoundingRadius * BoundingRadiusMultiplicator).Points.Any(
                                        p => circle.IsInside(p))
                                    select position.Hero);
                            }
                            else
                            {
                                lHits.AddRange(
                                    from position in positions
                                    where circle.IsInside(position.UnitPosition)
                                    select position.Hero);
                            }

                            if ((lHits.Count > hits.Count || lHits.Count == hits.Count && mec.Radius < radius ||
                                 lHits.Count == hits.Count &&
                                 spell.From.Distance(circle.Center.To3D()) < spell.From.Distance(center)) &&
                                lHits.Any(p => p.NetworkId == target.NetworkId))
                            {
                                center = To3D2(circle.Center);
                                radius = mec.Radius;
                                hits.Clear();
                                hits.AddRange(lHits);
                            }
                        }
                    }
                    if (!center.Equals(Vector3.Zero))
                    {
                        return(new Result(center, hits));
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
            return(new Result(Vector3.Zero, new List <Obj_AI_Hero>()));
        }
Exemple #13
0
        private void btnKreirajMec_Click(object sender, EventArgs e)
        {
            Mec mec = new Mec();

            PopuniSetove();

            string   time     = cmbTermini.SelectedItem as string;
            TimeSpan realTime = TimeSpan.Parse(time);


            mec.Prvi_clan_Id  = PrijavaClana.PrijavljeniCLan.ID;
            mec.Drugi_clan_Id = odabraniSuigrac.ID;
            mec.Datum         = dtpDatumMeca.Value.Date;
            mec.Teren         = OdaberiTeren();
            mec.Vrijeme       = realTime;
            if (rbtnSluzbeni.Checked)
            {
                mec.Turnir = OdaberiTurnir();
            }
            else
            {
                mec.Turnir = null;
            }

            mec.Sets.Add(set1);
            mec.Sets.Add(set2);
            if (rbtn2Dobivena.Checked && ProvjeriRezultatMecaNaDvaDobivena())
            {
                if (ProvjeriGemove(txtIgracSet3.Text, txtSuigracSet3.Text))
                {
                    set3.Rezultat_prvi_clan  = int.Parse(txtIgracSet3.Text);
                    set3.Rezultat_drugi_clan = int.Parse(txtSuigracSet3.Text);
                    mec.Sets.Add(set3);
                }
                else
                {
                    MessageBox.Show("Rezultati trećeg seta moraju biti nenegativni cijeli brojevi!", "Upozorenje!");
                }
            }
            else if (rbtn3Dobivena.Checked)
            {
                if (ProvjeriGemove(txtIgracSet3.Text, txtSuigracSet3.Text))
                {
                    set3.Rezultat_prvi_clan  = int.Parse(txtIgracSet3.Text);
                    set3.Rezultat_drugi_clan = int.Parse(txtSuigracSet3.Text);
                    mec.Sets.Add(set3);
                }
                else
                {
                    MessageBox.Show("Rezultati trećeg seta moraju biti nenegativni cijeli brojevi!", "Upozorenje!");
                }

                if (ProvjeriPotrebuZaCetvrtimSetom())
                {
                    if (ProvjeriGemove(txtIgracSet4.Text, txtSuigracSet4.Text))
                    {
                        set4.Rezultat_prvi_clan  = int.Parse(txtIgracSet4.Text);
                        set4.Rezultat_drugi_clan = int.Parse(txtSuigracSet4.Text);
                        mec.Sets.Add(set4);
                    }
                    else
                    {
                        MessageBox.Show("Rezultati četvrtog seta moraju biti nenegativni cijeli brojevi!", "Upozorenje!");
                    }

                    if (ProvjeriPotrebuZaPetimSetom())
                    {
                        if (ProvjeriGemove(txtIgracSet5.Text, txtSuigracSet5.Text))
                        {
                            set5.Rezultat_prvi_clan  = int.Parse(txtIgracSet5.Text);
                            set5.Rezultat_drugi_clan = int.Parse(txtSuigracSet5.Text);
                            mec.Sets.Add(set5);
                        }
                        else
                        {
                            MessageBox.Show("Rezultati petog seta moraju biti nenegativni cijeli brojevi!", "Upozorenje!");
                        }
                    }
                }
            }

            if (odabirSuigraca)
            {
                if (unosZadovoljava)
                {
                    if (ProvjeraValjanostiRezultataMeca(mec))
                    {
                        if (ProvjeravaIzjednacenRezultat(mec))
                        {
                            tennisTrackEntities.Mec.Add(mec);
                            tennisTrackEntities.SaveChanges();
                            MessageBox.Show("Meč je dodan!", "Obavijest");
                        }
                        else
                        {
                            MessageBox.Show("Rezultat završenog meča ne može biti izjednačen", "Upozorenje");
                        }
                    }
                    else
                    {
                        MessageBox.Show("Uneseni rezultati nisu valjani!", "Upozorenje!");
                    }
                }
                else
                {
                    MessageBox.Show("Rezultati svih setova moraju biti nenegativni cijeli brojevi!", "Upozorenje!");
                }
            }
            else
            {
                MessageBox.Show("Suigrač nije odabran!", "Upozorenje!");
            }
        }
Exemple #14
0
        /// <summary>
        /// Gets the circular aoe cast position.
        /// </summary>
        /// <param name="unit">The unit.</param>
        /// <param name="delay">The delay.</param>
        /// <param name="radius">The radius.</param>
        /// <param name="range">The range.</param>
        /// <param name="speed">The speed.</param>
        /// <param name="from">From.</param>
        /// <param name="collision">if set to <c>true</c> the spell has collision.</param>
        /// <returns>PredictionOutput.</returns>
        public PredictionOutput GetCircularAoeCastPosition(
            Obj_AI_Base unit,
            float delay,
            float radius,
            float range,
            float speed,
            Vector3 from,
            bool collision)
        {
            var result = this.GetCastPosition(unit, delay, radius, range, speed, from, collision, SkillType.Circle);
            var points = new List <Vector3>();

            var mainCastPoisition = result.CastPosition;
            var mainHitChance     = result.HitChance;
            var mainPosition      = result.PredictedPosition;

            points.Add(mainPosition);

            points.AddRange(
                ObjectManager.Get <Obj_AI_Hero>()
                .Where(x => x.NetworkId != unit.NetworkId && x.IsValidTarget(range * 1.5f))
                .Select(
                    x => this.GetCastPosition(
                        x,
                        delay,
                        radius,
                        range,
                        speed,
                        from,
                        collision,
                        SkillType.Circle))
                .Where(
                    x => x.PredictedPosition.Distance(from) < range + radius &&
                    x.HitChance != HitChance.Collision).Select(x => x.PredictedPosition));

            while (points.Count > 1)
            {
                var mec = Mec.FindMinimumEnclosingCircle(points.Cast <Vector2>());

                if (mec.Radius <= radius + unit.BoundingRadius - 8)
                {
                    return(new PredictionOutput()
                    {
                        CastPosition = new Vector3(
                            mec.Center.X,
                            NavMesh.GetHeightForWorld(mec.Center.X, mec.Center.Y),
                            mec.Center.Y),
                        HitChance = mainHitChance,
                        AoeTargetsHit = points.Count
                    });
                }

                var maxDist      = -1f;
                var maxDistIndex = 0;

                for (var i = 1; i < points.Count; i++)
                {
                    var d = Vector3.DistanceSquared(points[i], points[0]);

                    if (!(d > maxDist) && !(Math.Abs(maxDist - (-1)) < float.Epsilon))
                    {
                        continue;
                    }

                    maxDistIndex = i;
                    maxDist      = d;
                }

                points.RemoveAt(maxDistIndex);
            }

            return(new PredictionOutput()
            {
                CastPosition = mainCastPoisition,
                HitChance = mainHitChance,
                AoeTargetsHit = points.Count,
                PredictedPosition = mainPosition
            });
        }
Exemple #15
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, TenisDbContext context)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                app.UseHsts();
            }
            app.UseHttpsRedirection();
            app.UseStaticFiles();

            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller=Home}/{action=Index}/{id?}");
            });

            var igrac1 = new Igrac
            {
                Godine = 33,
                Ime    = "Novak Djokovic",
                Rang   = 1,
                Slika  = "https://www.gstatic.com/tv/thumb/persons/633923/633923_v9_ba.jpg"
            };

            var igrac2 = new Igrac
            {
                Godine = 35,
                Ime    = "Rafael Nadal",
                Rang   = 2,
                Slika  = "https://www.tennisworldusa.org/imgb/93582/rafael-nadal-i-had-injuries-but-i-never-lost-motivation-.jpg"
            };

            context.Igraci.Add(igrac1);
            context.Igraci.Add(igrac2);

            var mec1 = new Mec
            {
                Igrac1   = igrac1,
                Igrac2   = igrac2,
                Lokacija = "asd"
            };
            var mec2 = new Mec
            {
                Igrac1   = igrac1,
                Igrac2   = igrac2,
                Lokacija = "123"
            };

            context.Mecevi.Add(mec1);
            context.Mecevi.Add(mec2);

            context.SaveChanges();
        }