public AccountDetailsDTO GetAccountInfoByUsername(string username) { try { using (var context = new HugoLANDContext()) { CompteJoueur account = context.CompteJoueurs .Where(p => p.NomJoueur == username) .First(); AccountDetailsDTO a = new AccountDetailsDTO { Id = account.Id, Email = account.Courriel, LastName = account.Nom, PlayerName = account.NomJoueur, FirstName = account.Prenom, TypeUtilisateur = account.TypeUtilisateur }; return(a); } } catch { return(null); } }
public List <WorldItemDetailsDTO> ReturnWorldItems(string world, int mapBeginX, int mapBeginY) { try { using (HugoLANDContext context = new HugoLANDContext()) { return(context.Mondes.First(w => w.Description == world) .ObjetMondes .Where(obj => ((obj.x >= mapBeginX) && (obj.x < mapBeginX + 8)) && ((obj.y >= mapBeginY) && (obj.y < mapBeginY + 8))) .Select(m => new WorldItemDetailsDTO { ID = m.Id, Description = m.Description, x = m.x, y = m.y, World = m.Monde.Id, TypeObject = m.TypeObjet }).ToList()); } } catch { return(null); } }
public List <HeroDetailsDTO> ReturnHerosFromAccount(int idCompteJoueur) { try { using (var context = new HugoLANDContext()) { return(context.CompteJoueurs.Find(idCompteJoueur)?.Heros .Select(p => new HeroDetailsDTO { Id = p.Id, Level = p.Niveau, Experience = (int)p.Experience, x = p.x, y = p.y, StatStr = p.StatStr, StatDex = p.StatDex, StatReg = p.StatReg, StatVitality = p.StatVitalite, HeroName = p.NomHero, isConnected = p.EstConnecte, World = p.Monde.Description, Class = p.Classe.NomClasse }).ToList()); } } catch { return(null); } }
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); } }
public List <HeroDetailsDTO> ReturnHeroes(string world, int mapBeginX, int mapBeginY) { try { using (HugoLANDContext context = new HugoLANDContext()) { return(context.Mondes.First(w => w.Description == world) .Heros .Where(obj => ((obj.x >= mapBeginX) && (obj.x < mapBeginX + 8)) && ((obj.y >= mapBeginY) && (obj.y < mapBeginY + 8)) && obj.EstConnecte == true) .Select(m => new HeroDetailsDTO { Id = m.Id, x = m.x, y = m.y, StatDex = m.StatDex, StatReg = m.StatReg, StatStr = m.StatStr, StatVitality = m.StatVitalite, Class = m.Classe.NomClasse, isConnected = m.EstConnecte, Experience = (int)m.Experience, HeroName = m.NomHero, Level = m.Niveau, UserName = m.CompteJoueur.Nom, World = m.Monde.Description }).ToList()); } } catch { return(null); } }
public List <MonsterDetailsDTO> ReturnMonsters(string world, int mapBeginX, int mapBeginY) { try { using (HugoLANDContext context = new HugoLANDContext()) { return(context.Mondes.First(w => w.Description == world) .Monstres .Where(obj => ((obj.x >= mapBeginX) && (obj.x < mapBeginX + 8)) && ((obj.y >= mapBeginY) && (obj.y < mapBeginY + 8))) .Select(m => new MonsterDetailsDTO { Id = m.Id, Nom = m.Nom, x = m.x, y = m.y, ImageId = m.ImageId, Niveau = m.Niveau, StatDmgMax = m.StatDmgMax, StatDmgMin = m.StatDmgMin, StatPV = m.StatPV }).ToList()); } } catch { return(null); } }
public List <ItemDetailsDTO> ReturnItems(string world, int mapBeginX, int mapBeginY) { try { using (HugoLANDContext context = new HugoLANDContext()) { return(context.Mondes.First(w => w.Description == world) .Items .Where(obj => ((obj.x >= mapBeginX) && (obj.x < mapBeginX + 8)) && ((obj.y >= mapBeginY) && (obj.y < mapBeginY + 8)) && obj.Hero is null) .Select(m => new ItemDetailsDTO { Id = m.Id, Nom = m.Nom, x = m.x, y = m.y, ImageId = m.ImageId, Description = m.Description }).ToList()); } } catch { return(null); } }
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); } }
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); } } }
public frmAdmin() { InitializeComponent(); context = new HugoLANDContext(); ModifAdminValidator = new ModifAdminValidator(); txtPassword.PasswordChar = '*'; }
public static void SupprimeEffetItem(int id) { using (HugoLANDContext context = new HugoLANDContext()) { context.EffetItems.Remove(context.EffetItems.Find(id)); context.SaveChanges(); } }
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(); } }
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(); } }
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); } }
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); } }
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); } }
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); } }
public string Authentification(string Username, string Password) { ObjectParameter message = new ObjectParameter("message", typeof(string)); try { using (HugoLANDContext context = new HugoLANDContext()) { context.Connexion(Username, Password, message); } } catch { message.Value = "NETWORKERROR"; } return((string)message.Value); }
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); } }
public HeroDetailsDTO ReturnHero(string idhero) { try { using (var context = new HugoLANDContext()) { return(context.Heros .Where(p => p.Id == Int32.Parse(idhero)) .Select(e => new HeroDetailsDTO { Id = e.Id }).First()); } } catch { return(null); } }
public ClassDetailsDTO GetClassByName(string name) { using (var context = new HugoLANDContext()) { try { return(context.Classes .Where(p => p.NomClasse.StartsWith(name)) .Select(p => new ClassDetailsDTO { Id = p.Id, ClassName = p.NomClasse }).FirstOrDefault()); } catch { return(null); } } }
public async void MoveHero(HeroDetailsDTO dto, int newX, int newY) { try { using (var context = new HugoLANDContext()) { var hero = context.Heros.Find(dto.Id); var world = context.Mondes.First(w => w.Description == dto.World); bool cannotWalk = world.Heros.Any(h => h.x == newX && h.y == newY && h.EstConnecte && h.StatVitalite > 0); if (!cannotWalk) { hero.x = newX; hero.y = newY; await context.SaveChangesAsync(); } } } catch { } }
public List <WorldDetailsDTO> GetAllWorldNames() { try { using (HugoLANDContext context = new HugoLANDContext()) { return(context.Mondes .Select(m => new WorldDetailsDTO { ID = m.Id, Description = m.Description, LimiteX = m.LimiteX, LimiteY = m.LimiteY }).ToList()); } } catch { return(null); } }
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); } }
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); } }
public List <ItemDetailsDTO> GetPlayerInventory(int HeroID) { try { using (HugoLANDContext context = new HugoLANDContext()) { return(context.Items.Where(c => c.Hero.Id == HeroID).Select(m => new ItemDetailsDTO { Description = m.Description, Id = m.Id, ImageId = m.ImageId, Nom = m.Nom, x = m.x, y = m.y }).ToList()); } } catch { return(null); } }
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"); }
public WorldDetailsDTO GetWorldByName(string worldName) { try { using (var context = new HugoLANDContext()) { return(context.Mondes .Where(p => p.Description.StartsWith(worldName)) .Select(p => new WorldDetailsDTO { ID = p.Id, Description = p.Description, LimiteX = p.LimiteX, LimiteY = p.LimiteY }).FirstOrDefault()); } } catch { return(null); } }
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); } }
public List <ClassDetailsDTO> GetAllClasses() { using (var context = new HugoLANDContext()) { try { return(context.Classes .Select(p => new ClassDetailsDTO { Id = p.Id, ClassName = p.NomClasse, Description = p.Description, StatBaseStr = p.StatBaseStr, StatBaseDex = p.StatBaseDex, StatBaseReg = p.StatBaseReg, StatBaseVitality = p.StatBaseVitalite }).ToList()); } catch { return(null); } } }