예제 #1
0
 public BallParticleSystem(YellokillerGame game, int howManyEffects, Heros heros, Carte carte)
     : base(game, howManyEffects)
 {
     this.heros = heros;
     this.carte = carte;
     distance = heros.Distance_Hero_Mur(carte);
 }
예제 #2
0
        public Shuriken(Vector2 position, Heros heros, ContentManager content)
            : base(position)
        {
            base.LoadContent(content, "shuriken");
            Origin = new Vector2(Texture.Width / 2, Texture.Height / 2);

            this.position.X = position.X + 8;
            this.position.Y = position.Y + 4;
            elapsed = 0;
            circle = MathHelper.Pi * 2;
            ShurikenExists = false;

            rectangle = new Rectangle((int)position.X, (int)position.Y, 12, 12);

            if (heros.isheros == true)
            {
                if (heros.Regarde_Gauche)
                    direction = -Vector2.UnitX;
                else if (heros.Regarde_Bas)
                    direction = Vector2.UnitY;
                else if (heros.Regarde_Droite)
                    direction = Vector2.UnitX;
                else if (heros.Regarde_Haut)
                    direction = -Vector2.UnitY;
            }
        }
예제 #3
0
        public void Update(GameTime gameTime, Carte carte, Heros heros1, Heros heros2, Rectangle camera, List<EnnemiMort> morts, Rectangle fumeeHeros1, Rectangle fumeeHeros2)
        {
            base.Update(gameTime, new Rectangle((int)Index * 24, 0, 19, 26), new Rectangle((int)Index * 24, 63, 19, 26), new Rectangle((int)Index * 24, 96, 19, 26), new Rectangle((int)Index * 24, 32, 19, 26), heros1, heros2, morts, fumeeHeros1, fumeeHeros2);

            if (parcours.Count > 1 && RetourneCheminNormal)
                if (Chemin == null || Chemin.Count == 0)
                {
                    Etape++;
                    Depart = carte.Cases[(int)positionDesiree.Y / 28, (int)positionDesiree.X / 28];
                    Arrivee = parcours[(Etape + 1) % parcours.Count];
                    Chemin = Pathfinding.CalculChemin(carte, Depart, Arrivee);
                }

            if (Collision(heros1.Rectangle, fumeeHeros1, fumeeHeros2))
            {
                Depart = carte.Cases[(int)positionDesiree.Y / 28, (int)positionDesiree.X / 28];
                Arrivee = carte.Cases[heros1.Y, heros1.X];
                Chemin = Pathfinding.CalculChemin(carte, Depart, Arrivee);
                RetourneCheminNormal = false;
            }
            else if (heros2 != null && Collision(heros2.Rectangle, fumeeHeros1, fumeeHeros2))
            {
                Depart = carte.Cases[(int)positionDesiree.Y / 28, (int)positionDesiree.X / 28];
                Arrivee = carte.Cases[heros2.Y, heros2.X];
                Chemin = Pathfinding.CalculChemin(carte, Depart, Arrivee);
                RetourneCheminNormal = false;
            }
            else if (this.Alerte && !RetourneCheminNormal && Chemin.Count == 0)
            {
                Depart = carte.Cases[(int)positionDesiree.Y / 28, (int)positionDesiree.X / 28];
                Arrivee = parcours[Etape % parcours.Count];
                Chemin = Pathfinding.CalculChemin(carte, Depart, Arrivee);
                RetourneCheminNormal = true;
            }
        }
예제 #4
0
        public ExplosionParticleSystem(YellokillerGame game, int howManyEffects, Heros heros, Carte carte, int maxspeed)
            : base(game, howManyEffects)
        {
            this.maxspeed = maxspeed;

            this.heros = heros;
            this.carte = carte;
            distance = heros.Distance_Hero_Mur(carte);
        }
예제 #5
0
        // surcharge
        public void AddParticles(Vector2 where, Heros heros)
        {
            // the number of particles we want for this effect is a random number
            // somewhere between the two constants specified by the subclasses.
            int numParticles =
                MoteurParticule.Random.Next(minNumParticles, maxNumParticles);

            // create that many particles, if you can.
            for (int i = 0; i < numParticles && freeParticles.Count > 0; i++)
            {
                // grab a particle from the freeParticles queue, and Initialize it.
                Particle p = freeParticles[0];
                freeParticles.RemoveAt(0);
                InitializeParticle(p, where, heros);
            }
        }
예제 #6
0
파일: Garde.cs 프로젝트: Ayro64/yellokiller
        public void Update(GameTime gameTime, Carte carte, Heros heros1, Heros heros2, Rectangle camera, List<EnnemiMort> ennemisMorts, Rectangle fumeeHeros1, Rectangle fumeeHeros2)
        {
            if (Collision(heros1.Rectangle, fumeeHeros1, fumeeHeros2))
            {
                Depart = carte.Cases[Y, X];
                Arrivee = carte.Cases[heros1.Y, heros1.X];
                Chemin = Pathfinding.CalculChemin(carte, Depart, Arrivee);
            }
            else if (heros2 != null && (Collision(heros2.Rectangle, fumeeHeros1, fumeeHeros2)))
            {
                Depart = carte.Cases[Y, X];
                Arrivee = carte.Cases[heros2.Y, heros2.X];
                Chemin = Pathfinding.CalculChemin(carte, Depart, Arrivee);
            }

            base.Update(gameTime, new Rectangle((int)Index * 24, 0, 16, 24), new Rectangle((int)Index * 24, 64, 16, 24), new Rectangle((int)Index * 24, 97, 16, 24), new Rectangle((int)Index * 24, 33, 16, 24), heros1, heros2, ennemisMorts, fumeeHeros1, fumeeHeros2);
        }
예제 #7
0
파일: Dungeon.cs 프로젝트: Zboubinours/tp
 public Dungeon(RandGenerator g, short width, short height)
 {
     // Création du héros, NPC
     _npc = new List<NPC>();
     _heros = new Heros(17, 33, '*'); // Au  _heros = new Heros((short)(Width/2 +1), (short)(Height/2+1), '*');
     // Init du dungeon
     R = g;
     Width = width;
     Height = height;
     _map = new Elements[width, height];
     _view = new Visibility[width, height];
     for (int w = 0; w < _map.GetLength(0); w++)
     {
         for (int h = 0; h < _map.GetLength(1); h++)
         {
             _map[w, h] = Elements.Empty;
             _view[w, h] = Visibility.Visible;
         }
     }
 }
예제 #8
0
파일: Boss.cs 프로젝트: Ayro64/yellokiller
        public void Update(GameTime gameTime, List<Shuriken> shuriken, Carte carte, Heros heros1, Heros heros2, Rectangle camera, List<EnnemiMort> morts, Rectangle fumeeHeros1, Rectangle fumeeHeros2)
        {
            base.Update(gameTime, new Rectangle((int)Index * 24, 0, 16, 24), new Rectangle((int)Index * 24, 64, 16, 24), new Rectangle((int)Index * 24, 97, 16, 24), new Rectangle((int)Index * 24, 33, 16, 24), heros1, heros2, morts, fumeeHeros1, fumeeHeros2);

            if (!RetourneCheminNormal && Collision(heros1.Rectangle, fumeeHeros1, fumeeHeros2))
            {
                Depart = carte.Cases[Y, X];
                Arrivee = carte.Cases[heros1.Y, heros1.X];
                Chemin = Pathfinding.CalculChemin(carte, Depart, Arrivee);
            }
            else if (!RetourneCheminNormal && heros2 != null && (Collision(heros2.Rectangle, fumeeHeros1, fumeeHeros2)))
            {
                Depart = carte.Cases[Y, X];
                Arrivee = carte.Cases[heros2.Y, heros2.X];
                Chemin = Pathfinding.CalculChemin(carte, Depart, Arrivee);
            }

            if (Math.Abs(Origine.X - X) > 4 || Math.Abs(Origine.Y - Y) > 4)
            {
                RetourneCheminNormal = true;
                Depart = carte.Cases[Y, X];
                Arrivee = carte.Cases[(int)Origine.Y, (int)Origine.X];
                Chemin = Pathfinding.CalculChemin(carte, Depart, Arrivee);
            }
            else
                RetourneCheminNormal = false;

            IA.Esquive_Shuriken.Boss_Esquive_Shuriken(heros1, this, shuriken, carte, camera);

            if (Vie < 5 && Chemin.Count == 0)
            {
                if (heros1.Regarde_Bas && position.Y > heros1.position.Y)
                    SourceRectangle = new Rectangle(26, 0, 16, 24);
                else if (heros1.Regarde_Gauche && position.X < heros1.position.X)
                    SourceRectangle = new Rectangle(26, 33, 16, 24);
               else if (heros1.Regarde_Haut && position.Y < heros1.position.Y)
                    SourceRectangle = new Rectangle(26, 64, 16, 24);
                else if (heros1.Regarde_Droite && position.X > heros1.position.X)
                    SourceRectangle = new Rectangle(26, 97, 16, 24);
            }
        }
예제 #9
0
        public MoteurParticule(YellokillerGame game, SpriteBatch spriteBatch, Carte carte, Heros heros1, Heros heros2, List<Statue> _statue)
        {
            this.game = game;
            this.spriteBatch = spriteBatch;

            hadoken_heros1 = new ExplosionParticleSystem(game, 1, heros1, carte, 50);
            game.Components.Add(hadoken_heros1);

            ball1 = new BallParticleSystem(game, 1, heros1, carte);
            game.Components.Add(ball1);

            foreach (Statue statue in _statue)
            {
                explosion_statue = new Statue_Explosion(game, 20, carte, statue, statue.Distance_Statue_Mur(carte));
                game.Components.Add(explosion_statue);
            }

            fume_hadoken = new ExplosionSmokeParticleSystem(game, 2);
            game.Components.Add(fume_hadoken);

            fumigene1 = new Fumigene(game, 9, heros1, carte);
            game.Components.Add(fumigene1);

            fume = new SmokePlumeParticleSystem(game, 9);
            game.Components.Add(fume);

            try
            {
                hadoken_heros2 = new ExplosionParticleSystem(game, 1, heros2, carte, 50);
                game.Components.Add(hadoken_heros2);
                ball2 = new BallParticleSystem(game, 1, heros2, carte);
                fumigene2 = new Fumigene(game, 9, heros2, carte);
                game.Components.Add(fumigene2);
                game.Components.Add(ball2);
            }
            catch (NullReferenceException)
            { }
        }
 public async Task <Object> AddHero(Heros hero)
 {
     HeroContext.Heros.Add(hero);
     return(await HeroContext.SaveChangesAsync());
 }
예제 #11
0
 public Jeu()
 {
     Heros = new Heros(15);
 }
예제 #12
0
 public static bool Collision_Patrouilleur_Heros(List<Patrouilleur> _patrouilleurs, Heros heros1, Heros heros2, SoundBank soundBank)
 {
     for (int b = 0; b < _patrouilleurs.Count; b++)
     {
         if (_patrouilleurs[b].Rectangle.Intersects(heros1.Rectangle))
         {
             ServiceHelper.Get<IGamePadService>().Vibration(50);
             soundBank.PlayCue("CriMortHero");
             return true;
         }
     }
     if (heros2 != null)
     {
         for (int b = 0; b < _patrouilleurs.Count; b++)
         {
             if (_patrouilleurs[b].Rectangle.Intersects(heros2.Rectangle))
             {
                 ServiceHelper.Get<IGamePadService>().Vibration(50);
                 soundBank.PlayCue("CriMortHero");
                 return true;
             }
         }
     }
     return false;
 }
예제 #13
0
 public static bool Collision_Heros_Dark_Hero(Heros heros, Dark_Hero dark, SoundBank SB)
 {
     if (dark != null && heros.Rectangle.Intersects(dark.Rectangle))
     {
         SB.PlayCue("dark");
         return true;
     }
     return false;
 }
