Skip to content

Commit

Permalink
exp
Browse files Browse the repository at this point in the history
新增Rp面板 sm_rp 查看局内玩家详细数据
改动exp算法 降低游戏时长对exp的影响
将对抗总局数纳入算法
  • Loading branch information
cH1yoi committed Dec 8, 2024
1 parent 8048121 commit 4193cfd
Show file tree
Hide file tree
Showing 3 changed files with 144 additions and 15 deletions.
16 changes: 12 additions & 4 deletions Dedicated Server Install Guide/demo/cleanup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,22 @@ total_files=0
log_message "开始清理任务..."
log_message "检查目录: $DEMO_DIR"

# 添加调试信息,显示找到的文件
found_files=$(find "$DEMO_DIR" -type f -name "*.zip" -mtime +$DAYS_TO_KEEP)
log_message "找到的文件: $found_files"

while IFS= read -r file; do
size=$(stat -f %z "$file" 2>/dev/null || stat -c %s "$file" 2>/dev/null)
# 使用 -c 选项确保输出格式一致
size=$(sudo stat -c %s "$file" 2>/dev/null)
if [ $? -ne 0 ]; then
log_message "无法获取文件大小: $file"
continue
fi
size_mb=$(echo "scale=2; $size/1024/1024" | bc)

log_message "删除文件: $file (${size_mb}MB)"

rm "$file"
sudo rm "$file"

total_size=$((total_size + size))
total_files=$((total_files + 1))
Expand All @@ -33,5 +42,4 @@ log_message "- 删除文件数: $total_files"
log_message "- 释放空间: ${total_size_mb}MB"
log_message "----------------------------------------"

find "$DEMO_DIR" -type d -empty -delete 2>/dev/null

