public void SinglePlayerAttack(NumberGenerator numberGenerator) { if (!context.GameCharacters.SingleOrDefault(ch => ch.CharacterId == characterId).SpellsId.Any()) { throw new ArgumentException("You cannot make an attack due to lack of spells!"); } var spellsId = context.GameCharacters.SingleOrDefault(ch => ch.CharacterId == characterId && ch.GameId == roomId).SpellsId.ToList(); var dbSpells = context.Spells; var spells = new List <Spell>(); foreach (var id in spellsId) { spells.Add(dbSpells.FirstOrDefault(x => x.Id == id)); } Console.WriteLine("You can use one of the following spells to attack..."); var counter = 1; foreach (var spell in spells) { Console.WriteLine($"{counter}. {spell.Name}"); Console.WriteLine($"Description: {spell.Description}"); Console.WriteLine($"Damage: {spell.DamageBonus} + your weapon's dmg"); Console.WriteLine($"Range: {spell.SpellRange}"); counter++; } Console.WriteLine($"Please select the number of your desired spell:"); var num = numberGenerator.GenerateNumber(1, counter); var chosenSpell = spells[num - 1]; var chNum = context.GameCharacters.FirstOrDefault(c => c.CharacterId == characterId && c.GameId == roomId) .MapSectionNumber; var spellRange = chosenSpell.SpellRange; List <int> positions = PositionsInRange(chNum, spellRange); var availableCharactersToAttack = SeeAvailableCharacters(positions); if (availableCharactersToAttack.Count == 0) { throw new ArgumentException("Sorry, there ain't any characters in your range..."); } Console.WriteLine($"You can attack the following characters:"); int characterCounter = 1; foreach (var availableCharacter in availableCharactersToAttack) { var character = context.Characters.SingleOrDefault(c => c.Id == availableCharacter.CharacterId); var player = context.Players.SingleOrDefault(p => p.Id == availableCharacter.PlayerId); Console.WriteLine($"{characterCounter}.{character.Name}[{player.Username}] - currently has {availableCharacter.Health}hp and {availableCharacter.Armour}armour. Current possition - {context.GameCharacters.SingleOrDefault(gc => gc.CharacterId == character.Id && gc.GameId == roomId).MapSectionNumber}"); characterCounter++; } Console.WriteLine($"Please select the number of the character you want to attack:"); var charNum = numberGenerator.GenerateNumber(1, characterCounter); var chosenCharacter = availableCharactersToAttack[charNum - 1]; AttackCharacter(chosenSpell, chosenCharacter); }
private void CheckIfSpecialSquare(MapSection[][] map, int i, int j, int positionNumber, Character character, int roomId) { //Character moves back by 3 positions if he is on GoBackSquare if (map[i][j].isGoBackSquare) { Console.WriteLine("Oops, it seems you stopped on a special square..."); positionNumber -= 3; if (j >= 3) { if (j == 3) { j = 0; } else { j -= 3; } } else { var toTakeDown = 3 - j; if (i == 0) { throw new ArgumentException($"Cannot move back from {i}{j}"); } else { i -= 1; j = map[i].Length - 1; toTakeDown--; j -= toTakeDown; } } positionNumber = map[i][j].Number; UpdateCharacterPositionInDb(character, map[i][j].X, map[i][j].Y, positionNumber, roomId); Console.WriteLine($"{character.Name} moves back by 3 positions to square number {positionNumber} :)"); CheckIfSpecialSquare(map, i, j, positionNumber, character, roomId); } //Character goes forward by 3 positions if he is on GoBackSquare else if (map[i][j].isGoForwardSquare) { Console.WriteLine("Oops, it seems you stopped on a special square..."); positionNumber += 3; if (j <= 6) { j += 3; } else //if(j != 9) { var thisRowAdd = 9 - j; var nextRowAdd = 3 - thisRowAdd; if (i == map.Length - 1) { throw new ArgumentException($"Cannot move forward from {i}{j}"); } else { i += 1; j = 0; if (j == 0) { nextRowAdd--; } j += nextRowAdd; } } positionNumber = map[i][j].Number; UpdateCharacterPositionInDb(character, map[i][j].X, map[i][j].Y, positionNumber, roomId); Console.WriteLine($"{character.Name} moves forward with 3 positions to square number {positionNumber} ^.^"); CheckIfSpecialSquare(map, i, j, positionNumber, character, roomId); } //ToDo else if (map[i][j].isMysterySquare) { Console.WriteLine("Oops, it seems you stopped on a special square..."); var num = numberGenerator.GenerateNumber(1, 3); if (num == 1) { //play mini game //Can be found in Miscellaneous/SpecialSquares/MysterySquare/MiniGameAction.cs MiniGameAction msa = new MiniGameAction(); isSingle = false; msa.PlayMiniGame(isSingle); if (msa.DemolitionFalcons) { //All characters return to the first square var characters = context.GameCharacters.Where(g => g.GameId == roomId).ToList(); foreach (var charche in characters) { context.GameCharacters.FirstOrDefault(c => c.CharacterId == charche.CharacterId).CharacterPositionX = map[0][0].X; context.GameCharacters.FirstOrDefault(c => c.CharacterId == charche.CharacterId).CharacterPositionY = map[0][0].Y; context.GameCharacters.FirstOrDefault(c => c.CharacterId == charche.CharacterId).MapSectionNumber = map[0][0].Number; context.SaveChanges(); } } else if (msa.GoBack) { var toGoBackWith = msa.GoBackWith; positionNumber -= toGoBackWith; if (j >= toGoBackWith) { if (j == toGoBackWith) { j = 0; } else { j -= toGoBackWith; } } else { var toTakeDown = toGoBackWith - j; if (i == 0) { throw new ArgumentException($"Cannot move back from {i}{j}"); } else { i -= 1; j = map[i].Length - 1; toTakeDown--; j -= toTakeDown; } } positionNumber = map[i][j].Number; UpdateCharacterPositionInDb(character, map[i][j].X, map[i][j].Y, positionNumber, roomId); Console.WriteLine($"{character.Name} moves back by {toGoBackWith} positions to square number {positionNumber} :)"); CheckIfSpecialSquare(map, i, j, positionNumber, character, roomId); } else if (msa.MoveForward) { var toMoveForwardWith = msa.MoveForwardWith; positionNumber += toMoveForwardWith; if (j < map[i].Length - toMoveForwardWith) { j += toMoveForwardWith; } else //if(j != 9) { var thisRowAdd = 9 - j; var nextRowAdd = toMoveForwardWith - thisRowAdd; if (i == map.Length - 1) { throw new ArgumentException($"Cannot move forward from {i}{j}"); } else { i += 1; j = 0; if (j == 0) { nextRowAdd--; } j += nextRowAdd; } } positionNumber = map[i][j].Number; UpdateCharacterPositionInDb(character, map[i][j].X, map[i][j].Y, positionNumber, roomId); Console.WriteLine($"{character.Name} moves forward with {toMoveForwardWith} positions to square number {positionNumber} ^.^"); CheckIfSpecialSquare(map, i, j, positionNumber, character, roomId); } } else { var doubleChance = new DoubleChance(); isSingle = false; doubleChance.StartDoubleChance(context, roomId, character, positionNumber, map, i, j, isSingle); } } //ToDo else if (map[i][j].isBonusSquare) { Console.WriteLine("Oops, it seems you stopped on a special square..."); Console.WriteLine($"{character.Name} is on a bonus square :)"); BonusSquareAction bsa = new BonusSquareAction(context, roomId, character); //Gets a random spell drawn with a special algorythm that allow the character to atack another character bsa.GetSpell(""); } }