예제 #14
0
        public static void Collision_Armes_Ennemis(Heros heros1, Heros heros2, List<Garde> _gardes, List<Patrouilleur> _Patrouilleurs, List<Patrouilleur_a_cheval> _PatrouilleursAChevaux, List<Boss> _Boss, List<Shuriken> listeShuriken, MoteurParticule particule, SoundBank soundBank, ref List<EnnemiMort> morts, ContentManager content)
        {
            if (_gardes.Count != 0)
            {
                for (int i = 0; i < _gardes.Count; i++)
                {
                    if (_gardes[i].Rectangle.Intersects(particule.Rectangle_Hadoken_heros1(heros1)) ||
                        _gardes[i].Rectangle.Intersects(particule.Rectangle_Ball_heros1(heros1)) ||
                        heros1.AttaqueAuSabre(_gardes[i].X, _gardes[i].Y))
                    {
                        soundBank.PlayCue("cri");
                        morts.Add(new EnnemiMort(new Vector2(28 * _gardes[i].X, 28 * _gardes[i].Y), content, EnnemiMort.TypeEnnemiMort.garde));
                        if (_gardes[i].Alerte)
                            GameplayScreen.Alerte = false;
                        _gardes.RemoveAt(i);
                        break;
                    }
                    if (heros2 != null)
                    {
                        if (_gardes[i].Rectangle.Intersects(particule.Rectangle_Hadoken_heros2(heros2)) ||
                            _gardes[i].Rectangle.Intersects(particule.Rectangle_Ball_heros2(heros2)) ||
                            heros2.AttaqueAuSabre(_gardes[i].X, _gardes[i].Y))
                        {
                            soundBank.PlayCue("cri");
                            morts.Add(new EnnemiMort(new Vector2(28 * _gardes[i].X, 28 * _gardes[i].Y), content, EnnemiMort.TypeEnnemiMort.garde));
                            if (_gardes[i].Alerte)
                                GameplayScreen.Alerte = false;
                            _gardes.RemoveAt(i);
                            break;
                        }
                    }
                    for (int j = 0; j < listeShuriken.Count; j++)
                        if (_gardes[i].Rectangle.Intersects(listeShuriken[j].Rectangle))
                        {
                            soundBank.PlayCue("cri");
                            ServiceHelper.Get<IGamePadService>().Vibration(20);
                            morts.Add(new EnnemiMort(new Vector2(28 * _gardes[i].X, 28 * _gardes[i].Y), content, EnnemiMort.TypeEnnemiMort.garde));
                            if (_gardes[i].Alerte)
                                GameplayScreen.Alerte = false;
                            _gardes.RemoveAt(i);
                            listeShuriken.RemoveAt(j);
                            break;
                        }
                }
            }

            if (_Patrouilleurs.Count != 0)
            {
                for (int i = 0; i < _Patrouilleurs.Count; i++)
                {
                    if (_Patrouilleurs[i].Rectangle.Intersects(particule.Rectangle_Hadoken_heros1(heros1)) ||
                        _Patrouilleurs[i].Rectangle.Intersects(particule.Rectangle_Ball_heros1(heros1)) ||
                        heros1.AttaqueAuSabre(_Patrouilleurs[i].X, _Patrouilleurs[i].Y))
                    {
                        soundBank.PlayCue("Bruitage patrouilleur");
                        morts.Add(new EnnemiMort(new Vector2(28 * _Patrouilleurs[i].X, 28 * _Patrouilleurs[i].Y), content, EnnemiMort.TypeEnnemiMort.patrouilleur));
                        if (_Patrouilleurs[i].Alerte)
                            GameplayScreen.Alerte = false;
                        _Patrouilleurs.RemoveAt(i);
                        break;
                    }
                    if (heros2 != null)
                    {
                        if (_Patrouilleurs[i].Rectangle.Intersects(particule.Rectangle_Hadoken_heros2(heros2)) ||
                            _Patrouilleurs[i].Rectangle.Intersects(particule.Rectangle_Ball_heros2(heros2)) ||
                            heros2.AttaqueAuSabre(_Patrouilleurs[i].X, _Patrouilleurs[i].Y))
                        {
                            soundBank.PlayCue("Bruitage patrouilleur");
                            morts.Add(new EnnemiMort(new Vector2(28 * _Patrouilleurs[i].X, 28 * _Patrouilleurs[i].Y), content, EnnemiMort.TypeEnnemiMort.patrouilleur));
                            if (_Patrouilleurs[i].Alerte)
                                GameplayScreen.Alerte = false;
                            _Patrouilleurs.RemoveAt(i);
                            break;
                        }
                    }
                    for (int j = 0; j < listeShuriken.Count; j++)
                        if (_Patrouilleurs[i].Rectangle.Intersects(listeShuriken[j].Rectangle))
                        {
                            soundBank.PlayCue("Bruitage patrouilleur");
                            morts.Add(new EnnemiMort(new Vector2(28 * _Patrouilleurs[i].X, 28 * _Patrouilleurs[i].Y), content, EnnemiMort.TypeEnnemiMort.patrouilleur));
                            if (_Patrouilleurs[i].Alerte)
                                GameplayScreen.Alerte = false;
                            _Patrouilleurs.RemoveAt(i);
                            listeShuriken.RemoveAt(j);
                            break;
                        }
                }
            }

            if (_PatrouilleursAChevaux.Count != 0)
            {
                for (int i = 0; i < _PatrouilleursAChevaux.Count; i++)
                {
                    if ((_PatrouilleursAChevaux[i].Rectangle.Intersects(particule.Rectangle_Hadoken_heros1(heros1)) ||
                        _PatrouilleursAChevaux[i].Rectangle.Intersects(particule.Rectangle_Ball_heros1(heros1))) ||
                        heros1.AttaqueAuSabre(_PatrouilleursAChevaux[i].X, _PatrouilleursAChevaux[i].Y))
                    {
                        soundBank.PlayCue("Bruitage cheval");
                        morts.Add(new EnnemiMort(new Vector2(28 * _PatrouilleursAChevaux[i].X, 28 * _PatrouilleursAChevaux[i].Y), content, EnnemiMort.TypeEnnemiMort.patrouilleurACheval));
                        if (_PatrouilleursAChevaux[i].Alerte)
                            GameplayScreen.Alerte = false;
                        _PatrouilleursAChevaux.RemoveAt(i);
                        break;
                    }
                    if (heros2 != null)
                    {
                        if (_PatrouilleursAChevaux[i].Rectangle.Intersects(particule.Rectangle_Hadoken_heros2(heros2)) ||
                            _PatrouilleursAChevaux[i].Rectangle.Intersects(particule.Rectangle_Ball_heros2(heros2)) ||
                            heros2.AttaqueAuSabre(_PatrouilleursAChevaux[i].X, _PatrouilleursAChevaux[i].Y))
                        {
                            soundBank.PlayCue("Bruitage cheval");
                            morts.Add(new EnnemiMort(new Vector2(28 * _PatrouilleursAChevaux[i].X, 28 * _PatrouilleursAChevaux[i].Y), content, EnnemiMort.TypeEnnemiMort.patrouilleurACheval));
                            if (_PatrouilleursAChevaux[i].Alerte)
                                GameplayScreen.Alerte = false;
                            _PatrouilleursAChevaux.RemoveAt(i);
                            break;
                        }
                    }
                    for (int j = 0; j < listeShuriken.Count; j++)
                        if (_PatrouilleursAChevaux[i].Rectangle.Intersects(listeShuriken[j].Rectangle))
                        {
                            soundBank.PlayCue("Bruitage cheval");
                            morts.Add(new EnnemiMort(new Vector2(28 * _PatrouilleursAChevaux[i].X, 28 * _PatrouilleursAChevaux[i].Y), content, EnnemiMort.TypeEnnemiMort.patrouilleurACheval));
                            if (_PatrouilleursAChevaux[i].Alerte)
                                GameplayScreen.Alerte = false;
                            _PatrouilleursAChevaux.RemoveAt(i);
                            listeShuriken.RemoveAt(j);
                            break;
                        }
                }
            }

            if (_Boss.Count != 0)
            {
                for (int i = 0; i < _Boss.Count; i++)
                {
                    if (_Boss[i].Vie < 0 || heros1.AttaqueAuSabre(_Boss[i].X, _Boss[i].Y))
                    {
                        _Boss[i].Vie = 5;
                        morts.Add(new EnnemiMort(new Vector2(28 * _Boss[i].X, 28 * _Boss[i].Y), content, EnnemiMort.TypeEnnemiMort.boss));
                        if (_Boss[i].Alerte)
                            GameplayScreen.Alerte = false;
                        _Boss.RemoveAt(i);
                        soundBank.PlayCue("cri");
                    }
                    else if (_Boss[i].Rectangle.Intersects(particule.Rectangle_Hadoken_heros1(heros1)))
                    {
                        _Boss[i].Vie = _Boss[i].Vie - 2;
                        soundBank.PlayCue("Bruitage boss touche");
                        particule.Rectangle_Hadoken_Est_Present_Hero1 = false;
                    }
                    else if (_Boss[i].Rectangle.Intersects(particule.Rectangle_Ball_heros1(heros1)))
                    {
                        _Boss[i].Vie = _Boss[i].Vie - 2;
                        soundBank.PlayCue("Bruitage boss touche");
                        particule.Rectangle_Ball_Est_Present_Hero1 = false;
                    }
                    else if (heros2 != null)
                    {
                        if (_Boss[i].Vie < 0 || heros2.AttaqueAuSabre(_Boss[i].X, _Boss[i].Y))
                        {
                            _Boss[i].Vie = 5;
                            morts.Add(new EnnemiMort(new Vector2(28 * _Boss[i].X, 28 * _Boss[i].Y), content, EnnemiMort.TypeEnnemiMort.boss));
                            if (_Boss[i].Alerte)
                                GameplayScreen.Alerte = false;
                            _Boss.RemoveAt(i);
                            soundBank.PlayCue("cri");
                        }
                        else if (_Boss[i].Rectangle.Intersects(particule.Rectangle_Hadoken_heros2(heros2)))
                        {
                            _Boss[i].Vie = _Boss[i].Vie - 2;
                            soundBank.PlayCue("Bruitage boss touche");
                            particule.Rectangle_Hadoken_Est_Present_Hero2 = false;
                        }
                        else if (_Boss[i].Rectangle.Intersects(particule.Rectangle_Ball_heros2(heros2)))
                        {
                            _Boss[i].Vie = _Boss[i].Vie - 2;
                            soundBank.PlayCue("Bruitage boss touche");
                            particule.Rectangle_Ball_Est_Present_Hero2 = false;
                        }
                    }
                    for (int j = 0; j < listeShuriken.Count; j++)
                        if (_Boss.Count > 0 && _Boss[i].Rectangle.Intersects(listeShuriken[j].Rectangle))
                        {
                            // une fois que le shuriken a touché le boss, le boss regarder vers le heros
                            if (listeShuriken[j].Direction == Vector2.UnitY)
                                _Boss[i].SourceRectangle = new Rectangle(26, 0, 16, 24);
                            else if (listeShuriken[j].Direction == -Vector2.UnitX)
                                _Boss[i].SourceRectangle = new Rectangle(26, 33, 16, 24);
                            else if (listeShuriken[j].Direction == -Vector2.UnitY)
                                _Boss[i].SourceRectangle = new Rectangle(26, 64, 16, 24);
                            else if (listeShuriken[j].Direction == Vector2.UnitX)
                                _Boss[i].SourceRectangle = new Rectangle(26, 97, 16, 24);

                            soundBank.PlayCue("Bruitage boss touche");
                            _Boss[i].Vie--;
                            listeShuriken.RemoveAt(j);
                            break;
                        }
                }
            }
        }
        public async Task <IActionResult> PostHerosLocations([FromBody] PassedGameData <int?> passedData)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            DateTime now = DateTime.UtcNow;

            if (passedData.UserToken == null || passedData.ActionToken == null)
            {
                return(BadRequest(new DataError("securityErr", "No authorization controll.")));
            }
            UserToken dbtoken = Security.CheckUserToken(this._context, passedData.UserToken);

            if (dbtoken == null)
            {
                return(BadRequest(new DataError("securityErr", "Your data has probably been stolen or modified manually. We suggest password's change.")));
            }
            else
            {
                if (!dbtoken.IsTimeValid(now))
                {
                    return(BadRequest(new DataError("timeoutErr", "You have been too long inactive. Relogin is required.")));
                }
                else
                {
                    dbtoken.UpdateToken(now);
                }
            }
            Heros       hero      = _context.Heros.FirstOrDefault(e => e.Name == passedData.ActionToken.HeroName);
            ActionToken gametoken = Security.CheckActionToken(_context, passedData.ActionToken, hero.HeroId);

            if (gametoken == null)
            {
                return(BadRequest(new DataError("securityErr", "Your data has probably been stolen or modified manually. We suggest password's change.")));
            }
            else
            {
                if (!gametoken.IsTimeValid(now))
                {
                    return(BadRequest(new DataError("timeoutErr", "You have been too long inactive. Relogin is required.")));
                }
                else
                {
                    gametoken.UpdateToken(now);
                }
            }
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                return(BadRequest(new DataError("databaseErr", "Failed to update tokens.")));
            }

            // can load location status - update status -> function (?)

            var location = _context.HerosLocations.FirstOrDefault(e => (e.HeroId == hero.HeroId) && (e.LocationIdentifier == hero.CurrentLocation));

            if (location == null)
            {
                return(BadRequest(new DataError("LocationErr", "Location is not available.")));
            }
            var descr = _context.LocationsDb.FirstOrDefault(e => e.LocationIdentifier == location.LocationIdentifier);

            if (descr == null)
            {
                return(BadRequest(new DataError("LocationErr", "LocationData is not available.")));
            }
            try
            {
                // TODO check location type -> vitual class or what?
                int LocationType = descr.LocationGlobalType;
                if (LocationType != 2)
                {
                    LocationDescription description = JsonConvert.DeserializeObject <LocationDescription>(descr.Sketch);
                    LocationState       state       = JsonConvert.DeserializeObject <LocationState>(location.Description);
                    description.LocationGlobalType = LocationType;

                    if (hero.Status == 1)
                    {
                        Traveling travel = _context.Traveling.FirstOrDefault(e => e.HeroId == hero.HeroId);
                        if (travel == null)
                        {
                            throw new Exception("Traveling hero without travel in DB.");
                        }
                        if (travel.HasEnded(now))
                        {
                            state                = description.MoveTo(travel.UpdatedLocationID(), state);
                            hero.Status          = 0;
                            location.Description = JsonConvert.SerializeObject(state);
                            _context.Traveling.Remove(travel);
                            try
                            {
                                await _context.SaveChangesAsync();
                            }
                            catch (DbUpdateException)
                            {
                                return(BadRequest(new DataError("databaseErr", "Failed to remove travel.")));
                            }
                            LocationResult <MainNodeResult> locationResult = description.GenLocalForm(state);
                            return(Ok(new { success = true, location = locationResult }));
                        }
                        else
                        {
                            return(BadRequest(new DataError("LocationErr", "Travel is not finished")));
                        }
                    }
                    else
                    {
                        return(BadRequest(new DataError("LocationErr", "Hero is not in travel mode")));
                    }
                }
                else
                {
                    InstanceDescription description = JsonConvert.DeserializeObject <InstanceDescription>(descr.Sketch);
                    InstanceState       state       = JsonConvert.DeserializeObject <InstanceState>(location.Description);
                    description.LocationGlobalType = LocationType;

                    if (hero.Status == 1)
                    {
                        Traveling travel = _context.Traveling.FirstOrDefault(e => e.HeroId == hero.HeroId);
                        if (travel == null)
                        {
                            throw new Exception("Traveling hero without travel in DB.");
                        }
                        if (travel.HasEnded(now))
                        {
                            state                = description.MoveTo(travel.UpdatedLocationID(), state);
                            hero.Status          = 0;
                            location.Description = JsonConvert.SerializeObject(state);
                            _context.Traveling.Remove(travel);
                            try
                            {
                                await _context.SaveChangesAsync();
                            }
                            catch (DbUpdateException)
                            {
                                return(BadRequest(new DataError("databaseErr", "Failed to remove travel.")));
                            }
                            LocationResult <InstanceNodeResult> locationResult = description.GenLocalForm(state);
                            return(Ok(new { success = true, location = locationResult }));
                        }
                        else
                        {
                            return(BadRequest(new DataError("LocationErr", "Travel is not finished")));
                        }
                    }
                    else
                    {
                        return(BadRequest(new DataError("LocationErr", "Hero is not in travel mode")));
                    }
                }
            }
            catch
            {
                return(BadRequest(new DataError("LocationErr", "Location is not available.")));
            }
        }
예제 #16
0
 public void UpdateBall(Heros heros)
 {
     if (heros.NumeroHero == 1)
         ball1.AddParticles(new Vector2(heros.position.X - Camera.X, heros.position.Y - Camera.Y), heros);
     else
         ball2.AddParticles(new Vector2(heros.position.X - Camera.X, heros.position.Y - Camera.Y), heros);
 }
예제 #17
0
    public IEnumerator playAttack(List <Card> pSelfBoard, Heros pSelfHeros, List <Card> pEnnemyBoard, Heros pEnnemyHeros)
    {
        yield return(new WaitForSeconds(1f));

        List <Card> selfBoard   = pSelfBoard.Clone( );
        List <Card> ennemyBoard = pEnnemyBoard.Clone( );

        float delay = 0f;

        foreach (Card creature in selfBoard)
        {
            Card toRemove = null;
            foreach (Card target in ennemyBoard)
            {
                if (!creature.isSleeping && creature.attack >= target.life)
                {
                    creature.attackTarget(target, delay);
                    toRemove = target;
                    delay   += .8f;
                    break;
                }
            }

            if (!creature.isSleeping && !creature.alreadyAttack)
            {
                creature.attackTarget(pEnnemyHeros, delay);
                delay += .8f;
            }

            if (toRemove)
            {
                ennemyBoard.Remove(toRemove);
            }
        }

        if (pSelfHeros.cost <= mMana)
        {
            foreach (Card target in ennemyBoard)
            {
                if (pSelfHeros.attack >= target.life)
                {
                    pSelfHeros.attackTarget(target, delay);
                    delay += .8f;
                    break;
                }
            }

            if (!pSelfHeros.alreadAttacked)
            {
                pSelfHeros.attackTarget(pEnnemyHeros, delay);
                delay += .8f;
            }
        }

        end(delay);
    }
