Exemplo n.º 1
0
 public bool CreateHero(HeroDetailsDTO dto)
 {
     try
     {
         using (var context = new HugoLANDContext())
         {
             Monde        monde        = context.Mondes.First(m => m.Description == dto.World);
             Classe       classe       = context.Classes.First(c => c.NomClasse == dto.Class);
             CompteJoueur compteJoueur = context.CompteJoueurs.First(a => a.NomJoueur == dto.UserName);
             var          hero         = new Hero
             {
                 Niveau       = 1,
                 Experience   = 0,
                 x            = 0,
                 y            = 0,
                 StatStr      = dto.StatStr,
                 StatDex      = dto.StatDex,
                 StatReg      = dto.StatReg,
                 StatVitalite = dto.StatVitality,
                 NomHero      = dto.HeroName,
                 EstConnecte  = false,
                 Classe       = classe,
                 CompteJoueur = compteJoueur,
                 Monde        = monde
             };
             context.Entry(hero).State = EntityState.Added;
             context.SaveChanges();
         }
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Exemplo n.º 2
0
 public bool SaveClass(ClassDetailsDTO dto)
 {
     using (HugoLANDContext context = new HugoLANDContext())
     {
         try
         {
             var currClass = new Classe()
             {
                 Id               = dto.Id,
                 NomClasse        = dto.ClassName,
                 Description      = dto.Description,
                 StatBaseStr      = dto.StatBaseStr,
                 StatBaseDex      = dto.StatBaseDex,
                 StatBaseReg      = dto.StatBaseReg,
                 StatBaseVitalite = dto.StatBaseVitality,
             };
             context.Entry(currClass).State = EntityState.Modified;
             context.SaveChanges();
             return(true);
         }
         catch
         {
             return(false);
         }
     }
 }
Exemplo n.º 3
0
 public bool CreateClass(ClassDetailsDTO newClass, WorldDetailsDTO world)
 {
     try
     {
         using (HugoLANDContext context = new HugoLANDContext())
         {
             Monde monde  = context.Mondes.Find(world.ID);
             var   classe = new Classe()
             {
                 NomClasse        = newClass.ClassName,
                 Description      = newClass.Description,
                 StatBaseStr      = newClass.StatBaseStr,
                 StatBaseDex      = newClass.StatBaseDex,
                 StatBaseReg      = newClass.StatBaseReg,
                 StatBaseVitalite = newClass.StatBaseVitality,
                 Monde            = monde,
             };
             context.Entry(classe).State = EntityState.Added;
             context.SaveChanges();
             return(true);
         }
     }
     catch
     {
         return(false);
     }
 }
Exemplo n.º 4
0
 public static void SupprimeEffetItem(int id)
 {
     using (HugoLANDContext context = new HugoLANDContext())
     {
         context.EffetItems.Remove(context.EffetItems.Find(id));
         context.SaveChanges();
     }
 }
Exemplo n.º 5
0
 public static void ModifEffetItem(int id, int changedValeurEffet, int changedTypeEffet)
 {
     using (HugoLANDContext context = new HugoLANDContext())
     {
         EffetItem effetItems = context.EffetItems.Find(id);
         effetItems.ValeurEffet = changedValeurEffet;
         effetItems.TypeEffet   = changedTypeEffet;
         context.SaveChanges();
     }
 }
Exemplo n.º 6
0
 public static void CreeEffetItem(int newValeurEffet, int newTypeEffet, int idItem)
 {
     using (HugoLANDContext context = new HugoLANDContext())
     {
         Item item = context.Items.Find(idItem);
         context.EffetItems.Add(new EffetItem
         {
             ValeurEffet = newValeurEffet,
             TypeEffet   = newTypeEffet,
             Item        = item
         });
         context.SaveChanges();
     }
 }
Exemplo n.º 7
0
        public HeroDetailsDTO ReplaceHeroToBones(HeroDetailsDTO hero, int X, int Y, int world, bool force = false)
        {
            using (var context = new HugoLANDContext())
            {
                Hero currHero;
                Item item;


                try
                {
                    currHero              = context.Heros.Find(hero.Id);
                    currHero.x            = 0;
                    currHero.y            = 0;
                    currHero.StatVitalite = currHero.Classe.StatBaseVitalite;

                    context.Mondes.Find(world).Items.Add(new Item {
                        Nom = "Bones", Description = "Bones", x = X, y = Y, ImageId = 168
                    });
                    item = context.Items.Where(x => x.Monde.Id == world && x.x == X && x.y == Y).FirstOrDefault();
                }
                catch
                {
                    return(hero);
                }

                int itr         = force ? 5 : 1;
                var currVersion = currHero.RowVersion;
                do
                {
                    try
                    {
                        context.SaveChanges();
                        return(hero);
                    }
                    catch (DbUpdateConcurrencyException)
                    {
                        if (itr > 0)
                        {
                            var objContext = ((IObjectContextAdapter)context).ObjectContext;
                            objContext.Refresh(RefreshMode.ClientWins, currHero);
                            objContext.Refresh(RefreshMode.ClientWins, item);
                            itr--;
                        }
                    }
                } while (itr > 0 && currVersion != currHero.RowVersion);

                return(hero);
            }
        }
Exemplo n.º 8
0
        public int RemoveHealthVSHero(HeroDetailsDTO heroVs, bool force = false)
        {
            using (var context = new HugoLANDContext())
            {
                Hero   currHero;
                double heroDamage = 0.00;

                // Dommage [pts] = Chance [%] × Dextérité du Héros [%] × Forces du Héros, où la Chance est une valeur aléatoire entre 0 et 1.
                try
                {
                    currHero = context.Heros.Find(heroVs.Id);
                    double pourcent = _rnd.NextDouble();

                    heroDamage = (pourcent * ((double)currHero.StatDex / 100) * (double)currHero.StatStr);


                    currHero.StatVitalite -= (int)heroDamage;
                }
                catch
                {
                    return((int)heroDamage);
                }

                int itr         = force ? 5 : 1;
                var currVersion = currHero.RowVersion;
                do
                {
                    try
                    {
                        context.SaveChanges();
                        heroVs.StatVitality = currHero.StatVitalite;
                        return((int)heroDamage);
                    }
                    catch (DbUpdateConcurrencyException)
                    {
                        if (itr > 0)
                        {
                            var objContext = ((IObjectContextAdapter)context).ObjectContext;
                            objContext.Refresh(RefreshMode.ClientWins, currHero);
                            itr--;
                        }
                    }
                } while (itr > 0 && currVersion != currHero.RowVersion);

                return((int)heroDamage);
            }
        }
Exemplo n.º 9
0
        public bool DeleteClass(ClassDetailsDTO dto)
        {
            try
            {
                using (HugoLANDContext context = new HugoLANDContext())
                {
                    var        delClass              = context.Classes.Find(dto.Id);
                    List <int> listDelHero           = new List <int>();
                    List <int> listDelHeroItems      = new List <int>();
                    List <int> listDelHeroInventaire = new List <int>();
                    foreach (Hero hero in delClass.Heros)
                    {
                        listDelHero.Add(hero.Id);
                        foreach (Item item in hero.Items)
                        {
                            listDelHeroItems.Add(item.Id);
                        }
                        foreach (InventaireHero inv in hero.InventaireHeroes)
                        {
                            listDelHeroInventaire.Add(inv.IdInventaireHero);
                        }
                    }
                    foreach (int id in listDelHeroItems)
                    {
                        context.Entry(context.Items.Find(id)).State = EntityState.Deleted;
                    }
                    foreach (int id in listDelHeroInventaire)
                    {
                        context.Entry(context.InventaireHeroes.Find(id)).State = EntityState.Deleted;
                    }
                    foreach (int id in listDelHero)
                    {
                        context.Entry(context.Heros.Find(id)).State = EntityState.Deleted;
                    }


                    context.Entry(delClass).State = EntityState.Deleted;
                    context.SaveChanges();
                    return(true);
                }
            }
            catch
            {
                return(false);
            }
        }
Exemplo n.º 10
0
 public bool DeleteHero(HeroDetailsDTO dto)
 {
     try
     {
         using (var context = new HugoLANDContext())
         {
             var hero = context.Heros.Find(dto.Id);
             context.Entry(hero).State = EntityState.Deleted;
             context.SaveChanges();
         }
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Exemplo n.º 11
0
        public void ReplaceMonsterToBones(MonsterDetailsDTO monster, int world, bool force = false)
        {
            using (var context = new HugoLANDContext())
            {
                Monstre currMonstre;
                Item    item;

                currMonstre = context.Monstres.First(m => m.Id == monster.Id);

                try
                {
                    context.Monstres.Remove(currMonstre);
                    context.Mondes.Find(world).Items.Add(new Item {
                        Nom = "Bones", Description = "Bones", x = monster.x, y = monster.y, ImageId = 168
                    });

                    item = context.Items.Where(x => x.Monde.Id == world && x.x == monster.x && x.y == monster.y).FirstOrDefault();
                }
                catch
                {
                    return;
                }

                int itr         = force ? 5 : 1;
                var currVersion = currMonstre.RowVersion;
                do
                {
                    try
                    {
                        context.SaveChanges();
                        return;
                    }
                    catch (DbUpdateConcurrencyException)
                    {
                        if (itr > 0)
                        {
                            var objContext = ((IObjectContextAdapter)context).ObjectContext;
                            objContext.Refresh(RefreshMode.ClientWins, currMonstre);
                            objContext.Refresh(RefreshMode.ClientWins, item);
                            itr--;
                        }
                    }
                } while (itr > 0 && currVersion != currMonstre.RowVersion);
            }
        }
Exemplo n.º 12
0
        public int RemoveHealthMonster(MonsterDetailsDTO monster, int heroDamage, bool force = false)
        {
            using (var context = new HugoLANDContext())
            {
                Monstre currMonster;

                try
                {
                    currMonster         = context.Monstres.Find(monster.Id);
                    currMonster.StatPV -= heroDamage;
                }
                catch
                {
                    return(monster.StatPV);
                }

                int itr         = force ? 5 : 1;
                var currVersion = currMonster.RowVersion;
                do
                {
                    try
                    {
                        context.SaveChanges();
                        monster.StatPV = currMonster.StatPV;
                        return(monster.StatPV);
                    }
                    catch (DbUpdateConcurrencyException)
                    {
                        if (itr > 0)
                        {
                            var objContext = ((IObjectContextAdapter)context).ObjectContext;
                            objContext.Refresh(RefreshMode.ClientWins, currMonster);
                            itr--;
                        }
                    }
                } while (itr > 0 && currVersion != currMonster.RowVersion);

                return(monster.StatPV);
            }
        }
Exemplo n.º 13
0
        public int RemoveHealth(HeroDetailsDTO hero, int heroDamage, bool force = false)
        {
            using (var context = new HugoLANDContext())
            {
                Hero currHero;

                try
                {
                    currHero = context.Heros.Find(hero.Id);
                    currHero.StatVitalite -= heroDamage;
                }
                catch
                {
                    return(heroDamage); //DOES NOT PICK UP ITEM
                }

                int itr         = force ? 5 : 1;
                var currVersion = currHero.RowVersion;
                do
                {
                    try
                    {
                        context.SaveChanges();
                        hero.StatVitality = currHero.StatVitalite;
                        return(heroDamage);
                    }
                    catch (DbUpdateConcurrencyException)
                    {
                        if (itr > 0)
                        {
                            var objContext = ((IObjectContextAdapter)context).ObjectContext;
                            objContext.Refresh(RefreshMode.ClientWins, currHero);
                            itr--;
                        }
                    }
                } while (itr > 0 && currVersion != currHero.RowVersion);

                return(heroDamage);
            }
        }
Exemplo n.º 14
0
        public string DisconnectHero(int heroID, bool force = false)
        {
            using (var context = new HugoLANDContext())
            {
                Hero currHero;
                try
                {
                    currHero = context.Heros.First(h => h.Id == heroID);
                }
                catch
                {
                    return("ERROR");
                }


                int itr = force ? 5 : 1;
                currHero.EstConnecte = false;
                var currVersionHero = currHero.RowVersion;

                do
                {
                    try
                    {
                        context.SaveChanges();
                        return("SUCCESS");
                    }
                    catch (DbUpdateConcurrencyException)
                    {
                        if (itr > 0)
                        {
                            var objContext = ((IObjectContextAdapter)context).ObjectContext;
                            objContext.Refresh(RefreshMode.ClientWins, currHero);
                            itr--;
                        }
                    }
                } while (itr > 0 && currVersionHero != currHero.RowVersion);
            }
            return("ERROR");
        }
Exemplo n.º 15
0
        public void AddExp(HeroDetailsDTO hero, int qte, bool force = false)
        {
            using (var context = new HugoLANDContext())
            {
                Hero currHero;
                try
                {
                    currHero = context.Heros.Find(hero.Id);

                    currHero.Experience += qte;
                }
                catch {
                    return;
                }

                int itr         = force ? 5 : 1;
                var currVersion = currHero.RowVersion;
                do
                {
                    try
                    {
                        context.SaveChanges();
                        return;
                    }
                    catch (DbUpdateConcurrencyException)
                    {
                        if (itr > 0)
                        {
                            var objContext = ((IObjectContextAdapter)context).ObjectContext;
                            objContext.Refresh(RefreshMode.ClientWins, currHero);
                            itr--;
                        }
                    }
                } while (itr > 0 && currVersion != currHero.RowVersion);
            }
        }
Exemplo n.º 16
0
        public HeroDetailsDTO PicksUpItem(string itemType, int world, int X, int Y, HeroDetailsDTO hero, bool force = false)
        {
            using (var context = new HugoLANDContext())
            {
                Hero currHero;
                Item item;
                try
                {
                    currHero     = context.Heros.Find(hero.Id);
                    item         = context.Mondes.Find(world).Items.FirstOrDefault(i => i.x == X && i.y == Y && i.Hero == null);
                    item.Hero    = currHero;
                    item.x       = null;
                    item.y       = null;
                    item.ImageId = null;
                    switch (itemType)
                    {
                    case "food":
                        hero.StatVitality += 10;
                        break;

                    case "armour":
                        currHero.StatReg = 1;
                        break;

                    case "attack":
                        currHero.StatStr = 1;
                        break;

                    default:
                        break;
                    }
                }
                catch
                {
                    return(hero); //DOES NOT PICK UP ITEM
                }

                int itr             = force ? 5 : 1;
                var currVersionHero = currHero.RowVersion;
                var currVersionItem = item.RowVersion;
                do
                {
                    try
                    {
                        context.SaveChanges();
                        hero.StatVitality = currHero.StatVitalite;
                        hero.StatStr      = currHero.StatStr;
                        hero.StatReg      = currHero.StatReg;
                        return(hero);
                    }
                    catch (DbUpdateConcurrencyException)
                    {
                        if (itr > 0)
                        {
                            var objContext = ((IObjectContextAdapter)context).ObjectContext;
                            objContext.Refresh(RefreshMode.ClientWins, item);
                            objContext.Refresh(RefreshMode.ClientWins, currHero);
                            itr--;
                        }
                    }
                } while (itr > 0 && currVersionHero != currHero.RowVersion && currVersionItem != currHero.RowVersion);

                return(hero);
            }
        }