public async Task ReturnSkills(CommandContext ctx, string boat) { bn = new BoatNicknames(); string chibi = "chibi.png"; //string to append to make filename - if ship is a retrofit this is changed edited later boat = boatNickname(boat); //If the name passed was a nickname, turn it into the filename and store it string shipCalled = boat + ".json"; //create full file name for boat called string boatCap = formatName(boat); //format boat name into user friendly aesthetic if (File.Exists(@"wikia\Ships\" + shipCalled)) { #region JSONDESERIALISE //read json, then deserialize it var json = string.Empty; using (var fs = File.OpenRead(@"wikia\Ships\" + shipCalled)) using (var sr = new StreamReader(fs, new UTF8Encoding(false))) json = await sr.ReadToEndAsync().ConfigureAwait(false); var configShip = JsonConvert.DeserializeObject <ConfigShip>(json); //for nested json objects, parse specifically JObject jo = JObject.Parse(json); #endregion #region VALUEFORMATTING //if a ship does not have a retrofit, the retrofit hp stat will be blank so use this as a test case if (jo.SelectToken("stats.120retrofit.hp").ToString() != string.Empty) //does have retrofit { chibi = "kaichibi.png"; //adds kai onto the string to get the right chibi } string boatName = configShip.Name; string skill1 = (jo.SelectToken("skill.1", errorWhenNoMatch: false) != null) ? jo.SelectToken("skill.1.name").ToString() + "\n" + jo.SelectToken("skill.1.type").ToString() + "\n" + jo.SelectToken("skill.1.description").ToString() + "\n \n" : "Skill 1 not found \n \n"; string skill2 = (jo.SelectToken("skill.2", errorWhenNoMatch: false) != null) ? jo.SelectToken("skill.2.name").ToString() + "\n" + jo.SelectToken("skill.2.type").ToString() + "\n" + jo.SelectToken("skill.2.description").ToString() + "\n \n": "Skill 2 not found \n \n"; string skill3 = (jo.SelectToken("skill.3", errorWhenNoMatch: false) != null) ? jo.SelectToken("skill.3.name").ToString() + "\n" + jo.SelectToken("skill.3.type").ToString() + "\n" + jo.SelectToken("skill.3.description").ToString() + "\n \n" : "Skill 3 not found \n \n"; #endregion if (File.Exists(@"chibis\" + boatName + chibi)) //check if the file exists before trying to send it { await ctx.Channel.SendFileAsync(@"chibis\" + boatName + chibi).ConfigureAwait(false); } await ctx.Channel.SendMessageAsync(skill1 + skill2 + skill3).ConfigureAwait(false); } else { await ctx.Channel.SendMessageAsync(boatCap + "? Who is she, buli...? (Please check your spelling. Nickname not recognised? @piggyapocalypse with the boat and nickname. New boats may not be available)").ConfigureAwait(false); } }
public async Task shipGeneral(CommandContext ctx, string boat) { bn = new BoatNicknames(); string chibi = "chibi.png"; //string to append to make filename - if ship is a retrofit this is changed edited later boat = boatNickname(boat); //If the name passed was a nickname, turn it into the filename and store it string shipCalled = boat + ".json"; //create full file name for boat called string boatCap = formatName(boat); //format boat name into user friendly aesthetic if (File.Exists(@"wikia\Ships\" + shipCalled)) { #region JSONDESERIALISE //read json, then deserialize it var json = string.Empty; using (var fs = File.OpenRead(@"wikia\Ships\" + shipCalled)) using (var sr = new StreamReader(fs, new UTF8Encoding(false))) json = await sr.ReadToEndAsync().ConfigureAwait(false); var configShip = JsonConvert.DeserializeObject <ConfigShip>(json); //for nested json objects, parse specifically JObject jo = JObject.Parse(json); #endregion #region VALUEFORMATTING //if a ship does not have a retrofit, the retrofit hp stat will be blank so use this as a test case if (jo.SelectToken("stats.120retrofit.hp").ToString() != string.Empty) //does have retrofit { chibi = "kaichibi.png"; //adds kai onto the string to get the right chibi } string artist = jo.SelectToken("artist.pixiv").ToString(); artist = (artist == string.Empty) ? artist : "Not Found"; string boatName = configShip.Name; string Name = "Name: " + configShip.faction + " " + boatCap + "\n"; string boatRarity = "Rarity: " + configShip.Rarity + "\n"; string boatClass = "Class: " + configShip.ShipClass + "\n"; string boatType = "Type: " + configShip.type + "\n"; string boatGet = "Obtainable: " + configShip.AcquisitionMethod + "\n"; string boatVA = "Voice Actress: " + configShip.VoiceActress + "\n"; artist = "Artist Pixiv: " + artist; #endregion if (File.Exists(@"chibis\" + boatName + chibi)) //check if the file exists before trying to send it { await ctx.Channel.SendFileAsync(@"chibis\" + boatName + chibi).ConfigureAwait(false); } await ctx.Channel.SendMessageAsync(Name + boatRarity + boatClass + boatType + boatGet + boatVA + artist).ConfigureAwait(false); } else { await ctx.Channel.SendMessageAsync(boatCap + "? Who is she, buli...? (Please check your spelling. Nickname not recognised? @piggyapocalypse with the boat and nickname. New boats may not be available)").ConfigureAwait(false); } }
public async Task shipStats(CommandContext ctx, string boat) { bn = new BoatNicknames(); string hp, firepower, torpedo, antiAir, aviation, reload, hit, evasion, speed, luck, asw, oxygen, ammo, cost, armor; string normChibi = "chibi.png"; boat = boatNickname(boat); string shipCalled = boat + ".json"; //file name for boat called string boatCap = formatName(boat); if (File.Exists(@"wikia\Ships\" + shipCalled)) { #region JSONDESERALISE //read json, then deserialize it var json = string.Empty; using (var fs = File.OpenRead(@"wikia\Ships\" + shipCalled)) using (var sr = new StreamReader(fs, new UTF8Encoding(false))) json = await sr.ReadToEndAsync().ConfigureAwait(false); //configureAwait false - the thread that starts this task does not have to be the one to continue it - faster var configShip = JsonConvert.DeserializeObject <ConfigShip>(json); JObject jo = JObject.Parse(json); #endregion string boatName = configShip.Name; string Name = "Name: " + configShip.faction + " " + boatCap + "\n"; if (jo.SelectToken("stats.120retrofit.hp").ToString() == string.Empty) //doesn't have retrofit { hp = jo.SelectToken("stats.120.hp").ToString(); firepower = jo.SelectToken("stats.120.firepower").ToString(); torpedo = jo.SelectToken("stats.120.torpedo").ToString(); antiAir = jo.SelectToken("stats.120.antiAir").ToString(); aviation = jo.SelectToken("stats.120.aviation").ToString(); reload = jo.SelectToken("stats.120.reload").ToString(); hit = jo.SelectToken("stats.120.hit").ToString(); evasion = jo.SelectToken("stats.120.evasion").ToString(); speed = jo.SelectToken("stats.120.speed").ToString(); luck = jo.SelectToken("stats.120.luck").ToString(); asw = jo.SelectToken("stats.120.asw").ToString(); oxygen = jo.SelectToken("stats.120.oxygen").ToString(); ammo = jo.SelectToken("stats.120.ammo").ToString(); cost = jo.SelectToken("stats.120.cost").ToString(); armor = jo.SelectToken("stats.120.armor").ToString(); } else { hp = jo.SelectToken("stats.120.hp").ToString(); firepower = jo.SelectToken("stats.120retrofit.firepower").ToString(); torpedo = jo.SelectToken("stats.120retrofit.torpedo").ToString(); antiAir = jo.SelectToken("stats.120retrofit.antiAir").ToString(); aviation = jo.SelectToken("stats.120retrofit.aviation").ToString(); reload = jo.SelectToken("stats.120retrofit.reload").ToString(); hit = jo.SelectToken("stats.120retrofit.hit").ToString(); evasion = jo.SelectToken("stats.120retrofit.evasion").ToString(); speed = jo.SelectToken("stats.120retrofit.speed").ToString(); luck = jo.SelectToken("stats.120retrofit.luck").ToString(); asw = jo.SelectToken("stats.120retrofit.asw").ToString(); oxygen = jo.SelectToken("stats.120retrofit.oxygen").ToString(); ammo = jo.SelectToken("stats.120retrofit.ammo").ToString(); cost = jo.SelectToken("stats.120retrofit.cost").ToString(); armor = jo.SelectToken("stats.120retrofit.armor").ToString(); normChibi = "kaichibi.png"; } hp = "Health: " + hp + "\n"; firepower = "Firepower: " + firepower + "\n"; torpedo = "Torpedo: " + torpedo + "\n"; antiAir = "Anti Air: " + antiAir + "\n"; aviation = "Aviation: " + aviation + "\n"; reload = "Reload: " + reload + "\n"; hit = "Hit: " + hit + "\n"; evasion = "Evasion: " + evasion + "\n"; speed = "Speed: " + speed + "\n"; luck = "Luck: " + luck + "\n"; asw = "ASW: " + asw + "\n"; oxygen = "Oxygen: " + oxygen + "\n"; ammo = "Ammo: " + ammo + "\n"; cost = "Cost: " + cost + "\n"; armor = "Armor: " + armor; if (File.Exists(@"chibis\" + boatName + normChibi)) { await ctx.Channel.SendFileAsync(@"chibis\" + boatName + normChibi).ConfigureAwait(false); } ; await ctx.Channel.SendMessageAsync("- \n" + Name + hp + firepower + torpedo + antiAir + aviation + reload + evasion + speed + luck + asw + oxygen + ammo + cost + armor).ConfigureAwait(false); } else { await ctx.Channel.SendMessageAsync(boatCap + "? Who is she, buli...? (Please check your spelling. Nickname not recognised? @piggyapocalypse with the boat and nickname. New boats may not be available)").ConfigureAwait(false); } }