예제 #18
0
    public void Join(int pViewID)
    {
        int pVID = pViewID / 1000;

        if (!Players.ContainsKey(pVID))
        {
            if (myID == 0)
            {
                myID = pVID;
            }
            Players.Add(pVID, false);
            //Debug.Log(" ID : " + pVID + " Joined");
        }
        if (!Heros.ContainsKey(pVID))
        {
            Heros.Add(pVID, hcp.E_HeroType.Soldier);
            //Debug.Log("My Hero is Soldier");
        }
        if (!Teams.ContainsKey(pVID))
        {
            TeamACount = 0;
            TeamBCount = 0;
            foreach (KeyValuePair <int, string> pair in Teams)
            {
                if (pair.Value == hcp.Constants.teamA_LayerName)
                {
                    TeamACount++;
                }
                else if (pair.Value == hcp.Constants.teamB_LayerName)
                {
                    TeamBCount++;
                }
            }
            if ((TeamACount <= TeamBCount))
            {
                //Debug.Log("Assigned A");
                Teams.Add(pVID, hcp.Constants.teamA_LayerName);
            }
            else
            {
                //Debug.Log("Assigned B");
                Teams.Add(pVID, hcp.Constants.teamB_LayerName);
            }
        }
        int[] DicpView = new int[Players.Count];
        Players.Keys.CopyTo(DicpView, 0);
        string[] DicTeam = new string[Teams.Count];
        Teams.Values.CopyTo(DicTeam, 0);
        bool[] DicPlayer = new bool[Players.Count];
        Players.Values.CopyTo(DicPlayer, 0);
        int[] DicHero = new int[Heros.Count];
        int   count   = 0;

        foreach (KeyValuePair <int, hcp.E_HeroType> items in Heros)
        {
            DicHero[count] = (int)items.Value;
            count++;
        }

        photonView.RPC("MasterDictionary", RpcTarget.Others, DicpView, DicTeam, DicPlayer, DicHero, pViewID);
    }
        public async Task <IActionResult> PostHeros([FromBody] PassedData <string> passedData)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            DateTime now = DateTime.UtcNow;

            if (passedData.UserToken == null)
            {
                return(BadRequest(new DataError("securityErr", "No authorization controll.")));
            }
            UserToken dbtoken = Security.CheckUserToken(this._context, passedData.UserToken);

            if (dbtoken == null)
            {
                return(BadRequest(new DataError("securityErr", "Your data has probably been stolen or modified manually. We suggest password's change.")));
            }
            else
            {
                if (!dbtoken.IsTimeValid(now))
                {
                    return(BadRequest(new DataError("timeoutErr", "You have been too long inactive. Relogin is required.")));
                }
                else
                {
                    dbtoken.UpdateToken(now);
                }
            }
            Heros hero = _context.Heros.Where(e => e.Name == passedData.Data).Join(_context.UsersHeros.Where(e => e.UserName == dbtoken.UserName), e => e.HeroId, e => e.HeroId, (a, b) => a).FirstOrDefault();

            if (hero == null)
            {
                return(BadRequest(new DataError("noHeroErr", "Hero is not available.")));
            }
            ActionToken       actionToken = Security.GenerateActionToken(hero.HeroId, _context);
            ActionTokenResult tokenResult = new ActionTokenResult()
            {
                HeroName = hero.Name,
                Token    = actionToken.HashedToken,
            };

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                return(BadRequest(new DataError("databaseErr", "Failed to update tokens.")));
            }

            try
            {
                var heroStatus = LocationHandler.GetHeroGeneralStatus(_context, hero, now);

                // equipment generation
                var Equipment = _context.Equipment.FirstOrDefault(e => e.HeroId == hero.HeroId);
                if (Equipment == null)
                {
                    return(BadRequest(new DataError("equipmentErr", "Hero is without equipment.")));
                }

                List <int?> used = new List <int?>
                {
                    Equipment.Armour, Equipment.Bracelet, Equipment.FirstHand, Equipment.Gloves, Equipment.Helmet, Equipment.Neckles, Equipment.Ring1, Equipment.Ring2,
                    Equipment.SecondHand, Equipment.Shoes, Equipment.Trousers
                };
                var ItemsOn = used.Where(e => e.HasValue).Select(e => e.Value).ToList();

                var Backpack  = _context.Backpack.Where(e => e.HeroId == hero.HeroId);
                var UsedItems = Backpack.Select(e => e.ItemId).Distinct().ToList();
                UsedItems.AddRange(ItemsOn);
                UsedItems = UsedItems.Distinct().OrderBy(e => e).ToList();

                var ItemsInUse = _context.Items.Join(UsedItems, e => e.ItemId, e => e, (a, b) => a).ToArray();

                EquipmentResult EQ = Equipment.GenResult(ItemsInUse.ToArray(), Backpack.ToList());

                return(Ok(new { success = true, actiontoken = tokenResult, hero = hero.GenResult(EQ, heroStatus.Location, heroStatus.StatusData) }));
            }
            catch (Exception e)
            {
                return(BadRequest(new DataError("statusErr", e.Message)));
            }
        }
예제 #20
0
 public Fumigene(YellokillerGame game, int howManyEffects, Heros heros, Carte carte)
     : base(game, howManyEffects)
 {
     this.heros = heros;
     this.carte = carte;
 }
        public async Task <IActionResult> PostHealing([FromBody] PassedGameData <int?> passedData)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            DateTime now = DateTime.UtcNow;

            if (passedData.UserToken == null || passedData.ActionToken == null)
            {
                return(BadRequest(new DataError("securityErr", "No authorization controll.")));
            }
            UserToken dbtoken = Security.CheckUserToken(this._context, passedData.UserToken);

            if (dbtoken == null)
            {
                return(BadRequest(new DataError("securityErr", "Your data has probably been stolen or modified manually. We suggest password's change.")));
            }
            else
            {
                if (!dbtoken.IsTimeValid(now))
                {
                    return(BadRequest(new DataError("timeoutErr", "You have been too long inactive. Relogin is required.")));
                }
                else
                {
                    dbtoken.UpdateToken(now);
                }
            }
            Heros       hero      = _context.Heros.FirstOrDefault(e => e.Name == passedData.ActionToken.HeroName);
            ActionToken gametoken = Security.CheckActionToken(_context, passedData.ActionToken, hero.HeroId);

            if (gametoken == null)
            {
                return(BadRequest(new DataError("securityErr", "Your data has probably been stolen or modified manually. We suggest password's change.")));
            }
            else
            {
                if (!gametoken.IsTimeValid(now))
                {
                    return(BadRequest(new DataError("timeoutErr", "You have been too long inactive. Relogin is required.")));
                }
                else
                {
                    gametoken.UpdateToken(now);
                }
            }
            // now do your stuff...
            if (hero.Status == 2)
            {
                var heal = _context.Healing.FirstOrDefault(e => e.HeroId == hero.HeroId);
                if (heal == null)
                {
                    return(BadRequest(new DataError("heroHpSucc", "Hero has no healing progress.")));
                }
                int newHP = heal.FinalHealth(now);
                hero.Hp = newHP;
                HeroCalculator.CheckHeroHP(hero, _context);

                _context.Healing.Remove(heal);
                hero.Status = 0;
                try
                {
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateException)
                {
                    return(BadRequest(new DataError("databaseErr", "Failed to update tokens.")));
                }
                return(Ok(new { success = true, newHP = hero.Hp }));
            }
            else
            {
                return(BadRequest(new DataError("LocationErr", "Hero is not healing.")));
            }
        }
예제 #22
0
        public async Task <IActionResult> PostLocationAction([FromBody] PassedGameData <int> passedData)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            DateTime now = DateTime.UtcNow;

            if (passedData.UserToken == null || passedData.ActionToken == null)
            {
                return(BadRequest(new DataError("securityErr", "No authorization controll.")));
            }
            UserToken dbtoken = Security.CheckUserToken(this._context, passedData.UserToken);

            if (dbtoken == null)
            {
                return(BadRequest(new DataError("securityErr", "Your data has probably been stolen or modified manually. We suggest password's change.")));
            }
            else
            {
                if (!dbtoken.IsTimeValid(now))
                {
                    return(BadRequest(new DataError("timeoutErr", "You have been too long inactive. Relogin is required.")));
                }
                else
                {
                    dbtoken.UpdateToken(now);
                }
            }
            Heros       hero      = _context.Heros.FirstOrDefault(e => e.Name == passedData.ActionToken.HeroName);
            ActionToken gametoken = Security.CheckActionToken(_context, passedData.ActionToken, hero.HeroId);

            if (gametoken == null)
            {
                return(BadRequest(new DataError("securityErr", "Your data has probably been stolen or modified manually. We suggest password's change.")));
            }
            else
            {
                if (!gametoken.IsTimeValid(now))
                {
                    return(BadRequest(new DataError("timeoutErr", "You have been too long inactive. Relogin is required.")));
                }
                else
                {
                    gametoken.UpdateToken(now);
                }
            }
            // now do your stuff...
            if (hero.Status == 0)
            {
                var location = _context.HerosLocations.FirstOrDefault(e => (e.HeroId == hero.HeroId) && (e.LocationIdentifier == hero.CurrentLocation));
                if (location == null)
                {
                    return(BadRequest(new DataError("LocationErr", "Location is not available.")));
                }
                var descr = _context.LocationsDb.FirstOrDefault(e => e.LocationIdentifier == location.LocationIdentifier);
                if (descr == null)
                {
                    return(BadRequest(new DataError("LocationErr", "LocationData is not available.")));
                }
                try
                {
                    // TODO check location type
                    int LocationType = descr.LocationGlobalType;
                    if (LocationType != 2)
                    {
                        LocationDescription description = JsonConvert.DeserializeObject <LocationDescription>(descr.Sketch);
                        LocationState       state       = JsonConvert.DeserializeObject <LocationState>(location.Description);
                        description.LocationGlobalType = descr.LocationGlobalType;

                        var CurrentNode = description.MainNodes.FirstOrDefault(e => e.NodeID == state.CurrentLocation);

                        if (CurrentNode.Data == -1)
                        {
                            try
                            {
                                await _context.SaveChangesAsync();
                            }
                            catch (DbUpdateException)
                            {
                                return(BadRequest(new DataError("databaseErr", "Failed to remember travel.")));
                            }
                            return(BadRequest(new DataError("notImplementedErr", "This feature has not been implemented yet. We are working on it!")));
                        }
                        try
                        {
                            if (!LocationHandler.OptionsForLocation.ContainsKey(CurrentNode.LocationType))
                            {
                                throw new Exception();
                            }
                            if (!LocationHandler.LocationTypeFunctions.ContainsKey(LocationHandler.OptionsForLocation[CurrentNode.LocationType][passedData.Data]))
                            {
                                throw new Exception();
                            }
                            var func = LocationHandler.LocationTypeFunctions[LocationHandler.OptionsForLocation[CurrentNode.LocationType][passedData.Data]];
                            func(_context, hero, CurrentNode.Data);
                            try
                            {
                                await _context.SaveChangesAsync();
                            }
                            catch (DbUpdateException)
                            {
                                return(BadRequest(new DataError("databaseErr", "Failed to remember action.")));
                            }
                        }
                        catch (OperationException e)
                        {
                            return(BadRequest(new DataError(e.ErrorClass, e.Message)));
                        }
                        catch
                        {
                            return(BadRequest(new DataError("notImplementedErr", "This feature has not been implemented yet. We are working on it!")));
                        }
                    }
                    else
                    {
                        InstanceDescription description = JsonConvert.DeserializeObject <InstanceDescription>(descr.Sketch);
                        InstanceState       state       = JsonConvert.DeserializeObject <InstanceState>(location.Description);
                        description.LocationGlobalType = descr.LocationGlobalType;

                        var CurrentNode = description.MainNodes.FirstOrDefault(e => e.NodeID == state.CurrentLocation);

                        if (CurrentNode.Data == -1)
                        {
                            try
                            {
                                await _context.SaveChangesAsync();
                            }
                            catch (DbUpdateException)
                            {
                                return(BadRequest(new DataError("databaseErr", "Failed to remember travel.")));
                            }
                            return(BadRequest(new DataError("notImplementedErr", "This feature has not been implemented yet. We are working on it!")));
                        }
                        try
                        {
                            if (!LocationHandler.OptionsForInstances.ContainsKey(CurrentNode.InstanceType))
                            {
                                throw new Exception();
                            }
                            if (!LocationHandler.InstanceTypeFunctions.ContainsKey(LocationHandler.OptionsForInstances[CurrentNode.InstanceType][passedData.Data]))
                            {
                                throw new Exception();
                            }
                            var func = LocationHandler.InstanceTypeFunctions[LocationHandler.OptionsForInstances[CurrentNode.InstanceType][passedData.Data]];
                            func(_context, hero, CurrentNode.Data);
                            try
                            {
                                await _context.SaveChangesAsync();
                            }
                            catch (DbUpdateException)
                            {
                                return(BadRequest(new DataError("databaseErr", "Failed to remember action.")));
                            }
                        }
                        catch
                        {
                            return(BadRequest(new DataError("notImplementedErr", "This feature has not been implemented yet. We are working on it!")));
                        }
                    }
                    // load new hero status
                    try
                    {
                        var heroStatus = LocationHandler.GetHeroGeneralStatus(_context, hero, now);
                        return(Ok(new { success = true, location = heroStatus.Location, statusData = heroStatus.StatusData, heroStatus = heroStatus.HeroStatus }));
                    }
                    catch (Exception e)
                    {
                        return(BadRequest(new DataError("statusErr", e.Message)));
                    }
                }
                catch
                {
                    return(BadRequest(new DataError("LocationErr", "Location is not available.")));
                }
            }
            else
            {
                return(BadRequest(new DataError("LocationErr", "Hero is not able to change state.")));
            }
        }
