mirror of
https://github.com/oshima-studios/OshimaGameModule.git
synced 2026-01-19 14:08:23 +00:00
添加非卖品,添加领取活动任务奖励逻辑
This commit is contained in:
parent
ddef4792b8
commit
58128cf128
@ -31,6 +31,7 @@ namespace Oshima.FunGame.OshimaModules.Models
|
||||
public static List<Item> DrawCardItems { get; } = [];
|
||||
public static List<Item> CharacterLevelBreakItems { get; } = [];
|
||||
public static List<Item> SkillLevelUpItems { get; } = [];
|
||||
public static List<Item> NotForSaleItems { get; } = [];
|
||||
public static Dictionary<OshimaRegion, List<Item>> ExploreItems { get; } = [];
|
||||
public static List<Item> UserDailyItems { get; } = [];
|
||||
public static List<Skill> ItemSkills { get; } = [];
|
||||
|
||||
@ -297,8 +297,8 @@ namespace Oshima.FunGame.OshimaServers
|
||||
totalStats.AvgActionTurn = totalStats.ActionTurn / totalStats.Plays;
|
||||
totalStats.AvgLiveTime = Calculation.Round2Digits(totalStats.LiveTime / totalStats.Plays);
|
||||
totalStats.AvgEarnedMoney = totalStats.TotalEarnedMoney / totalStats.Plays;
|
||||
totalStats.Winrates = Calculation.Round4Digits(Convert.ToDouble(totalStats.Wins) / Convert.ToDouble(totalStats.Plays));
|
||||
totalStats.Top3rates = Calculation.Round4Digits(Convert.ToDouble(totalStats.Top3s) / Convert.ToDouble(totalStats.Plays));
|
||||
totalStats.Winrate = Calculation.Round4Digits(Convert.ToDouble(totalStats.Wins) / Convert.ToDouble(totalStats.Plays));
|
||||
totalStats.Top3rate = Calculation.Round4Digits(Convert.ToDouble(totalStats.Top3s) / Convert.ToDouble(totalStats.Plays));
|
||||
}
|
||||
if (totalStats.LiveRound != 0) totalStats.DamagePerRound = Calculation.Round2Digits(totalStats.TotalDamage / totalStats.LiveRound);
|
||||
if (totalStats.ActionTurn != 0) totalStats.DamagePerTurn = Calculation.Round2Digits(totalStats.TotalDamage / totalStats.ActionTurn);
|
||||
|
||||
@ -74,9 +74,12 @@ namespace Oshima.FunGame.OshimaServers.Service
|
||||
new 青石(), new 莲花(), new 陶罐(), new 海灵芝(), new 四叶草(), new 露珠(), new 茉莉花(), new 绿萝(), new 檀木扇(), new 鸟蛋(), new 竹笋(), new 晶核(), new 手工围巾(), new 柳条篮(), new 风筝(), new 羽毛(), new 发光髓(),
|
||||
new 紫罗兰(), new 松果(), new 电气水晶(), new 薄荷(), new 竹节(), new 铁砧(), new 冰雾花(), new 海草(), new 磐石(), new 砂砾(), new 铁甲贝壳(), new 蜥蜴尾巴(), new 古老钟摆(), new 枯藤()]);
|
||||
|
||||
FunGameConstant.NotForSaleItems.AddRange([]);
|
||||
|
||||
FunGameConstant.AllItems.AddRange(FunGameConstant.Equipment);
|
||||
FunGameConstant.AllItems.AddRange(FunGameConstant.Items);
|
||||
FunGameConstant.AllItems.AddRange(FunGameConstant.UserDailyItems);
|
||||
FunGameConstant.AllItems.AddRange(FunGameConstant.NotForSaleItems);
|
||||
|
||||
foreach (OshimaRegion region in FunGameConstant.Regions)
|
||||
{
|
||||
@ -84,8 +87,8 @@ namespace Oshima.FunGame.OshimaServers.Service
|
||||
FunGameConstant.ExploreItems.Add(region, items);
|
||||
}
|
||||
|
||||
long[] userDailyItemIds = [.. FunGameConstant.UserDailyItems.Select(i => i.Id)];
|
||||
FunGameConstant.DrawCardItems.AddRange(FunGameConstant.AllItems.Where(i => !FunGameConstant.ItemCanNotDrawCard.Contains(i.ItemType) && !userDailyItemIds.Contains(i.Id)));
|
||||
long[] notDrawIds = [.. FunGameConstant.UserDailyItems.Union(FunGameConstant.NotForSaleItems).Select(i => i.Id)];
|
||||
FunGameConstant.DrawCardItems.AddRange(FunGameConstant.AllItems.Where(i => !FunGameConstant.ItemCanNotDrawCard.Contains(i.ItemType) && !notDrawIds.Contains(i.Id)));
|
||||
FunGameConstant.CharacterLevelBreakItems.AddRange([new 升华之印(), new 流光之印(), new 永恒之印(), new 原初之印(), new 创生之印()]);
|
||||
FunGameConstant.SkillLevelUpItems.AddRange([new 技能卷轴(), new 智慧之果(), new 奥术符文(), new 混沌之核(), new 法则精粹()]);
|
||||
|
||||
@ -2072,8 +2075,8 @@ namespace Oshima.FunGame.OshimaServers.Service
|
||||
}
|
||||
else
|
||||
{
|
||||
int index = Random.Shared.Next(FunGameConstant.AllItems.Count);
|
||||
item = FunGameConstant.AllItems[index].Copy();
|
||||
int index = Random.Shared.Next(FunGameConstant.DrawCardItems.Count);
|
||||
item = FunGameConstant.DrawCardItems[index].Copy();
|
||||
}
|
||||
item.Character = null;
|
||||
(int min, int max) = (0, 0);
|
||||
@ -2157,6 +2160,7 @@ namespace Oshima.FunGame.OshimaServers.Service
|
||||
return $"此商品【{goods.Name}】限量购买 {goods.Quota} 件!\r\n你已经购买了 {buyCount} 件,想要购买 {count} 件,超过了购买限制。";
|
||||
}
|
||||
|
||||
List<string> buyCost = [];
|
||||
foreach (string needy in goods.Prices.Keys)
|
||||
{
|
||||
if (needy == General.GameplayEquilibriumConstant.InGameCurrency)
|
||||
@ -2170,6 +2174,7 @@ namespace Oshima.FunGame.OshimaServers.Service
|
||||
if (user.Inventory.Credits >= reduce)
|
||||
{
|
||||
user.Inventory.Credits -= reduce;
|
||||
buyCost.Add($"{reduce} {needy}");
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -2187,6 +2192,7 @@ namespace Oshima.FunGame.OshimaServers.Service
|
||||
if (user.Inventory.Materials >= reduce)
|
||||
{
|
||||
user.Inventory.Materials -= reduce;
|
||||
buyCost.Add($"{reduce} {needy}");
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -2200,6 +2206,7 @@ namespace Oshima.FunGame.OshimaServers.Service
|
||||
{
|
||||
points -= reduce;
|
||||
pc.Add("forgepoints", points);
|
||||
buyCost.Add($"{reduce} {needy}");
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -2213,6 +2220,7 @@ namespace Oshima.FunGame.OshimaServers.Service
|
||||
{
|
||||
points -= reduce;
|
||||
pc.Add("horseRacingPoints", points);
|
||||
buyCost.Add($"{reduce} {needy}");
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -2226,6 +2234,7 @@ namespace Oshima.FunGame.OshimaServers.Service
|
||||
{
|
||||
points -= reduce;
|
||||
pc.Add("cooperativePoints", points);
|
||||
buyCost.Add($"{reduce} {needy}");
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -2278,7 +2287,7 @@ namespace Oshima.FunGame.OshimaServers.Service
|
||||
}
|
||||
|
||||
msg += $"恭喜你成功购买 {count} 件【{goods.Name}】!\r\n" + (goods.Quota > 0 ? $"此商品限购 {goods.Quota} 件,你还可以再购买 {goods.Quota - count - buyCount} 件。\r\n" : "") +
|
||||
$"总计消费:{(goods.Prices.Count > 0 ? string.Join("、", goods.Prices.Select(kv => $"{kv.Value * count:0.##} {kv.Key}")) : "免单")}\r\n" +
|
||||
$"总计消费:{(goods.Prices.Count > 0 ? string.Join("、", buyCost) : "免单")}\r\n" +
|
||||
$"包含物品:{string.Join("、", goods.Items.Select(i => $"[{ItemSet.GetQualityTypeName(i.QualityType)}|{ItemSet.GetItemTypeName(i.ItemType)}] {i.Name} * {count}"))}\r\n" +
|
||||
$"{store.Name}期待你的下次光临。";
|
||||
|
||||
@ -4366,19 +4375,27 @@ namespace Oshima.FunGame.OshimaServers.Service
|
||||
if (activity != null)
|
||||
{
|
||||
builder.Append("商品售价:");
|
||||
bool add = false;
|
||||
foreach (string price in goods.Prices.Keys)
|
||||
if (goods.Prices.Count > 0)
|
||||
{
|
||||
if (add) builder.Append('、');
|
||||
switch (activity)
|
||||
bool add = false;
|
||||
foreach (string price in goods.Prices.Keys)
|
||||
{
|
||||
case "双旦活动":
|
||||
builder.Append($"{goods.Prices[price] / 2:0.##} {price}(-50%,原价:{goods.Prices[price]:0.##} {price})");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
if (add) builder.Append('、');
|
||||
switch (activity)
|
||||
{
|
||||
case "双旦活动":
|
||||
builder.Append($"{goods.Prices[price] / 2:0.##} {price}(-50%,原价:{goods.Prices[price]:0.##} {price})");
|
||||
break;
|
||||
default:
|
||||
builder.Append($"{goods.Prices[price]:0.##} {price}");
|
||||
break;
|
||||
}
|
||||
if (!add) add = true;
|
||||
}
|
||||
if (!add) add = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
builder.Append("免费");
|
||||
}
|
||||
builder.AppendLine();
|
||||
}
|
||||
|
||||
@ -1148,8 +1148,8 @@ namespace Oshima.FunGame.OshimaServers.Service
|
||||
totalStats.AvgControlTime = Calculation.Round2Digits(totalStats.ControlTime / totalStats.Plays);
|
||||
totalStats.AvgShield = Calculation.Round2Digits(totalStats.TotalShield / totalStats.Plays);
|
||||
totalStats.AvgEarnedMoney = totalStats.TotalEarnedMoney / totalStats.Plays;
|
||||
totalStats.Winrates = Calculation.Round4Digits(Convert.ToDouble(totalStats.Wins) / Convert.ToDouble(totalStats.Plays));
|
||||
totalStats.Top3rates = Calculation.Round4Digits(Convert.ToDouble(totalStats.Top3s) / Convert.ToDouble(totalStats.Plays));
|
||||
totalStats.Winrate = Calculation.Round4Digits(Convert.ToDouble(totalStats.Wins) / Convert.ToDouble(totalStats.Plays));
|
||||
totalStats.Top3rate = Calculation.Round4Digits(Convert.ToDouble(totalStats.Top3s) / Convert.ToDouble(totalStats.Plays));
|
||||
}
|
||||
if (totalStats.LiveRound != 0) totalStats.DamagePerRound = Calculation.Round2Digits(totalStats.TotalDamage / totalStats.LiveRound);
|
||||
if (totalStats.ActionTurn != 0) totalStats.DamagePerTurn = Calculation.Round2Digits(totalStats.TotalDamage / totalStats.ActionTurn);
|
||||
|
||||
77
OshimaServers/Service/Utility.cs
Normal file
77
OshimaServers/Service/Utility.cs
Normal file
@ -0,0 +1,77 @@
|
||||
using System.Data;
|
||||
|
||||
namespace Oshima.FunGame.OshimaServers.Service
|
||||
{
|
||||
public class Utility
|
||||
{
|
||||
public static class DataSetConverter
|
||||
{
|
||||
/// <summary>
|
||||
/// 将DataSet转换为Dictionary列表
|
||||
/// </summary>
|
||||
/// <param name="dataSet">输入的DataSet</param>
|
||||
/// <returns>Dictionary列表,每个Dictionary代表一行数据</returns>
|
||||
public static List<Dictionary<string, object>> ConvertDataSetToDictionary(DataSet dataSet)
|
||||
{
|
||||
List<Dictionary<string, object>> result = [];
|
||||
|
||||
if (dataSet == null || dataSet.Tables.Count == 0)
|
||||
return result;
|
||||
|
||||
foreach (DataTable table in dataSet.Tables)
|
||||
{
|
||||
foreach (DataRow row in table.Rows)
|
||||
{
|
||||
Dictionary<string, object> rowDict = [];
|
||||
|
||||
foreach (DataColumn column in table.Columns)
|
||||
{
|
||||
// 处理DBNull值
|
||||
if (row[column] != DBNull.Value)
|
||||
{
|
||||
rowDict[column.ColumnName] = row[column];
|
||||
}
|
||||
}
|
||||
|
||||
result.Add(rowDict);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将DataSet的第一张表转换为Dictionary列表
|
||||
/// </summary>
|
||||
/// <param name="dataSet">输入的DataSet</param>
|
||||
/// <returns>Dictionary列表,每个Dictionary代表一行数据</returns>
|
||||
public static List<Dictionary<string, object>> ConvertFirstTableToDictionary(DataSet dataSet)
|
||||
{
|
||||
List<Dictionary<string, object>> result = [];
|
||||
|
||||
if (dataSet == null || dataSet.Tables.Count == 0)
|
||||
return result;
|
||||
|
||||
DataTable table = dataSet.Tables[0];
|
||||
|
||||
foreach (DataRow row in table.Rows)
|
||||
{
|
||||
Dictionary<string, object> rowDict = [];
|
||||
|
||||
foreach (DataColumn column in table.Columns)
|
||||
{
|
||||
// 处理DBNull值
|
||||
if (row[column] != DBNull.Value)
|
||||
{
|
||||
rowDict[column.ColumnName] = row[column];
|
||||
}
|
||||
}
|
||||
|
||||
result.Add(rowDict);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -92,9 +92,9 @@ namespace Oshima.FunGame.WebAPI.Controllers
|
||||
List<string> names = [.. FunGameSimulation.CharacterStatistics.OrderByDescending(kv => kv.Value.MVPs).Select(kv => kv.Key.GetName())];
|
||||
builder.AppendLine($"MVP次数:{stats.MVPs}(#{names.IndexOf(character.GetName()) + 1})");
|
||||
|
||||
names = [.. FunGameSimulation.CharacterStatistics.OrderByDescending(kv => kv.Value.Winrates).Select(kv => kv.Key.GetName())];
|
||||
builder.AppendLine($"胜率:{stats.Winrates * 100:0.##}%(#{names.IndexOf(character.GetName()) + 1})");
|
||||
builder.AppendLine($"前三率:{stats.Top3rates * 100:0.##}%");
|
||||
names = [.. FunGameSimulation.CharacterStatistics.OrderByDescending(kv => kv.Value.Winrate).Select(kv => kv.Key.GetName())];
|
||||
builder.AppendLine($"胜率:{stats.Winrate * 100:0.##}%(#{names.IndexOf(character.GetName()) + 1})");
|
||||
builder.AppendLine($"前三率:{stats.Top3rate * 100:0.##}%");
|
||||
|
||||
names = [.. FunGameSimulation.CharacterStatistics.OrderByDescending(kv => kv.Value.Rating).Select(kv => kv.Key.GetName())];
|
||||
builder.AppendLine($"技术得分:{stats.Rating:0.0#}(#{names.IndexOf(character.GetName()) + 1})");
|
||||
@ -149,8 +149,8 @@ namespace Oshima.FunGame.WebAPI.Controllers
|
||||
|
||||
List<string> names = [.. FunGameSimulation.TeamCharacterStatistics.OrderByDescending(kv => kv.Value.MVPs).Select(kv => kv.Key.GetName())];
|
||||
builder.AppendLine($"MVP次数:{stats.MVPs}(#{names.IndexOf(character.GetName()) + 1})");
|
||||
names = [.. FunGameSimulation.TeamCharacterStatistics.OrderByDescending(kv => kv.Value.Winrates).Select(kv => kv.Key.GetName())];
|
||||
builder.AppendLine($"胜率:{stats.Winrates * 100:0.##}%(#{names.IndexOf(character.GetName()) + 1})");
|
||||
names = [.. FunGameSimulation.TeamCharacterStatistics.OrderByDescending(kv => kv.Value.Winrate).Select(kv => kv.Key.GetName())];
|
||||
builder.AppendLine($"胜率:{stats.Winrate * 100:0.##}%(#{names.IndexOf(character.GetName()) + 1})");
|
||||
names = [.. FunGameSimulation.TeamCharacterStatistics.OrderByDescending(kv => kv.Value.Rating).Select(kv => kv.Key.GetName())];
|
||||
builder.AppendLine($"技术得分:{stats.Rating:0.0#}(#{names.IndexOf(character.GetName()) + 1})");
|
||||
|
||||
@ -168,7 +168,7 @@ namespace Oshima.FunGame.WebAPI.Controllers
|
||||
if (team)
|
||||
{
|
||||
List<string> strings = [];
|
||||
IEnumerable<Character> ratings = FunGameSimulation.TeamCharacterStatistics.OrderByDescending(kv => kv.Value.Winrates).Select(kv => kv.Key);
|
||||
IEnumerable<Character> ratings = FunGameSimulation.TeamCharacterStatistics.OrderByDescending(kv => kv.Value.Winrate).Select(kv => kv.Key);
|
||||
foreach (Character character in ratings)
|
||||
{
|
||||
StringBuilder builder = new();
|
||||
@ -176,7 +176,7 @@ namespace Oshima.FunGame.WebAPI.Controllers
|
||||
builder.AppendLine(character.ToStringWithOutUser());
|
||||
builder.AppendLine($"总计参赛数:{stats.Plays}");
|
||||
builder.AppendLine($"总计冠军数:{stats.Wins}");
|
||||
builder.AppendLine($"胜率:{stats.Winrates * 100:0.##}%");
|
||||
builder.AppendLine($"胜率:{stats.Winrate * 100:0.##}%");
|
||||
builder.AppendLine($"技术得分:{stats.Rating:0.0#}");
|
||||
builder.AppendLine($"MVP次数:{stats.MVPs}");
|
||||
strings.Add(builder.ToString());
|
||||
@ -186,7 +186,7 @@ namespace Oshima.FunGame.WebAPI.Controllers
|
||||
else
|
||||
{
|
||||
List<string> strings = [];
|
||||
IEnumerable<Character> ratings = FunGameSimulation.CharacterStatistics.OrderByDescending(kv => kv.Value.Winrates).Select(kv => kv.Key);
|
||||
IEnumerable<Character> ratings = FunGameSimulation.CharacterStatistics.OrderByDescending(kv => kv.Value.Winrate).Select(kv => kv.Key);
|
||||
foreach (Character character in ratings)
|
||||
{
|
||||
StringBuilder builder = new();
|
||||
@ -194,8 +194,8 @@ namespace Oshima.FunGame.WebAPI.Controllers
|
||||
builder.AppendLine(character.ToStringWithOutUser());
|
||||
builder.AppendLine($"总计参赛数:{stats.Plays}");
|
||||
builder.AppendLine($"总计冠军数:{stats.Wins}");
|
||||
builder.AppendLine($"胜率:{stats.Winrates * 100:0.##}%");
|
||||
builder.AppendLine($"前三率:{stats.Top3rates * 100:0.##}%");
|
||||
builder.AppendLine($"胜率:{stats.Winrate * 100:0.##}%");
|
||||
builder.AppendLine($"前三率:{stats.Top3rate * 100:0.##}%");
|
||||
builder.AppendLine($"技术得分:{stats.Rating:0.0#}");
|
||||
builder.AppendLine($"上次排名:{stats.LastRank} / 场均名次:{stats.AvgRank:0.##}");
|
||||
builder.AppendLine($"MVP次数:{stats.MVPs}");
|
||||
@ -221,7 +221,7 @@ namespace Oshima.FunGame.WebAPI.Controllers
|
||||
builder.AppendLine(character.ToStringWithOutUser());
|
||||
builder.AppendLine($"总计参赛数:{stats.Plays}");
|
||||
builder.AppendLine($"总计冠军数:{stats.Wins}");
|
||||
builder.AppendLine($"胜率:{stats.Winrates * 100:0.##}%");
|
||||
builder.AppendLine($"胜率:{stats.Winrate * 100:0.##}%");
|
||||
builder.AppendLine($"技术得分:{stats.Rating:0.0#}");
|
||||
builder.AppendLine($"MVP次数:{stats.MVPs}");
|
||||
strings.Add(builder.ToString());
|
||||
@ -239,8 +239,8 @@ namespace Oshima.FunGame.WebAPI.Controllers
|
||||
builder.AppendLine(character.ToStringWithOutUser());
|
||||
builder.AppendLine($"总计参赛数:{stats.Plays}");
|
||||
builder.AppendLine($"总计冠军数:{stats.Wins}");
|
||||
builder.AppendLine($"胜率:{stats.Winrates * 100:0.##}%");
|
||||
builder.AppendLine($"前三率:{stats.Top3rates * 100:0.##}%");
|
||||
builder.AppendLine($"胜率:{stats.Winrate * 100:0.##}%");
|
||||
builder.AppendLine($"前三率:{stats.Top3rate * 100:0.##}%");
|
||||
builder.AppendLine($"技术得分:{stats.Rating:0.0#}");
|
||||
builder.AppendLine($"上次排名:{stats.LastRank} / 场均名次:{stats.AvgRank:0.##}");
|
||||
builder.AppendLine($"MVP次数:{stats.MVPs}");
|
||||
@ -9177,6 +9177,71 @@ namespace Oshima.FunGame.WebAPI.Controllers
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost("receiveactivityawards")]
|
||||
public string ReceiveActivityAwards([FromQuery] long uid = -1, [FromQuery] long aid = -1, [FromQuery] long qid = -1)
|
||||
{
|
||||
try
|
||||
{
|
||||
PluginConfig pc = FunGameService.GetUserConfig(uid, out bool isTimeout);
|
||||
if (isTimeout)
|
||||
{
|
||||
return busy;
|
||||
}
|
||||
|
||||
string msg = "";
|
||||
if (pc.Count > 0)
|
||||
{
|
||||
User user = FunGameService.GetUser(pc);
|
||||
|
||||
if (FunGameService.Activities.FirstOrDefault(a => a.Id == aid) is Activity activity)
|
||||
{
|
||||
if (activity.Status == ActivityState.InProgress || activity.Status == ActivityState.Ended)
|
||||
{
|
||||
if (activity.Quests.FirstOrDefault(q => q.Id == qid) is Quest quest)
|
||||
{
|
||||
if (quest.Status == QuestState.Completed)
|
||||
{
|
||||
msg = "该任务未完成!";
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
msg = "没有指定的任务。";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
msg = "该活动不在可领取奖励的时间内。";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
msg = "没有指定的活动。";
|
||||
}
|
||||
|
||||
FunGameService.SetUserConfigButNotRelease(uid, pc, user);
|
||||
return msg;
|
||||
}
|
||||
else
|
||||
{
|
||||
return noSaved;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
if (Logger.IsEnabled(Microsoft.Extensions.Logging.LogLevel.Error)) Logger.LogError(e, "Error: {e}", e);
|
||||
return busy;
|
||||
}
|
||||
finally
|
||||
{
|
||||
FunGameService.ReleaseUserSemaphoreSlim(uid);
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost("template")]
|
||||
public string Template([FromQuery] long uid = -1)
|
||||
{
|
||||
|
||||
@ -1,7 +1,10 @@
|
||||
using System.Data;
|
||||
using System.Text;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Milimoe.FunGame.Core.Api.Transmittal;
|
||||
using Milimoe.FunGame.Core.Entity;
|
||||
using Milimoe.FunGame.Core.Library.Exception;
|
||||
using Oshima.FunGame.OshimaServers.Service;
|
||||
using Oshima.FunGame.WebAPI.Constant;
|
||||
|
||||
namespace Oshima.FunGame.WebAPI.Controllers
|
||||
@ -22,12 +25,12 @@ namespace Oshima.FunGame.WebAPI.Controllers
|
||||
SQLHelper? sql = Statics.RunningPlugin.Controller.SQLHelper;
|
||||
if (sql != null)
|
||||
{
|
||||
sql.Script = "select * from saints where `group` = @group order by sc" + (!reverse ? " desc" : "");
|
||||
sql.Script = "select qq UID, '-' as Times, SC, Remark, Record from saints where `group` = @group order by sc" + (!reverse ? " desc" : "");
|
||||
sql.Parameters.Add("group", group);
|
||||
sql.ExecuteDataSet();
|
||||
if (sql.Success)
|
||||
{
|
||||
List<Dictionary<string, object>> data = DataSetConverter.ConvertFirstTableToDictionary(sql.DataSet);
|
||||
List<Dictionary<string, object>> data = Utility.DataSetConverter.ConvertFirstTableToDictionary(sql.DataSet);
|
||||
dict["data"] = data;
|
||||
return dict;
|
||||
}
|
||||
@ -44,74 +47,29 @@ namespace Oshima.FunGame.WebAPI.Controllers
|
||||
return dict;
|
||||
}
|
||||
|
||||
public static class DataSetConverter
|
||||
[HttpGet("ratings")]
|
||||
public Dictionary<string, object> GetRatings()
|
||||
{
|
||||
/// <summary>
|
||||
/// 将DataSet转换为Dictionary列表
|
||||
/// </summary>
|
||||
/// <param name="dataSet">输入的DataSet</param>
|
||||
/// <returns>Dictionary列表,每个Dictionary代表一行数据</returns>
|
||||
public static List<Dictionary<string, object>> ConvertDataSetToDictionary(DataSet dataSet)
|
||||
Dictionary<string, object> dict = [];
|
||||
List<Dictionary<string, object>> data = [];
|
||||
|
||||
IEnumerable<Character> ratings = FunGameSimulation.TeamCharacterStatistics.OrderByDescending(kv => kv.Value.Rating).Select(kv => kv.Key);
|
||||
foreach (Character character in ratings)
|
||||
{
|
||||
List<Dictionary<string, object>> result = [];
|
||||
|
||||
if (dataSet == null || dataSet.Tables.Count == 0)
|
||||
return result;
|
||||
|
||||
foreach (DataTable table in dataSet.Tables)
|
||||
{
|
||||
foreach (DataRow row in table.Rows)
|
||||
{
|
||||
Dictionary<string, object> rowDict = [];
|
||||
|
||||
foreach (DataColumn column in table.Columns)
|
||||
{
|
||||
// 处理DBNull值
|
||||
if (row[column] != DBNull.Value)
|
||||
{
|
||||
rowDict[column.ColumnName] = row[column];
|
||||
}
|
||||
}
|
||||
|
||||
result.Add(rowDict);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
Dictionary<string, object> table = [];
|
||||
StringBuilder builder = new();
|
||||
CharacterStatistics stats = FunGameSimulation.TeamCharacterStatistics[character];
|
||||
table["Character"] = character.ToStringWithOutUser();
|
||||
table["Maps"] = stats.Plays;
|
||||
table["Wins"] = stats.Wins;
|
||||
table["Winrate"] = $"{stats.Winrate * 100:0.##}%";
|
||||
table["Rating"] = $"{stats.Rating:0.0#}";
|
||||
table["MVPs"] = stats.MVPs;
|
||||
data.Add(table);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将DataSet的第一张表转换为Dictionary列表
|
||||
/// </summary>
|
||||
/// <param name="dataSet">输入的DataSet</param>
|
||||
/// <returns>Dictionary列表,每个Dictionary代表一行数据</returns>
|
||||
public static List<Dictionary<string, object>> ConvertFirstTableToDictionary(DataSet dataSet)
|
||||
{
|
||||
List<Dictionary<string, object>> result = [];
|
||||
|
||||
if (dataSet == null || dataSet.Tables.Count == 0)
|
||||
return result;
|
||||
|
||||
DataTable table = dataSet.Tables[0];
|
||||
|
||||
foreach (DataRow row in table.Rows)
|
||||
{
|
||||
Dictionary<string, object> rowDict = [];
|
||||
|
||||
foreach (DataColumn column in table.Columns)
|
||||
{
|
||||
// 处理DBNull值
|
||||
if (row[column] != DBNull.Value)
|
||||
{
|
||||
rowDict[column.ColumnName] = row[column];
|
||||
}
|
||||
}
|
||||
|
||||
result.Add(rowDict);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
dict["data"] = data;
|
||||
return dict;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user