Beispiel #1
0
        public IActionResult BestiaryList()
        {
            var context = PFDAL.GetContext();
            var model   = new Views.DM.Bestiary_.CreateModel(context);

            return(View(model));
        }
        public IActionResult Test()
        {
            var data = PFDAL.GetContext().CampaignData;

            Console.WriteLine($"LiveDisplayAPI - {data.Count()} entries in CampaignData");
            return(Ok($"API is listening! {data.Count()}"));
        }
Beispiel #3
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
#if !DEBUG
            services.Configure <MvcOptions>(options =>
            {
                options.Filters.Add(new RequireHttpsAttribute());
            });
#endif
            services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
            .AddJwtBearer(options =>
            {
                options.TokenValidationParameters = new TokenValidationParameters
                {
                    ValidateIssuer           = true,
                    ValidateAudience         = true,
                    ValidateLifetime         = true,
                    ValidateIssuerSigningKey = true,
                    ValidIssuer      = PFConfig.JWT_ISSUER,
                    ValidAudience    = PFConfig.JWT_ISSUER,
                    IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(PFConfig.JWT_KEY))
                };
            });

            services.AddMvc();

            services.AddDbContext <PFDBContext>(options =>
                                                options.UseSqlServer($"Server={PFConfig.DB_ADDR};Database={PFConfig.DB_DB};User Id={PFConfig.DB_USER};Password={PFConfig.DB_PASS}"));

            using (var context = PFDAL.GetContext())
            {
                context.Database.Migrate();
            }
        }
Beispiel #4
0
        // Menu 1
        private static void Test()
        {
            var cs = $"Server={PFConfig.DB_ADDR};Database={PFConfig.DB_DB};User Id={PFConfig.DB_USER};Password={PFConfig.DB_PASS}";

            Console.WriteLine(cs);
            var context = PFDAL.GetContext(false);

            PFDBInitializer.Initialize(context);
            Console.WriteLine(context.Bestiary.First().Name);
        }
Beispiel #5
0
        public IActionResult CampaignLiveDisplay(int campaignId)
        {
            var context  = PFDAL.GetContext();
            var campaign = context.Campaign.Find(campaignId);

            if (campaign == null || campaign.CampaignId == 0)
            {
                return(NotFound());
            }

            var model = new LiveDisplayModel()
            {
                ActivePlayer = Player,
                CampaignId   = campaignId,
                CampaignName = campaign.CampaignName,
                FantasyDate  = "{}",
                ChatRoom     = new PFDBCommon.DBModels.ChatRoom
                {
                    ChatRoomId   = -1,
                    ChatRoomName = "NONE"
                }
            };

            var campaignData = context.CampaignData.Where(x => x.CampaignId == campaign.CampaignId);

            if (campaignData != null)
            {
                var campaignDate = campaignData.FirstOrDefault(x => x.Key == PFConfig.STR_FANTASYDATE);
                if (campaignDate != null)
                {
                    var seasons      = context.Season.ToList();
                    var months       = context.Month.ToList();
                    var CurrentDate  = new FantasyDate(campaignDate.Value);
                    var CurrentMonth = months.FirstOrDefault(x => x.MonthOrder == CurrentDate.Month);
                    var grandDate    = $"YEAR {CurrentDate.Year} AA, Season of {seasons.FirstOrDefault(x => x.SeasonId == CurrentMonth.SeasonId)?.Name}, Month of {CurrentMonth?.Name}, Day {CurrentDate.Day}";
                    model.FantasyDate = JsonConvert.SerializeObject(new { grandDate, date = campaignDate.Value, monthName = CurrentMonth.Name, day = CurrentDate.Day, campaignId });
                }

                var displayMap = campaignData.FirstOrDefault(x => x.Key == PFConfig.STR_LIVEDISPLAYMAP);
                if (displayMap != null)
                {
                    model.MapPath = displayMap.Value;
                }

                var mapData = campaignData.FirstOrDefault(x => x.Key == PFConfig.STR_LIVEDISPLAYMAPDATA);
                if (mapData != null)
                {
                    model.MapSaveData = mapData.Value;
                }
            }
            return(View("LiveDisplay", model));
        }
Beispiel #6
0
        public IActionResult CharacterSheet(int characterId)
        {
            var context   = PFDAL.GetContext();
            var character = context.Character.Find(characterId);

            if (character != null)
            {
                var model = new CharacterSheetViewModel();
                model.Character = character;

                return(View(model));
            }

            return(NotFound());
        }