예제 #23
0
        public async Task <IActionResult> PostHerosLocations([FromBody] PassedGameData <int?> passedData)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            DateTime now = DateTime.UtcNow;

            if (passedData.UserToken == null || passedData.ActionToken == null)
            {
                return(BadRequest(new DataError("securityErr", "No authorization controll.")));
            }
            UserToken dbtoken = Security.CheckUserToken(this._context, passedData.UserToken);

            if (dbtoken == null)
            {
                return(BadRequest(new DataError("securityErr", "Your data has probably been stolen or modified manually. We suggest password's change.")));
            }
            else
            {
                if (!dbtoken.IsTimeValid(now))
                {
                    return(BadRequest(new DataError("timeoutErr", "You have been too long inactive. Relogin is required.")));
                }
                else
                {
                    dbtoken.UpdateToken(now);
                }
            }
            Heros       hero      = _context.Heros.FirstOrDefault(e => e.Name == passedData.ActionToken.HeroName);
            ActionToken gametoken = Security.CheckActionToken(_context, passedData.ActionToken, hero.HeroId);

            if (gametoken == null)
            {
                return(BadRequest(new DataError("securityErr", "Your data has probably been stolen or modified manually. We suggest password's change.")));
            }
            else
            {
                if (!gametoken.IsTimeValid(now))
                {
                    return(BadRequest(new DataError("timeoutErr", "You have been too long inactive. Relogin is required.")));
                }
                else
                {
                    gametoken.UpdateToken(now);
                }
            }
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                return(BadRequest(new DataError("databaseErr", "Failed to update tokens.")));
            }
            // can do stuff

            var Equipment = _context.Equipment.FirstOrDefault(e => e.HeroId == hero.HeroId);

            if (Equipment == null)
            {
                return(BadRequest(new DataError("equipmentErr", "Hero is without equipment.")));
            }
            List <int?> used = new List <int?>
            {
                Equipment.Armour, Equipment.Bracelet, Equipment.FirstHand, Equipment.Gloves, Equipment.Neckles, Equipment.Ring1, Equipment.Ring2,
                Equipment.SecondHand, Equipment.Shoes, Equipment.Trousers
            };
            var ItemsOn = used.Where(e => e.HasValue).Select(e => e.Value).ToList();

            var Backpack  = _context.Backpack.Where(e => e.HeroId == hero.HeroId);
            var UsedItems = Backpack.Select(e => e.ItemId).Distinct().ToList();

            UsedItems.AddRange(ItemsOn);
            UsedItems = UsedItems.Distinct().OrderBy(e => e).ToList();

            var ItemsInUse = _context.Items.Join(UsedItems, e => e.ItemId, e => e, (a, b) => a).ToArray();

            EquipmentResult EQ = Equipment.GenResult(ItemsInUse.ToArray(), Backpack.ToList());

            return(Ok(new { success = true, equipment = EQ }));
        }
예제 #24
0
        public void UpdateExplosions_heros(Heros heros)
        {
            if (heros.NumeroHero == 1)
                hadoken_heros1.AddParticles(new Vector2(heros.position.X - Camera.X, heros.position.Y - Camera.Y), heros);
            else
                hadoken_heros2.AddParticles(new Vector2(heros.position.X - Camera.X, heros.position.Y - Camera.Y), heros);

            fume_hadoken.AddParticles(new Vector2(heros.position.X - Camera.X, heros.position.Y - Camera.Y), heros);
        }
        public async Task <IActionResult> PostFighting([FromBody] PassedGameData <bool> passedData)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            DateTime now = DateTime.UtcNow;

            if (passedData.UserToken == null || passedData.ActionToken == null)
            {
                return(BadRequest(new DataError("securityErr", "No authorization controll.")));
            }
            UserToken dbtoken = Security.CheckUserToken(this._context, passedData.UserToken);

            if (dbtoken == null)
            {
                return(BadRequest(new DataError("securityErr", "Your data has probably been stolen or modified manually. We suggest password's change.")));
            }
            else
            {
                if (!dbtoken.IsTimeValid(now))
                {
                    return(BadRequest(new DataError("timeoutErr", "You have been too long inactive. Relogin is required.")));
                }
                else
                {
                    dbtoken.UpdateToken(now);
                }
            }
            Heros       hero      = _context.Heros.FirstOrDefault(e => e.Name == passedData.ActionToken.HeroName);
            ActionToken gametoken = Security.CheckActionToken(_context, passedData.ActionToken, hero.HeroId);

            if (gametoken == null)
            {
                return(BadRequest(new DataError("securityErr", "Your data has probably been stolen or modified manually. We suggest password's change.")));
            }
            else
            {
                if (!gametoken.IsTimeValid(now))
                {
                    return(BadRequest(new DataError("timeoutErr", "You have been too long inactive. Relogin is required.")));
                }
                else
                {
                    gametoken.UpdateToken(now);
                }
            }
            // now do your stuff...
            if (hero.Status == 3)
            {
                // to pass
                object statusData = null;
                var    Added      = new List <EquipmentModifyResult.EquipmentModification>();
                var    newItems   = new List <ItemResult>();

                var fight = _context.Fighting.FirstOrDefault(e => e.HeroId == hero.HeroId);
                if (fight == null)
                {
                    return(BadRequest(new DataError("fightErr", "Hero has no fight data.")));
                }
                if (!fight.IsOver)
                {
                    return(BadRequest(new DataError("fightErr", "Fight has not been finished.")));
                }
                if (hero.Hp > 0)
                {
                    hero.Status = 0;
                    if (fight.Loot.HasValue && passedData.Data)
                    {
                        var Item = _context.Items.FirstOrDefault(e => e.ItemId == fight.Loot.Value);
                        if (Item == null)
                        {
                            return(BadRequest(new DataError("itemErr", "Looted item not found.")));
                        }
                        newItems.Add((ItemResult)Item);
                        var heroBackpack = _context.Backpack.Where(e => e.HeroId == hero.HeroId);
                        int count        = heroBackpack.Count();
                        if (count > 0)
                        {
                            var Equipment = _context.Equipment.FirstOrDefault(e => e.HeroId == hero.HeroId);
                            if (Equipment == null)
                            {
                                return(BadRequest(new DataError("heroErr", "Hero without equipment.")));
                            }
                            if (Equipment.BackpackSize <= count)
                            {
                                return(BadRequest(new DataError("backpackErr", "In order to add this reward, you need to remove one item from backpack or resign from reward.")));
                            }
                            if (heroBackpack.Where(e => e.SlotNr == 0).Count() > 0)
                            {
                                var preSlot = heroBackpack.FirstOrDefault(e => heroBackpack.Where(f => f.SlotNr == e.SlotNr + 1).Count() == 0);
                                _context.Backpack.Add(new Backpack()
                                {
                                    HeroId = hero.HeroId,
                                    ItemId = fight.Loot.Value,
                                    SlotNr = preSlot.SlotNr + 1,
                                });
                                Added.Add(new EquipmentModifyResult.EquipmentModification()
                                {
                                    ItemID = fight.Loot.Value, Target = "Backpack" + (preSlot.SlotNr + 1)
                                });
                            }
                            else
                            {
                                _context.Backpack.Add(new Backpack()
                                {
                                    HeroId = hero.HeroId,
                                    ItemId = fight.Loot.Value,
                                    SlotNr = 0,
                                });
                                Added.Add(new EquipmentModifyResult.EquipmentModification()
                                {
                                    ItemID = fight.Loot.Value, Target = "Backpack" + 0
                                });
                            }
                        }
                        else
                        {
                            _context.Backpack.Add(new Backpack()
                            {
                                HeroId = hero.HeroId,
                                ItemId = fight.Loot.Value,
                                SlotNr = 0,
                            });
                            Added.Add(new EquipmentModifyResult.EquipmentModification()
                            {
                                ItemID = fight.Loot.Value, Target = "Backpack" + 0
                            });
                        }
                    }
                    var enemy = _context.Enemies.FirstOrDefault(e => e.EnemyId == fight.EnemyId);
                    if (enemy == null)
                    {
                        return(BadRequest(new DataError("fightErr", "Enemy not found.")));
                    }
                    hero.Experience += HeroCalculator.ExpForFight(hero.Lvl, enemy.Lvl);
                    bool update = false;
                    while (hero.Experience >= HeroCalculator.ExpToLevel(hero.Lvl + 1))
                    {
                        hero.Lvl += 1;
                        update    = true;
                    }
                    if (update)
                    {
                        var(hp, sl) = HeroCalculator.HPSLmax(hero, _context);
                        hero.Hp     = hp;
                    }
                }
                else
                {
                    hero.Status = 2;
                    var(hp, sl) = HeroCalculator.HPSLmax(hero, _context);
                    if (hero.Hp >= hp)
                    {
                        hero.Hp = hp;
                        try
                        {
                            await _context.SaveChangesAsync();
                        }
                        catch (DbUpdateException)
                        {
                            return(BadRequest(new DataError("databaseErr", "Failed to update tokens.")));
                        }
                    }
                    int     time = HeroCalculator.RecoveryTime(hp, hero.Hp, hero.Lvl) / hero.VelocityFactor;
                    Healing heal = new Healing()
                    {
                        EndTime    = now.AddSeconds(time),
                        HeroId     = hero.HeroId,
                        StartHp    = hero.Hp,
                        StartHpmax = hp,
                        StartTime  = now,
                    };
                    this._context.Healing.Add(heal);

                    statusData = heal.GenHealingResult(now);
                }
                // TODO update map!
                _context.Fighting.Remove(fight);
                try
                {
                    var location = LocationHandler.InstanceClearCurrent(_context, hero);
                    try
                    {
                        await _context.SaveChangesAsync();
                    }
                    catch (DbUpdateException)
                    {
                        return(BadRequest(new DataError("databaseErr", "Failed to update tokens.")));
                    }
                    return(Ok(new { success = true, heroStatus = hero.Status, newHP = hero.Hp, newHPmax = HeroCalculator.BaseHP(hero.Lvl), newLvl = hero.Lvl, newExp = hero.Experience, location, statusData, added = Added.ToArray(), newItems = newItems.ToArray() }));
                }
                catch (OperationException e)
                {
                    return(BadRequest(new DataError(e.ErrorClass, e.Message)));
                }
            }
            else
            {
                return(BadRequest(new DataError("LocationErr", "Hero is not in the fight.")));
            }
        }
예제 #26
0
 public static void Boss_Esquive_Shuriken(Heros heros, Boss boss, List<Shuriken> shuriken, Carte carte, Rectangle camera)
 {
     foreach (Shuriken _shuriken in shuriken)
     {
         if (boss.VaEnHaut && boss.VaEnBas && boss.VaADroite && boss.VaAGauche)
         {
             if (_shuriken.Direction == Vector2.UnitX && boss.Regarde_Gauche && Math.Abs(boss.X - _shuriken.X) < 4 && boss.Y == _shuriken.Y)
             // si le shuriken va a droite , le shuriken est a moins de 4 cases du boss et que le shuriken
             // et le boss sont sur la meme position en Y alors :
             {
                 if (boss.Y + 1 < Taille_Map.HAUTEUR_MAP && carte.Cases[boss.Y + 1, boss.X].EstFranchissable)
                 // si le boss n est pas tout en bas de la map ou coller vers le bas a une texture non franchissable :
                 {
                     boss.positionDesiree.Y += 28; // il descend
                     boss.VaEnBas = false;
                     break; // Jpense que c'est inutile, mais on sait jamais
                 }
                 // si il est colle a une texture non franchissable :
                 else if (boss.Y - 1 >= 0 && carte.Cases[boss.Y - 1, boss.X].EstFranchissable)
                 {
                     boss.positionDesiree.Y -= 28; // il monte
                     boss.VaEnHaut = false;
                     break;
                 }
             }
             else if (_shuriken.Direction == Vector2.UnitY && boss.Regarde_Haut && Math.Abs(boss.Y - _shuriken.Y) < 4 && boss.X == _shuriken.X)
             // si le shuriken va en bas, le shuriken est a moins de 7 cases du boss et que le shuriken
             // et le boss sont sur la meme position en X alors :
             {
                 if (boss.X + 1 < Taille_Map.LARGEUR_MAP && carte.Cases[boss.Y, boss.X + 1].EstFranchissable)
                 {
                     boss.positionDesiree.X += 28; // il va a droite
                     boss.VaADroite = false;
                     break;
                 }
                 // si il est colle a une texture non franchissable :
                 else if (boss.X - 1 >= 0 && carte.Cases[boss.Y, boss.X - 1].EstFranchissable)
                 {
                     boss.positionDesiree.X -= 28; // il va a gauche
                     boss.VaAGauche = false;
                     break;
                 }
             }
             else if (_shuriken.Direction == -Vector2.UnitX && boss.Regarde_Droite && Math.Abs(boss.X - _shuriken.X) < 4 && boss.Y == _shuriken.Y)
             // si le shuriken va a droite , le shuriken est a moins de 7 cases du boss et que le shuriken
             // et le boss sont sur la meme position en Y alors :
             {
                 if (boss.Y + 1 < Taille_Map.HAUTEUR_MAP && carte.Cases[boss.Y + 1, boss.X].EstFranchissable)
                 // si le boss n est pas tout en bas de la map ou coller vers le bas a une texture non franchissable :
                 {
                     boss.positionDesiree.Y -= 28; // il descend
                     boss.VaEnHaut = false;
                     break; // Jpense que c'est inutile, mais on sait jamais
                 }
                 // si il est colle a une texture non franchissable :
                 else if (boss.Y - 1 >= 0 && carte.Cases[boss.Y - 1, boss.X].EstFranchissable)
                 {
                     boss.positionDesiree.Y += 28; // il monte
                     boss.VaEnBas = false;
                     break;
                 }
             }
             else if (_shuriken.Direction == -Vector2.UnitY && boss.Regarde_Bas && Math.Abs(boss.Y - _shuriken.Y) < 4 && boss.X == _shuriken.X)
             // si le shuriken va en bas, le shuriken est a moins de 7 cases du boss et que le shuriken
             // et le boss sont sur la meme position en X alors :
             {
                 if (boss.X + 1 < Taille_Map.LARGEUR_MAP && carte.Cases[boss.Y, boss.X + 1].EstFranchissable)
                 {
                     boss.positionDesiree.X -= 28; // il va a droite
                     boss.VaAGauche = false;
                     break;
                 }
                 // si il est colle a une texture non franchissable :
                 else if (boss.X - 1 >= 0 && carte.Cases[boss.Y, boss.X - 1].EstFranchissable)
                 {
                     boss.positionDesiree.X += 28; // il va a gauche
                     boss.VaADroite = false;
                     break;
                 }
             }
         }
     }
 }
        public async Task <IActionResult> PostFighting([FromBody] PassedGameData <FightingCalculator.AttackType> passedData)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            DateTime now = DateTime.UtcNow;

            if (passedData.UserToken == null || passedData.ActionToken == null)
            {
                return(BadRequest(new DataError("securityErr", "No authorization controll.")));
            }
            UserToken dbtoken = Security.CheckUserToken(this._context, passedData.UserToken);

            if (dbtoken == null)
            {
                return(BadRequest(new DataError("securityErr", "Your data has probably been stolen or modified manually. We suggest password's change.")));
            }
            else
            {
                if (!dbtoken.IsTimeValid(now))
                {
                    return(BadRequest(new DataError("timeoutErr", "You have been too long inactive. Relogin is required.")));
                }
                else
                {
                    dbtoken.UpdateToken(now);
                }
            }
            Heros       hero      = _context.Heros.FirstOrDefault(e => e.Name == passedData.ActionToken.HeroName);
            ActionToken gametoken = Security.CheckActionToken(_context, passedData.ActionToken, hero.HeroId);

            if (gametoken == null)
            {
                return(BadRequest(new DataError("securityErr", "Your data has probably been stolen or modified manually. We suggest password's change.")));
            }
            else
            {
                if (!gametoken.IsTimeValid(now))
                {
                    return(BadRequest(new DataError("timeoutErr", "You have been too long inactive. Relogin is required.")));
                }
                else
                {
                    gametoken.UpdateToken(now);
                }
            }
            // now do your stuff...
            if (hero.Status == 3)
            {
                var fighting = _context.Fighting.FirstOrDefault(e => e.HeroId == hero.HeroId);
                if (fighting == null)
                {
                    return(BadRequest(new DataError("fightingErr", "Failed to load fight. Hero is not in fight.")));
                }
                if (fighting.IsOver)
                {
                    return(BadRequest(new DataError("fightingErr", "Fight is already finished!")));
                }
                var enemy = _context.Enemies.FirstOrDefault(e => e.EnemyId == fighting.EnemyId);
                if (enemy == null)
                {
                    return(BadRequest(new DataError("fightingErr", "Failed to load enemy.")));
                }
                var Logs = FightingCalculator.MakeTurn(fighting, hero, enemy, passedData.Data, this._context);
                try
                {
                    await _context.SaveChangesAsync();

                    var result = fighting.GenResult(_context, hero, enemy);
                    result.Log = Logs;
                    return(Ok(new { success = true, fightingData = result, heroHP = hero.Hp }));
                }
                catch (DbUpdateException)
                {
                    return(BadRequest(new DataError("databaseErr", "Failed to update tokens.")));
                }
            }
            else
            {
                return(BadRequest(new DataError("LocationErr", "Hero is not fighting.")));
            }
        }
