Skip to content

Commit

Permalink
Merge pull request #408 from UnrealMultiple/main
Browse files Browse the repository at this point in the history
修复: Economics.WeaponPlus数据库报错
  • Loading branch information
Controllerdestiny authored Aug 19, 2024
2 parents e02ba08 + c240ae3 commit 0ce2d79
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 125 deletions.
6 changes: 3 additions & 3 deletions AutoPluginManager/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ public class Plugin : TerrariaPlugin
{
public override string Name => "AutoPluginManager";

public override Version Version => new(2, 0, 0, 2);
public override Version Version => new(2, 0, 0,3);

public override string Author => "少司命,Cai";

public override string Description => "自动更新你的插件!";

private const string ReleaseUrl = "https://github.com/Controllerdestiny/TShockPlugin/releases/download/V1.0.0.0/Plugins.zip";
private const string ReleaseUrl = "https://github.com/UnrealMultiple/TShockPlugin/releases/download/V1.0.0.0/Plugins.zip";

private const string PUrl = "https://github.moeyy.xyz/";

private const string PluginsUrl = "https://raw.githubusercontent.com/Controllerdestiny/TShockPlugin/master/Plugins.json";
private const string PluginsUrl = "https://raw.githubusercontent.com/UnrealMultiple/TShockPlugin/master/Plugins.json";

private static readonly HttpClient _httpClient = new();

Expand Down
236 changes: 116 additions & 120 deletions Economics.WeaponPlus/WeaponPlusDB.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,159 +4,155 @@
using TShockAPI;
using TShockAPI.DB;

namespace Economics.WeaponPlus
{
public class WeaponPlusDB
{
#region 创建数据库表
private readonly IDbConnection database;
namespace Economics.WeaponPlus;

private readonly string tableName;
public class WeaponPlusDB
{
#region 创建数据库表
private readonly IDbConnection database;

public WeaponPlusDB(IDbConnection database)
{
this.database = database;
tableName = "WeaponPlusDBBasedOnEconomics";
SqlTable table = new SqlTable(tableName, new SqlColumn("owner", (MySqlDbType)752), new SqlColumn("itemID", (MySqlDbType)3), new SqlColumn("itemName", (MySqlDbType)752), new SqlColumn("lable", (MySqlDbType)3), new SqlColumn("level", (MySqlDbType)3), new SqlColumn("damage_level", (MySqlDbType)3), new SqlColumn("scale_level", (MySqlDbType)3), new SqlColumn("knockBack_level", (MySqlDbType)3), new SqlColumn("useSpeed_level", (MySqlDbType)3), new SqlColumn("shootSpeed_level", (MySqlDbType)3), new SqlColumn("allCost", (MySqlDbType)8));
IQueryBuilder queryBuilder = database.GetSqlType() == SqlType.Sqlite ? new SqliteQueryCreator() : new MysqlQueryCreator();
queryBuilder.CreateTable(table);
SqlTableCreator sqlTableCreator = new SqlTableCreator(database, queryBuilder);
sqlTableCreator.EnsureTableStructure(table);
}
#endregion
public WeaponPlusDB(IDbConnection database)
{
this.database = database;
SqlTable table = new SqlTable("WeaponPlusDBBasedOnEconomics", new SqlColumn("owner", (MySqlDbType)752), new SqlColumn("itemID", (MySqlDbType)3), new SqlColumn("itemName", (MySqlDbType)752), new SqlColumn("lable", (MySqlDbType)3), new SqlColumn("level", (MySqlDbType)3), new SqlColumn("damage_level", (MySqlDbType)3), new SqlColumn("scale_level", (MySqlDbType)3), new SqlColumn("knockBack_level", (MySqlDbType)3), new SqlColumn("useSpeed_level", (MySqlDbType)3), new SqlColumn("shootSpeed_level", (MySqlDbType)3), new SqlColumn("allCost", (MySqlDbType)8));
IQueryBuilder queryBuilder = database.GetSqlType() == SqlType.Sqlite ? new SqliteQueryCreator() : new MysqlQueryCreator();
queryBuilder.CreateTable(table);
SqlTableCreator sqlTableCreator = new SqlTableCreator(database, queryBuilder);
sqlTableCreator.EnsureTableStructure(table);
}
#endregion

#region 读取数据库从拥有者处获取物品数据
public WItem[] ReadDBGetWItemsFromOwner(string owner, int ID = 0)
#region 读取数据库从拥有者处获取物品数据
public WItem[] ReadDBGetWItemsFromOwner(string owner, int ID = 0)
{
List<WItem> list = new List<WItem>();
try
{
List<WItem> list = new List<WItem>();
try
using (QueryResult queryResult = database.QueryReader(ID == 0 ? "SELECT * FROM WeaponPlusDBBasedOnEconomics WHERE owner = @0" : "SELECT * FROM WeaponPlusDBBasedOnEconomics WHERE owner = @0 And itemID = @1", owner, ID))
{
using (QueryResult queryResult = database.QueryReader("SELECT * FROM @0 WHERE `@1` And itemID = `@2`", tableName, owner, ID == 0 ? "" : ID))
while (queryResult.Read())
{
while (queryResult.Read())
WItem wItem = new WItem(queryResult.Get<int>("itemID"), owner)
{
WItem wItem = new WItem(queryResult.Get<int>("itemID"), owner)
{
lable = queryResult.Get<int>("lable"),
damage_level = queryResult.Get<int>("damage_level"),
scale_level = queryResult.Get<int>("scale_level"),
knockBack_level = queryResult.Get<int>("knockBack_level"),
useSpeed_level = queryResult.Get<int>("useSpeed_level"),
shootSpeed_level = queryResult.Get<int>("shootSpeed_level"),
allCost = queryResult.Get<long>("allCost")
};
list.Add(wItem);
}
lable = queryResult.Get<int>("lable"),
damage_level = queryResult.Get<int>("damage_level"),
scale_level = queryResult.Get<int>("scale_level"),
knockBack_level = queryResult.Get<int>("knockBack_level"),
useSpeed_level = queryResult.Get<int>("useSpeed_level"),
shootSpeed_level = queryResult.Get<int>("shootSpeed_level"),
allCost = queryResult.Get<long>("allCost")
};
list.Add(wItem);
}
return list.ToArray();
}
catch (Exception ex)
{
TShock.Log.Error("错误:ReadDBGetWItemsFromOwner " + ex.ToString());
TSPlayer.All.SendErrorMessage("错误:ReadDBGetWItemsFromOwner " + ex.ToString());
Console.WriteLine("错误:ReadDBGetWItemsFromOwner " + ex.ToString());
return list.ToArray();
}
return list.ToArray();
}
#endregion

#region 写入数据
public bool WriteDB(WItem[] WItem)
catch (Exception ex)
{
if (WItem.Length == 0)
{
return false;
}
bool result = true;
foreach (WItem wItem in WItem)
{
if (wItem == null || wItem.Level == 0 || string.IsNullOrWhiteSpace(wItem.owner))
{
continue;
}
try
{
if (ReadDBGetWItemsFromOwner(wItem.owner, wItem.id).Length == 0)
{
database.Query("INSERT INTO @11 (owner, itemName, itemID, lable, level, damage_level, scale_level, knockBack_level, useSpeed_level, shootSpeed_level, allCost) VALUES (@0, @1, @2, @3, @4, @5, @6, @7, @8, @9, @10);", wItem.owner, Lang.GetItemNameValue(wItem.id), wItem.id, wItem.lable, wItem.Level, wItem.damage_level, wItem.scale_level, wItem.knockBack_level, wItem.useSpeed_level, wItem.shootSpeed_level, wItem.allCost, tableName);
}
else
{
database.Query("UPDATE @10 SET lable = @0, level = @1, damage_level = @4, scale_level = @5, knockBack_level = @6, useSpeed_level = @7, shootSpeed_level = @8, allCost = @9 WHERE owner = @2 And itemID = @3;", wItem.lable, wItem.Level, wItem.owner, wItem.id, wItem.damage_level, wItem.scale_level, wItem.knockBack_level, wItem.useSpeed_level, wItem.shootSpeed_level, wItem.allCost, tableName);
}
}
catch (Exception ex)
{
TShock.Log.Error("错误:WriteDB " + ex.ToString());
TSPlayer.All.SendErrorMessage("错误:WriteDB " + ex.ToString());
Console.WriteLine("错误:WriteDB " + ex.ToString());
result = false;
}
}
return result;
TShock.Log.Error("错误:ReadDBGetWItemsFromOwner " + ex.ToString());
TSPlayer.All.SendErrorMessage("错误:ReadDBGetWItemsFromOwner " + ex.ToString());
Console.WriteLine("错误:ReadDBGetWItemsFromOwner " + ex.ToString());
return list.ToArray();
}
}
#endregion

public bool WriteDB(WItem? WItem)
#region 写入数据
public bool WriteDB(WItem[] WItem)
{
if (WItem.Length == 0)
{
if (WItem == null || WItem.Level <= 0 || string.IsNullOrWhiteSpace(WItem.owner))
return false;
}
bool result = true;
foreach (WItem wItem in WItem)
{
if (wItem == null || wItem.Level == 0 || string.IsNullOrWhiteSpace(wItem.owner))
{
return false;
continue;
}
try
{
if (ReadDBGetWItemsFromOwner(WItem.owner, WItem.id).Length == 0)
if (ReadDBGetWItemsFromOwner(wItem.owner, wItem.id).Length == 0)
{
database.Query("INSERT INTO @11 (owner, itemName, itemID, lable, level, damage_level, scale_level, knockBack_level, useSpeed_level, shootSpeed_level, allCost) VALUES (@0, @1, @2, @3, @4, @5, @6, @7, @8, @9, @10);", WItem.owner, Lang.GetItemNameValue(WItem.id), WItem.id, WItem.lable, WItem.Level, WItem.damage_level, WItem.scale_level, WItem.knockBack_level, WItem.useSpeed_level, WItem.shootSpeed_level, WItem.allCost, tableName);
return true;
database.Query("INSERT INTO WeaponPlusDBBasedOnEconomics (owner, itemName, itemID, lable, level, damage_level, scale_level, knockBack_level, useSpeed_level, shootSpeed_level, allCost) VALUES (@0, @1, @2, @3, @4, @5, @6, @7, @8, @9, @10);", wItem.owner, Lang.GetItemNameValue(wItem.id), wItem.id, wItem.lable, wItem.Level, wItem.damage_level, wItem.scale_level, wItem.knockBack_level, wItem.useSpeed_level, wItem.shootSpeed_level, wItem.allCost);
}
else
{
database.Query("UPDATE WeaponPlusDBBasedOnEconomics SET lable = @0, level = @1, damage_level = @4, scale_level = @5, knockBack_level = @6, useSpeed_level = @7, shootSpeed_level = @8, allCost = @9 WHERE owner = @2 And itemID = @3;", wItem.lable, wItem.Level, wItem.owner, wItem.id, wItem.damage_level, wItem.scale_level, wItem.knockBack_level, wItem.useSpeed_level, wItem.shootSpeed_level, wItem.allCost);
}
database.Query("UPDATE @10 SET lable = @0, level = @1, damage_level = @4, scale_level = @5, knockBack_level = @6, useSpeed_level = @7, shootSpeed_level = @8, allCost = @9 WHERE owner = @2 And itemID = @3;", WItem.lable, WItem.Level, WItem.owner, WItem.id, WItem.damage_level, WItem.scale_level, WItem.knockBack_level, WItem.useSpeed_level, WItem.shootSpeed_level, WItem.allCost, tableName);
return true;
}
catch (Exception ex)
{
TShock.Log.Error("错误:WriteDB2 " + ex.ToString());
TSPlayer.All.SendErrorMessage("错误:WriteDB2 " + ex.ToString());
Console.WriteLine("错误:WriteDB2 " + ex.ToString());
return false;
TShock.Log.Error("错误:WriteDB " + ex.ToString());
TSPlayer.All.SendErrorMessage("错误:WriteDB " + ex.ToString());
Console.WriteLine("错误:WriteDB " + ex.ToString());
result = false;
}
}
#endregion
return result;
}

#region 删除指定数据表
public bool DeleteDB(string owner, int ID = 0)
public bool WriteDB(WItem? WItem)
{
if (WItem == null || WItem.Level <= 0 || string.IsNullOrWhiteSpace(WItem.owner))
{
try
return false;
}
try
{
if (ReadDBGetWItemsFromOwner(WItem.owner, WItem.id).Length == 0)
{
database.Query("DELETE FROM @0 WHERE owner = `@1` And itemID = `@2`", tableName, owner, ID == 0 ? "" : ID);
database.Query("INSERT INTO WeaponPlusDBBasedOnEconomics (owner, itemName, itemID, lable, level, damage_level, scale_level, knockBack_level, useSpeed_level, shootSpeed_level, allCost) VALUES (@0, @1, @2, @3, @4, @5, @6, @7, @8, @9, @10);", WItem.owner, Lang.GetItemNameValue(WItem.id), WItem.id, WItem.lable, WItem.Level, WItem.damage_level, WItem.scale_level, WItem.knockBack_level, WItem.useSpeed_level, WItem.shootSpeed_level, WItem.allCost);
return true;
}
catch (Exception ex)
{
TShock.Log.Error("错误:DeleteDB " + ex.ToString());
TSPlayer.All.SendErrorMessage("错误:DeleteDB " + ex.ToString());
Console.WriteLine("错误:DeleteDB " + ex.ToString());
return false;
}
database.Query("UPDATE WeaponPlusDBBasedOnEconomics SET lable = @0, level = @1, damage_level = @4, scale_level = @5, knockBack_level = @6, useSpeed_level = @7, shootSpeed_level = @8, allCost = @9 WHERE owner = @2 And itemID = @3;", WItem.lable, WItem.Level, WItem.owner, WItem.id, WItem.damage_level, WItem.scale_level, WItem.knockBack_level, WItem.useSpeed_level, WItem.shootSpeed_level, WItem.allCost);
return true;
}
catch (Exception ex)
{
TShock.Log.Error("错误:WriteDB2 " + ex.ToString());
TSPlayer.All.SendErrorMessage("错误:WriteDB2 " + ex.ToString());
Console.WriteLine("错误:WriteDB2 " + ex.ToString());
return false;
}
#endregion
}
#endregion

#region 删除所有数据表
public bool DeleteDBAll()
#region 删除指定数据表
public bool DeleteDB(string owner, int ID = 0)
{
try
{
try
{
database.Query("DROP TABLE @0", tableName);
WeaponPlus.DB = new WeaponPlusDB(TShock.DB);
return true;
}
catch (Exception ex)
{
TShock.Log.Error("错误:DeleteDBAll " + ex.ToString());
TSPlayer.All.SendErrorMessage("错误:DeleteDBAll " + ex.ToString());
Console.WriteLine("错误:DeleteDBAll " + ex.ToString());
return false;
}
database.Query(ID == 0 ? "SELECT * FROM WeaponPlusDBBasedOnEconomics WHERE owner = @0" : "SELECT * FROM WeaponPlusDBBasedOnEconomics WHERE owner = @0 And itemID = @1", owner, ID);
return true;
}
catch (Exception ex)
{
TShock.Log.Error("错误:DeleteDB " + ex.ToString());
TSPlayer.All.SendErrorMessage("错误:DeleteDB " + ex.ToString());
Console.WriteLine("错误:DeleteDB " + ex.ToString());
return false;
}
}
#endregion

#region 删除所有数据表
public bool DeleteDBAll()
{
try
{
database.Query("DROP TABLE WeaponPlusDBBasedOnEconomics");
WeaponPlus.DB = new WeaponPlusDB(TShock.DB);
return true;
}
catch (Exception ex)
{
TShock.Log.Error("错误:DeleteDBAll " + ex.ToString());
TSPlayer.All.SendErrorMessage("错误:DeleteDBAll " + ex.ToString());
Console.WriteLine("错误:DeleteDBAll " + ex.ToString());
return false;
}
#endregion
}
#endregion
}
4 changes: 2 additions & 2 deletions WeaponPlusCostCoin/WeaponPlus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ namespace WeaponPlus
public partial class WeaponPlus : TerrariaPlugin
{
#region 插件信息
public override string Name => "WeaponPlusCostCoin";
public override string Name => "Economics.WeaponPlus";
public override string Author => "z枳";
public override string Description => "允许在基础属性上强化任何武器, Allow any weapon to be strengthened on basic attributes";
public override Version Version => new Version(1, 0, 0, 2);
public override Version Version => new Version(1, 0, 0, 3);
#endregion

#region 实例变量
Expand Down

0 comments on commit 0ce2d79

Please sign in to comment.