\CayciV2Bot\CayciV2Bot\Controllers\AlbionController.cs
Return Back
using CayciV2Bot.Core;
using CayciV2Bot.Models;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Web;
using System.Drawing;
using System.Drawing.Imaging;
using System.Net;
using System.IO;
namespace CayciV2Bot.Controllers
{
public class AlbionController : Controller
{
const int startX = 1;
const int startY = 1;
const int itemSize = 72;
const int spaceBetween = 18;
[HttpGet]
public IActionResult Index()
{
return View();
}
public async Task<Image> GetImageStreamFromPicUrl(string itemId, string quality)
{
WebResponse wrFileResponse;
try
{
var baseURL = "https://render.albiononline.com/v1/item/" + itemId + ".png?quality=" + quality;
wrFileResponse = await WebRequest.Create(baseURL).GetResponseAsync();
}
catch
{
var baseURL = "https://albiononline2d.ams3.cdn.digitaloceanspaces.com/thumbnails/orig/" + itemId;
wrFileResponse = await WebRequest.Create(baseURL).GetResponseAsync();
}
using var objWebStream = wrFileResponse.GetResponseStream();
var ms = new MemoryStream();
await objWebStream.CopyToAsync(ms, 8192);
return Image.FromStream(ms);
}
public async Task<MemoryStream> PlayerEquipmentBuilder(AlbionEquipment playerEquipment)
{
Image itemImage;
using var playerEquipmentImage = new Bitmap(Environment.CurrentDirectory + "/resources/albion/base.png");
using var g = Graphics.FromImage(playerEquipmentImage);
var row = 0;
if (playerEquipment.Bag != null)
{
itemImage = await ItemBuilder(playerEquipment.Bag);
g.DrawImage(
itemImage,
(spaceBetween * 1) + (itemSize * 0) + startX,
spaceBetween + (row * itemSize) + (spaceBetween / 2 * (row + 1)) + startY);
}
if (playerEquipment.Head != null)
{
itemImage = await ItemBuilder(playerEquipment.Head);
g.DrawImage(
itemImage,
(spaceBetween * 2) + (itemSize * 1) + startX,
(spaceBetween / 2) + (row * itemSize) + (spaceBetween / 2 * (row + 1)) + startY);
}
if (playerEquipment.Cape != null)
{
itemImage = await ItemBuilder(playerEquipment.Cape);
g.DrawImage(
itemImage,
(spaceBetween * 3) + (itemSize * 2) + startX,
spaceBetween + (row * itemSize) + (spaceBetween / 2 * (row + 1)) + startY);
}
row = 1;
if (playerEquipment.MainHand != null)
{
itemImage = await ItemBuilder(playerEquipment.MainHand);
g.DrawImage(
itemImage,
(spaceBetween * 1) + (itemSize * 0) + startX,
spaceBetween + (row * itemSize) + (spaceBetween / 2 * (row + 1)) + startY);
}
if (playerEquipment.Armor != null)
{
itemImage = await ItemBuilder(playerEquipment.Armor);
g.DrawImage(
itemImage,
(spaceBetween * 2) + (itemSize * 1) + startX,
(spaceBetween / 2) + (row * itemSize) + (spaceBetween / 2 * (row + 1)) + startY);
}
if (playerEquipment.OffHand != null)
{
itemImage = await ItemBuilder(playerEquipment.OffHand);
g.DrawImage(
itemImage,
(spaceBetween * 3) + (itemSize * 2) + startX,
spaceBetween + (row * itemSize) + (spaceBetween / 2 * (row + 1)) + startY);
}
row = 2;
if (playerEquipment.Potion != null)
{
itemImage = await ItemBuilder(playerEquipment.Potion);
g.DrawImage(
itemImage,
(spaceBetween * 1) + (itemSize * 0) + startX,
spaceBetween + (row * itemSize) + (spaceBetween / 2 * (row + 1)) + startY);
}
if (playerEquipment.Shoes != null)
{
itemImage = await ItemBuilder(playerEquipment.Shoes);
g.DrawImage(
itemImage,
(spaceBetween * 2) + (itemSize * 1) + startX,
(spaceBetween / 2) + (row * itemSize) + (spaceBetween / 2 * (row + 1)) + startY);
}
if (playerEquipment.Food != null)
{
itemImage = await ItemBuilder(playerEquipment.Food);
g.DrawImage(
itemImage,
(spaceBetween * 3) + (itemSize * 2) + startX,
spaceBetween + (row * itemSize) + (spaceBetween / 2 * (row + 1)) + startY);
}
row = 3;
if (playerEquipment.Mount != null)
{
itemImage = await ItemBuilder(playerEquipment.Mount);
g.DrawImage(
itemImage,
(spaceBetween * 2) + (itemSize * 1) + startX,
(spaceBetween / 2) + (row * itemSize) + (spaceBetween / 2 * (row + 1)) + startY);
}
var memoryStream = new MemoryStream();
playerEquipmentImage.Save(memoryStream, ImageFormat.Png);
g.Dispose();
return memoryStream;
}
public async Task<Image> ItemBuilder(AlbionItemProperties albionItem)
{
var albionItemImage = new Bitmap(itemSize, itemSize);
using var g = Graphics.FromImage(albionItemImage);
var itemImage = await GetImageStreamFromPicUrl(albionItem.Type, albionItem.Quality);
g.DrawImage(itemImage, 0, 0, itemSize, itemSize);
g.DrawString(albionItem.Count,
new Font(FontFamily.GenericMonospace, 12, FontStyle.Bold, GraphicsUnit.Pixel), Brushes.White,
new PointF(
(float)((itemSize * 0.67) + startX),
(float)((itemSize * 0.62) + startY)));
g.Save();
g.Dispose();
return albionItemImage;
}
public async Task<MemoryStream> PlayerInventoryBuilder(List<AlbionItemProperties> albionEquipmentList)
{
var memoryStream = new MemoryStream();
const int columnCount = 10;
var albionEquipmentListCount = albionEquipmentList.Count(c => c != null);
if (albionEquipmentListCount <= 0)
{
var emptyInventoryImage = new Bitmap(columnCount * itemSize, 1);
using var gr = Graphics.FromImage(emptyInventoryImage);
gr.Clear(ColorTranslator.FromHtml("#E5C4A3"));
emptyInventoryImage.Save(memoryStream, ImageFormat.Png);
gr.Dispose();
return memoryStream;
}
var x = albionEquipmentListCount / (float)columnCount;
var rowCount = (int)Math.Ceiling(x);
var row = 0;
var itemCount = 0;
var playerInventoryImage = new Bitmap(columnCount * itemSize, rowCount * itemSize);
using var g = Graphics.FromImage(playerInventoryImage);
g.Clear(ColorTranslator.FromHtml("#E5C4A3"));
foreach (var albionItem in albionEquipmentList)
{
if (albionItem != null)
{
var albionItemImage = await ItemBuilder(albionItem);
g.DrawImage(albionItemImage, (itemCount * albionItemImage.Width) + startX, (row * albionItemImage.Height) + startY);
itemCount++;
if (itemCount >= columnCount)
{
itemCount = 0;
row++;
}
}
}
playerInventoryImage.Save(memoryStream, ImageFormat.Png);
g.Dispose();
return memoryStream;
}
public async Task<MemoryStream> KillerVictimInventoryBuilder(JToken eventObject)
{
var memoryStream = new MemoryStream();
var killerPlayer = eventObject["Killer"];
var killerPlayerEquipment = killerPlayer["Equipment"].ToObject<AlbionEquipment>();
var killerEquipmentImage = Image.FromStream(await PlayerEquipmentBuilder(killerPlayerEquipment));
var killerNameGuild = new Bitmap(killerEquipmentImage.Width, itemSize / 2);
var sf = new StringFormat
{
LineAlignment = StringAlignment.Center,
Alignment = StringAlignment.Center
};
using (Graphics g = Graphics.FromImage(killerNameGuild))
{
g.Clear(ColorTranslator.FromHtml("#E5C4A3"));
var allyGuildPlyrStr = killerPlayer["AllianceName"].ToString() != "" ? $"[{killerPlayer["AllianceName"]}] {killerPlayer["GuildName"]}" : killerPlayer["GuildName"].ToString();
allyGuildPlyrStr = killerPlayer["Name"] + "\r\n" + allyGuildPlyrStr;
g.DrawString(allyGuildPlyrStr,
new Font(FontFamily.GenericMonospace, 18, FontStyle.Bold, GraphicsUnit.Pixel), Brushes.SteelBlue,
new PointF(killerEquipmentImage.Width / 2, killerNameGuild.Height / 2), sf);
}
var killerImage = new Bitmap(killerNameGuild.Width, killerNameGuild.Height + killerEquipmentImage.Height);
using (Graphics g = Graphics.FromImage(killerImage))
{
g.DrawImage(killerEquipmentImage, 0, killerNameGuild.Height);
g.Save();
g.DrawImage(killerNameGuild, 0, spaceBetween / 2);
var ipStr = "IP:" + Convert.ToInt32((float)killerPlayer["AverageItemPower"]).ToString();
g.DrawString(ipStr,
new Font(FontFamily.GenericMonospace, 16, FontStyle.Bold, GraphicsUnit.Pixel), Brushes.Brown,
new PointF((killerEquipmentImage.Width / 2) + (72 / 2) + (18 / 2), (4 * 72) + (4 * (18 / 2))));
}
var victimPlayer = eventObject["Victim"];
var victimPlayerEquipment = victimPlayer["Equipment"].ToObject<AlbionEquipment>();
var victimEquipmentImage = Image.FromStream(await PlayerEquipmentBuilder(victimPlayerEquipment));
var victimNameGuild = new Bitmap(victimEquipmentImage.Width, itemSize / 2);
using (Graphics g = Graphics.FromImage(victimNameGuild))
{
g.Clear(ColorTranslator.FromHtml("#E5C4A3"));
var allyGuildPlyrStr = victimPlayer["AllianceName"].ToString() != "" ? $"[{victimPlayer["AllianceName"]}] {victimPlayer["GuildName"]}" : victimPlayer["GuildName"].ToString();
allyGuildPlyrStr = victimPlayer["Name"] + "\r\n" + allyGuildPlyrStr;
g.DrawString(allyGuildPlyrStr,
new Font(FontFamily.GenericMonospace, 18, FontStyle.Bold, GraphicsUnit.Pixel), Brushes.Red,
new PointF(victimEquipmentImage.Width / 2, victimNameGuild.Height / 2), sf);
}
var victimImage = new Bitmap(victimNameGuild.Width, victimNameGuild.Height + victimEquipmentImage.Height);
using (Graphics g = Graphics.FromImage(victimImage))
{
g.DrawImage(victimEquipmentImage, 0, victimNameGuild.Height);
g.Save();
g.DrawImage(victimNameGuild, 0, spaceBetween / 2);
var ipStr = "IP:" + Convert.ToInt32((float)victimPlayer["AverageItemPower"]).ToString();
g.DrawString(ipStr,
new Font(FontFamily.GenericMonospace, 16, FontStyle.Bold, GraphicsUnit.Pixel), Brushes.Brown,
new PointF((victimEquipmentImage.Width / 2) + (72 / 2) + (18 / 2), (4 * 72) + (4 * (18 / 2))));
}
var divider = new Bitmap((3 * spaceBetween) + (2 * itemSize), killerImage.Height);
var killDateImage = new Bitmap(new Bitmap(Environment.CurrentDirectory + "/resources/albion/body/kill_date.png"), new Size(itemSize, itemSize));
var killedImage = new Bitmap(Environment.CurrentDirectory + "/resources/albion/body/killed.png");
var killFameImage = new Bitmap(new Bitmap(Environment.CurrentDirectory + "/resources/albion/body/kill_fame.png"), new Size(itemSize / 3, itemSize / 3));
var killFameStr = eventObject["TotalVictimKillFame"].ToString();
var killDate = (DateTime)eventObject["TimeStamp"];
var killDateStr = killDate.ToShortDateString() + "\r\n" + killDate.ToLongTimeString();
sf.LineAlignment = StringAlignment.Near;
using (Graphics g = Graphics.FromImage(divider))
{
g.Clear(ColorTranslator.FromHtml("#E5C4A3"));
g.DrawImage(killDateImage, (divider.Width - killDateImage.Width) / 2, spaceBetween);
g.DrawImage(killedImage, (divider.Width - killedImage.Width) / 2, spaceBetween + (1 * itemSize) + (spaceBetween / 2 * 3));
g.DrawImage(killFameImage, (divider.Width - killFameImage.Width) / 2, spaceBetween + (2 * itemSize) + (spaceBetween / 2 * 3));
g.DrawString(killFameStr,
new Font(FontFamily.GenericMonospace, 16, FontStyle.Bold, GraphicsUnit.Pixel), Brushes.Brown,
new PointF(divider.Width / 2, (spaceBetween * 3) + (2 * itemSize) + (spaceBetween / 2 * 3)), sf);
g.DrawString(killDateStr,
new Font(FontFamily.GenericMonospace, 16, FontStyle.Bold, GraphicsUnit.Pixel), Brushes.Brown,
new PointF(divider.Width / 2, (spaceBetween * 3) + (3 * itemSize) + (spaceBetween / 2 * 3)), sf);
}
var killerVictimImage = new Bitmap(killerEquipmentImage.Width + divider.Width + victimEquipmentImage.Width, killerImage.Height);
using (Graphics g = Graphics.FromImage(killerVictimImage))
{
g.Clear(ColorTranslator.FromHtml("#E5C4A3"));
g.DrawImage(killerImage, 0, 0);
g.DrawImage(divider, killerImage.Width, 0);
g.DrawImage(victimImage, killerImage.Width + divider.Width, 0);
}
var victimInventoryList = JsonConvert.DeserializeObject<List<AlbionItemProperties>>(victimPlayer["Inventory"].ToString());
var victimInventoryImage = Image.FromStream(await PlayerInventoryBuilder(victimInventoryList));
var killerVictimInventoryImage = new Bitmap(killerVictimImage.Width, killerVictimImage.Height + (spaceBetween * 2) + victimInventoryImage.Height);
using (Graphics g = Graphics.FromImage(killerVictimInventoryImage))
{
g.Clear(ColorTranslator.FromHtml("#E5C4A3"));
g.DrawImage(killerVictimImage, 0, 0);
g.DrawString("Victim Inventory: ",
new Font(FontFamily.GenericMonospace, 16, FontStyle.Bold, GraphicsUnit.Pixel), Brushes.Brown,
new PointF(spaceBetween, killerVictimImage.Height + (spaceBetween / 2)));
g.DrawImage(victimInventoryImage, 0, killerVictimImage.Height + (spaceBetween * 2));
}
killerVictimInventoryImage.Save(memoryStream, ImageFormat.Png);
return memoryStream;
}
[HttpGet]
public async Task<string> PlayerCheck(string playerName, string checkType = "kills")
{
var player = new JObject();
var playerEventList = new JArray();
using (var httpClient = new HttpClient())
{
var uriString = "https://gameinfo.albiononline.com/api/gameinfo/search";
var uriBuilder = new UriBuilder(uriString);
var query = HttpUtility.ParseQueryString(uriBuilder.Query);
query["q"] = playerName;
uriBuilder.Query = query.ToString();
uriString = uriBuilder.ToString();
httpClient.DefaultRequestHeaders.Accept.Clear();
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
httpClient.DefaultRequestHeaders.Add("User-Agent", "CRYALP.com");
var httpResponse = await httpClient.GetAsync(uriString);
httpResponse.EnsureSuccessStatusCode();
var httpResponseContent = await httpResponse.Content.ReadAsStringAsync();
var jsonObject = JObject.Parse(httpResponseContent);
player = jsonObject["players"].FirstOrDefault()?.ToObject<JObject>();
}
using (var httpClient = new HttpClient())
{
var uriString = "https://gameinfo.albiononline.com/api/gameinfo/players/" + player["Id"] + "/" + checkType;
var uriBuilder = new UriBuilder(uriString);
var query = HttpUtility.ParseQueryString(uriBuilder.Query);
uriBuilder.Query = query.ToString();
uriString = uriBuilder.ToString();
httpClient.DefaultRequestHeaders.Accept.Clear();
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
httpClient.DefaultRequestHeaders.Add("User-Agent", "CRYALP.com");
var httpResponse = await httpClient.GetAsync(uriString);
httpResponse.EnsureSuccessStatusCode();
var httpResponseContent = await httpResponse.Content.ReadAsStringAsync();
playerEventList = JArray.Parse(httpResponseContent);
}
return playerEventList.ToString();
}
[HttpGet]
public async Task<string> PlayerSearch(string playerName)
{
using var httpClient = new HttpClient();
var uriString = "https://gameinfo.albiononline.com/api/gameinfo/search";
var uriBuilder = new UriBuilder(uriString);
var query = HttpUtility.ParseQueryString(uriBuilder.Query);
query["q"] = playerName;
uriBuilder.Query = query.ToString();
uriString = uriBuilder.ToString();
httpClient.DefaultRequestHeaders.Accept.Clear();
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
httpClient.DefaultRequestHeaders.Add("User-Agent", "CRYALP.com");
var httpResponse = await httpClient.GetAsync(uriString);
httpResponse.EnsureSuccessStatusCode();
var httpResponseContent = await httpResponse.Content.ReadAsStringAsync();
var jsonObject = JObject.Parse(httpResponseContent);
return jsonObject["players"].FirstOrDefault()?.ToObject<JObject>()["Id"].ToString();
}
[HttpGet]
public async Task<string> SearchMarket(string itemName)
{
var itemId = "";
var enchantment = "";
using (var httpClient = new HttpClient())
{
var uriString = "https://raw.githubusercontent.com/broderickhyman/ao-bin-dumps/master/formatted/items.json";
var uriBuilder = new UriBuilder(uriString);
var query = HttpUtility.ParseQueryString(uriBuilder.Query);
uriBuilder.Query = query.ToString();
uriString = uriBuilder.ToString();
httpClient.DefaultRequestHeaders.Accept.Clear();
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
httpClient.DefaultRequestHeaders.Add("User-Agent", "CRYALP.com");
var httpResponse = await httpClient.GetAsync(uriString);
httpResponse.EnsureSuccessStatusCode();
var httpResponseContent = await httpResponse.Content.ReadAsStringAsync();
var jsonObjectArray = JArray.Parse(httpResponseContent);
var _functionsModule = new FunctionsModule();
if (itemName.Contains(" ench "))
{
var splittedItemName = itemName.Split(" ench ");
itemName = _functionsModule.RemoveSpecialCharacters(splittedItemName[0]).ToLower().Replace(" ", ".*");
enchantment = splittedItemName[1];
}
else
{
itemName = _functionsModule.RemoveSpecialCharacters(itemName).ToLower().Replace(" ", ".*");
}
foreach (var jobject in jsonObjectArray.Cast<JObject>())
{
if (jobject.GetValue("LocalizedNames").HasValues)
{
var localizedName = jobject.GetValue("LocalizedNames").ToObject<JObject>().GetValue("EN-US").ToString();
localizedName = _functionsModule.RemoveSpecialCharacters(localizedName).ToLower();
if (Regex.IsMatch(localizedName, "(?i)" + itemName))
{
itemId = jobject.GetValue("UniqueName").ToString();
break;
}
}
}
}
using (var httpClient = new HttpClient())
{
if (enchantment != "")
{
itemId = itemId + "@" + enchantment;
}
var uriString = "https://www.albion-online-data.com/api/v2/stats/prices/" + itemId;
var uriBuilder = new UriBuilder(uriString);
var query = HttpUtility.ParseQueryString(uriBuilder.Query);
uriBuilder.Query = query.ToString();
uriString = uriBuilder.ToString();
httpClient.DefaultRequestHeaders.Accept.Clear();
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
httpClient.DefaultRequestHeaders.Add("User-Agent", "CRYALP.com");
var httpResponse = await httpClient.GetAsync(uriString);
httpResponse.EnsureSuccessStatusCode();
var httpResponseContent = await httpResponse.Content.ReadAsStringAsync();
var albionItemList = new List<AlbionItem>();
var jsonObjectArray = JArray.Parse(httpResponseContent);
foreach (var jobject in jsonObjectArray.Cast<JObject>())
{
var qualities = new Dictionary<int, string>() {
{1, "Normal"},
{2, "Good"},
{3, "Outstanding"},
{4, "Excellent"},
{5, "Masterpiece"},
};
var sellPriceMin = (int)jobject.GetValue("sell_price_min");
if (sellPriceMin > 0)
{
var albionItem = new AlbionItem
{
ItemId = jobject.GetValue("item_id").ToString(),
PhotoURL = "https://albiononline2d.ams3.cdn.digitaloceanspaces.com/thumbnails/orig/" + itemId,
City = jobject.GetValue("city").ToString(),
QualityId = (int)jobject.GetValue("quality"),
Quality = qualities[(int)jobject.GetValue("quality")],
SellPriceMin = sellPriceMin,
SellPriceMinDate = (DateTime)jobject.GetValue("sell_price_min_date"),
SellPriceMax = (int)jobject.GetValue("sell_price_max"),
SellPriceMaxDate = (DateTime)jobject.GetValue("sell_price_max_date"),
BuyPriceMin = (int)jobject.GetValue("buy_price_min"),
BuyPriceMinDate = (DateTime)jobject.GetValue("buy_price_min_date"),
BuyPriceMax = (int)jobject.GetValue("buy_price_max"),
BuyPriceMaxDate = (DateTime)jobject.GetValue("buy_price_max_date")
};
albionItemList.Add(albionItem);
}
}
var albionItemLinqList = albionItemList.OrderBy(ail => ail.City).ThenBy(ail => ail.QualityId);
return JsonConvert.SerializeObject(albionItemLinqList);
}
}
[HttpGet]
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error()
{
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
}
}
}
using CayciV2Bot.Models;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Web;
using System.Drawing;
using System.Drawing.Imaging;
using System.Net;
using System.IO;
namespace CayciV2Bot.Controllers
{
public class AlbionController : Controller
{
const int startX = 1;
const int startY = 1;
const int itemSize = 72;
const int spaceBetween = 18;
[HttpGet]
public IActionResult Index()
{
return View();
}
public async Task<Image> GetImageStreamFromPicUrl(string itemId, string quality)
{
WebResponse wrFileResponse;
try
{
var baseURL = "https://render.albiononline.com/v1/item/" + itemId + ".png?quality=" + quality;
wrFileResponse = await WebRequest.Create(baseURL).GetResponseAsync();
}
catch
{
var baseURL = "https://albiononline2d.ams3.cdn.digitaloceanspaces.com/thumbnails/orig/" + itemId;
wrFileResponse = await WebRequest.Create(baseURL).GetResponseAsync();
}
using var objWebStream = wrFileResponse.GetResponseStream();
var ms = new MemoryStream();
await objWebStream.CopyToAsync(ms, 8192);
return Image.FromStream(ms);
}
public async Task<MemoryStream> PlayerEquipmentBuilder(AlbionEquipment playerEquipment)
{
Image itemImage;
using var playerEquipmentImage = new Bitmap(Environment.CurrentDirectory + "/resources/albion/base.png");
using var g = Graphics.FromImage(playerEquipmentImage);
var row = 0;
if (playerEquipment.Bag != null)
{
itemImage = await ItemBuilder(playerEquipment.Bag);
g.DrawImage(
itemImage,
(spaceBetween * 1) + (itemSize * 0) + startX,
spaceBetween + (row * itemSize) + (spaceBetween / 2 * (row + 1)) + startY);
}
if (playerEquipment.Head != null)
{
itemImage = await ItemBuilder(playerEquipment.Head);
g.DrawImage(
itemImage,
(spaceBetween * 2) + (itemSize * 1) + startX,
(spaceBetween / 2) + (row * itemSize) + (spaceBetween / 2 * (row + 1)) + startY);
}
if (playerEquipment.Cape != null)
{
itemImage = await ItemBuilder(playerEquipment.Cape);
g.DrawImage(
itemImage,
(spaceBetween * 3) + (itemSize * 2) + startX,
spaceBetween + (row * itemSize) + (spaceBetween / 2 * (row + 1)) + startY);
}
row = 1;
if (playerEquipment.MainHand != null)
{
itemImage = await ItemBuilder(playerEquipment.MainHand);
g.DrawImage(
itemImage,
(spaceBetween * 1) + (itemSize * 0) + startX,
spaceBetween + (row * itemSize) + (spaceBetween / 2 * (row + 1)) + startY);
}
if (playerEquipment.Armor != null)
{
itemImage = await ItemBuilder(playerEquipment.Armor);
g.DrawImage(
itemImage,
(spaceBetween * 2) + (itemSize * 1) + startX,
(spaceBetween / 2) + (row * itemSize) + (spaceBetween / 2 * (row + 1)) + startY);
}
if (playerEquipment.OffHand != null)
{
itemImage = await ItemBuilder(playerEquipment.OffHand);
g.DrawImage(
itemImage,
(spaceBetween * 3) + (itemSize * 2) + startX,
spaceBetween + (row * itemSize) + (spaceBetween / 2 * (row + 1)) + startY);
}
row = 2;
if (playerEquipment.Potion != null)
{
itemImage = await ItemBuilder(playerEquipment.Potion);
g.DrawImage(
itemImage,
(spaceBetween * 1) + (itemSize * 0) + startX,
spaceBetween + (row * itemSize) + (spaceBetween / 2 * (row + 1)) + startY);
}
if (playerEquipment.Shoes != null)
{
itemImage = await ItemBuilder(playerEquipment.Shoes);
g.DrawImage(
itemImage,
(spaceBetween * 2) + (itemSize * 1) + startX,
(spaceBetween / 2) + (row * itemSize) + (spaceBetween / 2 * (row + 1)) + startY);
}
if (playerEquipment.Food != null)
{
itemImage = await ItemBuilder(playerEquipment.Food);
g.DrawImage(
itemImage,
(spaceBetween * 3) + (itemSize * 2) + startX,
spaceBetween + (row * itemSize) + (spaceBetween / 2 * (row + 1)) + startY);
}
row = 3;
if (playerEquipment.Mount != null)
{
itemImage = await ItemBuilder(playerEquipment.Mount);
g.DrawImage(
itemImage,
(spaceBetween * 2) + (itemSize * 1) + startX,
(spaceBetween / 2) + (row * itemSize) + (spaceBetween / 2 * (row + 1)) + startY);
}
var memoryStream = new MemoryStream();
playerEquipmentImage.Save(memoryStream, ImageFormat.Png);
g.Dispose();
return memoryStream;
}
public async Task<Image> ItemBuilder(AlbionItemProperties albionItem)
{
var albionItemImage = new Bitmap(itemSize, itemSize);
using var g = Graphics.FromImage(albionItemImage);
var itemImage = await GetImageStreamFromPicUrl(albionItem.Type, albionItem.Quality);
g.DrawImage(itemImage, 0, 0, itemSize, itemSize);
g.DrawString(albionItem.Count,
new Font(FontFamily.GenericMonospace, 12, FontStyle.Bold, GraphicsUnit.Pixel), Brushes.White,
new PointF(
(float)((itemSize * 0.67) + startX),
(float)((itemSize * 0.62) + startY)));
g.Save();
g.Dispose();
return albionItemImage;
}
public async Task<MemoryStream> PlayerInventoryBuilder(List<AlbionItemProperties> albionEquipmentList)
{
var memoryStream = new MemoryStream();
const int columnCount = 10;
var albionEquipmentListCount = albionEquipmentList.Count(c => c != null);
if (albionEquipmentListCount <= 0)
{
var emptyInventoryImage = new Bitmap(columnCount * itemSize, 1);
using var gr = Graphics.FromImage(emptyInventoryImage);
gr.Clear(ColorTranslator.FromHtml("#E5C4A3"));
emptyInventoryImage.Save(memoryStream, ImageFormat.Png);
gr.Dispose();
return memoryStream;
}
var x = albionEquipmentListCount / (float)columnCount;
var rowCount = (int)Math.Ceiling(x);
var row = 0;
var itemCount = 0;
var playerInventoryImage = new Bitmap(columnCount * itemSize, rowCount * itemSize);
using var g = Graphics.FromImage(playerInventoryImage);
g.Clear(ColorTranslator.FromHtml("#E5C4A3"));
foreach (var albionItem in albionEquipmentList)
{
if (albionItem != null)
{
var albionItemImage = await ItemBuilder(albionItem);
g.DrawImage(albionItemImage, (itemCount * albionItemImage.Width) + startX, (row * albionItemImage.Height) + startY);
itemCount++;
if (itemCount >= columnCount)
{
itemCount = 0;
row++;
}
}
}
playerInventoryImage.Save(memoryStream, ImageFormat.Png);
g.Dispose();
return memoryStream;
}
public async Task<MemoryStream> KillerVictimInventoryBuilder(JToken eventObject)
{
var memoryStream = new MemoryStream();
var killerPlayer = eventObject["Killer"];
var killerPlayerEquipment = killerPlayer["Equipment"].ToObject<AlbionEquipment>();
var killerEquipmentImage = Image.FromStream(await PlayerEquipmentBuilder(killerPlayerEquipment));
var killerNameGuild = new Bitmap(killerEquipmentImage.Width, itemSize / 2);
var sf = new StringFormat
{
LineAlignment = StringAlignment.Center,
Alignment = StringAlignment.Center
};
using (Graphics g = Graphics.FromImage(killerNameGuild))
{
g.Clear(ColorTranslator.FromHtml("#E5C4A3"));
var allyGuildPlyrStr = killerPlayer["AllianceName"].ToString() != "" ? $"[{killerPlayer["AllianceName"]}] {killerPlayer["GuildName"]}" : killerPlayer["GuildName"].ToString();
allyGuildPlyrStr = killerPlayer["Name"] + "\r\n" + allyGuildPlyrStr;
g.DrawString(allyGuildPlyrStr,
new Font(FontFamily.GenericMonospace, 18, FontStyle.Bold, GraphicsUnit.Pixel), Brushes.SteelBlue,
new PointF(killerEquipmentImage.Width / 2, killerNameGuild.Height / 2), sf);
}
var killerImage = new Bitmap(killerNameGuild.Width, killerNameGuild.Height + killerEquipmentImage.Height);
using (Graphics g = Graphics.FromImage(killerImage))
{
g.DrawImage(killerEquipmentImage, 0, killerNameGuild.Height);
g.Save();
g.DrawImage(killerNameGuild, 0, spaceBetween / 2);
var ipStr = "IP:" + Convert.ToInt32((float)killerPlayer["AverageItemPower"]).ToString();
g.DrawString(ipStr,
new Font(FontFamily.GenericMonospace, 16, FontStyle.Bold, GraphicsUnit.Pixel), Brushes.Brown,
new PointF((killerEquipmentImage.Width / 2) + (72 / 2) + (18 / 2), (4 * 72) + (4 * (18 / 2))));
}
var victimPlayer = eventObject["Victim"];
var victimPlayerEquipment = victimPlayer["Equipment"].ToObject<AlbionEquipment>();
var victimEquipmentImage = Image.FromStream(await PlayerEquipmentBuilder(victimPlayerEquipment));
var victimNameGuild = new Bitmap(victimEquipmentImage.Width, itemSize / 2);
using (Graphics g = Graphics.FromImage(victimNameGuild))
{
g.Clear(ColorTranslator.FromHtml("#E5C4A3"));
var allyGuildPlyrStr = victimPlayer["AllianceName"].ToString() != "" ? $"[{victimPlayer["AllianceName"]}] {victimPlayer["GuildName"]}" : victimPlayer["GuildName"].ToString();
allyGuildPlyrStr = victimPlayer["Name"] + "\r\n" + allyGuildPlyrStr;
g.DrawString(allyGuildPlyrStr,
new Font(FontFamily.GenericMonospace, 18, FontStyle.Bold, GraphicsUnit.Pixel), Brushes.Red,
new PointF(victimEquipmentImage.Width / 2, victimNameGuild.Height / 2), sf);
}
var victimImage = new Bitmap(victimNameGuild.Width, victimNameGuild.Height + victimEquipmentImage.Height);
using (Graphics g = Graphics.FromImage(victimImage))
{
g.DrawImage(victimEquipmentImage, 0, victimNameGuild.Height);
g.Save();
g.DrawImage(victimNameGuild, 0, spaceBetween / 2);
var ipStr = "IP:" + Convert.ToInt32((float)victimPlayer["AverageItemPower"]).ToString();
g.DrawString(ipStr,
new Font(FontFamily.GenericMonospace, 16, FontStyle.Bold, GraphicsUnit.Pixel), Brushes.Brown,
new PointF((victimEquipmentImage.Width / 2) + (72 / 2) + (18 / 2), (4 * 72) + (4 * (18 / 2))));
}
var divider = new Bitmap((3 * spaceBetween) + (2 * itemSize), killerImage.Height);
var killDateImage = new Bitmap(new Bitmap(Environment.CurrentDirectory + "/resources/albion/body/kill_date.png"), new Size(itemSize, itemSize));
var killedImage = new Bitmap(Environment.CurrentDirectory + "/resources/albion/body/killed.png");
var killFameImage = new Bitmap(new Bitmap(Environment.CurrentDirectory + "/resources/albion/body/kill_fame.png"), new Size(itemSize / 3, itemSize / 3));
var killFameStr = eventObject["TotalVictimKillFame"].ToString();
var killDate = (DateTime)eventObject["TimeStamp"];
var killDateStr = killDate.ToShortDateString() + "\r\n" + killDate.ToLongTimeString();
sf.LineAlignment = StringAlignment.Near;
using (Graphics g = Graphics.FromImage(divider))
{
g.Clear(ColorTranslator.FromHtml("#E5C4A3"));
g.DrawImage(killDateImage, (divider.Width - killDateImage.Width) / 2, spaceBetween);
g.DrawImage(killedImage, (divider.Width - killedImage.Width) / 2, spaceBetween + (1 * itemSize) + (spaceBetween / 2 * 3));
g.DrawImage(killFameImage, (divider.Width - killFameImage.Width) / 2, spaceBetween + (2 * itemSize) + (spaceBetween / 2 * 3));
g.DrawString(killFameStr,
new Font(FontFamily.GenericMonospace, 16, FontStyle.Bold, GraphicsUnit.Pixel), Brushes.Brown,
new PointF(divider.Width / 2, (spaceBetween * 3) + (2 * itemSize) + (spaceBetween / 2 * 3)), sf);
g.DrawString(killDateStr,
new Font(FontFamily.GenericMonospace, 16, FontStyle.Bold, GraphicsUnit.Pixel), Brushes.Brown,
new PointF(divider.Width / 2, (spaceBetween * 3) + (3 * itemSize) + (spaceBetween / 2 * 3)), sf);
}
var killerVictimImage = new Bitmap(killerEquipmentImage.Width + divider.Width + victimEquipmentImage.Width, killerImage.Height);
using (Graphics g = Graphics.FromImage(killerVictimImage))
{
g.Clear(ColorTranslator.FromHtml("#E5C4A3"));
g.DrawImage(killerImage, 0, 0);
g.DrawImage(divider, killerImage.Width, 0);
g.DrawImage(victimImage, killerImage.Width + divider.Width, 0);
}
var victimInventoryList = JsonConvert.DeserializeObject<List<AlbionItemProperties>>(victimPlayer["Inventory"].ToString());
var victimInventoryImage = Image.FromStream(await PlayerInventoryBuilder(victimInventoryList));
var killerVictimInventoryImage = new Bitmap(killerVictimImage.Width, killerVictimImage.Height + (spaceBetween * 2) + victimInventoryImage.Height);
using (Graphics g = Graphics.FromImage(killerVictimInventoryImage))
{
g.Clear(ColorTranslator.FromHtml("#E5C4A3"));
g.DrawImage(killerVictimImage, 0, 0);
g.DrawString("Victim Inventory: ",
new Font(FontFamily.GenericMonospace, 16, FontStyle.Bold, GraphicsUnit.Pixel), Brushes.Brown,
new PointF(spaceBetween, killerVictimImage.Height + (spaceBetween / 2)));
g.DrawImage(victimInventoryImage, 0, killerVictimImage.Height + (spaceBetween * 2));
}
killerVictimInventoryImage.Save(memoryStream, ImageFormat.Png);
return memoryStream;
}
[HttpGet]
public async Task<string> PlayerCheck(string playerName, string checkType = "kills")
{
var player = new JObject();
var playerEventList = new JArray();
using (var httpClient = new HttpClient())
{
var uriString = "https://gameinfo.albiononline.com/api/gameinfo/search";
var uriBuilder = new UriBuilder(uriString);
var query = HttpUtility.ParseQueryString(uriBuilder.Query);
query["q"] = playerName;
uriBuilder.Query = query.ToString();
uriString = uriBuilder.ToString();
httpClient.DefaultRequestHeaders.Accept.Clear();
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
httpClient.DefaultRequestHeaders.Add("User-Agent", "CRYALP.com");
var httpResponse = await httpClient.GetAsync(uriString);
httpResponse.EnsureSuccessStatusCode();
var httpResponseContent = await httpResponse.Content.ReadAsStringAsync();
var jsonObject = JObject.Parse(httpResponseContent);
player = jsonObject["players"].FirstOrDefault()?.ToObject<JObject>();
}
using (var httpClient = new HttpClient())
{
var uriString = "https://gameinfo.albiononline.com/api/gameinfo/players/" + player["Id"] + "/" + checkType;
var uriBuilder = new UriBuilder(uriString);
var query = HttpUtility.ParseQueryString(uriBuilder.Query);
uriBuilder.Query = query.ToString();
uriString = uriBuilder.ToString();
httpClient.DefaultRequestHeaders.Accept.Clear();
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
httpClient.DefaultRequestHeaders.Add("User-Agent", "CRYALP.com");
var httpResponse = await httpClient.GetAsync(uriString);
httpResponse.EnsureSuccessStatusCode();
var httpResponseContent = await httpResponse.Content.ReadAsStringAsync();
playerEventList = JArray.Parse(httpResponseContent);
}
return playerEventList.ToString();
}
[HttpGet]
public async Task<string> PlayerSearch(string playerName)
{
using var httpClient = new HttpClient();
var uriString = "https://gameinfo.albiononline.com/api/gameinfo/search";
var uriBuilder = new UriBuilder(uriString);
var query = HttpUtility.ParseQueryString(uriBuilder.Query);
query["q"] = playerName;
uriBuilder.Query = query.ToString();
uriString = uriBuilder.ToString();
httpClient.DefaultRequestHeaders.Accept.Clear();
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
httpClient.DefaultRequestHeaders.Add("User-Agent", "CRYALP.com");
var httpResponse = await httpClient.GetAsync(uriString);
httpResponse.EnsureSuccessStatusCode();
var httpResponseContent = await httpResponse.Content.ReadAsStringAsync();
var jsonObject = JObject.Parse(httpResponseContent);
return jsonObject["players"].FirstOrDefault()?.ToObject<JObject>()["Id"].ToString();
}
[HttpGet]
public async Task<string> SearchMarket(string itemName)
{
var itemId = "";
var enchantment = "";
using (var httpClient = new HttpClient())
{
var uriString = "https://raw.githubusercontent.com/broderickhyman/ao-bin-dumps/master/formatted/items.json";
var uriBuilder = new UriBuilder(uriString);
var query = HttpUtility.ParseQueryString(uriBuilder.Query);
uriBuilder.Query = query.ToString();
uriString = uriBuilder.ToString();
httpClient.DefaultRequestHeaders.Accept.Clear();
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
httpClient.DefaultRequestHeaders.Add("User-Agent", "CRYALP.com");
var httpResponse = await httpClient.GetAsync(uriString);
httpResponse.EnsureSuccessStatusCode();
var httpResponseContent = await httpResponse.Content.ReadAsStringAsync();
var jsonObjectArray = JArray.Parse(httpResponseContent);
var _functionsModule = new FunctionsModule();
if (itemName.Contains(" ench "))
{
var splittedItemName = itemName.Split(" ench ");
itemName = _functionsModule.RemoveSpecialCharacters(splittedItemName[0]).ToLower().Replace(" ", ".*");
enchantment = splittedItemName[1];
}
else
{
itemName = _functionsModule.RemoveSpecialCharacters(itemName).ToLower().Replace(" ", ".*");
}
foreach (var jobject in jsonObjectArray.Cast<JObject>())
{
if (jobject.GetValue("LocalizedNames").HasValues)
{
var localizedName = jobject.GetValue("LocalizedNames").ToObject<JObject>().GetValue("EN-US").ToString();
localizedName = _functionsModule.RemoveSpecialCharacters(localizedName).ToLower();
if (Regex.IsMatch(localizedName, "(?i)" + itemName))
{
itemId = jobject.GetValue("UniqueName").ToString();
break;
}
}
}
}
using (var httpClient = new HttpClient())
{
if (enchantment != "")
{
itemId = itemId + "@" + enchantment;
}
var uriString = "https://www.albion-online-data.com/api/v2/stats/prices/" + itemId;
var uriBuilder = new UriBuilder(uriString);
var query = HttpUtility.ParseQueryString(uriBuilder.Query);
uriBuilder.Query = query.ToString();
uriString = uriBuilder.ToString();
httpClient.DefaultRequestHeaders.Accept.Clear();
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
httpClient.DefaultRequestHeaders.Add("User-Agent", "CRYALP.com");
var httpResponse = await httpClient.GetAsync(uriString);
httpResponse.EnsureSuccessStatusCode();
var httpResponseContent = await httpResponse.Content.ReadAsStringAsync();
var albionItemList = new List<AlbionItem>();
var jsonObjectArray = JArray.Parse(httpResponseContent);
foreach (var jobject in jsonObjectArray.Cast<JObject>())
{
var qualities = new Dictionary<int, string>() {
{1, "Normal"},
{2, "Good"},
{3, "Outstanding"},
{4, "Excellent"},
{5, "Masterpiece"},
};
var sellPriceMin = (int)jobject.GetValue("sell_price_min");
if (sellPriceMin > 0)
{
var albionItem = new AlbionItem
{
ItemId = jobject.GetValue("item_id").ToString(),
PhotoURL = "https://albiononline2d.ams3.cdn.digitaloceanspaces.com/thumbnails/orig/" + itemId,
City = jobject.GetValue("city").ToString(),
QualityId = (int)jobject.GetValue("quality"),
Quality = qualities[(int)jobject.GetValue("quality")],
SellPriceMin = sellPriceMin,
SellPriceMinDate = (DateTime)jobject.GetValue("sell_price_min_date"),
SellPriceMax = (int)jobject.GetValue("sell_price_max"),
SellPriceMaxDate = (DateTime)jobject.GetValue("sell_price_max_date"),
BuyPriceMin = (int)jobject.GetValue("buy_price_min"),
BuyPriceMinDate = (DateTime)jobject.GetValue("buy_price_min_date"),
BuyPriceMax = (int)jobject.GetValue("buy_price_max"),
BuyPriceMaxDate = (DateTime)jobject.GetValue("buy_price_max_date")
};
albionItemList.Add(albionItem);
}
}
var albionItemLinqList = albionItemList.OrderBy(ail => ail.City).ThenBy(ail => ail.QualityId);
return JsonConvert.SerializeObject(albionItemLinqList);
}
}
[HttpGet]
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error()
{
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
}
}
}