예제 #28
0
 public static void Collisions_Heros_Interrupteurs(Heros heros1, Heros heros2, ref List<Interrupteur> interrupteurs, SoundBank soundBank, Carte carte)
 {
     foreach (Interrupteur bouton in interrupteurs)
         if (heros1.X == bouton.position.X && heros1.Y == bouton.position.Y || heros2 != null && heros2.X == bouton.position.X && heros2.Y == bouton.position.Y)
             bouton.OuvrirPorte(soundBank, carte);
 }
예제 #29
0
        public void Update(GameTime gameTime, Carte carte, Heros heros, Rectangle camera)
        {
            rectangle.X = (int)position.X + 1;
            rectangle.Y = (int)position.Y + 1;

            if (pseudoChrono < 10 && Math.Sqrt((this.X - heros.X) * (this.X - heros.X) + (this.Y - heros.Y) * (this.Y - heros.Y)) > 5)
                pseudoChrono += gameTime.ElapsedGameTime.TotalSeconds;
            else
            {
                pseudoChrono = 0;
                depart = carte.Cases[Y, X];
                arrivee = carte.Cases[heros.Y, heros.X];
                chemin = Pathfinding.CalculChemin(carte, depart, arrivee);
            }

            if (chemin != null && chemin.Count != 0)
            {
                if (VaEnHaut && VaEnBas && VaADroite && VaAGauche)
                {
                    if ((int)chemin[chemin.Count - 1].X < X)
                    {
                        positionDesiree.X -= 28;
                        VaAGauche = false;
                        chemin.RemoveAt(chemin.Count - 1);
                    }
                    else if ((int)chemin[chemin.Count - 1].X > X)
                    {
                        positionDesiree.X += 28;
                        VaADroite = false;
                        chemin.RemoveAt(chemin.Count - 1);
                    }
                    else if ((int)chemin[chemin.Count - 1].Y < Y)
                    {
                        positionDesiree.Y -= 28;
                        VaEnHaut = false;
                        chemin.RemoveAt(chemin.Count - 1);
                    }
                    else if ((int)chemin[chemin.Count - 1].Y > Y)
                    {
                        positionDesiree.Y += 28;
                        VaEnBas = false;
                        chemin.RemoveAt(chemin.Count - 1);
                    }
                    else
                        chemin.RemoveAt(chemin.Count - 1);
                }
            }

            if (SourceRectangle.Value.Y == 0)
            {
                SourceRectangle = new Rectangle((int)Index * 24, 0, 16, 24);
                Regarde_Haut = true;
            }
            else
                Regarde_Haut = false;

            if (SourceRectangle.Value.Y == 97)
            {
                SourceRectangle = new Rectangle((int)Index * 24, 97, 16, 24);
                Regarde_Gauche = true;
            }
            else
                Regarde_Gauche = false;

            if (SourceRectangle.Value.Y == 64)
            {
                SourceRectangle = new Rectangle((int)Index * 24, 64, 16, 24);
                Regarde_Bas = true;
            }
            else
                Regarde_Bas = false;

            if (SourceRectangle.Value.Y == 33)
            {
                SourceRectangle = new Rectangle((int)Index * 24, 33, 16, 24);
                Regarde_Droite = true;
            }
            else
                Regarde_Droite = false;

            if (!VaEnHaut)
            {
                if (position != positionDesiree)
                {
                    position.Y -= VitesseSprite;
                    SourceRectangle = new Rectangle((int)Index * 24, 0, 16, 24);
                    Index += gameTime.ElapsedGameTime.Milliseconds * VitesseAnimation;

                    if (Index >= MaxIndex)
                        Index = 0f;
                }
                else
                {
                    VaEnHaut = true;
                    position = positionDesiree;
                    Index = 0f;
                }
            }

            if (!VaEnBas)
            {
                if (position != positionDesiree)
                {
                    position.Y += VitesseSprite;
                    SourceRectangle = new Rectangle((int)Index * 24, 64, 16, 24);
                    Index += gameTime.ElapsedGameTime.Milliseconds * VitesseAnimation;

                    if (Index >= MaxIndex)
                        Index = 0f;
                }
                else
                {
                    VaEnBas = true;
                    position = positionDesiree;
                    Index = 0f;
                }
            }

            if (!VaAGauche)
            {
                if (position != positionDesiree)
                {
                    position.X -= VitesseSprite;
                    SourceRectangle = new Rectangle((int)Index * 24, 97, 16, 24);
                    Index += gameTime.ElapsedGameTime.Milliseconds * VitesseAnimation;

                    if (Index >= MaxIndex)
                        Index = 0f;
                }
                else
                {
                    VaAGauche = true;
                    position = positionDesiree;
                    Index = 0f;
                }
            }

            if (!VaADroite)
            {
                if (position != positionDesiree)
                {
                    position.X += VitesseSprite;
                    SourceRectangle = new Rectangle((int)Index * 24, 33, 16, 24);
                    Index += gameTime.ElapsedGameTime.Milliseconds * VitesseAnimation;

                    if (Index >= MaxIndex)
                        Index = 0f;
                }
                else
                {
                    VaADroite = true;
                    position = positionDesiree;
                    Index = 0f;
                }
            }
        }
예제 #30
0
        public static bool Collision_Heros_Bonus(ref Heros heros1, ref Heros heros2, ref List<Bonus> bonus, SoundBank soundBank)
        {
            for (int u = 0; u < bonus.Count; u++)
            {
                if (heros1.X == bonus[u].X && heros1.Y == bonus[u].Y)
                {
                    switch (bonus[u].TypeBonus)
                    {
                        case TypeBonus.shuriken:
                            heros1.NombreShuriken += 3;
                            bonus.RemoveAt(u);
                            soundBank.PlayCue("shurikenobt");
                            break;
                        case TypeBonus.hadoken:
                            heros1.NombreHadoken++;
                            bonus.RemoveAt(u);
                            soundBank.PlayCue("hadokenobt");
                            break;
                        case TypeBonus.checkPoint:
                            bonus.RemoveAt(u);
                            soundBank.PlayCue("CheckPoint");
                            return true;
                    }
                }
            }

            if (heros2 != null)
            {
                for (int u = 0; u < bonus.Count; u++)
                {
                    if (heros2.X == bonus[u].X && heros2.Y == bonus[u].Y)
                    {
                        switch (bonus[u].TypeBonus)
                        {
                            case TypeBonus.shuriken:
                                heros2.NombreShuriken += 3;
                                bonus.RemoveAt(u);
                                soundBank.PlayCue("shurikenobt");
                                break;
                            case TypeBonus.hadoken:
                                heros2.NombreHadoken++;
                                bonus.RemoveAt(u);
                                soundBank.PlayCue("hadokenobt");
                                break;
                            case TypeBonus.checkPoint:
                                bonus.RemoveAt(u);
                                soundBank.PlayCue("CheckPoint");
                                return true;
                        }
                    }
                }
            }
            return false;
        }
        public async Task <IActionResult> PostTraveling([FromBody] PassedGameData <int?> passedData)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            DateTime now = DateTime.UtcNow;

            if (passedData.UserToken == null || passedData.ActionToken == null)
            {
                return(BadRequest(new DataError("securityErr", "No authorization controll.")));
            }
            UserToken dbtoken = Security.CheckUserToken(this._context, passedData.UserToken);

            if (dbtoken == null)
            {
                return(BadRequest(new DataError("securityErr", "Your data has probably been stolen or modified manually. We suggest password's change.")));
            }
            else
            {
                if (!dbtoken.IsTimeValid(now))
                {
                    return(BadRequest(new DataError("timeoutErr", "You have been too long inactive. Relogin is required.")));
                }
                else
                {
                    dbtoken.UpdateToken(now);
                }
            }
            Heros       hero      = _context.Heros.FirstOrDefault(e => e.Name == passedData.ActionToken.HeroName);
            ActionToken gametoken = Security.CheckActionToken(_context, passedData.ActionToken, hero.HeroId);

            if (gametoken == null)
            {
                return(BadRequest(new DataError("securityErr", "Your data has probably been stolen or modified manually. We suggest password's change.")));
            }
            else
            {
                if (!gametoken.IsTimeValid(now))
                {
                    return(BadRequest(new DataError("timeoutErr", "You have been too long inactive. Relogin is required.")));
                }
                else
                {
                    gametoken.UpdateToken(now);
                }
            }
            // if can go there
            if (hero.Status == 1)
            {
                try
                {
                    var Travel = _context.Traveling.FirstOrDefault(e => e.HeroId == hero.HeroId);
                    if (Travel == null || Travel.HasEnded(now) || Travel.IsReverse)
                    {
                        throw new Exception();
                    }
                    Travel.IsReverse   = true;
                    Travel.ReverseTime = now;
                    TravelResult travelResult = Travel.GenTravelResult(now);
                    try
                    {
                        await _context.SaveChangesAsync();

                        return(Ok(new { success = true, travel = travelResult }));
                    }
                    catch (DbUpdateException)
                    {
                        return(BadRequest(new DataError("databaseErr", "Failed to remember travel.")));
                    }
                }
                catch
                {
                    return(BadRequest(new DataError("TravelErr", "Travel reverse is not available.")));
                }
            }
            else
            {
                return(BadRequest(new DataError("LocationErr", "Hero is not in the travel.")));
            }
        }
예제 #32
0
        public static bool Collision_Heros_ExplosionStatues(List<Statue> _statues, Heros heros1, Heros heros2, MoteurParticule particule, SoundBank soundBank)
        {
            if (_statues.Count != 0)
            {
                for (int i = 0; i < _statues.Count; i++)
                {
                    if (heros1.Rectangle.Intersects(particule.Rectangle_Hadoken_Statue(_statues[i])))
                    {
                        ServiceHelper.Get<IGamePadService>().Vibration(50);
                        soundBank.PlayCue("CriMortHero");
                        return true;
                    }
                    if (heros2 != null)
                    {
                        if (heros2.Rectangle.Intersects(particule.Rectangle_Hadoken_Statue(_statues[i])))
                        {
                            ServiceHelper.Get<IGamePadService>().Vibration(50);
                            soundBank.PlayCue("CriMortHero");
                            return true;
                        }

                    }
                }
            }
            return false;
        }
 public void Parse(GameBitBuffer buffer)
 {
     Field0 = buffer.ReadInt(32);
     Field1 = buffer.ReadCharArray(256);
     Field2 = buffer.ReadCharArray(256);
     Field3 = buffer.ReadInt(32);
     Field4 = buffer.ReadInt(32);
     tItemTypeTable = new Items();
     tItemTypeTable.Parse(buffer);
     tItemTable = new Items();
     tItemTable.Parse(buffer);
     tExperienceTable = new ExperienceTable();
     tExperienceTable.Parse(buffer);
     tHelpCodesTable = new HelpCodes();
     tHelpCodesTable.Parse(buffer);
     tMonsterLevelTable = new MonsterLevelTable();
     tMonsterLevelTable.Parse(buffer);
     tAffixTable = new AffixTable();
     tAffixTable.Parse(buffer);
     tHeroTable = new Heros();
     tHeroTable.Parse(buffer);
     tMovementStyleTable = new MovementStyles();
     tMovementStyleTable.Parse(buffer);
     tLabelGBIDTable = new Labels();
     tLabelGBIDTable.Parse(buffer);
     tLootDistTable = new LootDistributionTable();
     tLootDistTable.Parse(buffer);
     tRareItemNamesTable = new RareItemNamesTable();
     tRareItemNamesTable.Parse(buffer);
     tMonsterAffixesTable = new MonsterAffixesTable();
     tMonsterAffixesTable.Parse(buffer);
     tMonsterNamesTable = new RareMonsterNamesTable();
     tMonsterNamesTable.Parse(buffer);
     tSocketedEffectTable = new SocketedEffectsTable();
     tSocketedEffectTable.Parse(buffer);
     tItemEnhancementTable = new ItemEnhancementTable();
     tItemEnhancementTable.Parse(buffer);
     tItemDropTable = new ItemDropTable();
     tItemDropTable.Parse(buffer);
     tItemLevelModTable = new ItemLevelModTable();
     tItemLevelModTable.Parse(buffer);
     tQualityClassTable = new QualityClassTable();
     tQualityClassTable.Parse(buffer);
     tHirelingTable = new Hirelings();
     tHirelingTable.Parse(buffer);
     tSetItemBonusTable = new SetItemBonusTable();
     tSetItemBonusTable.Parse(buffer);
     tEliteModTable = new EliteModifiers();
     tEliteModTable.Parse(buffer);
     tItemTierTable = new ItemTiers();
     tItemTierTable.Parse(buffer);
     tPowerFormulaTable = new PowerFormulaTable();
     tPowerFormulaTable.Parse(buffer);
     tRecipeTable = new RecipesTable();
     tRecipeTable.Parse(buffer);
     tScriptedAchievementEventsTable = new ScriptedAchievementEventsTable();
     tScriptedAchievementEventsTable.Parse(buffer);
 }
