Skip to content

Commit

Permalink
更新信息显示方式
Browse files Browse the repository at this point in the history
添加了信息显示方式
1 全局默认
2 头上全局
3 头上个人
  • Loading branch information
Cybeta committed Apr 3, 2022
1 parent d20732a commit b0cf709
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 52 deletions.
10 changes: 7 additions & 3 deletions POBC.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.IO;
using System.Reflection;
using Terraria;
using Terraria.Localization;
using TerrariaApi.Server;
using TShockAPI;
using TShockAPI.Hooks;
Expand Down Expand Up @@ -35,6 +36,7 @@ public class POBCSystem : TerrariaPlugin
public Data data;
public override void Initialize()
{
File();
Db.Connect();
data = new Data(d => (d * 147 / 100) / 2 * Config.Multiple);
ServerApi.Hooks.GameInitialize.Register(this, OnInitialize);
Expand All @@ -43,7 +45,7 @@ public override void Initialize()
ServerApi.Hooks.NetGetData.Register(this, GetData);//抓包
PlayerHooks.PlayerPostLogin += Login;
PlayerHooks.PlayerLogout += UserOut;
File();

}


Expand Down Expand Up @@ -87,9 +89,9 @@ private void Login(PlayerPostLoginEventArgs e)

public void KillID(NpcKilledEventArgs args)
{
if (!Config.IsIgnored(args.npc.netID))
if(!Config.IsIgnored(args.npc.netID))
{
data.SettleNPC(args.npc.whoAmI);
data.SettleNPC(args.npc.whoAmI,Config.infodisplay,Config.displaytext);
}
}

Expand Down Expand Up @@ -279,6 +281,8 @@ public void File()
TShock.Log.ConsoleError("[POBC] 读取配置文件发生错误!\n{0}".SFormat(ex.ToString()));
}
}


}
}

29 changes: 17 additions & 12 deletions POBC2.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>lib\ServerPlugins\</OutputPath>
<OutputPath>..\..\..\tshock\TShock4.5.17_Terraria_1.4.3.6\ServerPlugins\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
Expand All @@ -32,18 +32,21 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Mono.Data.Sqlite">
<HintPath>..\..\..\tshock\Tshock-1.4.1.1\ServerPlugins\Mono.Data.Sqlite.dll</HintPath>
<Reference Include="Mono.Data.Sqlite, Version=2.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\tshock\TShock4.5.17_Terraria_1.4.3.6\Mono.Data.Sqlite.dll</HintPath>
</Reference>
<Reference Include="MySql.Data">
<HintPath>..\..\..\tshock\Tshock-1.4.1.1\ServerPlugins\MySql.Data.dll</HintPath>
<Reference Include="MySql.Data, Version=6.9.8.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\tshock\TShock4.5.17_Terraria_1.4.3.6\MySql.Data.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>lib\Newtonsoft.Json.dll</HintPath>
<HintPath>..\..\..\tshock\Tshock 4.5.4\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="OTAPI">
<HintPath>..\..\..\tshock\Tshock-1.4.1.1\ServerPlugins\OTAPI.dll</HintPath>
<Reference Include="OTAPI, Version=1.4.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\tshock\TShock4.5.17_Terraria_1.4.3.6\OTAPI.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
Expand All @@ -53,11 +56,13 @@
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
<Reference Include="TerrariaServer">
<HintPath>..\..\..\tshock\Tshock-1.4.1.1\ServerPlugins\TerrariaServer.exe</HintPath>
<Reference Include="TerrariaServer, Version=1.4.0.2, Culture=neutral, processorArchitecture=x86">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\tshock\TShock4.5.17_Terraria_1.4.3.6\TerrariaServer.exe</HintPath>
</Reference>
<Reference Include="TShockAPI">
<HintPath>..\..\..\tshock\Tshock-1.4.1.1\ServerPlugins\TShockAPI.dll</HintPath>
<Reference Include="TShockAPI, Version=4.4.0.0, Culture=neutral, processorArchitecture=x86">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\tshock\TShock4.5.17_Terraria_1.4.3.6\ServerPlugins\TShockAPI.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions POBC2.csproj.user
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
<StartAction>Program</StartAction>
<StartProgram>C:\Users\cy332\Desktop\tshock\Tshock-1.4.1.1\TerrariaServer.exe</StartProgram>
<StartWorkingDirectory>C:\Users\cy332\Desktop\tshock\Tshock-1.4.1.1\</StartWorkingDirectory>
<StartProgram>C:\Users\cy\Desktop\tshock\TShock4.5.17_Terraria_1.4.3.6\TerrariaServer.exe</StartProgram>
<StartWorkingDirectory>C:\Users\cy\Desktop\tshock\TShock4.5.17_Terraria_1.4.3.6\</StartWorkingDirectory>
</PropertyGroup>
</Project>
2 changes: 2 additions & 0 deletions config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ namespace POBC2
public class POBCConfin
{
public int[] IgnoreNpc = new int[0];
public int infodisplay = 1;
public string displaytext = "ÄãÒò»÷°ÜÁË{Name}¶ø»ñµÃ{coin}¾­Ñé";
public int Multiple = 1;
public bool PlayerKillFine = true;
public double DeductionPercentage = 0.1;
Expand Down
75 changes: 72 additions & 3 deletions data.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.ComponentModel.Design;
using System.Linq;
using Terraria;
using Terraria.Localization;
using TShockAPI;

namespace POBC2
Expand All @@ -27,7 +28,7 @@ public void ClearPlayer(int index)
}
}