Beispiel #7
0
        public List <MonsterSpawnEdit> GetMonsterSpawnEdit()
        {
            var ret     = new List <MonsterSpawnEdit>();
            var context = PFDAL.GetContext();

            var retList = from ms in context.MonsterSpawn
                          join b in context.Bestiary on ms.BestiaryId equals b.BestiaryId
                          join t in context.BestiaryType on b.Type equals t.BestiaryTypeId
                          select new MonsterSpawnEdit
            {
                BestiaryId  = ms.BestiaryId,
                ContinentId = ms.ContinentId,
                CR          = b.Cr,
                Name        = b.Name,
                PlaneId     = ms.PlaneId,
                SeasonId    = ms.SeasonId,
                TimeId      = ms.TimeId,
                Type        = t.Name
            };

            foreach (var item in retList)
            {
                var types = from st in context.BestiarySubType
                            join t in context.BestiaryType on st.BestiaryTypeId equals t.BestiaryTypeId
                            where st.BestiaryId == item.BestiaryId
                            select t.Name;

                if (types.Count() > 0)
                {
                    item.Type += " (";
                    foreach (var type in types.OrderBy(x => x))
                    {
                        item.Type += type + ", ";
                    }
                    item.Type.Remove(item.Type.Length - 2);
                    item.Type += ")";
                }
            }

            if (retList != null)
            {
                ret = retList.ToList();
            }

            return(ret);
        }
Beispiel #8
0
        public RandomEncounterResult GenerateRandomEncounters(RandomEncounterRequest request)
        {
            var context       = PFDAL.GetContext();
            var encounterList = new List <RandomEncounterItem>();
            var groupMon      = new List <Bestiary>();
            var validSpawns   = from s in context.MonsterSpawn
                                join b in context.Bestiary on s.BestiaryId equals b.BestiaryId
                                where (s.ContinentId == request.ContinentId || request.ContinentId <= 0) &&
                                (s.SeasonId == request.SeasonId || request.SeasonId <= 0) &&
                                (s.TimeId == request.TimeId || request.TimeId <= 0) &&
                                b.CharacterFlag == request.Npc
                                select b;

            foreach (var cr in request.Crs)
            {
                Bestiary mon = new Bestiary();
                if (request.Group && (groupMon.Select(x => x.Cr).Contains(cr)))
                {
                    mon = groupMon.First(x => x.Cr == cr);
                }
                else
                {
                    var monList = validSpawns.Where(x => x.Cr == cr || cr == (int)CRSpecial.ALL).ToList();
                    if (monList.Count > 0)
                    {
                        mon = monList.ElementAt(random.Next(monList.Count));
                    }
                }

                if (mon != null)
                {
                    groupMon.Add(mon);
                    encounterList.Add(new RandomEncounterItem()
                    {
                        BestiaryId = mon.BestiaryId, Cr = mon.Cr, Name = mon.Name
                    });
                }
            }

            return(new RandomEncounterResult()
            {
                EncounterItems = encounterList,
                Message = $"Generated {encounterList.Count} items",
                Success = encounterList.Any()
            });
        }
Beispiel #9
0
        public RandomWeatherResult GenerateRandomWeatherTable(RandomWeatherRequest request)
        {
            var context = PFDAL.GetContext();
            var ret     = new RandomWeatherResult()
            {
                ContinentId = request.ContinentId,
                SeasonId    = request.SeasonId
            };

            var validWeathers = from c in context.ContinentWeather
                                where (c.ContinentId == request.ContinentId || c.ContinentId == 0) &&
                                (c.SeasonId == request.SeasonId || c.SeasonId == 0)
                                select c;

            ret.WeatherList = validWeathers.ToList();
            ret.Success     = true;

            return(ret);
        }
Beispiel #10
0
 // Menu 4
 private static void UpdateTables()
 {
     foreach (var env in PFDAL.GetContext(false).Environment)
     {
         Console.WriteLine(env.Name);
         var context = PFDAL.GetContext(false);
         var e       = context.Environment.First(x => x.EnvironmentId == env.EnvironmentId);
         //context.Environment.Attach(e).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
         if (e.Name.StartsWith(" "))
         {
             e.Name = e.Name.Substring(1);
         }
         if (e.Name.StartsWith("or "))
         {
             e.Name = e.Name.Substring(3);
         }
         e.Name = e.Name.Replace(")", "").Trim();
         context.SaveChanges();
     }
 }
Beispiel #11
0
        public List <Environment> EnvironmentsForContinent(int continentId)
        {
            var ret     = new List <Environment>();
            var context = PFDAL.GetContext();

            if (continentId == 0)
            {
                ret.AddRange(context.Environment);
            }
            else
            {
                var envList = from ce in context.ContinentEnvironment
                              join e in context.Environment on ce.EnvironmentId equals e.EnvironmentId
                              where ce.ContinentId == continentId
                              select e;

                ret.AddRange(envList);
            }

            return(ret);
        }
        public IActionResult UpdateDate(int campaignId)
        {
            var context = PFDAL.GetContext();
            var data    = context.CampaignData.Where(x => x.CampaignId == campaignId);
            var date    = data.FirstOrDefault(x => x.Key.Equals(PFConfig.STR_FANTASYDATE))?.Value;

            if (!string.IsNullOrWhiteSpace(date))
            {
                var seasons      = context.Season.ToList();
                var months       = context.Month.ToList();
                var CurrentDate  = new FantasyDate(date);
                var CurrentMonth = months.FirstOrDefault(x => x.MonthOrder == CurrentDate.Month);
                var grandDate    = $"YEAR {CurrentDate.Year} AA, Season of {seasons.FirstOrDefault(x => x.SeasonId == CurrentMonth.SeasonId)?.Name}, Month of {CurrentMonth?.Name}, Day {CurrentDate.Day}";
                _hubContext.Clients.All.SendAsync("ReceiveDate", new { grandDate, date, monthName = CurrentMonth.Name, day = CurrentDate.Day, campaignId });
                // TODO - only send update to clients connected to the campaignId

                return(Ok());
            }

            return(BadRequest("No date found for campaign " + campaignId));
        }
