protected override bool OnPlayerChatHooked(PlayerInfo playerInfo, string message) { if (message == QueryListCmd) { List <CityPositionDto> dtos = _cityPositionService.GetAll("CityName ASC"); if (dtos.Count == 0) { SdtdConsole.Instance.SendMessageToPlayer(playerInfo.SteamID, "[00FF00]暂无公共城镇信息"); } else { SdtdConsole.Instance.SendMessageToPlayer(playerInfo.SteamID, "[00FF00]可用公共城镇:"); StringBuilder returnCmd = new StringBuilder(); int index = 1; foreach (var item in dtos) { returnCmd.Append(string.Format("pm {0} \"[00FF00]{1}{2}\"\r\n", playerInfo.SteamID, index, FormatCmd(playerInfo, QueryListTips, item))); ++index; } SdtdConsole.Instance.SendCmd(returnCmd.ToString()); } } else { CityPositionDto cityPosition = _cityPositionService.GetDataByID(message); if (cityPosition == null) { return(false); } else { var teleRecord = _teleRecordService.GetDataByID(playerInfo.SteamID); if (teleRecord != null && string.IsNullOrEmpty(teleRecord.LastTeleDateTime) == false) { int timeSpan = (int)(DateTime.Now - DateTime.Parse(teleRecord.LastTeleDateTime)).TotalSeconds; if (timeSpan < TeleInterval)// 正在冷却 { SdtdConsole.Instance.SendMessageToPlayer(playerInfo.SteamID, FormatCmd(playerInfo, TeleFailTips2, TeleInterval - timeSpan)); return(true); } } int playerScore = _scoreInfoService.GetPlayerScore(playerInfo.SteamID); if (playerScore < cityPosition.TeleNeedScore)// 积分不足 { SdtdConsole.Instance.SendMessageToPlayer(playerInfo.SteamID, FormatCmd(playerInfo, TeleFailTips1, cityPosition)); } else { _scoreInfoService.DeductPlayerScore(playerInfo.SteamID, cityPosition.TeleNeedScore); SdtdConsole.Instance.TelePlayer(playerInfo.SteamID, cityPosition.Pos); SdtdConsole.Instance.SendGlobalMessage(FormatCmd(playerInfo, TeleSucceedTips, cityPosition)); // 记录传送日期 var dto = new TeleRecordDto() { SteamID = playerInfo.SteamID, LastTeleDateTime = DateTime.Now.ToString() }; if (teleRecord == null) { _teleRecordService.Add(dto); } else { _teleRecordService.Update(dto); } Log.Info(string.Format("玩家: {0} SteamID: {1} 传送到了: {2}", playerInfo.PlayerName, playerInfo.SteamID, cityPosition.CityName)); } } } return(true); }
protected override bool OnPlayerChatHooked(PlayerInfo playerInfo, string message) { if (message == QueryListCmd) { QueryList(playerInfo); } else if (message.StartsWith(SetHomeCmdPrefix) && message.Length > SetHomeCmdPrefix.Length) { string homeName = message.Substring(SetHomeCmdPrefix.Length + 1); if (string.IsNullOrEmpty(homeName)) { SdtdConsole.Instance.SendMessageToPlayer(playerInfo.SteamID, "Home名称不能为空"); return(true); } List <HomePositionDto> dtos = _homePositionService.GetDataBySteamID(playerInfo.SteamID); _currentPlayerOwnedHomeCount = dtos.Count; if (_currentPlayerOwnedHomeCount >= MaxCanSetCount) { SdtdConsole.Instance.SendMessageToPlayer(playerInfo.SteamID, FormatCmd(playerInfo, Tips3)); } else { int playerScore = _scoreInfoService.GetPlayerScore(playerInfo.SteamID); if (playerScore < GetSetHomeNeedScore())// 设置需要积分不足提示 { SdtdConsole.Instance.SendMessageToPlayer(playerInfo.SteamID, FormatCmd(playerInfo, Tips4)); } else { var dto = dtos.Find(p => p.HomeName == homeName); if (dto == null)// 首次设置Home成功提示 { dto = new HomePositionDto() { HomeName = homeName, PlayerName = playerInfo.PlayerName, SteamID = playerInfo.SteamID, Pos = playerInfo.Pos }; _homePositionService.Add(dto); SdtdConsole.Instance.SendMessageToPlayer(playerInfo.SteamID, FormatCmd(playerInfo, Tips6, dto)); } else// Home名称已存在覆盖提示 { dto.HomeName = homeName; dto.PlayerName = playerInfo.PlayerName; dto.SteamID = playerInfo.SteamID; dto.Pos = playerInfo.Pos; _homePositionService.Update(dto); SdtdConsole.Instance.SendMessageToPlayer(playerInfo.SteamID, FormatCmd(playerInfo, Tips5, dto)); } Log.Info(string.Format("玩家: {0} SteamID: {1} 设置了Home: {2} 三维坐标: {3}", playerInfo.PlayerName, playerInfo.SteamID, homeName, playerInfo.Pos)); } } } else if (message.StartsWith(TeleHomeCmdPrefix) && message.Length > TeleHomeCmdPrefix.Length) { string homeName = message.Substring(TeleHomeCmdPrefix.Length + 1); HomePositionDto dto = _homePositionService.GetDataBySteamIDAndHomeName(playerInfo.SteamID, homeName); if (dto == null) { SdtdConsole.Instance.SendMessageToPlayer(playerInfo.SteamID, FormatCmd(playerInfo, Tips8)); } else { var teleRecord = _teleRecordService.GetDataByID(playerInfo.SteamID); if (teleRecord != null && string.IsNullOrEmpty(teleRecord.LastTeleDateTime) == false) { int timeSpan = (int)(DateTime.Now - DateTime.Parse(teleRecord.LastTeleDateTime)).TotalSeconds; if (timeSpan < TeleInterval)// 正在冷却 { SdtdConsole.Instance.SendMessageToPlayer(playerInfo.SteamID, FormatCmd(playerInfo, Tips9, TeleInterval - timeSpan)); return(true); } } int playerScore = _scoreInfoService.GetPlayerScore(playerInfo.SteamID); if (playerScore < TeleNeedScore)// 传送需要积分不足提示 { SdtdConsole.Instance.SendMessageToPlayer(playerInfo.SteamID, FormatCmd(playerInfo, Tips7)); } else { _scoreInfoService.DeductPlayerScore(playerInfo.SteamID, TeleNeedScore); SdtdConsole.Instance.TelePlayer(playerInfo.SteamID, dto.Pos); SdtdConsole.Instance.SendGlobalMessage(FormatCmd(playerInfo, Tips10, dto)); // 记录传送日期 var tempDto = new TeleRecordDto() { SteamID = playerInfo.SteamID, LastTeleDateTime = DateTime.Now.ToString() }; if (teleRecord == null) { _teleRecordService.Add(tempDto); } else { _teleRecordService.Update(tempDto); } Log.Info(string.Format("玩家: {0} SteamID: {1} 传送到了: {2}", playerInfo.PlayerName, playerInfo.SteamID, dto.HomeName)); } } } else { return(false); } return(true); }