public void SettleNPC(int index)
public void SettleNPC(int index, int infodisplay,string text)
{
int s = 0;
for (int i = 0; i < Main.maxPlayers + 1; ++i)
Expand All @@ -43,12 +44,51 @@ public void SettleNPC(int index)
if (string.IsNullOrEmpty(account)) continue;

int coin = calcExp(value);

if (coin == 0)
{
continue;
}
TShock.Players[i].SendWarningMessage($"你因击败了{Main.npc[index].GivenOrTypeName}而获得{coin}经验");
switch (infodisplay)
{
case 1:
if (text.Contains("{Name}"))
{
text = text.Replace("{Name}", Main.npc[index].GivenOrTypeName);
}
if (text.Contains("{coin}"))
{
text = text.Replace("{coin}", coin.ToString());
}
TShock.Players[i].SendWarningMessage(text);
break;
case 2:
if (text.Contains("{Name}"))
{
text = text.Replace("{Name}", Main.npc[index].GivenOrTypeName);
}
if (text.Contains("{coin}"))
{
text = text.Replace("{coin}", coin.ToString());
}
allmsg(i, text);
break;
case 3:
if (text.Contains("{Name}"))
{
text = text.Replace("{Name}", Main.npc[index].GivenOrTypeName);
}
if (text.Contains("{coin}"))
{
text = text.Replace("{coin}", coin.ToString());
}
playermsg(i, text);
break;
default:
TShock.Players[i].SendWarningMessage(text);
break;
}

//System.Diagnostics.Debug.WriteLine($"你因击败了{Main.npc[index].GivenOrTypeName}而获得{coin}经验");

if (Db.Queryuser(account))
Expand All @@ -62,5 +102,34 @@ public void AddDamage(int npc, int player, int damage)
{
this.damage[npc, player] += damage;
}

public void allmsg(int id, string msg)
{
Random rd = new Random();
int r = rd.Next(0, 255);
int g = rd.Next(0, 255);
int b = rd.Next(0, 255);
string message = msg;
Microsoft.Xna.Framework.Color c = new Microsoft.Xna.Framework.Color(r, g, b);
NetMessage.SendData(119,
-1, -1, NetworkText.FromLiteral(message), (int)c.PackedValue, TShock.Players[id].X, TShock.Players[id].Y + 50);



}
public void playermsg(int id, string msg)
{
Random rd = new Random();
int r = rd.Next(0, 255);
int g = rd.Next(0, 255);
int b = rd.Next(0, 255);
string message = msg;
Microsoft.Xna.Framework.Color c = new Microsoft.Xna.Framework.Color(r, g, b);

TShock.Players[id].SendData((PacketTypes)119, message, (int)c.PackedValue, TShock.Players[id].X, TShock.Players[id].Y + 50);



}
}
}
43 changes: 11 additions & 32 deletions db.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,46 +12,25 @@ namespace POBC2
//fixme: defend against the sql injection
public static class Db
{
private static IDbConnection db;


public static void Connect() //连接属性
{
switch (TShock.Config.StorageType.ToLower())
{
case "mysql":
string[] dbHost = TShock.Config.MySqlHost.Split(':');
db = new MySqlConnection()
{
ConnectionString = string.Format("Server={0}; Port={1}; Database={2}; Uid={3}; Pwd={4};",
dbHost[0],
dbHost.Length == 1 ? "3306" : dbHost[1],
TShock.Config.MySqlDbName,
TShock.Config.MySqlUsername,
TShock.Config.MySqlPassword)

};
break;

case "sqlite":
string sql = Path.Combine(TShock.SavePath, "tshock.sqlite");
db = new SqliteConnection(string.Format("uri=file://{0},Version=3", sql));
break;

}

SqlTableCreator sqlcreator = new SqlTableCreator(db, db.GetSqlType() == SqlType.Sqlite ? (IQueryBuilder)new SqliteQueryCreator() : new MysqlQueryCreator());
SqlTableCreator sqlcreator = new SqlTableCreator(TShock.DB, TShock.DB.GetSqlType() == SqlType.Sqlite ? (IQueryBuilder)new SqliteQueryCreator() : new MysqlQueryCreator());

sqlcreator.EnsureTableStructure(new SqlTable("POBC",
new SqlColumn("ID", MySqlDbType.Int32) { Primary = true, Unique = true, Length = 7, AutoIncrement = true },
new SqlColumn("UserName", MySqlDbType.Text) { Length = 500 },
new SqlColumn("Currency", MySqlDbType.Int32) { Length = 255 }));
}

public static bool Queryuser(string user)
{
bool u;
// string query = "SELECT * FROM POBC WHERE UserName = @user";
using (QueryResult reader = db.QueryReader("SELECT * FROM POBC WHERE UserName = @0",user))
using (QueryResult reader = TShock.DB.QueryReader("SELECT * FROM POBC WHERE UserName = @0",user))
{
if (reader.Read())
{
Expand All @@ -67,23 +46,23 @@ public static bool Queryuser(string user)

public static void UpC(string user, int data,string str="未填写原因")
{
// string query = $"UPDATE POBC SET Currency = Currency + {data} WHERE UserName = '{user};";
db.Query("UPDATE POBC SET Currency = Currency + @0 WHERE UserName = @1",data,user);
// string query = $"UPDATE POBC SET Currency = Currency + {data} WHERE UserName = '{user};";
TShock.DB.Query("UPDATE POBC SET Currency = Currency + @0 WHERE UserName = @1",data,user);
POBCSystem.Log($"\r\n{user}增加了{data}货币 原因:{str}");
}

public static void DownC(string user, int data,string str = "未填写原因")
{
// string query = $"UPDATE POBC SET Currency = Currency - {data} WHERE UserName = '{user}';";
db.Query("UPDATE POBC SET Currency = Currency - @0 WHERE UserName = @1",data,user);
// string query = $"UPDATE POBC SET Currency = Currency - {data} WHERE UserName = '{user}';";
TShock.DB.Query("UPDATE POBC SET Currency = Currency - @0 WHERE UserName = @1",data,user);
Directory.CreateDirectory(TShock.SavePath + $"\\POBC\\");
POBCSystem.Log($"\r\n{user}扣除了{data}货币 原因:{str}");
}
public static void Adduser(string user, int data ,string str="未填写原因")
{
// string query = $"INSERT INTO POBC (UserName,Currency) VALUES ('{user}','{data}');";
// string query = $"INSERT INTO POBC (UserName,Currency) VALUES ('{user}','{data}');";

db.Query("INSERT INTO POBC (UserName,Currency) VALUES (@0,@1)",user,data);
TShock.DB.Query("INSERT INTO POBC (UserName,Currency) VALUES (@0,@1)",user,data);

Directory.CreateDirectory(TShock.SavePath + $"\\POBC\\");
POBCSystem.Log($"\r\n{user}增加了{data}货币 原因:{str}");
Expand All @@ -93,7 +72,7 @@ public static int QueryCurrency(string user)
{
int u;
//string query = $"SELECT Currency FROM POBC WHERE UserName = '{user}'";
using (QueryResult reader = db.QueryReader("SELECT Currency FROM POBC WHERE UserName = @0", user))
using (QueryResult reader = TShock.DB.QueryReader("SELECT Currency FROM POBC WHERE UserName = @0", user))
{
if (reader.Read())
{
Expand Down

0 comments on commit b0cf709

Please sign in to comment.