Beispiel #13
0
        public void UpdateMonsterSpawn(UpdateMonsterSpawnRequest request)
        {
            var context = PFDAL.GetContext();

            var delList = from ms in context.MonsterSpawn
                          where ms.BestiaryId == request.BestiaryId &&
                          ms.ContinentId == request.ContinentId &&
                          ms.SeasonId == request.SeasonId
                          select ms;

            foreach (var item in delList)
            {
                context.MonsterSpawn.Remove(item);
            }

            foreach (var item in request.Spawns)
            {
                context.MonsterSpawn.Add(item);
            }

            context.SaveChanges();
        }
Beispiel #14
0
        public void UpdateContinentWeathers(ContinentWeatherUpdateRequest request)
        {
            if (request.ContinentId > 0 && request.SeasonId > 0)
            {
                var context   = PFDAL.GetContext();
                var removeCWs = context.ContinentWeather.Where(x => x.ContinentId == request.ContinentId && x.SeasonId == request.SeasonId);
                foreach (var item in removeCWs)
                {
                    context.ContinentWeather.Remove(item);
                    context.SaveChanges();
                }
            }

            if (request.UpdateList != null)
            {
                var context = PFDAL.GetContext();
                foreach (var item in request.UpdateList)
                {
                    context.ContinentWeather.Add(item);
                    context.SaveChanges();
                }
            }
        }
Beispiel #15
0
        public void UpdateSpawns(SpawnUpdateRequest request)
        {
            if (request.BestiaryId > 0)
            {
                var context      = PFDAL.GetContext();
                var removeSpawns = context.MonsterSpawn.Where(x => x.BestiaryId == request.BestiaryId).ToList();
                foreach (var item in removeSpawns)
                {
                    context.MonsterSpawn.Remove(item);
                    context.SaveChanges();
                }
            }

            if (request.SpawnList != null)
            {
                var context = PFDAL.GetContext();

                foreach (var item in request.SpawnList)
                {
                    context.MonsterSpawn.Add(item);
                    context.SaveChanges();
                }
            }
        }
Beispiel #16
0
        public SpellLookupResponse SpellLookup(SpellLookupRequest request)
        {
            var response = new SpellLookupResponse()
            {
                SpellDetails = new List <SpellDetail>(), Spells = new List <Spell>()
            };

            var context   = PFDAL.GetContext();
            var levelList = new List <int>();

            if (request.Lv0)
            {
                levelList.Add(0);
            }
            if (request.Lv1)
            {
                levelList.Add(1);
            }
            if (request.Lv2)
            {
                levelList.Add(2);
            }
            if (request.Lv3)
            {
                levelList.Add(3);
            }
            if (request.Lv4)
            {
                levelList.Add(4);
            }
            if (request.Lv5)
            {
                levelList.Add(5);
            }
            if (request.Lv6)
            {
                levelList.Add(6);
            }
            if (request.Lv7)
            {
                levelList.Add(7);
            }
            if (request.Lv8)
            {
                levelList.Add(8);
            }
            if (request.Lv9)
            {
                levelList.Add(9);
            }

            var spellList = from s in context.Spell
                            where (
                (request.Sor && levelList.Contains(s.Sor ?? -1)) ||
                (request.Wiz && levelList.Contains(s.Wiz ?? -1)) ||
                (request.Cleric && levelList.Contains(s.Cleric ?? -1)) ||
                (request.Druid && levelList.Contains(s.Druid ?? -1)) ||
                (request.Ranger && levelList.Contains(s.Ranger ?? -1)) ||
                (request.Bard && levelList.Contains(s.Bard ?? -1)) ||
                (request.Paladin && levelList.Contains(s.Paladin ?? -1)) ||
                (request.Alchemist && levelList.Contains(s.Alchemist ?? -1)) ||
                (request.Summoner && levelList.Contains(s.Summoner ?? -1)) ||
                (request.Witch && levelList.Contains(s.Witch ?? -1)) ||
                (request.Inquisitor && levelList.Contains(s.Inquisitor ?? -1)) ||
                (request.Oracle && levelList.Contains(s.Oracle ?? -1)) ||
                (request.Antipaladin && levelList.Contains(s.Antipaladin ?? -1)) ||
                (request.Magus && levelList.Contains(s.Magus ?? -1)) ||
                (request.Adept && levelList.Contains(s.Adept ?? -1)) ||
                (request.BloodRager && levelList.Contains(s.BloodRager ?? -1)) ||
                (request.Shaman && levelList.Contains(s.Shaman ?? -1)) ||
                (request.Psychic && levelList.Contains(s.Psychic ?? -1)) ||
                (request.Medium && levelList.Contains(s.Medium ?? -1)) ||
                (request.Mesmerist && levelList.Contains(s.Mesmerist ?? -1)) ||
                (request.Occultist && levelList.Contains(s.Occultist ?? -1)) ||
                (request.Spiritualist && levelList.Contains(s.Spiritualist ?? -1)) ||
                (request.Skald && levelList.Contains(s.Skald ?? -1)) ||
                (request.Investigator && levelList.Contains(s.Investigator ?? -1)) ||
                (request.Hunter && levelList.Contains(s.Hunter ?? -1))
                )
                            select s;

            if (spellList != null)
            {
                var spellDetails = from sd in context.SpellDetail
                                   where spellList.Select(x => x.SpellId).Contains(sd.SpellId)
                                   select sd;

                response.SpellDetails = spellDetails.ToList();
                response.Spells       = spellList.ToList();
            }

            return(response);
        }