sudo find "$DEMO_DIR" -type d -empty -delete 2>/dev/null
Binary file modified addons/sourcemod/plugins/exp_interface.smx
Binary file not shown.
143 changes: 132 additions & 11 deletions addons/sourcemod/scripting/exp_interface.sp
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,25 @@ enum struct PlayerInfo{
int smgkills;
int shotgunkills;
int type;
int gamesplayed;

// 理论最高分
int get_player_maxrankpoint(){
return this.gametime + this.versustotal;
return this.gametime + this.gamesplayed;
}

// 场均击杀
float kill_per_round(){
int kills = this.smgkills + this.shotgunkills;
return float(kills) / float(this.versustotal);
return float(kills) / float(this.gamesplayed);
}

float rock_per_round(){
return float(this.tankrocks) / float(this.versustotal);
return float(this.tankrocks) / float(this.gamesplayed);
}

float hour_per_round(){
return float(this.gametime) / float(this.versustotal);
return float(this.gametime) / float(this.gamesplayed);
}

// 击杀数修正
Expand All @@ -57,19 +58,131 @@ PlayerInfo PlayerInfoData[MAXPLAYERS];
int GetTimeOut[MAXPLAYERS] = {5};
Logger log;
Handle g_hForward_OnGetExp;

public void OnPluginStart(){
log = new Logger("exp_interface", LoggerType_NewLogFile);
log.IgnoreLevel = LogType_Info;
if (log.FileSize > 1024*1024*5) log.DelLogFile();
log.logfirst("exp interface log记录");

RegConsoleCmd("sm_rp", Command_ShowRPMenu, "显示玩家数据菜单");

for (int i = 1; i <= MaxClients; i++){
if (IsClientInGame(i) && !IsFakeClient(i)){
GetTimeOut[i] = MAX_RETRY;
CreateTimer(0.1, Timer_GetClientExp, i);
}
}
}

public Action Command_ShowRPMenu(int client, int args)
{
if(!IS_VALID_CLIENT(client)) return Plugin_Handled;

Menu menu = new Menu(RPMenuHandler);
menu.SetTitle("玩家数据查看\n ");

char name[64], info[8];
for(int i = 1; i <= MaxClients; i++)
{
if(IsClientInGame(i) && !IsFakeClient(i))
{
GetClientName(i, name, sizeof(name));
IntToString(i, info, sizeof(info));
menu.AddItem(info, name);
}
}

menu.Display(client, MENU_TIME_FOREVER);
return Plugin_Handled;
}

public int RPMenuHandler(Menu menu, MenuAction action, int param1, int param2)
{
switch(action)
{
case MenuAction_Select:
{
char info[8];
menu.GetItem(param2, info, sizeof(info));
int target = StringToInt(info);

if(IS_VALID_CLIENT(target) && IsClientInGame(target))
{
ShowPlayerStats(param1, target);
}
else
{
PrintToChat(param1, "选择的玩家已不在游戏中");
}
}
case MenuAction_End:
{
delete menu;
}
}
return 0;
}

void ShowPlayerStats(int client, int target)
{
Menu statsMenu = new Menu(StatsMenuHandler);

char title[256];
Format(title, sizeof(title), "%N 的详细数据\n ", target);
statsMenu.SetTitle(title);

char buffer[128];
Format(buffer, sizeof(buffer), "游戏时长: %d小时", PlayerInfoData[target].gametime);
statsMenu.AddItem("", buffer, ITEMDRAW_DISABLED);

Format(buffer, sizeof(buffer), "总分: %d", PlayerInfoData[target].rankpoint);
statsMenu.AddItem("", buffer, ITEMDRAW_DISABLED);

Format(buffer, sizeof(buffer), "对抗总场次: %d", PlayerInfoData[target].gamesplayed);
statsMenu.AddItem("", buffer, ITEMDRAW_DISABLED);

Format(buffer, sizeof(buffer), "完成场次: %d", PlayerInfoData[target].versustotal);
statsMenu.AddItem("", buffer, ITEMDRAW_DISABLED);

Format(buffer, sizeof(buffer), "对抗胜场: %d", PlayerInfoData[target].versuswin);
statsMenu.AddItem("", buffer, ITEMDRAW_DISABLED);

Format(buffer, sizeof(buffer), "胜率: %.1f%%", PlayerInfoData[target].winrounds * 100.0);
statsMenu.AddItem("", buffer, ITEMDRAW_DISABLED);

Format(buffer, sizeof(buffer), "SMG击杀: %d", PlayerInfoData[target].smgkills);
statsMenu.AddItem("", buffer, ITEMDRAW_DISABLED);

Format(buffer, sizeof(buffer), "散弹击杀: %d", PlayerInfoData[target].shotgunkills);
statsMenu.AddItem("", buffer, ITEMDRAW_DISABLED);

Format(buffer, sizeof(buffer), "Tank石头: %d", PlayerInfoData[target].tankrocks);
statsMenu.AddItem("", buffer, ITEMDRAW_DISABLED);

Format(buffer, sizeof(buffer), "场均击杀: %.1f", PlayerInfoData[target].kill_per_round());
statsMenu.AddItem("", buffer, ITEMDRAW_DISABLED);

Format(buffer, sizeof(buffer), "场均石头: %.1f", PlayerInfoData[target].rock_per_round());
statsMenu.AddItem("", buffer, ITEMDRAW_DISABLED);

statsMenu.Display(client, MENU_TIME_FOREVER);
}

public int StatsMenuHandler(Menu menu, MenuAction action, int param1, int param2)
{
if(action == MenuAction_End)
{
delete menu;
}
else if(action == MenuAction_Cancel)
{
if(param2 == MenuCancel_ExitBack)
{
Command_ShowRPMenu(param1, 0);
}
}
return 0;
}

public void OnClientPutInServer(int iClient)
Expand All @@ -89,6 +202,7 @@ public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max
RegPluginLibrary("exp_interface");
return APLRes_Success;
}

public int _Native_CheckAndGetAllClient(Handle plugin, int numParams)
{
if (log.IgnoreLevel == LogType_Debug){
Expand All @@ -100,7 +214,8 @@ public int _Native_CheckAndGetAllClient(Handle plugin, int numParams)
if (IsClientInGame(i) && !IsFakeClient(i)){
if (PlayerInfoData[i].rankpoint <= 0){
GetTimeOut[i] = MAX_RETRY;
CreateTimer(0.1, Timer_GetClientExp, i); }
CreateTimer(0.1, Timer_GetClientExp, i);
}
}
}
return 0;
Expand Down Expand Up @@ -129,7 +244,9 @@ public void ClearClientExpData(int client){
PlayerInfoData[client].versuswin = 0;
PlayerInfoData[client].versustotal = 0;
PlayerInfoData[client].winrounds = 0.0;
PlayerInfoData[client].gamesplayed = 0;
}

