private void Button_Add_Click(object sender, RoutedEventArgs e) { InputBox inputBox = new InputBox(); BuildCharacterConcept characterConcept = new BuildCharacterConcept(); CreateCharacterModel newCharacter = new CreateCharacterModel(); CreateCharacterStats newStats = new CreateCharacterStats(); CreateCharacterSkills newSkills = new CreateCharacterSkills(); inputBox.ShowDialog(); characterConcept.ShowDialog(); if (inputBox.Text.Text == "" || characterConcept.lvRaces.SelectedIndex < 0 || characterConcept.lvClases.SelectedIndex < 0 || characterConcept.lvAlignments.SelectedIndex < 0 || characterConcept.lvBackgrounds.SelectedIndex < 0) { MessageBox.Show("Error while add character"); } else { newCharacter.Name = inputBox.Text.Text; newCharacter.Race = (Races)characterConcept.lvRaces.SelectedIndex; newCharacter.Class = (Clases)characterConcept.lvClases.SelectedIndex; newCharacter.Aligment = (Aligments)characterConcept.lvAlignments.SelectedIndex; newCharacter.Background = (Backgrounds)characterConcept.lvBackgrounds.SelectedIndex; _characterService.Create(newCharacter, newStats, newSkills, _idUser); lvCharacters.Items.Add(newCharacter); } }
public MainWindow(CreateCharacterModel character, string username) { _character = character; _characterService = new CharacterService(_context); _characterRepository = new CharacterRepository(_context); _skillsRepository = new CharacterSkillsRepository(_context); _statsRepository = new CharacterStatsRepository(_context); _inventoryRepository = new CharacterInventoryRepository(_context); _characterItemRepository = new CharacterItemRepository(_context); InitializeComponent(); CreateCharacterSkills skills = new CreateCharacterSkills(); CreateCharacterStats stats = new CreateCharacterStats(); int characterId = _characterService.SetCharacter(character, skills, stats); _characterId = characterId; var charInventory = _inventoryRepository.Get().FirstOrDefault(u => u.Id == characterId).CharacterItems; _charInventory = charInventory; //this.DataContext = character; userName.Text = username; characterName.Text = character.Name; classNlevel.Text = character.Class.ToString() + " " + character.Level.ToString(); race.Text = character.Race.ToString(); aligment.Text = character.Aligment.ToString(); background.Text = character.Background.ToString(); armorClassNum.Text = character.ArmorClass.ToString(); initiativeNum.Text = character.Intitiative.ToString(); healthPoints.Text = character.HP.ToString() + "/" + character.HPMax.ToString(); speedNum.Text = character.Speed.ToString(); experiencePt.Text = character.Exp.ToString(); acrobatics.Text = "Acrobatics " + skills.Acrobatics.ToString(); animalHandling.Text = "Animal Handling " + skills.AnimalHandling.ToString(); athletics.Text = "Athletics " + skills.Athletics.ToString(); medicine.Text = "Medicine " + skills.Medicine.ToString(); persuasion.Text = "Persuasion " + skills.Persuasion.ToString(); religion.Text = "Religion " + skills.Religion.ToString(); sleightOfHand.Text = "Sleight of hand " + skills.SleightOfHand.ToString(); stealth.Text = "Stealth " + skills.Stealth.ToString(); survival.Text = "Survival " + skills.Survival.ToString(); charismaNum.Text = stats.Charisma.ToString(); constitutionNum.Text = stats.Constitution.ToString(); dexterityNum.Text = stats.Dexterity.ToString(); intelligenceNum.Text = stats.Intelligence.ToString(); strengthNum.Text = stats.Strength.ToString(); wisdomNum.Text = stats.Wisdom.ToString(); coins.Text = "Coins: " + character.Coins.ToString(); setEquipment(); setInventory(); timer = new DispatcherTimer(); timer.Tick += Timer_Tick; timer.Interval = new TimeSpan(0, 0, 1); timer.Start(); BackgroundWorker worker = new BackgroundWorker(); worker.WorkerReportsProgress = true; worker.DoWork += worker_DoWork; worker.ProgressChanged += worker_ProgressChanged; worker.RunWorkerAsync(); }
public int Create(CreateCharacterModel character, CreateCharacterStats stats, CreateCharacterSkills skills, int userId) { Random random = new Random(); character.HPMax = random.Next(30, 150); character.HP = character.HPMax; character.Intitiative = random.Next(-6, 10); character.Speed = random.Next(50); character.ArmorClass = random.Next(40); character.Coins = 0; character.Level = 1; character.Exp = 0; character.isFighting = false; stats.Charisma = random.Next(-4, 7); stats.Constitution = random.Next(-4, 7); stats.Dexterity = random.Next(-4, 7); stats.Intelligence = random.Next(-4, 7); stats.Strength = random.Next(-4, 7); stats.Wisdom = random.Next(-4, 7); skills.Acrobatics = random.Next(-2, 5); skills.AnimalHandling = random.Next(-2, 5); skills.Athletics = random.Next(-2, 5); skills.Medicine = random.Next(-2, 5); skills.Persuasion = random.Next(-2, 5); skills.Religion = random.Next(-2, 5); skills.SleightOfHand = random.Next(-2, 5); skills.Stealth = random.Next(-2, 5); skills.Survival = random.Next(-2, 5); _characterRepository.Add(new Character() { Name = character.Name, HPMax = character.HPMax, HP = character.HP, Race = character.Race, Class = character.Class, Aligment = character.Aligment, Background = character.Background, Intitiative = character.Intitiative, Speed = character.Speed, ArmorClass = character.ArmorClass, Coins = character.Coins, Level = character.Level, Exp = character.Exp, UserId = userId }); _skillsRepository.Add(new CharacterSkills() { Id = _characterRepository.Get().FirstOrDefault( u => u.Name == character.Name).Id, Acrobatics = skills.Acrobatics, AnimalHandling = skills.AnimalHandling, Athletics = skills.Athletics, Medicine = skills.Medicine, Persuasion = skills.Persuasion, Religion = skills.Religion, SleightOfHand = skills.SleightOfHand, Stealth = skills.Stealth, Survival = skills.Survival }); _statsRepository.Add(new CharacterStats() { Id = _characterRepository.Get().FirstOrDefault( u => u.Name == character.Name).Id, Charisma = stats.Charisma, Constitution = stats.Constitution, Dexterity = stats.Dexterity, Intelligence = stats.Intelligence, Strength = stats.Strength, Wisdom = stats.Wisdom }); _inventoryRepository.Add(new CharacterInventory() { Id = _characterRepository.Get().FirstOrDefault( u => u.Name == character.Name).Id, }); for (int i = 1; i <= 7; i++) { _characterItemRepository.Add(new CharacterItem() { ItemId = i, InventoryId = _characterRepository.Get().FirstOrDefault( u => u.Name == character.Name).Id }); } return(_characterRepository.Get().FirstOrDefault( u => u.Name == character.Name).Id); }
public LogModel TryToSpeak(CreateCharacterModel character, CreateCharacterSkills skills, CreateCharacterStats stats) { Random random = new Random(); logModel.enemyName = enemy.Name; logModel.enemyMaxHP = enemy.HPMax; logModel.enemyHP = enemy.HP; logModel.Looted = false; logModel.enemyCreated = false; logModel.returnModel = character.Name + " trying to speak with " + enemy.Name + "\n"; int charSpeak = random.Next(((stats.Charisma + 2) / (skills.Persuasion + 1)) + (skills.Persuasion + stats.Charisma) * 5); int needToSpeak = ((stats.Charisma + 2) / (skills.Persuasion + 1)) + (skills.Persuasion + stats.Charisma) * 4; if (charSpeak >= needToSpeak) { character.isFighting = false; character.Exp += enemy.ExpGained; enemyLooted = true; logModel.returnModel += character.Name + " sayed to " + enemy.Name + " that he don't want to kill somebody, and " + enemy.Name + " just listen, and go away"; } else { logModel.returnModel += enemy.Name + " didn't listen to " + character.Name + " and still want to kill him"; } return(logModel); }
public LogModel Fight(CreateCharacterModel character) { logModel.enemyName = enemy.Name; logModel.enemyMaxHP = enemy.HPMax; logModel.enemyHP = enemy.HP; logModel.Looted = false; logModel.enemyCreated = false; if (character.HP <= 0 || enemy.HP <= 0) { character.isFighting = false; if (enemy.HP <= 0 && character.HP > 0) { character.Exp += enemy.ExpGained; logModel.returnModel = character.Name + " killed " + enemy.Name; return(logModel); } return(Die(character)); } Random random = new Random(); CreateCharacterSkills skills = new CreateCharacterSkills(); CreateCharacterStats stats = new CreateCharacterStats(); _characterId = SetCharacter(character, skills, stats); int WeaponId = 0; foreach (var item in _charInventory) { if (item.ItemOf.TypeOfItem == typeOfItem.Weapon && item.isDressed == true) { WeaponId = item.ItemId; } } var charWeapon = _charInventory.FirstOrDefault(u => u.ItemId == WeaponId)?.ItemOf; int charPower = skills.SleightOfHand * 2 + stats.Strength; if (charPower <= 0) { charPower = 1; } int charEloquence = skills.Persuasion * 2 + stats.Charisma; if (charEloquence <= 0) { charEloquence = 1; } int sleightOfHand = random.Next(charPower); int persuasion = random.Next(charEloquence); // change strength and another, to more stuff int charInit = random.Next(character.Intitiative, 11); int charHit = (stats.Strength / skills.SleightOfHand) + (skills.SleightOfHand + stats.Strength) * 3 + charWeapon.equipmentBonus + character.Speed / 8; int charArm = random.Next(character.ArmorClass / 3 + stats.Constitution); int enemInit = random.Next(enemy.Intitiative, 11); int enemyHit = random.Next((enemy.HPMax + enemy.HP) / 4 + enemy.Speed / 9); int enemyArm = random.Next(enemy.ArmorClass); if (charHit <= 0) { charHit = 1; } else { charHit = random.Next(charHit); } if (charInit < enemInit) { if (enemyHit > charArm) { character.HP -= enemyHit; logModel.returnModel = enemy.Name + " hit " + character.Name + " by " + enemyHit.ToString(); } else { logModel.returnModel = enemy.Name + " tryed to attack but " + character.Name + "'s determination is stronger"; } } else { if (persuasion > sleightOfHand && enemy.HP == enemy.HPMax) { return(TryToSpeak(character, skills, stats)); } if (charHit > enemyArm) { enemy.HP -= charHit; logModel.enemyHP = enemy.HP; logModel.returnModel = character.Name + " hit " + enemy.Name + " by " + charHit.ToString(); } else { logModel.returnModel = character.Name + " just started to attack and his " + charWeapon.Name + " flew out of hand"; } } return(logModel); /*if (character.HP > 0) * return Walk(); * else return Die();*/ }
public int SetCharacter(CreateCharacterModel character, CreateCharacterSkills skills, CreateCharacterStats stats) { var characterRepository = _characterRepository.Get().FirstOrDefault( u => u.Name == character.Name); int characterId = characterRepository.Id; var SkillsTemp = _skillsRepository.Get().FirstOrDefault(u => u.Id == characterId); var StatsTemp = _statsRepository.Get().FirstOrDefault(u => u.Id == characterId); character.Aligment = characterRepository.Aligment; character.Background = characterRepository.Background; character.Class = characterRepository.Class; character.Race = characterRepository.Race; skills.Acrobatics = SkillsTemp.Acrobatics; skills.AnimalHandling = SkillsTemp.AnimalHandling; skills.Athletics = SkillsTemp.Athletics; skills.Medicine = SkillsTemp.Medicine; skills.Persuasion = SkillsTemp.Persuasion; skills.Religion = SkillsTemp.Religion; skills.SleightOfHand = SkillsTemp.SleightOfHand; skills.Stealth = SkillsTemp.Stealth; skills.Survival = SkillsTemp.Survival; stats.Charisma = StatsTemp.Charisma; stats.Constitution = StatsTemp.Constitution; stats.Dexterity = StatsTemp.Dexterity; stats.Intelligence = StatsTemp.Intelligence; stats.Strength = StatsTemp.Strength; stats.Wisdom = StatsTemp.Wisdom; return(characterId); }