Beispiel #17
0
        // Menu 2
        private static void UpdateBestiary()
        {
            var context = PFDAL.GetContext(false);

            //int i = 0;
            int[] idList = { 473, 474, 475, 476, 477, 478 };
            var   bList  = PFDAL.GetContext(false).Bestiary.Where(x => idList.Contains(x.BestiaryId));

            /*
             * foreach (var z in bList)
             * {
             * try
             * {
             *  var b = context.Bestiary.First(x => x.BestiaryId == z.BestiaryId);
             *
             *  // AbilityScores - split
             *  // Str 12, Dex 14, Con 13, Int 9, Wis 10, Cha 9
             *  // Handle creatures with no Con, Int, etc like undead or plants
             *  foreach (var item in b.AbilityScores.Split(','))
             *  {
             *    var stat = item.Trim();
             *    if (stat.StartsWith("Str", StringComparison.InvariantCultureIgnoreCase))
             *    {
             *      if (int.TryParse(Regex.Match(stat, "[0-9]+").ToString(), out int val))
             *        b.Str = val;
             *    }
             *    else if (stat.StartsWith("Dex", StringComparison.InvariantCultureIgnoreCase))
             *    {
             *      if (int.TryParse(Regex.Match(stat, "[0-9]+").ToString(), out int val))
             *        b.Dex = val;
             *    }
             *    else if (stat.StartsWith("Con", StringComparison.InvariantCultureIgnoreCase))
             *    {
             *      if (int.TryParse(Regex.Match(stat, "[0-9]+").ToString(), out int val))
             *        b.Con = val;
             *    }
             *    else if (stat.StartsWith("Int", StringComparison.InvariantCultureIgnoreCase))
             *    {
             *      if (int.TryParse(Regex.Match(stat, "[0-9]+").ToString(), out int val))
             *        b.Int = val;
             *    }
             *    else if (stat.StartsWith("Wis", StringComparison.InvariantCultureIgnoreCase))
             *    {
             *      if (int.TryParse(Regex.Match(stat, "[0-9]+").ToString(), out int val))
             *        b.Wis = val;
             *    }
             *    else if (stat.StartsWith("Cha", StringComparison.InvariantCultureIgnoreCase))
             *    {
             *      if (int.TryParse(Regex.Match(stat, "[0-9]+").ToString(), out int val))
             *        b.Cha = val;
             *    }
             *  }
             *
             *  if (!b.Str.HasValue)
             *    b.Str = 0;
             *  if (!b.Dex.HasValue)
             *    b.Dex = 0;
             *  if (!b.Con.HasValue)
             *    b.Con = 0;
             *  if (!b.Int.HasValue)
             *    b.Int = 0;
             *  if (!b.Wis.HasValue)
             *    b.Wis = 0;
             *  if (!b.Cha.HasValue)
             *    b.Cha = 0;
             *
             *  b.AbilityScores = null;
             *
             *  // AC - split, make sure AC is an int
             *  // 17, touch 17, flat-footed 12
             *  foreach (Match item in Regex.Matches(b.Ac, REGEX_SPLIT))
             *  {
             *    var ac = item.Groups[1].Value;
             *    if (ac.StartsWith("touch"))
             *    {
             *      if (int.TryParse(Regex.Match(ac, "[0-9]+").ToString(), out int val))
             *        b.Actouch = val;
             *    }
             *    else if (ac.StartsWith("flat"))
             *    {
             *      if (int.TryParse(Regex.Match(ac, "[0-9]+").ToString(), out int val))
             *        b.Acflat = val;
             *    }
             *    else
             *    {
             *      if (int.TryParse(Regex.Match(ac, "[0-9]+").ToString(), out int val))
             *        b.Ac = val.ToString();
             *    }
             *  }
             *
             *  // HD - remove parenthesis, make sure it's in AdB+C format
             *  b.Hd = b.Hd.Replace("(", "").Replace(")", "");
             *  if (!b.Hd.Contains("d"))
             *    b.Hd = "1d" + b.Hd;
             *  if (!b.Hd.Contains("+") && !b.Hd.Contains("-"))
             *    b.Hd = b.Hd + "+0";
             *
             *  if (!b.BaseAtk.HasValue)
             *    b.BaseAtk = 0;
             *
             *  // Speed - split, make sure base speed is an int
             *  // WAIT UNTIL ALT SPEEDS CHANGED TO INT
             *  // Burrow, Climb, Fly, Land, Swim
             *  //b.Speed;
             *
             *  if (!b.CharacterFlag.HasValue)
             *    b.CharacterFlag = false;
             *
             *  if (!b.Cmb.HasValue)
             *    b.Cmd = b.BaseAtk.Value + GetAbilityMod(b.Str.Value);
             *
             *  if (!b.Cmd.HasValue)
             *    b.Cmd = 10 + b.BaseAtk.Value + GetAbilityMod(b.Str.Value) + GetAbilityMod(b.Dex.Value);
             *
             *  if (!b.CompanionFlag.HasValue)
             *    b.CompanionFlag = false;
             *
             *  if (!b.Cr.HasValue)
             *  {
             *    int cr = -10;
             *    int.TryParse(Regex.Match(b.Hd, "[0-9]+").ToString(), out cr);
             *    b.Cr = cr;
             *  }
             *
             *  if (!b.DontUseRacialHd.HasValue)
             *    b.DontUseRacialHd = false;
             *
             *  if (!b.Fortitude.HasValue)
             *    b.Fortitude = GetAbilityMod(b.Con.Value);
             *
             *  if (!b.Hp.HasValue)
             *    b.Hp = 0;
             *
             *  if (!b.Init.HasValue)
             *    b.Init = GetAbilityMod(b.Dex.Value);
             *
             *  if (!b.IsTemplate.HasValue)
             *    b.IsTemplate = false;
             *
             *  if (!b.Mr.HasValue)
             *    b.Mr = 0;
             *
             *  if (!b.Mt.HasValue)
             *    b.Mt = 0;
             *
             *  if (!b.Reflex.HasValue)
             *    b.Reflex = GetAbilityMod(b.Dex.Value);
             *
             *  if (!b.Sr.HasValue)
             *    b.Sr = 0;
             *
             *  if (!b.UniqueMonster.HasValue)
             *    b.UniqueMonster = false;
             *
             *  if (!b.Will.HasValue)
             *    b.Will = GetAbilityMod(b.Wis.Value);
             *
             *  if (!b.Xp.HasValue)
             *    b.Xp = 0;
             *
             *  // Spawn
             *  context.MonsterSpawn.Add(new MonsterSpawn() { BestiaryId = b.BestiaryId });
             *
             *  //if (i++ >= 5)
             *  //{
             *  context.SaveChanges();
             *  context.Dispose();
             *  context = PFDAL.GetContext(false);
             *  //i = 0;
             *  Console.WriteLine("Finished BID " + b.BestiaryId.ToString());
             *  //}
             * }
             * catch (Exception ex)
             * {
             *  Console.WriteLine($"[{z.BestiaryId}] - {ex.Message}");
             *  if (ex.InnerException != null)
             *    Console.WriteLine("InnerException: " + ex.InnerException.Message);
             *
             *  context.Dispose();
             *  context = PFDAL.GetContext(false);
             * }
             * }
             */
            context.SaveChanges();
        }
