public bool LoadHeroes(int beginX, int beginY) { try { _heroes = heroService.ReturnHeroes(_worldName, beginX, beginY).ToList(); UpdatedCurrentHero = _heroes.First(h => h.Id == IdHero); _heroes.Remove(UpdatedCurrentHero); foreach (var hero in _heroes) { MapTile mapTile = Map[hero.x % 8, hero.y % 8]; mapTile.ObjectTile = _tiles["Hero"]; mapTile.ObjectTile.Health = hero.StatVitality; mapTile.SetObjectSprite(hero.x % 8, hero.y % 8); if (mapTile.ObjectTile.IsTransparent) { mapTile.ObjectSprite.ColorKey = Color.FromArgb(75, 75, 75); } } return(true); } catch { return(false); } }
private void frmSelectHero_FormClosing(object sender, FormClosingEventArgs e) { if (!_HeroSelected) { selectedHero = null; } }
public GameState(SizeF gameArea, HeroDetailsDTO hero) { GameArea = gameArea; Hero = hero; //Load inventory of player. _inventory = _serviceInventory.GetPlayerInventory(hero.Id).ToList(); //Load in all the tile definitions readTileDefinitions(@"gamedata\tilelookups.csv"); //Create the sprites for the UI int y = 50; _experienceSprite = new Sprite(this, 580, y, _tiles["Hero"].Bitmap, _tiles["Hero"].Rectangle, _tiles["Hero"].NumberOfFrames); _experienceSprite.ColorKey = Color.FromArgb(75, 75, 75); _healthSprite = new Sprite(this, 580, y += 74, _tiles["Food1"].Bitmap, _tiles["Food1"].Rectangle, _tiles["Food1"].NumberOfFrames); _healthSprite.ColorKey = Color.FromArgb(75, 75, 75); _attackSprite = new Sprite(this, 580, y += 74, _tiles["Attack"].Bitmap, _tiles["Attack"].Rectangle, _tiles["Attack"].NumberOfFrames); _attackSprite.ColorKey = Color.FromArgb(75, 75, 75); _armourSprite = new Sprite(this, 580, y += 74, _tiles["Armour"].Bitmap, _tiles["Armour"].Rectangle, _tiles["Armour"].NumberOfFrames); _armourSprite.ColorKey = Color.FromArgb(75, 75, 75); _treasureSprite = new Sprite(this, 580, y += 74, _tiles["Treasure2"].Bitmap, _tiles["Treasure2"].Rectangle, _tiles["Treasure2"].NumberOfFrames); _treasureSprite.ColorKey = Color.FromArgb(75, 75, 75); _potionSprite = new Sprite(this, 580, y += 74, _tiles["Potion"].Bitmap, _tiles["Potion"].Rectangle, _tiles["Potion"].NumberOfFrames); _potionSprite.ColorKey = Color.FromArgb(75, 75, 75); _brownKeySprite = new Sprite(this, 580, y += 74, _tiles["KeyBrown"].Bitmap, _tiles["KeyBrown"].Rectangle, _tiles["KeyBrown"].NumberOfFrames); _brownKeySprite.ColorKey = Color.FromArgb(75, 75, 75); _greenKeySprite = new Sprite(this, 654, y, _tiles["KeyGreen"].Bitmap, _tiles["KeyGreen"].Rectangle, _tiles["KeyGreen"].NumberOfFrames); _greenKeySprite.ColorKey = Color.FromArgb(75, 75, 75); _redKeySprite = new Sprite(this, 728, y, _tiles["KeyRed"].Bitmap, _tiles["KeyRed"].Rectangle, _tiles["KeyRed"].NumberOfFrames); _redKeySprite.ColorKey = Color.FromArgb(75, 75, 75); }
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); } }
private void btnStart_Click(object sender, EventArgs e) { frmSelectHero selecthero = new frmSelectHero(this); selecthero.ShowDialog(this); hero = selecthero.selectedHero; if (hero is object) { HugoWorld hugoWorld = new HugoWorld(hero); hugoWorld.ShowDialog(); //heroService.DisconnectHero(hero.Id, false); } }
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 HugoWorld(HeroDetailsDTO hero) { //Setup the form //Startup the game state currHero = hero; _currentWorld = wsc.GetWorldByName(hero.World); if (_currentWorld != null) { InitializeComponent(); SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.OptimizedDoubleBuffer, true); _gameState = new GameState(ClientSize, hero); initialize(); } else { MessageBox.Show("An error has occured while loading the map.", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
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 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); } }
private void btnCreateHeroFrm_Click(object sender, EventArgs e) { List <string> errors = VerifyInfo(); HeroDetailsDTO hero = new HeroDetailsDTO() { HeroName = txtnomHero.Text, StatDex = int.Parse(txtstatBaseDex.Text), StatReg = int.Parse(txtstatBaseReg.Text), StatStr = int.Parse(txtstatBaseStr.Text), StatVitality = int.Parse(txtstatBaseVitalite.Text), Class = cmbNomClass.Text, World = cmbDescription.Text, UserName = nomCompte }; var result = createHeroValidator.Validate(hero); foreach (var item in result.Errors) { errors.Add(item.ErrorMessage); } if (errors.Count() > 0) { MessageBox.Show(string.Join("\n", errors), "Errors", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { bool isSuccess = HeroService.CreateHero(hero); if (isSuccess) { MessageBox.Show("The hero has been created", "Success!", MessageBoxButtons.OK, MessageBoxIcon.None); this.Close(); } else { MessageBox.Show("An error has occured with the creation of the hero", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } }
private void btnJouerSelectHero_Click(object sender, EventArgs e) { bool error = false; if (cmbNomhero.Text != "") { if (herosList.Any(h => h.HeroName == cmbNomhero.Text)) { selectedHero = herosList[cmbNomhero.SelectedIndex]; if (HeroService.ConnectHero(selectedHero.Id, _main.accountDetails.Id, false) == "SUCCESS") { _HeroSelected = true; } else { selectedHero = null; MessageBox.Show("This hero is already in game or there has been an error!", "ERREUR", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } this.Close(); } else { error = true; } } else { error = true; } if (error) { MessageBox.Show("Please select a valid hero.", "ERREUR", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
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); } }
/// <summary> /// Vérifie la nouvelle position héro /// </summary> /// <param name="mapTile"></param> /// <param name="x"></param> /// <param name="y"></param> /// <returns></returns> private bool checkNextTile(MapTile mapTile, int x, int y) { //See if there is a door we need to open checkDoors(mapTile, x, y); //See if there is character to fight if (mapTile.ObjectTile != null && mapTile.ObjectTile.Category == "character") { if (mapTile.ObjectTile.Shortcut == "pri") { //Game is won Sounds.Kiss(); _gameState.GameIsWon = true; return(false); //Don't want to walk on her } Sounds.Fight(); if (mapTile.ObjectTile.Name == "Hero") { _heroSpriteFighting = true; _startFightTime = -1; HeroDetailsDTO heroVs = _currentArea._heroes.Where(h => (h.x % 8) == x && (h.y % 8) == y).FirstOrDefault(); double heroDamage = (_random.NextDouble() * ((double)heroVs.StatDex / 100) * (double)heroVs.StatStr); HeroService.RemoveHealth(_gameState.Hero, (int)heroDamage, force: false); double heroDamageVs = (_random.NextDouble() * ((double)_gameState.Hero.StatDex / 100) * (double)_gameState.Hero.StatStr); HeroService.RemoveHealth(heroVs, (int)heroDamageVs, false); if ((_gameState.Hero.StatVitality - heroDamage) <= 0) { _gameState.Health = 0; HeroService.ReplaceHeroToBones(_gameState.Hero, _gameState.Hero.x, _gameState.Hero.y, _currentWorld.ID, force: true); ResetHero(); _heroSprite.ColorKey = Color.FromArgb(75, 75, 75); } if ((heroVs.StatVitality - heroDamageVs) <= 0) { HeroService.AddExp(_gameState.Hero, heroVs.Experience, false); return(true); } else { return(false); } } else { _heroSpriteFighting = true; _startFightTime = -1; int heroDamage = 0; //A monsters attack ability is 1/2 their max health. Compare that to your armour //If you outclass them then there is still a chance of a lucky hit if (_random.Next((mapTile.ObjectTile.Health / 2) + 1) >= _gameState.Armour || (mapTile.ObjectTile.Health / 2 < _gameState.Armour && _random.Next(10) == 0)) { //Monsters do damage up to their max health - if they hit you. heroDamage = _random.Next(mapTile.ObjectTile.Health) + 1; _gameState.Health -= heroDamage; HeroService.RemoveHealth(_gameState.Hero, heroDamage, force: true); if (_gameState.Health <= 0) { _gameState.Health = 0; HeroService.ReplaceHeroToBones(_gameState.Hero, _gameState.Hero.x, _gameState.Hero.y, _currentWorld.ID, force: true); ResetHero(); _heroSprite.ColorKey = Color.FromArgb(75, 75, 75); return(false); } } //Hero _popups.Clear(); _popups.Add(new textPopup((int)_heroSprite.Location.X + 40, (int)_heroSprite.Location.Y + 20, (heroDamage != 0) ? heroDamage.ToString() : "miss")); //A monsters armour is 1/5 of their max health if (_random.Next(_gameState.Attack + 1) >= (mapTile.ObjectTile.Health / 5)) { if (damageMonster((int)(_random.NextDouble() * ((double)_gameState.Hero.StatDex / 100) * (double)_gameState.Hero.StatStr), mapTile, _currentArea._monsters.First(m => m.x % 8 == x && m.y % 8 == y))) { //Monster is dead now return(true); } } else { _popups.Add(new textPopup((int)mapTile.Sprite.Location.X + 40, (int)mapTile.Sprite.Location.Y + 20, "miss")); } //Monster not dead return(false); } } //If the next tile is a blocker then we can't move if (mapTile.Tile.IsBlock) { return(false); } return(true); }
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); } }