public Action Timer_GetClientExp(Handle timer, int iClient){
GetTimeOut[iClient]--;
ClearClientExpData(iClient);
Expand Down Expand Up @@ -157,7 +274,7 @@ public Action Timer_GetClientExp(Handle timer, int iClient){
Call_PushCell(res);
Call_Finish();
// global forward
log.info("[%N] Total: %i, gametime: %i, rankpoint: %i, shotgunkills: %i, smgkills:%i, tankrocks: %i, versuswin: %i, versustotal:%i, maxrankpoint: %i, kill_per_round: %.0f, rock_per_round: %.0f, hour_per_round: %.0f",
log.info("[%N] Total: %i, gametime: %i, rankpoint: %i, shotgunkills: %i, smgkills:%i, tankrocks: %i, versuswin: %i, versustotal:%i, gamesplayed: %i, maxrankpoint: %i, kill_per_round: %.0f, rock_per_round: %.0f, hour_per_round: %.0f",
iClient, res,
PlayerInfoData[iClient].gametime,
PlayerInfoData[iClient].rankpoint,
Expand All @@ -166,6 +283,7 @@ public Action Timer_GetClientExp(Handle timer, int iClient){
PlayerInfoData[iClient].tankrocks,
PlayerInfoData[iClient].versuswin,
PlayerInfoData[iClient].versustotal,
PlayerInfoData[iClient].gamesplayed,
PlayerInfoData[iClient].get_player_maxrankpoint(),
PlayerInfoData[iClient].kill_per_round(),
PlayerInfoData[iClient].rock_per_round(),
Expand All @@ -186,13 +304,13 @@ public int GetClientRP(int iClient){
PlayerInfoData[iClient].gametime = PlayerInfoData[iClient].gametime/3600;
status = SteamWorks_GetStatCell(iClient, "Stat.SpecAttack.Tank", PlayerInfoData[iClient].tankrocks) &&
SteamWorks_GetStatCell(iClient, "Stat.GamesLost.Versus", PlayerInfoData[iClient].versuslose) &&
SteamWorks_GetStatCell(iClient, "Stat.GamesWon.Versus", PlayerInfoData[iClient].versuswin);
SteamWorks_GetStatCell(iClient, "Stat.GamesWon.Versus", PlayerInfoData[iClient].versuswin) &&
SteamWorks_GetStatCell(iClient, "Stat.GamesPlayed.Versus", PlayerInfoData[iClient].gamesplayed);
if (!status) {
log.warning("获取 %N 的数据信息时失败了", iClient);
return -2;
}


PlayerInfoData[iClient].versustotal = PlayerInfoData[iClient].versuslose + PlayerInfoData[iClient].versuswin;
PlayerInfoData[iClient].smgkills = 0;
PlayerInfoData[iClient].shotgunkills = 0;
Expand Down Expand Up @@ -221,10 +339,13 @@ int Calculate_RP(PlayerInfo tPlayer)
int killtotal = tPlayer.shotgunkills + tPlayer.smgkills;
float shotgunperc = float(tPlayer.shotgunkills) / float(killtotal);
float maxrp = float(tPlayer.get_player_maxrankpoint()) * 1.135;

float rp =
0.55 * float(tPlayer.gametime) * (tPlayer.hour_per_round() > 5.73 ? 5.73 / tPlayer.hour_per_round() : 1.0) +
float(tPlayer.tankrocks) * 0.65 * (tPlayer.rock_per_round() > 1.88 ? 1.88 / tPlayer.rock_per_round() : 1.0) +
0.25 * float(tPlayer.gametime) * (tPlayer.hour_per_round() > 5.73 ? 5.73 / tPlayer.hour_per_round() : 1.0) +
0.40 * float(tPlayer.gamesplayed) +
float(tPlayer.tankrocks) * 0.75 * (tPlayer.rock_per_round() > 1.88 ? 1.88 / tPlayer.rock_per_round() : 1.0) +
(float(killtotal) * 0.005 * (tPlayer.kill_per_round() > 570.0 ? 570.0 / tPlayer.kill_per_round() : 1.0) * (shotgunperc));

if (rp > maxrp) rp = maxrp;
return RoundToNearest(rp);
}
}

0 comments on commit 4193cfd

Please sign in to comment.