public void Save(int userId, PlayerPvpData data) { bool exist; using (var reader = _database.QueryReader("SELECT * FROM PvpRecord WHERE Id=@0", userId)) { exist = reader?.Read() == true; } try { _database.Query(exist ? "UPDATE PvpRecord SET Eliminations = @0, Deaths = @1, DamageDone = @2, Endurance = @3, KillStreak = @4, BestKillStreak = @5 WHERE Id = @6;" : "INSERT INTO PvpRecord (Eliminations, Deaths, DamageDone, Endurance, KillStreak, BestKillStreak, Id) VALUES (@0, @1, @2, @3, @4, @5, @6);", data.Eliminations, data.Deaths, data.DamageDone, data.Endurance, data.KillStreak, data.BestKillStreak, userId); } catch (Exception ex) { TShock.Log.Error(ex.ToString()); } }
private static void OnGreetPlayer(GreetPlayerEventArgs args) { var player = TShock.Players[args.Who]; if (player == null) { return; } PlayerPvpData.LoadPlayerData(player); player.SetData(PvpAllow, true); }
private static void OnPlayerDamage(object sender, GetDataHandlers.PlayerDamageEventArgs args) { // 记录 伤害量 var data = PlayerPvpData.GetPlayerData(args.Player); var calculatedDmg = (int)Main.CalculatePlayerDamage(args.Damage, Main.player[args.ID].statDefense); data.Damage(calculatedDmg); // 记录 承受伤害量 PlayerPvpData.GetPlayerData(args.ID).Hurt(calculatedDmg); }
private static void OnLeave(LeaveEventArgs args) { var player = TShock.Players[args.Who]; var data = PlayerPvpData.GetPlayerData(player); if (data == null) { return; } PvpDatas.Save(player.Account.ID, data); }
private static void OnPostSaveWorld(bool useCloudSaving, bool resetTime) { foreach (var plr in TShock.Players.Where(p => p?.Active == true && p.TPlayer?.hostile == true)) { var data = PlayerPvpData.GetPlayerData(plr); if (data == null) { continue; } PvpDatas.Save(plr.Account.ID, data); } }
private void OnTimerUpdate(object sender, ElapsedEventArgs elapsedEventArgs) { if (!Config.AutoBroadcastBestKiller) { return; } if (++_timerCount < Config.AutoBroadcastSeconds) { return; } if (Main.player.Where(p => p?.active == true).All(p => !p.hostile)) { return; } var max = (from player in TShock.Players where player?.Active == true && player.RealPlayer && player.TPlayer.hostile let data = PlayerPvpData.GetPlayerData(player.Index) orderby data.KillStreak descending select data).ToArray(); var sb = new StringBuilder(new string('=', 10)).Append("PvP战绩排行").AppendLine(new string('=', 10)); for (var i = 0; i < 3; ++i) { if (max.Length <= i) { break; } sb .Append($"第{(i + 1).ToChineseCharacterDigit()}名: {max[i].KillStreak.ToChineseCharacterDigit()}连杀".PadRight(13)) .Append(" —— ") .AppendLine(TShock.Players[max.ElementAt(i).PlayerIndex].Name); } var sbText = sb.ToString().TrimEnd(); foreach (var player in TShock.Players.Where(p => p != null && p.Active && p.RealPlayer && p.TPlayer.hostile)) { player.SendMessage(sbText, Color.Orange); } _timerCount = 0; }
private static void OnKillMe(object sender, GetDataHandlers.KillMeEventArgs args) { if (!args.Pvp) { return; } args.Player.RespawnTimer = Nanami.Config.RespawnPvPSeconds; var data = PlayerPvpData.GetPlayerData(args.Player); // 处理死亡事件 data.Die(args.Damage); var killer = args.PlayerDeathReason.SourcePlayerIndex; var killerProj = args.PlayerDeathReason.SourceProjectileType; var killerItem = args.PlayerDeathReason.SourceItemType; var deathText = "被{0}的{1}杀死了!"; if (killerProj != 0) { deathText = string.Format(deathText, TShock.Players[killer].Name, Lang.GetProjectileName(killerProj)); } else if (killerItem != 0) { deathText = string.Format(deathText, TShock.Players[killer].Name, Lang.GetItemNameValue(killerItem)); } else { deathText = $"被{TShock.Players[killer].Name}杀死了!"; } // 处理杀死事件 var killerData = PlayerPvpData.GetPlayerData(killer); killerData.Kill(ref deathText); args.PlayerDeathReason.SourceCustomReason = args.Player.Name + deathText; Main.player[args.PlayerId].KillMe(args.PlayerDeathReason, args.Damage, args.Direction, true); NetMessage.SendPlayerDeath(args.PlayerId, args.PlayerDeathReason, args.Damage, args.Direction, true, -1, args.Player.Index); args.Handled = true; }
public PlayerPvpData Load(TSPlayer player) { try { using (var reader = _database.QueryReader("SELECT * FROM PvpRecord WHERE Id=@0", player.Account.ID)) { if (reader?.Read() == true) { return(PlayerPvpData.LoadFromDb(player.Index, reader)); } } } catch (Exception ex) { TShock.Log.Error(ex.ToString()); } return(new PlayerPvpData(player.Index)); }
private static void Show(CommandArgs args) { if (args.Parameters.Count == 0 && !args.Player.RealPlayer) { args.Player.SendErrorMessage("只有玩家才能使用战绩."); return; } var player = args.Player; if (args.Parameters.Count > 0) { var players = TSPlayer.FindByNameOrID(string.Join(" ", args.Parameters)); if (players.Count == 0) { args.Player.SendErrorMessage("指定玩家无效!"); return; } if (players.Count > 1) { args.Player.SendMultipleMatchError(players.Select(p => p.Name)); return; } player = players.Single(); if (!player.GetData <bool>(PvpAllow) && !args.Player.HasPermission("nanami.pvp.showother")) { args.Player.SendErrorMessage("{0} 已经禁止别人查看其战绩.", player.Name); return; } } var dt = PlayerPvpData.GetPlayerData(player.Index); args.Player.SendInfoMessage($"{"---- {0}的PvP战绩 ----",38}", player.Name); args.Player.SendInfoMessage($"{"",11}* | 消灭 {dt.Eliminations,8} | {"连续消灭数目",6} {dt.KillStreak,8} |"); args.Player.SendInfoMessage($"{"",11}* | 伤害 {dt.DamageDone,8} | {"总承受伤害量",6} {dt.Endurance,8} |"); args.Player.SendInfoMessage($"{"",11}* | 死亡 {dt.Deaths,8} | {"最大连续消灭",6} {dt.BestKillStreak,8} |"); }