Beispiel #18
0
        // Menu 6
        private static void UpdateNPC()
        {
            int i       = 0;
            var npcList = PFDAL.GetContext(false).Npc;

            foreach (var z in npcList)
            {
                try
                {
                    var context = PFDAL.GetContext(false);
                    var npc     = context.Npc.First(x => x.Npcid == z.Npcid);
                    var b       = new Bestiary();
                    context.Bestiary.Attach(b);

                    // AbilityScores - split
                    // Str 12, Dex 14, Con 13, Int 9, Wis 10, Cha 9
                    // Handle creatures with no Con, Int, etc like undead or plants
                    foreach (var item in npc.AbilityScores.Split(','))
                    {
                        var stat = item.Trim();
                        if (stat.StartsWith("Str", StringComparison.InvariantCultureIgnoreCase))
                        {
                            if (int.TryParse(Regex.Match(stat, "[0-9]+").ToString(), out int val))
                            {
                                b.Str = val;
                            }
                        }
                        else if (stat.StartsWith("Dex", StringComparison.InvariantCultureIgnoreCase))
                        {
                            if (int.TryParse(Regex.Match(stat, "[0-9]+").ToString(), out int val))
                            {
                                b.Dex = val;
                            }
                        }
                        else if (stat.StartsWith("Con", StringComparison.InvariantCultureIgnoreCase))
                        {
                            if (int.TryParse(Regex.Match(stat, "[0-9]+").ToString(), out int val))
                            {
                                b.Con = val;
                            }
                        }
                        else if (stat.StartsWith("Int", StringComparison.InvariantCultureIgnoreCase))
                        {
                            if (int.TryParse(Regex.Match(stat, "[0-9]+").ToString(), out int val))
                            {
                                b.Int = val;
                            }
                        }
                        else if (stat.StartsWith("Wis", StringComparison.InvariantCultureIgnoreCase))
                        {
                            if (int.TryParse(Regex.Match(stat, "[0-9]+").ToString(), out int val))
                            {
                                b.Wis = val;
                            }
                        }
                        else if (stat.StartsWith("Cha", StringComparison.InvariantCultureIgnoreCase))
                        {
                            if (int.TryParse(Regex.Match(stat, "[0-9]+").ToString(), out int val))
                            {
                                b.Cha = val;
                            }
                        }
                    }

                    npc.AbilityScores = null;

                    // AC - split, make sure AC is an int
                    // 17, touch 17, flat-footed 12
                    foreach (Match item in Regex.Matches(npc.Ac, REGEX_SPLIT))
                    {
                        var ac = item.Groups[1].Value;
                        if (ac.StartsWith("touch"))
                        {
                            if (int.TryParse(Regex.Match(ac, "[0-9]+").ToString(), out int val))
                            {
                                b.Actouch = val;
                            }
                        }
                        else if (ac.StartsWith("flat"))
                        {
                            if (int.TryParse(Regex.Match(ac, "[0-9]+").ToString(), out int val))
                            {
                                b.Acflat = val;
                            }
                        }
                        else
                        {
                            if (int.TryParse(Regex.Match(ac, "[0-9]+").ToString(), out int val))
                            {
                                b.Ac = val;
                            }
                        }
                    }

                    // HD - remove parenthesis, make sure it's in AdB+C format
                    b.Hd = npc.Hd.Replace("(", "").Replace(")", "");
                    if (!b.Hd.Contains("d"))
                    {
                        b.Hd = "1d" + b.Hd;
                    }
                    if (!b.Hd.Contains("+") && !b.Hd.Contains("-"))
                    {
                        b.Hd = b.Hd + "+0";
                    }

                    b.BaseAtk = npc.BaseAtk ?? 0;

                    b.CharacterFlag = true;

                    b.Cmb = npc.Cmb ?? b.BaseAtk + GetAbilityMod(b.Str);

                    b.Cmd = npc.Cmd ?? 10 + b.BaseAtk + GetAbilityMod(b.Str) + GetAbilityMod(b.Dex);

                    b.CompanionFlag = npc.CompanionFlag ?? false;

                    if (npc.Cr.HasValue)
                    {
                        b.Cr = npc.Cr.Value;
                    }
                    else
                    {
                        int cr = -10;
                        int.TryParse(Regex.Match(npc.Hd, "[0-9]+").ToString(), out cr);
                        b.Cr = cr;
                    }

                    b.DontUseRacialHd = false;

                    b.Fortitude = npc.Fort ?? GetAbilityMod(b.Con);

                    b.Hp = npc.Hp ?? 0;

                    b.Init = npc.Init ?? GetAbilityMod(b.Dex);

                    b.IsTemplate = npc.IsTemplate ?? false;

                    b.Mr = npc.Mr ?? 0;

                    b.Mt = npc.Mt ?? 0;

                    b.Reflex = npc.Ref ?? GetAbilityMod(b.Dex);

                    int.TryParse(npc.Sr, out int sr);
                    b.Sr = sr;

                    b.UniqueMonster = npc.UniqueMonster ?? false;

                    b.Will = npc.Will ?? GetAbilityMod(b.Wis);

                    b.Xp = npc.Xp ?? 0;

                    context.SaveChanges(); // Make sure we have a BestiaryId for our new NPC

                    // Spawn
                    context.MonsterSpawn.Add(new MonsterSpawn()
                    {
                        BestiaryId = b.BestiaryId
                    });

                    // Feat
                    // Improved Initiative, Iron Will, Lightning Reflexes, Skill Focus (Perception)
                    if (!string.IsNullOrWhiteSpace(b.Feats))
                    {
                        foreach (Match m in Regex.Matches(b.Feats, REGEX_SPLIT))
                        {
                            string feat  = m.Groups[1].Value;
                            string notes = null;
                            if (feat.Contains("("))
                            {
                                notes = feat.Split('(')[1].TrimEnd(')');
                                feat  = feat.Split('(')[0].Trim();
                            }
                            if (feat.EndsWith('B'))
                            {
                                feat = feat.Substring(0, feat.Length - 1);
                            }
                            var f = new BestiaryFeat
                            {
                                BestiaryId = b.BestiaryId,
                                FeatId     = context.Feat.FirstOrDefault(x => feat.Equals(x.Name, StringComparison.InvariantCultureIgnoreCase))?.FeatId ?? 0,
                                Notes      = notes
                            };

                            context.BestiaryFeat.Add(f);
                        }
                    }

                    // Skill
                    if (!string.IsNullOrWhiteSpace(b.Skills))
                    {
                        foreach (Match m in Regex.Matches(b.Skills, REGEX_SPLIT))
                        {
                            string skill = m.Groups[1].Value;
                            string notes = null;
                            int    bonus = 0;

                            if (skill.Contains("("))
                            {
                                var idxA = skill.IndexOf('(') + 1;
                                var idxB = skill.LastIndexOf(')');
                                notes = skill.Substring(idxA, idxB - idxA);
                                var newName = skill.Substring(0, --idxA) + skill.Substring(++idxB, skill.Length - idxB); // -- and ++ to make sure parentheses are dropped
                                skill = newName.Trim();
                            }

                            if (skill.Contains("+"))
                            {
                                var skillsplit = skill.Split('+');
                                bonus = Convert.ToInt32(Regex.Match(skillsplit[1], "[0-9]+").Value);

                                skill = skill.Split('+')[0].Trim();
                            }
                            else if (skill.Contains("-"))
                            {
                                var skillsplit = skill.Split('-');
                                bonus = Convert.ToInt32(Regex.Match(skillsplit[1], "[0-9]+").Value) * -1;
                                skill = skillsplit[0].Trim();
                            }

                            if (!context.Skill.Select(x => x.Name.ToLower()).Contains(skill.ToLower()))
                            {
                                context.Skill.Add(new Skill()
                                {
                                    Name        = skill,
                                    Description = "UPDATE ME",
                                    TrainedOnly = false
                                });
                                context.SaveChanges();
                            }

                            var s = new BestiarySkill
                            {
                                BestiaryId = b.BestiaryId,
                                SkillId    = context.Skill.FirstOrDefault(x => skill.Equals(x.Name, StringComparison.InvariantCultureIgnoreCase))?.SkillId ?? 0,
                                Notes      = notes
                            };

                            context.BestiarySkill.Add(s);
                            context.SaveChanges();
                        }
                    }

                    context.SaveChanges();

                    if (i++ >= 5)
                    {
                        i = 0;
                        Console.WriteLine("Finished NPCID " + npc.Npcid.ToString());
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"[{z.Npcid}] - {ex.Message}");
                    if (ex.InnerException != null)
                    {
                        Console.WriteLine("InnerException: " + ex.InnerException.Message);
                    }
                }
            }
        }