예제 #34
0
        public async Task <IActionResult> PostHealing([FromBody] PassedGameData <int?> passedData)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            DateTime now = DateTime.UtcNow;

            if (passedData.UserToken == null || passedData.ActionToken == null)
            {
                return(BadRequest(new DataError("securityErr", "No authorization controll.")));
            }
            UserToken dbtoken = Security.CheckUserToken(this._context, passedData.UserToken);

            if (dbtoken == null)
            {
                return(BadRequest(new DataError("securityErr", "Your data has probably been stolen or modified manually. We suggest password's change.")));
            }
            else
            {
                if (!dbtoken.IsTimeValid(now))
                {
                    return(BadRequest(new DataError("timeoutErr", "You have been too long inactive. Relogin is required.")));
                }
                else
                {
                    dbtoken.UpdateToken(now);
                }
            }
            Heros       hero      = _context.Heros.FirstOrDefault(e => e.Name == passedData.ActionToken.HeroName);
            ActionToken gametoken = Security.CheckActionToken(_context, passedData.ActionToken, hero.HeroId);

            if (gametoken == null)
            {
                return(BadRequest(new DataError("securityErr", "Your data has probably been stolen or modified manually. We suggest password's change.")));
            }
            else
            {
                if (!gametoken.IsTimeValid(now))
                {
                    return(BadRequest(new DataError("timeoutErr", "You have been too long inactive. Relogin is required.")));
                }
                else
                {
                    gametoken.UpdateToken(now);
                }
            }
            // now do your stuff...
            if (hero.Status == 0)
            {
                var(hp, sl) = HeroCalculator.HPSLmax(hero, _context);
                if (hero.Hp >= hp)
                {
                    hero.Hp = hp;
                    try
                    {
                        await _context.SaveChangesAsync();

                        return(BadRequest(new DataError("heroHpSucc", "Hero has already full HP.")));
                    }
                    catch (DbUpdateException)
                    {
                        return(BadRequest(new DataError("databaseErr", "Failed to update tokens.")));
                    }
                }
                int     time = HeroCalculator.RecoveryTime(hp, hero.Hp, hero.Lvl) / hero.VelocityFactor;
                Healing heal = new Healing()
                {
                    EndTime    = now.AddSeconds(time),
                    HeroId     = hero.HeroId,
                    StartHp    = hero.Hp,
                    StartHpmax = hp,
                    StartTime  = now,
                };
                this._context.Healing.Add(heal);
                hero.Status = 2;
                try
                {
                    await _context.SaveChangesAsync();

                    HealingResult result = heal.GenHealingResult(now);
                    return(Ok(new { success = true, healing = result }));
                }
                catch (DbUpdateException)
                {
                    return(BadRequest(new DataError("databaseErr", "Failed to update tokens.")));
                }
            }
            else
            {
                return(BadRequest(new DataError("LocationErr", "Hero is not able to change state.")));
            }
        }
        public async Task <IActionResult> PostHeros([FromBody] PassedData <PassedRemoveCharacter> passedData)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            DateTime now = DateTime.UtcNow;

            if (passedData.UserToken == null)
            {
                return(BadRequest(new DataError("securityErr", "No authorization controll.")));
            }
            UserToken dbtoken = Security.CheckUserToken(this._context, passedData.UserToken);

            if (dbtoken == null)
            {
                return(BadRequest(new DataError("securityErr", "Your data has probably been stolen or modified manually. We suggest password's change.")));
            }
            else
            {
                if (!dbtoken.IsTimeValid(now))
                {
                    return(BadRequest(new DataError("timeoutErr", "You have been too long inactive. Relogin is required.")));
                }
                else
                {
                    dbtoken.UpdateToken(now);
                }
            }
            Users user = _context.Users.FirstOrDefault(e => e.Name == dbtoken.UserName);

            if (user.Password != HashClass.GenHash(passedData.Data.Password))
            {
                return(BadRequest(new DataError("passwordErr", "Password is incorrect.")));
            }
            Heros      herotoremove      = _context.Heros.FirstOrDefault(e => e.Name == passedData.Data.HeroName);
            UsersHeros conntoremove      = _context.UsersHeros.FirstOrDefault(e => e.UserName == dbtoken.UserName && e.HeroId == herotoremove.HeroId);
            var        tokentoremove     = _context.ActionToken.Where(e => e.HeroId == herotoremove.HeroId);
            var        locationstoremove = _context.HerosLocations.Where(e => e.HeroId == herotoremove.HeroId);
            var        travelingtoremove = _context.Traveling.Where(e => e.HeroId == herotoremove.HeroId);
            var        equipmenttoremove = _context.Equipment.Where(e => e.HeroId == herotoremove.HeroId);
            var        backpacktoremove  = _context.Backpack.Where(e => e.HeroId == herotoremove.HeroId);
            var        healingremove     = _context.Healing.Where(e => e.HeroId == herotoremove.HeroId);
            var        fightingremove    = _context.Fighting.Where(e => e.HeroId == herotoremove.HeroId);

            // TODO: remove other features

            if (tokentoremove.Count() > 0)
            {
                _context.ActionToken.RemoveRange(tokentoremove);
            }
            if (locationstoremove.Count() > 0)
            {
                _context.HerosLocations.RemoveRange(locationstoremove);
            }
            if (travelingtoremove.Count() > 0)
            {
                _context.Traveling.RemoveRange(travelingtoremove);
            }
            if (equipmenttoremove.Count() > 0)
            {
                _context.Equipment.RemoveRange(equipmenttoremove);
            }
            if (backpacktoremove.Count() > 0)
            {
                _context.Backpack.RemoveRange(backpacktoremove);
            }
            if (healingremove.Count() > 0)
            {
                _context.Healing.RemoveRange(healingremove);
            }
            if (fightingremove.Count() > 0)
            {
                _context.Fighting.RemoveRange(fightingremove);
            }

            _context.Heros.Remove(herotoremove);
            _context.UsersHeros.Remove(conntoremove);

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                return(BadRequest(new DataError("serverErr", "Failed to remove hero.")));
            }
            return(Ok(new { success = true, removedHero = herotoremove.Name }));
        }
예제 #36
0
        public MemContext()
        {
            var account = new Account
            {
                Id          = 1,
                Name        = "My Test Account",
                Paid        = true,
                PaidUtc     = new DateTime(2016, 1, 1),
                AccountType = AccountType.Gold
            };

            Accounts.Add(account);
            var user = new User
            {
                Id        = 1,
                Name      = "Joe User",
                AccountId = 1,
                Account   = account,
                Active    = true
            };

            Users.Add(user);
            account.Users = new List <User> {
                user
            };
            var account2 = new Account
            {
                Id          = 2,
                Name        = "Another Test Account",
                Paid        = false,
                AccountType = AccountType.Silver
            };

            Accounts.Add(account2);
            var user2 = new User
            {
                Id        = 2,
                Name      = "Late Paying User",
                AccountId = 2,
                Account   = account2
            };

            Users.Add(user2);
            MutateMes.Add(new MutateMe
            {
                Id    = 1,
                Value = 0,
            });
            account2.Users = new List <User> {
                user2
            };

            var human = new Human
            {
                Id     = 1,
                Name   = "Han Solo",
                Height = 5.6430448
            };

            Heros.Add(human);
            var stormtrooper = new Stormtrooper
            {
                Id             = 2,
                Name           = "FN-2187",
                Height         = 4.9,
                Specialization = "Imperial Snowtrooper"
            };

            Heros.Add(stormtrooper);
            var droid = new Droid
            {
                Id              = 3,
                Name            = "R2-D2",
                PrimaryFunction = "Astromech"
            };

            Heros.Add(droid);

            var vehicle = new Vehicle
            {
                Id      = 1,
                Name    = "Millennium falcon",
                OwnerId = human.Id
            };

            Vehicles.Add(vehicle);
            human.Vehicles = new List <Vehicle> {
                vehicle
            };
            var vehicle2 = new Vehicle
            {
                Id      = 2,
                Name    = "Speeder bike",
                OwnerId = stormtrooper.Id
            };

            Vehicles.Add(vehicle2);
            stormtrooper.Vehicles = new List <Vehicle> {
                vehicle2
            };
        }
예제 #37
0
 // pour gerer les collisions
 public Rectangle Rectangle_Fumigene_Heros2(Heros heros)
 {
     if (heros != null && fumigene2.FreeParticleCount < 135)
         return new Rectangle((int)heros.position.X - 28 * 3, (int)heros.position.Y - 28 * 3, 28 * 6, 28 * 6);
     else
         return Rectangle.Empty;
 }
예제 #38
0
 public Heros AddHeros(Heros h)
 {
     h.id = DataHeros.SuperHeros.Max(sh => sh.id) + 1;
     DataHeros.SuperHeros.Add(h);
     return(h);
 }
예제 #39
0
 // pour gerer les collisions
 public Rectangle Rectangle_Fumigene_Heros1(Heros heros)
 {
     if (fumigene1.FreeParticleCount < 135 )
         return new Rectangle((int)heros.position.X - 28 * 3, (int)heros.position.Y - 28 * 3, 28 * 6, 28 * 6);
     else // pas de rectangle
         return Rectangle.Empty;
 }
예제 #40
0
        // surcharge
        protected virtual void InitializeParticle(Particle p, Vector2 where, Heros heros)
        {
            // first, call PickRandomDirection to figure out which way the particle
            // will be moving. velocity and acceleration's values will come from this.
            Vector2 direction;

            if (heros.Regarde_Haut)
                direction = new Vector2(0, -1);
            else if (heros.Regarde_Bas)
                direction = new Vector2(0, 1);
            else if (heros.Regarde_Gauche)
                direction = new Vector2(-1, 0);
            else
                direction = new Vector2(1, 0);

            // pick some random values for our particle
            float velocity =
                MoteurParticule.RandomBetween(minInitialSpeed, maxInitialSpeed);
            float acceleration =
                MoteurParticule.RandomBetween(minAcceleration, maxAcceleration);
            float lifetime =
                MoteurParticule.RandomBetween(minLifetime, maxLifetime);
            float scale =
                MoteurParticule.RandomBetween(minScale, maxScale);
            float rotationSpeed =
                MoteurParticule.RandomBetween(minRotationSpeed, maxRotationSpeed);

            // then initialize it with those random values. initialize will save those,
            // and make sure it is marked as active.
            p.Initialize(
                where, velocity * direction, acceleration * direction,
                lifetime, scale, rotationSpeed);
        }
예제 #41
0
 public void UpdateFumigene(Heros heros)
 {
     if (heros.NumeroHero == 1)
         fumigene1.AddParticles(new Vector2(heros.position.X - Camera.X, heros.position.Y - Camera.Y), heros);
     else
         fumigene2.AddParticles(new Vector2(heros.position.X - Camera.X, heros.position.Y - Camera.Y), heros);
 }
예제 #42
0
파일: Jeu.cs 프로젝트: EmnaGARES/Git1
 public Jeu(IFournisseurMeteo fournisseurMeteo)
 {
     Heros             = new Heros(15);
     _fournisseurMeteo = fournisseurMeteo;
 }
예제 #43
0
        protected override void InitializeParticle(Particle p, Vector2 where, Heros heros)
        {
            base.InitializeParticle(p, where, heros);

            p.Acceleration = -p.Velocity / p.Lifetime;
        }
예제 #44
0
        public void Update(GameTime gameTime, Rectangle sourceRectangle1, Rectangle sourceRectangle2, Rectangle sourceRectangle3, Rectangle sourceRectangle4, Heros heros1, Heros heros2, List<EnnemiMort> ennemisMorts, Rectangle fumeeHeros1, Rectangle fumeeHeros2)
        {
            rectangle.X = (int)position.X + 1;
            rectangle.Y = (int)position.Y + 1;
            UpdateChampDeVision(carte);
            MortDansLeChampDeVision(ennemisMorts, fumeeHeros1, fumeeHeros2);

            if (chemin != null && chemin.Count != 0)
            {
                if (VaEnHaut && VaEnBas && VaADroite && VaAGauche)
                {
                    if ((int)chemin[chemin.Count - 1].X < X)
                    {
                        positionDesiree.X -= 28;
                        VaAGauche = false;
                        chemin.RemoveAt(chemin.Count - 1);
                    }
                    else if ((int)chemin[chemin.Count - 1].X > X)
                    {
                        positionDesiree.X += 28;
                        VaADroite = false;
                        chemin.RemoveAt(chemin.Count - 1);
                    }
                    else if ((int)chemin[chemin.Count - 1].Y < Y)
                    {
                        positionDesiree.Y -= 28;
                        VaEnHaut = false;
                        chemin.RemoveAt(chemin.Count - 1);
                    }
                    else if ((int)chemin[chemin.Count - 1].Y > Y)
                    {
                        positionDesiree.Y += 28;
                        VaEnBas = false;
                        chemin.RemoveAt(chemin.Count - 1);
                    }
                    else
                        chemin.RemoveAt(chemin.Count - 1);
                }
            }
            else
                this.Alerte = false;

            if (SourceRectangle.Value.Y == sourceRectangle1.Y)
            {
                SourceRectangle = sourceRectangle1;
                Regarde_Haut = true;
            }
            else
                Regarde_Haut = false;

            if (SourceRectangle.Value.Y == sourceRectangle3.Y)
            {
                SourceRectangle = sourceRectangle3;
                Regarde_Gauche = true;
            }
            else
                Regarde_Gauche = false;

            if (SourceRectangle.Value.Y == sourceRectangle2.Y)
            {
                SourceRectangle = sourceRectangle2;
                Regarde_Bas = true;
            }
            else
                Regarde_Bas = false;

            if (SourceRectangle.Value.Y == sourceRectangle4.Y)
            {
                SourceRectangle = sourceRectangle4;
                Regarde_Droite = true;
            }
            else
                Regarde_Droite = false;

            if (!VaEnHaut)
            {
                if (position != positionDesiree)
                {
                    position.Y -= VitesseSprite;
                    SourceRectangle = sourceRectangle1;
                    Index += gameTime.ElapsedGameTime.Milliseconds * VitesseAnimation;

                    if (Index >= MaxIndex)
                        Index = 0f;
                }
                else
                {
                    VaEnHaut = true;
                    position = positionDesiree;
                    Index = 0f;
                }
            }

            if (!VaEnBas)
            {
                if (position != positionDesiree)
                {
                    position.Y += VitesseSprite;
                    SourceRectangle = sourceRectangle2;
                    Index += gameTime.ElapsedGameTime.Milliseconds * VitesseAnimation;

                    if (Index >= MaxIndex)
                        Index = 0f;
                }
                else
                {
                    VaEnBas = true;
                    position = positionDesiree;
                    Index = 0f;
                }
            }

            if (!VaAGauche)
            {
                if (position != positionDesiree)
                {
                    position.X -= VitesseSprite;
                    SourceRectangle = sourceRectangle3;
                    Index += gameTime.ElapsedGameTime.Milliseconds * VitesseAnimation;

                    if (Index >= MaxIndex)
                        Index = 0f;
                }
                else
                {
                    VaAGauche = true;
                    position = positionDesiree;
                    Index = 0f;
                }
            }

            if (!VaADroite)
            {
                if (position != positionDesiree)
                {
                    position.X += VitesseSprite;
                    SourceRectangle = sourceRectangle4;
                    Index += gameTime.ElapsedGameTime.Milliseconds * VitesseAnimation;

                    if (Index >= MaxIndex)
                        Index = 0f;
                }
                else
                {
                    VaADroite = true;
                    position = positionDesiree;
                    Index = 0f;
                }
            }
        }
        public async Task <IActionResult> PostHeros([FromBody] PassedGameData <bool[]> passedData)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            DateTime now = DateTime.UtcNow;

            if (passedData.UserToken == null || passedData.ActionToken == null)
            {
                return(BadRequest(new DataError("securityErr", "No authorization controll.")));
            }
            UserToken dbtoken = Security.CheckUserToken(this._context, passedData.UserToken);

            if (dbtoken == null)
            {
                return(BadRequest(new DataError("securityErr", "Your data has probably been stolen or modified manually. We suggest password's change.")));
            }
            else
            {
                if (!dbtoken.IsTimeValid(now))
                {
                    return(BadRequest(new DataError("timeoutErr", "You have been too long inactive. Relogin is required.")));
                }
                else
                {
                    dbtoken.UpdateToken(now);
                }
            }
            Heros       hero      = _context.Heros.FirstOrDefault(e => e.Name == passedData.ActionToken.HeroName);
            ActionToken gametoken = Security.CheckActionToken(_context, passedData.ActionToken, hero.HeroId);

            if (gametoken == null)
            {
                return(BadRequest(new DataError("securityErr", "Your data has probably been stolen or modified manually. We suggest password's change.")));
            }
            else
            {
                if (!gametoken.IsTimeValid(now))
                {
                    return(BadRequest(new DataError("timeoutErr", "You have been too long inactive. Relogin is required.")));
                }
                else
                {
                    gametoken.UpdateToken(now);
                }
            }
            // now do your stuff...
            if (hero.Invitational)
            {
                try
                {
                    if (passedData.Data[0])
                    {
                        hero.VelocityFactor = 10;
                    }
                    if (passedData.Data[1])
                    {
                        hero.Lvl        = 5;
                        hero.Experience = HeroCalculator.ExpToLevel(5);
                    }
                    if (passedData.Data[2])
                    {
                        var list = new List <Backpack>();
                        for (int i = 1; i <= 16; i++)
                        {
                            list.Add(new Backpack()
                            {
                                HeroId = hero.HeroId,
                                ItemId = i,
                                SlotNr = i - 1,
                            });
                        }
                        _context.Backpack.AddRange(list);
                    }
                    hero.Invitational = false;
                    await _context.SaveChangesAsync();

                    return(Ok(new { success = true }));
                }
                catch (DbUpdateException)
                {
                    return(BadRequest(new DataError("databaseErr", "Failed to update hero.")));
                }
            }
            else
            {
                return(BadRequest(new DataError("securityErr", "This option should be impossible to reach.")));
            }
        }
