public Race AddRaceToCharacter(int characterId, string racename) { using var db = new PathfinderContext(); Character character = db.Characters.Find(characterId); if (character == null) { return(null); } if (character.Race != null) { //TODO do something about the already existing race, a character has. } Race race = GetRace(racename); if (race == null) { return(null); } Console.WriteLine("Adding race {0} to character {1}", race.Name, character.Name); character.RaceName = race.Name; db.SaveChanges(); return(race); }
public bool RemoveSpellFromCharacter(Character character, int spellLevel, int spellIndex) { using var db = new PathfinderContext(); // KnownSpell spell = GetSpellFromSpellbook(character, spellLevel, spellIndex); Console.WriteLine("--------Trying to remove a spell to the character {0}", character.Name); //TODO Authorisation var query = from knownSpell in db.KnownSpells where knownSpell.CharacterId.Equals(character.Id) && knownSpell.SpellId.Equals(spellIndex) && knownSpell.SpellLevel.Equals(spellLevel) select knownSpell; if (query.Count() == 0 || query.First() == null) { Console.WriteLine("No spell found for that character."); return(false); } KnownSpell spell = query.First(); if (spell == null) { return(false); } db.KnownSpells.Remove(spell); db.SaveChanges(); return(true); }
public Character CreateCharacter(int playerId, string characterName = "Unknown") { using var db = new PathfinderContext(); Player player = GetPlayer(playerId); if (player == null) { return(null); } Character character = new Character() { //Player = player, PlayerId = playerId, Name = characterName, Id = db.Characters.Max(x => x.Id) + 1, Race = null, Class = new List <CharacterClasses>() }; //TODO Use the function in sql? Console.WriteLine("Creating a new Character owned by player {0}.", player.Username); db.Characters.Add(character); db.SaveChanges(); return(character); }
public static void Seed(this PathfinderContext context) { // Perform database delete and create context.Database.EnsureDeleted(); context.Database.EnsureCreated(); // Perform seed operations AddBloodlines(context); AddCastingTimes(context); AddComponentTypes(context); AddCurrencyUnits(context); AddDomains(context); AddHeroClasses(context); AddPatrons(context); AddReferenceSources(context); AddSavingThrows(context); AddSchools(context); //AddShapes(context); AddSpellDescriptors(context); AddSubschools(context); AddTimeUnits(context); // Save changes and release resources context.SaveChanges(); context.Dispose(); }
public bool RemoveClass(Character character, string className) { using var db = new PathfinderContext(); CharacterClasses _class = db.CharacterClasses.Find(character.Id, className); if (_class == null) { return(false); } db.CharacterClasses.Remove(_class); db.SaveChanges(); return(true); }
public bool DeleteCharacter(int playerId, int characterId) { using var db = new PathfinderContext(); var character = db.Characters.Find(characterId); if (character == null) { return(false); } Console.WriteLine("Removeing character with ID" + characterId); db.RemoveCharacterQuery.FromSqlRaw("select * from remove_character({0})", characterId); db.Characters.Remove(character); db.SaveChanges(); return(true); }
/// <summary> /// Adds a spell to the character spell relation. /// </summary> /// <param name="character">The character that will learn the spell</param> /// <param name="spellId">The ID of the spell to be taught</param> /// <param name="spellLevel">The level the spell is taught at</param> /// <returns></returns> public KnownSpell AddSpellToCharacter(Character character, int spellId, int spellLevel) //, string note=null) { using var db = new PathfinderContext(); Console.WriteLine("--------Trying to add a spell to the character {0}", character.Name); //TODO Authorisation var spell = GetSpell(spellId); if (spell == null) { Console.WriteLine("Error: Spell not Found"); return(null); } Console.WriteLine("spell found! Trying to add {0}", spell.Name); var query = from knownSpell in db.KnownSpells where knownSpell.CharacterId.Equals(character.Id) && knownSpell.SpellId.Equals(spellId) select knownSpell; // Console.WriteLine("The query gave the following result for spell: {0}, level {}", query.FirstOrDefault().SpellId, query.FirstOrDefault().SpellLevel); if (query.Count() != 0) { Console.WriteLine("Character already knows this spell!"); //Change spell level? return(null); } Console.WriteLine("Spell is not already in use! Adding to character"); KnownSpell newSpell = new KnownSpell() { CharacterId = character.Id, SpellId = spell.Id, Spell = spell, SpellLevel = spellLevel, Prepared = null, Note = null }; db.KnownSpells.Add(newSpell); db.SaveChanges(); return(newSpell); }
/// <summary> /// Levels up the character in one of their classes, simply by adding 1 to their level. /// </summary> /// <param name="character"></param> /// <param name="className"></param> /// <returns></returns> public CharacterClasses LevelUp(Character character, string className) { using var db = new PathfinderContext(); CharacterClasses _class = db.CharacterClasses.Find(character.Id, className); if (_class == null) { return(null); } if (_class.Level == 20) { return(null); } _class.Level++; db.SaveChanges(); return(_class); }
public Player CreatePlayer(string username, string password, string salt) { using var db = new PathfinderContext(); //Username check is made in the webservice Player player = new Player(); if (db.Players.Count() == 0) { player.Id = 1; } player.Id = db.Players.Max(x => x.Id) + 1; player.Username = username; player.Password = password; player.Salt = salt; Console.WriteLine("Creating a new player, {0}, with id {1}", player.Username, player.Id); db.Players.Add(player); db.SaveChanges(); return(player); }
/// <summary> /// Adds a new class to the character. If the character already has this class, their level will be updated. /// </summary> /// <param name="character"></param> /// <param name="className"></param> /// <param name="level">The level you want to set the character to</param> /// <returns></returns> public CharacterClasses AddClassToCharacter(Character character, string className, int level) { if (character == null) { return(null); } using var db = new PathfinderContext(); CharacterClasses newClass = null; Class _class = GetClass(className, level); if (_class == null) { return(null); } CharacterClasses hasClass = db.CharacterClasses.Find(character.Id, className); if (hasClass != null) { hasClass.Level = level; newClass = hasClass; } else { newClass = new CharacterClasses() { CharacterId = character.Id, ClassName = className, Level = level, //Class = _class }; db.CharacterClasses.Add(newClass); } db.SaveChanges(); return(newClass); }
public Character UpdateCharacter(int id, Character update) { using var db = new PathfinderContext(); Character character = db.Characters.Find(id); if (character == null) { return(null); } Character _character = GetCharacter(id); /*TODO: Change relevant fields here * Has to be done by changing individual fields. */ character.Name = update.Name; character.Alignment = update.Alignment; character.Gender = update.Gender; character.Age = update.Age; character.Deity = update.Deity; character.Homeland = update.Homeland; character.Height = update.Height; character.Weight = update.Weight; character.Hair = update.Hair; character.Eyes = update.Eyes; character.Experience = update.Experience; character.Strength.BaseScore = update.Strength.BaseScore; character.Strength.TempScore = update.Strength.TempScore; character.Strength.RacialModifier = update.Strength.RacialModifier; character.Dexterity.BaseScore = update.Dexterity.BaseScore; character.Dexterity.TempScore = update.Dexterity.TempScore; character.Dexterity.RacialModifier = update.Dexterity.RacialModifier; character.Constitution.BaseScore = update.Constitution.BaseScore; character.Constitution.TempScore = update.Constitution.TempScore; character.Constitution.RacialModifier = update.Constitution.RacialModifier; character.Intelligence.BaseScore = update.Intelligence.BaseScore; character.Intelligence.TempScore = update.Intelligence.TempScore; character.Intelligence.RacialModifier = update.Intelligence.RacialModifier; character.Wisdom.BaseScore = update.Wisdom.BaseScore; character.Wisdom.TempScore = update.Wisdom.TempScore; character.Wisdom.RacialModifier = update.Wisdom.RacialModifier; character.Charisma.BaseScore = update.Charisma.BaseScore; character.Charisma.TempScore = update.Charisma.TempScore; character.Charisma.RacialModifier = update.Charisma.RacialModifier; character.InitiativeMiscModifier = update.InitiativeMiscModifier; character.HitPoints = new HitPoints(update.HitPoints.CurrentHitPoints, update.HitPoints.MaxHitPoints, update.HitPoints.NonLethalDamage, update.HitPoints.Wounds); character.HitPoints.CurrentHitPoints = update.HitPoints.CurrentHitPoints; character.HitPoints.MaxHitPoints = update.HitPoints.MaxHitPoints; character.HitPoints.NonLethalDamage = update.HitPoints.NonLethalDamage; character.HitPoints.Wounds = update.HitPoints.Wounds; character.AC.Armour = update.AC.Armour; character.AC.Shield = update.AC.Shield; character.AC.NaturalArmour = update.AC.NaturalArmour; character.AC.Deflection = update.AC.Deflection; character.AC.Misc = update.AC.Misc; character.Speed = new Speed(update.Speed.BaseModifier, update.Speed.BaseTempModifier, update.Speed.Armour, update.Speed.Fly, update.Speed.Swim, update.Speed.Climb, update.Speed.Burrow, update.Speed.Temporary); character.Speed.BaseModifier = update.Speed.BaseModifier; character.Speed.BaseTempModifier = update.Speed.BaseTempModifier; character.Speed.Armour = update.Speed.Armour; character.Speed.Fly = update.Speed.Fly; character.Speed.Swim = update.Speed.Swim; character.Speed.Climb = update.Speed.Climb; character.Speed.Burrow = update.Speed.Burrow; character.Speed.Temporary = update.Speed.Temporary; character.Fortitude = new Character.Save(update.Fortitude.Magic, update.Fortitude.Misc, update.Fortitude.Temporary, update.Fortitude.Note); character.Fortitude.Magic = update.Fortitude.Magic; character.Fortitude.Misc = update.Fortitude.Misc; character.Fortitude.Temporary = update.Fortitude.Temporary; character.Fortitude.Note = update.Fortitude.Note; character.Reflex = new Character.Save(update.Reflex.Magic, update.Reflex.Misc, update.Reflex.Temporary, update.Reflex.Note); character.Reflex.Magic = update.Reflex.Magic; character.Reflex.Misc = update.Reflex.Misc; character.Reflex.Temporary = update.Reflex.Temporary; character.Reflex.Note = update.Reflex.Note; character.Will = new Character.Save(update.Will.Magic, update.Will.Misc, update.Will.Temporary, update.Will.Note); character.Will.Magic = update.Will.Magic; character.Will.Misc = update.Will.Misc; character.Will.Temporary = update.Will.Temporary; character.Will.Note = update.Will.Note; character.CMB = new CombatManeuverBonus(update.CMB.Misc, -update.CMB.Temp, update.CMB.Note); character.CMB.Misc = update.CMB.Misc; character.CMB.Temp = update.CMB.Temp; character.CMB.Note = update.CMB.Note; character.CMD = new CombatManeuverDefence(update.CMD.Misc, -update.CMD.Temp, update.CMD.Note); character.CMD.Misc = update.CMD.Misc; character.CMD.Temp = update.CMD.Temp; character.CMD.Note = update.CMD.Note; character.Resistance = update.Resistance; character.Immunity = update.Immunity; character.SpellResistance = update.SpellResistance; character.DamageReduction = update.DamageReduction; character.Copper = update.Copper; character.Silver = update.Silver; character.Gold = update.Gold; character.Platinum = update.Platinum; character.Languages = update.Languages; character.Note = update.Note; db.SaveChanges(); return(character); }
public string DataMigrate() { RawSpell tempspell; try { List <RawSpell> rawSpells = pfContext.RawSpells.ToList(); List <Spell> spells = new List <Spell>(); List <CurrencyUnit> currencyUnits = pfContext.CurrencyUnits.ToList(); List <Subschool> subschools = pfContext.Subschools.ToList(); List <CastingTime> castingTimes = pfContext.CastingTime.ToList(); List <School> schools = pfContext.Schools.ToList(); List <Bloodline> bloodlines = pfContext.Bloodlines.ToList(); List <HeroClass> heroClasses = pfContext.HeroClasses.ToList(); List <ComponentType> componentTypes = pfContext.ComponentTypes.ToList(); List <Descriptor> spellDescriptors = pfContext.SpellDescriptors.ToList(); List <Domain> domains = pfContext.Domains.ToList(); List <SavingThrow> savingThrows = pfContext.SavingThrows.ToList(); foreach (var rawSpell in rawSpells) { tempspell = rawSpell; Spell spell = new Spell() { Area = rawSpell.area, AugmentedText = rawSpell.augmented, CastingTime = castingTimes.FirstOrDefault(c => c.Name == rawSpell.casting_time), Description = rawSpell.description, Duration = rawSpell.duration, Effect = rawSpell.effect, HTMLDescription = rawSpell.description_formated, Mythic = rawSpell.mythic.HasValue ? rawSpell.mythic.Value : false, MythicText = rawSpell.mythic_text, Name = rawSpell.name, Range = rawSpell.range, ReferenceSource = pfContext.ReferenceSources.FirstOrDefault(c => c.Name == rawSpell.source), School = schools.FirstOrDefault(s => s.Name.ToLower() == rawSpell.school.ToLower()), ShortDescription = rawSpell.short_description, SpellLikeAbilityLevel = rawSpell.SLA_Level.HasValue ? rawSpell.SLA_Level.Value : -1, SpellResistance = !string.IsNullOrEmpty(rawSpell.spell_resistence) ? rawSpell.spell_resistence.ToLower().Contains("yes") : false, SpellResistanceHarmless = !string.IsNullOrEmpty(rawSpell.spell_resistence) ? rawSpell.spell_resistence.ToLower().Contains("harmless") : false, SpellResistanceObject = !string.IsNullOrEmpty(rawSpell.spell_resistence) ? rawSpell.spell_resistence.ToLower().Contains("object") : false, Targets = rawSpell.targets }; //Bloodlines if (!string.IsNullOrEmpty(rawSpell.bloodline)) { foreach (var bloodlineString in rawSpell.bloodline.Trim().Replace(" ", "").Split(',')) { string bloodline = bloodlineString.Split('(')[0]; int level = int.Parse(bloodlineString.Split('(')[1].TrimEnd(")".ToCharArray())); spell.BloodlineSpells.Add(new BloodlineSpell() { Bloodline = bloodlines.FirstOrDefault(b => b.Name == bloodline), level = level }); } } //Hero Classes if (rawSpell.adept.HasValue) { spell.Classes.Add(new SpellClass() { ClassLevel = rawSpell.adept.Value, HeroClass = heroClasses.FirstOrDefault(h => h.Name == "Adept") }); } if (rawSpell.alchemist.HasValue) { spell.Classes.Add(new SpellClass() { ClassLevel = rawSpell.alchemist.Value, HeroClass = heroClasses.FirstOrDefault(h => h.Name == "Alchemist") }); } if (rawSpell.antipaladin.HasValue) { spell.Classes.Add(new SpellClass() { ClassLevel = rawSpell.antipaladin.Value, HeroClass = heroClasses.FirstOrDefault(h => h.Name == "Antipaladin") }); } if (rawSpell.bard.HasValue) { spell.Classes.Add(new SpellClass() { ClassLevel = rawSpell.bard.Value, HeroClass = heroClasses.FirstOrDefault(h => h.Name == "Bard") }); } if (rawSpell.bloodrager.HasValue) { spell.Classes.Add(new SpellClass() { ClassLevel = rawSpell.bloodrager.Value, HeroClass = heroClasses.FirstOrDefault(h => h.Name == "Bloodrager") }); } if (rawSpell.cleric.HasValue) { spell.Classes.Add(new SpellClass() { ClassLevel = rawSpell.cleric.Value, HeroClass = heroClasses.FirstOrDefault(h => h.Name == "Cleric") }); } if (rawSpell.druid.HasValue) { spell.Classes.Add(new SpellClass() { ClassLevel = rawSpell.druid.Value, HeroClass = heroClasses.FirstOrDefault(h => h.Name == "Druid") }); } if (rawSpell.hunter.HasValue) { spell.Classes.Add(new SpellClass() { ClassLevel = rawSpell.hunter.Value, HeroClass = heroClasses.FirstOrDefault(h => h.Name == "Hunter") }); } if (rawSpell.inquisitor.HasValue) { spell.Classes.Add(new SpellClass() { ClassLevel = rawSpell.inquisitor.Value, HeroClass = heroClasses.FirstOrDefault(h => h.Name == "Inquisitor") }); } if (rawSpell.investigator.HasValue) { spell.Classes.Add(new SpellClass() { ClassLevel = rawSpell.investigator.Value, HeroClass = heroClasses.FirstOrDefault(h => h.Name == "Investigator") }); } if (rawSpell.magus.HasValue) { spell.Classes.Add(new SpellClass() { ClassLevel = rawSpell.magus.Value, HeroClass = heroClasses.FirstOrDefault(h => h.Name == "Magus") }); } if (rawSpell.medium.HasValue) { spell.Classes.Add(new SpellClass() { ClassLevel = rawSpell.medium.Value, HeroClass = heroClasses.FirstOrDefault(h => h.Name == "Medium") }); } if (rawSpell.mesmerist.HasValue) { spell.Classes.Add(new SpellClass() { ClassLevel = rawSpell.mesmerist.Value, HeroClass = heroClasses.FirstOrDefault(h => h.Name == "Mesmerist") }); } if (rawSpell.occultist.HasValue) { spell.Classes.Add(new SpellClass() { ClassLevel = rawSpell.occultist.Value, HeroClass = heroClasses.FirstOrDefault(h => h.Name == "Occultist") }); } if (rawSpell.oracle.HasValue) { spell.Classes.Add(new SpellClass() { ClassLevel = rawSpell.oracle.Value, HeroClass = heroClasses.FirstOrDefault(h => h.Name == "Oracle") }); } if (rawSpell.paladin.HasValue) { spell.Classes.Add(new SpellClass() { ClassLevel = rawSpell.paladin.Value, HeroClass = heroClasses.FirstOrDefault(h => h.Name == "Paladin") }); } if (rawSpell.psychic.HasValue) { spell.Classes.Add(new SpellClass() { ClassLevel = rawSpell.psychic.Value, HeroClass = heroClasses.FirstOrDefault(h => h.Name == "Psychic") }); } if (rawSpell.ranger.HasValue) { spell.Classes.Add(new SpellClass() { ClassLevel = rawSpell.ranger.Value, HeroClass = heroClasses.FirstOrDefault(h => h.Name == "Ranger") }); } if (rawSpell.shaman.HasValue) { spell.Classes.Add(new SpellClass() { ClassLevel = rawSpell.shaman.Value, HeroClass = heroClasses.FirstOrDefault(h => h.Name == "Shaman") }); } if (rawSpell.skald.HasValue) { spell.Classes.Add(new SpellClass() { ClassLevel = rawSpell.skald.Value, HeroClass = heroClasses.FirstOrDefault(h => h.Name == "Skald") }); } if (rawSpell.sor.HasValue) { spell.Classes.Add(new SpellClass() { ClassLevel = rawSpell.sor.Value, HeroClass = heroClasses.FirstOrDefault(h => h.Name == "Sorcerer") }); } if (rawSpell.spiritualist.HasValue) { spell.Classes.Add(new SpellClass() { ClassLevel = rawSpell.spiritualist.Value, HeroClass = heroClasses.FirstOrDefault(h => h.Name == "Spiritualist") }); } if (rawSpell.summoner.HasValue) { spell.Classes.Add(new SpellClass() { ClassLevel = rawSpell.summoner.Value, HeroClass = heroClasses.FirstOrDefault(h => h.Name == "Summoner") }); } if (rawSpell.witch.HasValue) { spell.Classes.Add(new SpellClass() { ClassLevel = rawSpell.witch.Value, HeroClass = heroClasses.FirstOrDefault(h => h.Name == "Witch") }); } if (rawSpell.wiz.HasValue) { spell.Classes.Add(new SpellClass() { ClassLevel = rawSpell.wiz.Value, HeroClass = heroClasses.FirstOrDefault(h => h.Name == "Wizard") }); } //Spell Components string rawComponentString = " , " + rawSpell.components; foreach (var lookupComponent in componentTypes) { string lookupSearch = ", " + lookupComponent.Symbol; if (rawComponentString.Contains(lookupSearch + ",") || rawComponentString.Contains(lookupSearch + " (")) { Currency materialCost = null; string material = ""; int index = rawComponentString.IndexOf(lookupSearch + " ("); if (index != -1) { material = rawComponentString.Substring(index + lookupSearch.Length + 2).Split(')')[0]; materialCost = new Currency() { Amount = rawSpell.material_costs.HasValue && rawSpell.costly_components.HasValue && rawSpell.costly_components.Value ? rawSpell.material_costs.Value : 0, CurrencyUnit = currencyUnits.FirstOrDefault(c => c.NameShort == "gp") }; } spell.Components.Add(new Component() { ComponentType = lookupComponent, Material = material, MaterialCost = materialCost }); } } //Spell Descriptors foreach (var descriptor in spellDescriptors) { if (!string.IsNullOrEmpty(rawSpell.descriptor) && rawSpell.descriptor.ToLower().Contains(descriptor.Name.ToLower())) { spell.Descriptors.Add(descriptor); } } //Spell Domains if (!string.IsNullOrEmpty(rawSpell.domain)) { foreach (var domain in rawSpell.domain.Split(',')) { string domainName = domain.Split('(')[0].Trim(); int level = int.Parse(domain.Split('(')[1].Split(')')[0].Trim()); spell.SpellDomains.Add(new SpellDomain() { Domain = domains.FirstOrDefault(d => d.Name == domainName), Level = level }); } } foreach (var savingThrow in savingThrows) { if (!string.IsNullOrEmpty(rawSpell.saving_throw) && rawSpell.saving_throw.ToLower().Contains(savingThrow.Name.ToLower())) { spell.SpellSavingThrows.Add(new SpellSavingThrow() { SavingThrow = savingThrow }); } } foreach (var subschool in subschools) { if (!string.IsNullOrEmpty(rawSpell.subschool) && rawSpell.subschool.ToLower().Contains(subschool.Name.ToLower())) { spell.SpellSubschools.Add(new SpellSubschool() { Subschool = subschool }); } } spells.Add(spell); } pfContext.Spells.AddRange(spells); pfContext.SaveChanges(); } catch (Exception e) { return(e.Message + e.InnerException?.Message); } return("success"); }