Beispiel #19
0
        // Menu 3
        private static void PopulateTables()
        {
            var bList = PFDAL.GetContext(false).Bestiary.Select(x => x);

            foreach (var b in bList)
            {
                var context = PFDAL.GetContext(false);

                // Feat
                // Improved Initiative, Iron Will, Lightning Reflexes, Skill Focus (Perception)
                if (!string.IsNullOrWhiteSpace(b.Feats))
                {
                    foreach (Match m in Regex.Matches(b.Feats, REGEX_SPLIT))
                    {
                        string feat  = m.Groups[1].Value;
                        string notes = null;
                        if (feat.Contains("("))
                        {
                            notes = feat.Split('(')[1].TrimEnd(')');
                            feat  = feat.Split('(')[0].Trim();
                        }
                        if (feat.EndsWith('B'))
                        {
                            feat = feat.Substring(0, feat.Length - 1);
                        }
                        var f = new BestiaryFeat
                        {
                            BestiaryId = b.BestiaryId,
                            FeatId     = context.Feat.FirstOrDefault(x => feat.Equals(x.Name, StringComparison.InvariantCultureIgnoreCase))?.FeatId ?? 0,
                            Notes      = notes
                        };

                        context.BestiaryFeat.Add(f);
                    }
                }

                // Subtype - COMPLETE
                // (chaotic, evil, extraplanar)
                //if (!string.IsNullOrWhiteSpace(b.SubType))
                //{
                //  foreach (var item in b.SubType.Replace("(", "").Replace(")", "").Split(','))
                //  {
                //    if (!context.BestiaryType.Any(x => x.Name.Equals(item.Trim(), StringComparison.InvariantCultureIgnoreCase)))
                //    {
                //      context.BestiaryType.Add(new BestiaryType() { Name = item.Trim() });
                //      context.SaveChanges();
                //    }

                //    var bType = context.BestiaryType.First(x => x.Name.Equals(item.Trim(), StringComparison.InvariantCultureIgnoreCase));
                //    context.BestiarySubType.Add(new BestiarySubType() { BestiaryId = b.BestiaryId, BestiaryTypeId = bType.BestiaryTypeId });
                //    context.SaveChanges();
                //  }

                //  b.SubType = null;
                //}

                // Environment - ALMOST COMPLETE
                //if (!string.IsNullOrWhiteSpace(b.Environment))
                //{
                //  foreach (var environment in b.Environment.Split(','))
                //  {
                //    string envName = environment.Trim();
                //    string notes = null;
                //    if (envName.Contains("("))
                //    {
                //      notes = envName.Split('(')[1].TrimEnd(')');
                //      envName = envName.Split('(')[0].Trim();
                //    }

                //    if (!context.Environment.Select(x => x.Name.ToLower()).Contains(envName.ToLower()))
                //    {
                //      context.Environment.Add(new PFDAL.Models.Environment()
                //      {
                //        Name = envName,
                //        Notes = null,
                //        Temperature = string.Empty,
                //        TravelSpeed = 0
                //      });
                //      context.SaveChanges();
                //    }

                //    var e = new BestiaryEnvironment
                //    {
                //      BestiaryId = b.BestiaryId,
                //      EnvironmentId = context.Environment.FirstOrDefault(x => envName.Equals(x.Name, StringComparison.InvariantCultureIgnoreCase))?.EnvironmentId ?? 0,
                //      Notes = notes
                //    };

                //    context.BestiaryEnvironment.Add(e);
                //    context.SaveChanges();
                //  }
                //}

                // Skill - NEEDS WORK
                if (!string.IsNullOrWhiteSpace(b.Skills))
                {
                    foreach (Match m in Regex.Matches(b.Skills, REGEX_SPLIT))
                    {
                        string skill = m.Groups[1].Value;
                        string notes = null;
                        int    bonus = 0;

                        if (skill.Contains("("))
                        {
                            var idxA = skill.IndexOf('(') + 1;
                            var idxB = skill.LastIndexOf(')');
                            notes = skill.Substring(idxA, idxB - idxA);
                            var newName = skill.Substring(0, --idxA) + skill.Substring(++idxB, skill.Length - idxB); // -- and ++ to make sure parentheses are dropped
                            skill = newName.Trim();
                        }

                        if (skill.Contains("+"))
                        {
                            var skillsplit = skill.Split('+');
                            if (skillsplit[1].Contains(" "))
                            {
                                bonus = Convert.ToInt32(skillsplit[1].Split(' ')[0]);
                            }
                            else
                            {
                                bonus = Convert.ToInt32(skillsplit[1]);
                            }

                            skill = skill.Split('+')[0].Trim();
                        }
                        else if (skill.Contains("-"))
                        {
                            bonus = Convert.ToInt32(skill.Split('-')[1]) * -1;
                            skill = skill.Split('-')[0].Trim();
                        }

                        if (!context.Skill.Select(x => x.Name.ToLower()).Contains(skill.ToLower()))
                        {
                            context.Skill.Add(new Skill()
                            {
                                Name        = skill,
                                Description = "UPDATE ME",
                                TrainedOnly = false
                            });
                            context.SaveChanges();
                        }

                        var s = new BestiarySkill
                        {
                            BestiaryId = b.BestiaryId,
                            SkillId    = context.Skill.FirstOrDefault(x => skill.Equals(x.Name, StringComparison.InvariantCultureIgnoreCase))?.SkillId ?? 0,
                            Notes      = notes
                        };

                        context.BestiarySkill.Add(s);
                        context.SaveChanges();
                    }
                }

                // Language - COMPLETE
                //if (!string.IsNullOrWhiteSpace(b.Languages))
                //{
                //  foreach (var language in b.Languages.Split(new string[] { ",", ";" }, StringSplitOptions.RemoveEmptyEntries))
                //  {
                //    string langName = language.Trim();
                //    string notes = null;
                //    if (langName.Contains("("))
                //    {
                //      notes = langName.Split('(')[1].TrimEnd(')');
                //      langName = langName.Split('(')[0].Trim();
                //    }

                //    if (!context.Language.Select(x => x.Name.ToLower()).Contains(langName.ToLower()))
                //    {
                //      context.Language.Add(new Language()
                //      {
                //        Name = langName,
                //        Notes = null
                //      });
                //      context.SaveChanges();
                //    }

                //    var l = new BestiaryLanguage
                //    {
                //      BestiaryId = b.BestiaryId,
                //      LanguageId = context.Language.FirstOrDefault(x => langName.Equals(x.Name, StringComparison.InvariantCultureIgnoreCase))?.LanguageId ?? 0,
                //      Notes = notes
                //    };

                //    context.BestiaryLanguage.Add(l);
                //    context.SaveChanges();
                //  }
                //}
            }
        }