예제 #46
0
        public async Task <IActionResult> PostTraveling([FromBody] PassedGameData <int> passedData)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            DateTime now = DateTime.UtcNow;

            if (passedData.UserToken == null || passedData.ActionToken == null)
            {
                return(BadRequest(new DataError("securityErr", "No authorization controll.")));
            }
            UserToken dbtoken = Security.CheckUserToken(this._context, passedData.UserToken);

            if (dbtoken == null)
            {
                return(BadRequest(new DataError("securityErr", "Your data has probably been stolen or modified manually. We suggest password's change.")));
            }
            else
            {
                if (!dbtoken.IsTimeValid(now))
                {
                    return(BadRequest(new DataError("timeoutErr", "You have been too long inactive. Relogin is required.")));
                }
                else
                {
                    dbtoken.UpdateToken(now);
                }
            }
            Heros       hero      = _context.Heros.FirstOrDefault(e => e.Name == passedData.ActionToken.HeroName);
            ActionToken gametoken = Security.CheckActionToken(_context, passedData.ActionToken, hero.HeroId);

            if (gametoken == null)
            {
                return(BadRequest(new DataError("securityErr", "Your data has probably been stolen or modified manually. We suggest password's change.")));
            }
            else
            {
                if (!gametoken.IsTimeValid(now))
                {
                    return(BadRequest(new DataError("timeoutErr", "You have been too long inactive. Relogin is required.")));
                }
                else
                {
                    gametoken.UpdateToken(now);
                }
            }
            // if can go there
            if (hero.Status == 0)
            {
                var location = _context.HerosLocations.FirstOrDefault(e => (e.HeroId == hero.HeroId) && (e.LocationIdentifier == hero.CurrentLocation));
                if (location == null)
                {
                    return(BadRequest(new DataError("LocationErr", "Location is not available.")));
                }
                var descr = _context.LocationsDb.FirstOrDefault(e => e.LocationIdentifier == location.LocationIdentifier);
                if (descr == null)
                {
                    return(BadRequest(new DataError("LocationErr", "LocationData is not available.")));
                }
                try
                {
                    // TODO check location type
                    AstarResult astar       = null;
                    int         TravelScale = 0;
                    int         Start       = -1;
                    string      StartName   = "";
                    int         Target      = -1;
                    string      TargetName  = "";

                    int LocationType = descr.LocationGlobalType;
                    if (LocationType != 2)
                    {
                        LocationDescription description = JsonConvert.DeserializeObject <LocationDescription>(descr.Sketch);
                        LocationState       state       = JsonConvert.DeserializeObject <LocationState>(location.Description);
                        description.LocationGlobalType = descr.LocationGlobalType;

                        int GlobalNodeID = description.GlobalMainNodeID(passedData.Data, state);
                        if (GlobalNodeID == state.CurrentLocation)
                        {
                            throw new Exception("Moving nowhere");
                        }
                        astar       = LocationHandler.DistanceToMove(description, state, passedData.Data);
                        TravelScale = description.TravelScale;
                        Start       = state.CurrentLocation;
                        StartName   = description.MainNodes.First(e => e.NodeID == state.CurrentLocation).Name;
                        Target      = GlobalNodeID;
                        TargetName  = description.MainNodes.First(e => e.NodeID == GlobalNodeID).Name;
                    }
                    else
                    {
                        InstanceDescription description = JsonConvert.DeserializeObject <InstanceDescription>(descr.Sketch);
                        InstanceState       state       = JsonConvert.DeserializeObject <InstanceState>(location.Description);
                        description.LocationGlobalType = descr.LocationGlobalType;

                        int GlobalNodeID = description.GlobalMainNodeID(passedData.Data, state);
                        if (GlobalNodeID == state.CurrentLocation)
                        {
                            throw new Exception("Moving nowhere");
                        }
                        astar       = LocationHandler.DistanceToMove(description, state, passedData.Data);
                        TravelScale = description.TravelScale;
                        Start       = state.CurrentLocation;
                        Target      = GlobalNodeID;
                        TargetName  = passedData.Data.ToString();
                    }

                    double TravelTime = LocationHandler.TimeTravel(astar.Distance, TravelScale, 18 * hero.VelocityFactor);

                    Traveling travel = new Traveling()
                    {
                        EndTime     = now.AddSeconds(TravelTime),
                        HeroId      = hero.HeroId,
                        IsReverse   = false,
                        ReverseTime = null,
                        Start       = Start,
                        StartName   = StartName,
                        StartTime   = now,
                        Target      = Target,
                        TargetName  = TargetName,
                    };
                    hero.Status = 1;
                    _context.Traveling.Add(travel);
                    TravelResult travelResult = travel.GenTravelResult(now);
                    try
                    {
                        await _context.SaveChangesAsync();

                        return(Ok(new { success = true, travel = travelResult }));
                    }
                    catch (DbUpdateException)
                    {
                        return(BadRequest(new DataError("databaseErr", "Failed to remember travel.")));
                    }
                }
                catch
                {
                    return(BadRequest(new DataError("LocationErr", "Location is not available.")));
                }
            }
            else
            {
                return(BadRequest(new DataError("LocationErr", "Hero is not able to travel.")));
            }
        }
예제 #47
0
        // pour gerer les collisions
        public Rectangle Rectangle_Hadoken_heros2(Heros heros)
        {
            if (GameplayScreen.Timer_Hero2 > 1) // apres une seconde mon timer se remet a zero
            {
                GameplayScreen.Enable_Timer_Hero2 = false;
                GameplayScreen.Timer_Hero2 = 0;
            }

            if (hadoken_heros2.FreeParticleCount == 100) // lorsque freeparticulecount = 100 le hadoken est termine
            {
                Rectangle_Hadoken_Est_Present_Hero2 = true;// je reinitialise donc mon rectangle
                direction_heros2_appele = heros.SourceRectangle.Value.Y;
            }// direction du heros au moment de l'appel pour pas quelle change durant le meme appel si je tourne mon heros.

            if (hadoken_heros2.FreeParticleCount < 100 && Rectangle_Hadoken_Est_Present_Hero2 && GameplayScreen.Timer_Hero2 > 0.5)
            { // j'attend une demi seconde avant de créer le rectangle pour geré la collision
                if (direction_heros2_appele == 133) // haut
                    return new Rectangle((int)heros.position.X, (int)heros.position.Y - (hadoken_heros2.LongueurHadoken * 28), 28, (hadoken_heros2.LongueurHadoken * 28));

                else if (direction_heros2_appele == 198) // bas
                    return new Rectangle((int)heros.position.X, (int)heros.position.Y, 28, (hadoken_heros2.LongueurHadoken * 28));

                else if (direction_heros2_appele == 230) // gauche
                    return new Rectangle((int)heros.position.X - (hadoken_heros2.LongueurHadoken * 28), (int)heros.position.Y, (hadoken_heros2.LongueurHadoken * 28), 28);

                else // droite
                    return new Rectangle((int)heros.position.X, (int)heros.position.Y, (hadoken_heros2.LongueurHadoken * 28), 28);
            }
            else // pas de rectangle
                return new Rectangle(0, 0, 0, 0);
        }
예제 #48
0
        public async Task <IActionResult> PostHeros([FromBody] PassedData <HeroPassed> data)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            DateTime now = DateTime.UtcNow;

            if (data.UserToken == null)
            {
                return(BadRequest(new DataError("securityErr", "No authorization controll.")));
            }
            UserToken dbtoken = Security.CheckUserToken(this._context, data.UserToken);

            if (dbtoken == null)
            {
                return(BadRequest(new DataError("securityErr", "Your data has probably been stolen or modified manually. We suggest password's change.")));
            }
            else
            {
                if (!dbtoken.IsTimeValid(now))
                {
                    return(BadRequest(new DataError("timeoutErr", "You have been too long inactive. Relogin is required.")));
                }
                else
                {
                    dbtoken.UpdateToken(now);
                }
            }
            int currheros = this._context.UsersHeros.Where(e => e.UserName == dbtoken.UserName).Count();

            if (currheros >= ServerOptions.MaxHerosPerAccount)
            {
                return(BadRequest(new DataError("herolimitErr", "You have reached maximum amount of heros per account.")));
            }
            int   ID    = this._context.Heros.Select(x => x.HeroId).DefaultIfEmpty(0).Max();
            Heros newly = new Heros()
            {
                Charisma = data.Data.Attributes[6],
                Country  = data.Data.Country,
                // starting location of type??
                CurrentLocation = 1,
                Dexterity       = data.Data.Attributes[2],
                Endurance       = data.Data.Attributes[1],
                Experience      = 0,
                HeroId          = ID + 1,
                Hp             = HeroCalculator.PureMaxHP(HeroCalculator.BaseHP(1), data.Data.Attributes),
                Intelligence   = data.Data.Attributes[5],
                Lvl            = 1,
                Name           = data.Data.Name,
                Nickname       = data.Data.Nickname,
                Orders         = 0,
                Origin         = data.Data.Origin,
                Reflex         = data.Data.Attributes[3],
                Sl             = 0,
                Slbase         = 0,
                Status         = 0,
                Strength       = data.Data.Attributes[0],
                Willpower      = data.Data.Attributes[7],
                Wisdom         = data.Data.Attributes[4],
                Invitational   = true,
                VelocityFactor = 1,
            };
            UsersHeros userheros = new UsersHeros()
            {
                HeroId   = newly.HeroId,
                UserName = dbtoken.UserName,
            };
            Equipment      eq       = Equipment.GenFreshEquipment(newly.HeroId);
            HerosLocations location = HerosLocations.GenInitialLocation(_context, newly.HeroId);

            _context.Heros.Add(newly);
            _context.UsersHeros.Add(userheros);
            _context.Equipment.Add(eq);
            _context.HerosLocations.Add(location);

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                return(BadRequest(new DataError("tokenErr", "Hero already exists.")));
            }
            return(Ok((HeroBrief)newly));
        }
        public async Task <IActionResult> PostEquipment([FromBody] PassedGameData <PassedChangeEqData> passedData)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            DateTime now = DateTime.UtcNow;

            if (passedData.UserToken == null || passedData.ActionToken == null)
            {
                return(BadRequest(new DataError("securityErr", "No authorization controll.")));
            }
            UserToken dbtoken = Security.CheckUserToken(this._context, passedData.UserToken);

            if (dbtoken == null)
            {
                return(BadRequest(new DataError("securityErr", "Your data has probably been stolen or modified manually. We suggest password's change.")));
            }
            else
            {
                if (!dbtoken.IsTimeValid(now))
                {
                    return(BadRequest(new DataError("timeoutErr", "You have been too long inactive. Relogin is required.")));
                }
                else
                {
                    dbtoken.UpdateToken(now);
                }
            }
            Heros       hero      = _context.Heros.FirstOrDefault(e => e.Name == passedData.ActionToken.HeroName);
            ActionToken gametoken = Security.CheckActionToken(_context, passedData.ActionToken, hero.HeroId);

            if (gametoken == null)
            {
                return(BadRequest(new DataError("securityErr", "Your data has probably been stolen or modified manually. We suggest password's change.")));
            }
            else
            {
                if (!gametoken.IsTimeValid(now))
                {
                    return(BadRequest(new DataError("timeoutErr", "You have been too long inactive. Relogin is required.")));
                }
                else
                {
                    gametoken.UpdateToken(now);
                }
            }
            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                return(BadRequest(new DataError("databaseErr", "Failed to update tokens.")));
            }
            // can do stuff

            var Equipment = _context.Equipment.FirstOrDefault(e => e.HeroId == hero.HeroId);

            if (Equipment == null)
            {
                return(BadRequest(new DataError("equipmentErr", "Hero is without equipment.")));
            }
            var Backpack = _context.Backpack.Where(e => e.HeroId == hero.HeroId);

            var Added   = new List <EquipmentModifyResult.EquipmentModification>();
            var Removed = new List <EquipmentModifyResult.EquipmentModification>();

            if (passedData.Data.From == passedData.Data.To)
            {
                return(Ok(new { success = true, changes = new EquipmentModifyResult()
                                {
                                    Added = Added.ToArray(), Removed = Removed.ToArray()
                                } }));
            }
            // BP -> BP
            if (passedData.Data.From.StartsWith("Backpack") && passedData.Data.To.StartsWith("Backpack"))
            {
                int fromSlot = int.Parse(passedData.Data.From.Substring(8));
                int toSlot   = int.Parse(passedData.Data.To.Substring(8));
                var fromItem = _context.Backpack.FirstOrDefault(e => e.HeroId == hero.HeroId && e.SlotNr == fromSlot);
                if (fromItem == null)
                {
                    return(BadRequest(new DataError("changeEqErr", "No initial item.")));
                }
                // remove from current and add to new
                Removed.Add(new EquipmentModifyResult.EquipmentModification()
                {
                    ItemID = null, Target = passedData.Data.From
                });
                Added.Add(new EquipmentModifyResult.EquipmentModification()
                {
                    ItemID = fromItem.ItemId, Target = passedData.Data.To
                });

                var toItem = _context.Backpack.FirstOrDefault(e => e.HeroId == hero.HeroId && e.SlotNr == toSlot);
                if (toItem == null)
                {
                    _context.Backpack.Remove(fromItem);
                    _context.Backpack.Add(new Backpack()
                    {
                        HeroId = hero.HeroId,
                        ItemId = fromItem.ItemId,
                        SlotNr = toSlot,
                    });
                }
                else
                {
                    Removed.Add(new EquipmentModifyResult.EquipmentModification()
                    {
                        ItemID = null, Target = passedData.Data.To
                    });
                    Added.Add(new EquipmentModifyResult.EquipmentModification()
                    {
                        ItemID = toItem.ItemId, Target = passedData.Data.From
                    });
                    int mem = toItem.ItemId;
                    toItem.ItemId   = fromItem.ItemId;
                    fromItem.ItemId = mem;
                }
            }
            // BP -> EQ
            if (passedData.Data.From.StartsWith("Backpack") && passedData.Data.To.StartsWith("Inventory"))
            {
                int fromSlot = int.Parse(passedData.Data.From.Substring(8));
                int toSlot   = int.Parse(passedData.Data.To.Substring(9));
                var fromItem = _context.Backpack.FirstOrDefault(e => e.HeroId == hero.HeroId && e.SlotNr == fromSlot);
                if (fromItem == null)
                {
                    return(BadRequest(new DataError("changeEqErr", "No initial item.")));
                }
                var passeditem = _context.Items.FirstOrDefault(e => e.ItemId == fromItem.ItemId);
                if (passeditem == null)
                {
                    return(BadRequest(new DataError("changeEqErr", "No initial item.")));
                }
                if (!EquipmentControll.CanEquip(passeditem, hero, toSlot))
                {
                    return(BadRequest(new DataError("changeEqErr", "Items requirements are not fullfilled.")));
                }
                Removed.Add(new EquipmentModifyResult.EquipmentModification()
                {
                    ItemID = null, Target = passedData.Data.From
                });
                Added.Add(new EquipmentModifyResult.EquipmentModification()
                {
                    ItemID = fromItem.ItemId, Target = passedData.Data.To
                });

                int?Target = null;
                switch (toSlot)
                {
                case 0:
                    Target = Equipment.Helmet;
                    break;

                case 1:
                    Target = Equipment.Ring1;
                    break;

                case 2:
                    Target = Equipment.Neckles;
                    break;

                case 3:
                    Target = Equipment.Ring2;
                    break;

                case 4:
                    Target = Equipment.Gloves;
                    break;

                case 5:
                    Target = Equipment.Armour;
                    break;

                case 6:
                    Target = Equipment.Bracelet;
                    break;

                case 7:
                    Target = Equipment.FirstHand;
                    break;

                case 8:
                    Target = Equipment.Trousers;
                    break;

                case 9:
                    Target = Equipment.SecondHand;
                    break;

                case 10:
                    Target = Equipment.Shoes;
                    break;
                }

                var toItem = Target;

                // update inventory
                switch (toSlot)
                {
                case 0:
                    Equipment.Helmet = fromItem.ItemId;
                    break;

                case 1:
                    Equipment.Ring1 = fromItem.ItemId;
                    break;

                case 2:
                    Equipment.Neckles = fromItem.ItemId;
                    break;

                case 3:
                    Equipment.Ring2 = fromItem.ItemId;
                    break;

                case 4:
                    Equipment.Gloves = fromItem.ItemId;
                    break;

                case 5:
                    Equipment.Armour = fromItem.ItemId;
                    break;

                case 6:
                    Equipment.Bracelet = fromItem.ItemId;
                    break;

                case 7:
                    Equipment.FirstHand = fromItem.ItemId;
                    break;

                case 8:
                    Equipment.Trousers = fromItem.ItemId;
                    break;

                case 9:
                    Equipment.SecondHand = fromItem.ItemId;
                    break;

                case 10:
                    Equipment.Shoes = fromItem.ItemId;
                    break;
                }

                // update backpack
                if (toItem == null)
                {
                    _context.Backpack.Remove(fromItem);
                }
                else
                {
                    Removed.Add(new EquipmentModifyResult.EquipmentModification()
                    {
                        ItemID = null, Target = passedData.Data.To
                    });
                    Added.Add(new EquipmentModifyResult.EquipmentModification()
                    {
                        ItemID = toItem, Target = passedData.Data.From
                    });
                    fromItem.ItemId = toItem.Value;
                }
            }
            // EQ -> BP
            if (passedData.Data.From.StartsWith("Inventory") && passedData.Data.To.StartsWith("Backpack"))
            {
                int fromSlot = int.Parse(passedData.Data.From.Substring(9));
                int toSlot   = int.Parse(passedData.Data.To.Substring(8));
                int?Target   = null;
                switch (fromSlot)
                {
                case 0:
                    Target = Equipment.Helmet;
                    break;

                case 1:
                    Target = Equipment.Ring1;
                    break;

                case 2:
                    Target = Equipment.Neckles;
                    break;

                case 3:
                    Target = Equipment.Ring2;
                    break;

                case 4:
                    Target = Equipment.Gloves;
                    break;

                case 5:
                    Target = Equipment.Armour;
                    break;

                case 6:
                    Target = Equipment.Bracelet;
                    break;

                case 7:
                    Target = Equipment.FirstHand;
                    break;

                case 8:
                    Target = Equipment.Trousers;
                    break;

                case 9:
                    Target = Equipment.SecondHand;
                    break;

                case 10:
                    Target = Equipment.Shoes;
                    break;
                }
                var fromItem = Target;
                if (fromItem == null)
                {
                    return(BadRequest(new DataError("changeEqErr", "No initial item.")));
                }

                var toItem = _context.Backpack.FirstOrDefault(e => e.HeroId == hero.HeroId && e.SlotNr == toSlot);
                if (toItem != null)
                {
                    // slot is being used
                    var passeditem = _context.Items.FirstOrDefault(e => e.ItemId == toItem.ItemId);
                    if (passeditem == null)
                    {
                        return(BadRequest(new DataError("changeEqErr", "No target item in DB.")));
                    }
                    if (!EquipmentControll.CanEquip(passeditem, hero, fromSlot))
                    {
                        return(BadRequest(new DataError("changeEqErr", "Items requirements are not fullfilled.")));
                    }
                }

                Removed.Add(new EquipmentModifyResult.EquipmentModification()
                {
                    ItemID = null, Target = passedData.Data.From
                });
                Added.Add(new EquipmentModifyResult.EquipmentModification()
                {
                    ItemID = fromItem.Value, Target = passedData.Data.To
                });

                // null if prev was empty lub itemID if existed
                int?invRes = toItem?.ItemId;
                // update inventory
                switch (fromSlot)
                {
                case 0:
                    Equipment.Helmet = invRes;
                    break;

                case 1:
                    Equipment.Ring1 = invRes;
                    break;

                case 2:
                    Equipment.Neckles = invRes;
                    break;

                case 3:
                    Equipment.Ring2 = invRes;
                    break;

                case 4:
                    Equipment.Gloves = invRes;
                    break;

                case 5:
                    Equipment.Armour = invRes;
                    break;

                case 6:
                    Equipment.Bracelet = invRes;
                    break;

                case 7:
                    Equipment.FirstHand = invRes;
                    break;

                case 8:
                    Equipment.Trousers = invRes;
                    break;

                case 9:
                    Equipment.SecondHand = invRes;
                    break;

                case 10:
                    Equipment.Shoes = invRes;
                    break;
                }

                // update backpack
                if (toItem == null)
                {
                    _context.Backpack.Add(new Backpack()
                    {
                        HeroId = hero.HeroId,
                        ItemId = fromItem.Value,
                        SlotNr = toSlot,
                    });
                }
                else
                {
                    Removed.Add(new EquipmentModifyResult.EquipmentModification()
                    {
                        ItemID = null, Target = passedData.Data.To
                    });
                    Added.Add(new EquipmentModifyResult.EquipmentModification()
                    {
                        ItemID = toItem.ItemId, Target = passedData.Data.From
                    });
                    toItem.ItemId = fromItem.Value;
                }
            }
            // EQ -> EQ
            if (passedData.Data.From.StartsWith("Inventory") && passedData.Data.To.StartsWith("Inventory"))
            {
                int fromSlot = int.Parse(passedData.Data.From.Substring(9));
                int toSlot   = int.Parse(passedData.Data.To.Substring(9));
                int?Target   = null;
                switch (fromSlot)
                {
                case 0:
                    Target = Equipment.Helmet;
                    break;

                case 1:
                    Target = Equipment.Ring1;
                    break;

                case 2:
                    Target = Equipment.Neckles;
                    break;

                case 3:
                    Target = Equipment.Ring2;
                    break;

                case 4:
                    Target = Equipment.Gloves;
                    break;

                case 5:
                    Target = Equipment.Armour;
                    break;

                case 6:
                    Target = Equipment.Bracelet;
                    break;

                case 7:
                    Target = Equipment.FirstHand;
                    break;

                case 8:
                    Target = Equipment.Trousers;
                    break;

                case 9:
                    Target = Equipment.SecondHand;
                    break;

                case 10:
                    Target = Equipment.Shoes;
                    break;
                }
                var fromItem = Target;
                if (fromItem == null)
                {
                    return(BadRequest(new DataError("changeEqErr", "No initial item.")));
                }
                Target = null;
                switch (toSlot)
                {
                case 0:
                    Target = Equipment.Helmet;
                    break;

                case 1:
                    Target = Equipment.Ring1;
                    break;

                case 2:
                    Target = Equipment.Neckles;
                    break;

                case 3:
                    Target = Equipment.Ring2;
                    break;

                case 4:
                    Target = Equipment.Gloves;
                    break;

                case 5:
                    Target = Equipment.Armour;
                    break;

                case 6:
                    Target = Equipment.Bracelet;
                    break;

                case 7:
                    Target = Equipment.FirstHand;
                    break;

                case 8:
                    Target = Equipment.Trousers;
                    break;

                case 9:
                    Target = Equipment.SecondHand;
                    break;

                case 10:
                    Target = Equipment.Shoes;
                    break;
                }
                var toItem = Target;

                var passeditem = _context.Items.FirstOrDefault(e => e.ItemId == fromItem.Value);
                if (passeditem == null)
                {
                    return(BadRequest(new DataError("changeEqErr", "No target item in DB.")));
                }
                if (!EquipmentControll.CanEquip(passeditem, hero, toSlot))
                {
                    return(BadRequest(new DataError("changeEqErr", "Items requirements are not fullfilled.")));
                }
                if (toItem != null)
                {
                    var passeditem2 = _context.Items.FirstOrDefault(e => e.ItemId == toItem.Value);
                    if (passeditem2 == null)
                    {
                        return(BadRequest(new DataError("changeEqErr", "No target item in DB.")));
                    }
                    if (!EquipmentControll.CanEquip(passeditem2, hero, fromSlot))
                    {
                        return(BadRequest(new DataError("changeEqErr", "Items requirements are not fullfilled.")));
                    }
                }

                Removed.Add(new EquipmentModifyResult.EquipmentModification()
                {
                    ItemID = null, Target = passedData.Data.From
                });
                Added.Add(new EquipmentModifyResult.EquipmentModification()
                {
                    ItemID = fromItem.Value, Target = passedData.Data.To
                });

                // update inventory
                switch (fromSlot)
                {
                case 0:
                    Equipment.Helmet = toItem;
                    break;

                case 1:
                    Equipment.Ring1 = toItem;
                    break;

                case 2:
                    Equipment.Neckles = toItem;
                    break;

                case 3:
                    Equipment.Ring2 = toItem;
                    break;

                case 4:
                    Equipment.Gloves = toItem;
                    break;

                case 5:
                    Equipment.Armour = toItem;
                    break;

                case 6:
                    Equipment.Bracelet = toItem;
                    break;

                case 7:
                    Equipment.FirstHand = toItem;
                    break;

                case 8:
                    Equipment.Trousers = toItem;
                    break;

                case 9:
                    Equipment.SecondHand = toItem;
                    break;

                case 10:
                    Equipment.Shoes = toItem;
                    break;
                }
                switch (toSlot)
                {
                case 0:
                    Equipment.Helmet = fromItem;
                    break;

                case 1:
                    Equipment.Ring1 = fromItem;
                    break;

                case 2:
                    Equipment.Neckles = fromItem;
                    break;

                case 3:
                    Equipment.Ring2 = fromItem;
                    break;

                case 4:
                    Equipment.Gloves = fromItem;
                    break;

                case 5:
                    Equipment.Armour = fromItem;
                    break;

                case 6:
                    Equipment.Bracelet = fromItem;
                    break;

                case 7:
                    Equipment.FirstHand = fromItem;
                    break;

                case 8:
                    Equipment.Trousers = fromItem;
                    break;

                case 9:
                    Equipment.SecondHand = fromItem;
                    break;

                case 10:
                    Equipment.Shoes = fromItem;
                    break;
                }
                if (toItem != null)
                {
                    Removed.Add(new EquipmentModifyResult.EquipmentModification()
                    {
                        ItemID = null, Target = passedData.Data.To
                    });
                    Added.Add(new EquipmentModifyResult.EquipmentModification()
                    {
                        ItemID = toItem.Value, Target = passedData.Data.From
                    });
                }
            }
            // Remove item
            if (passedData.Data.To == "Trash")
            {
                if (passedData.Data.From.StartsWith("Backpack"))
                {
                    int fromSlot = int.Parse(passedData.Data.From.Substring(8));
                    var fromItem = _context.Backpack.FirstOrDefault(e => e.HeroId == hero.HeroId && e.SlotNr == fromSlot);
                    if (fromItem == null)
                    {
                        return(BadRequest(new DataError("changeEqErr", "No initial item.")));
                    }
                    // remove from current and add to new
                    _context.Backpack.Remove(fromItem);
                    Removed.Add(new EquipmentModifyResult.EquipmentModification()
                    {
                        ItemID = null, Target = passedData.Data.From
                    });
                }
                if (passedData.Data.From.StartsWith("Inventory"))
                {
                    int fromSlot = int.Parse(passedData.Data.From.Substring(9));
                    switch (fromSlot)
                    {
                    case 0:
                        Equipment.Helmet = null;
                        break;

                    case 1:
                        Equipment.Ring1 = null;
                        break;

                    case 2:
                        Equipment.Neckles = null;
                        break;

                    case 3:
                        Equipment.Ring2 = null;
                        break;

                    case 4:
                        Equipment.Gloves = null;
                        break;

                    case 5:
                        Equipment.Armour = null;
                        break;

                    case 6:
                        Equipment.Bracelet = null;
                        break;

                    case 7:
                        Equipment.FirstHand = null;
                        break;

                    case 8:
                        Equipment.Trousers = null;
                        break;

                    case 9:
                        Equipment.SecondHand = null;
                        break;

                    case 10:
                        Equipment.Shoes = null;
                        break;
                    }
                    Removed.Add(new EquipmentModifyResult.EquipmentModification()
                    {
                        ItemID = null, Target = passedData.Data.From
                    });
                }
            }

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                return(BadRequest(new DataError("databaseErr", "Failed to update equipment.")));
            }
            return(Ok(new { success = true, changes = new EquipmentModifyResult()
                            {
                                Added = Added.ToArray(), Removed = Removed.ToArray()
                            } }));
        }