Skip to content

Commit

Permalink
适配性的大航海消息
Browse files Browse the repository at this point in the history
  • Loading branch information
CHKZL committed Jul 22, 2024
1 parent 38325b3 commit fefe7b3
Show file tree
Hide file tree
Showing 6 changed files with 145 additions and 65 deletions.
65 changes: 23 additions & 42 deletions Core/LiveChat/GuardBuyEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,61 +8,42 @@

namespace Core.LiveChat
{
public class SendGiftEventArgs : MessageEventArgs
public class GuardBuyEventArgs : MessageEventArgs
{
public long UserId { get; set; }

public string UserName { get; set; }

public int GuardLevel { get; set; }
public string GiftAction { get; set; }
/// <summary>
/// 礼物编号
/// </summary>
public int GiftId { get; set; }
/// <summary>
/// 礼物类型
/// </summary>
public int GiftType { get; set; }
/// <summary>
/// 礼物名称
/// </summary>
public string GiftName { get; set; }
/// <summary>
/// 礼物价值
/// 舰长等级:1-总督 2-提督 3-舰长
/// </summary>
public float GiftPrice { get; set; }
public int GuardLevel { get; set; }

public string GuardName { get; set; }

public int TotalCoin { get; set; }
/// <summary>
/// 礼物数量
/// 花费:单位金瓜子
/// </summary>
public int Amount { get; set; }
public int Price { get; set; }

public bool IsGoldGift { get; set; }
public long UserId { get; set; }

public string CoinType { get; set; }
public string UserName { get; set; }

public long Timestamp { get; set; }
//public string GiftId { get; set; }

public string AvatarUrl { get; set; }
/// <summary>
/// 数量
/// </summary>
public int Number { get; set; }
public long Timestamp { get; set; }

internal SendGiftEventArgs(JsonObject obj) : base(obj)
internal GuardBuyEventArgs(JsonObject obj) : base(obj)
{
UserId = (long)obj["data"]["uid"];
UserName = (string)obj["data"]["uname"];
TotalCoin = (int)obj["data"]["total_coin"];
Amount = (int)obj["data"]["num"];
GiftName = (string)obj["data"]["giftName"];
GiftId = (int)obj["data"]["giftId"];
GiftType = (int)obj["data"]["giftType"];
GiftPrice = (float)obj["data"]["price"];
GuardLevel = (int)obj["data"]["guard_level"];
GiftAction = (string)obj["data"]["action"];
CoinType = (string)obj["data"]["coin_type"];
IsGoldGift = (string)obj["data"]["coin_type"] == "gold";
Timestamp = (long)obj["data"]["timestamp"];
AvatarUrl = (string)obj["data"]["face"];
UserId = (long)obj["data"]["uid"];
UserName = (string)obj["data"]["username"];
GuardName = (string)obj["data"]["gift_name"];
Price = (int)obj["data"]["price"];
Number = (int)obj["data"]["num"];
Timestamp = (long)obj["data"]["start_time"];
//GiftId = obj["data"]["gift_id"].Value<string>();//舰长没有
}
}
}
55 changes: 55 additions & 0 deletions Core/LiveChat/GuardRenewEventArgs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using Core.LogModule;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.Json.Nodes;
using System.Threading.Tasks;

namespace Core.LiveChat
{
public class GuardRenewEventArgs : MessageEventArgs
{
/// <summary>
/// 舰长等级:1-总督 2-提督 3-舰长
/// </summary>
public int GuardLevel { get; set; }

public string GuardName { get; set; }

/// <summary>
/// 花费:单位金瓜子
/// </summary>
public int Price { get; set; }

public long UserId { get; set; }

public string UserName { get; set; }

/// <summary>
/// 数量
/// </summary>
public int Number { get; set; }
public long Timestamp { get; set; }

internal GuardRenewEventArgs(JsonObject obj) : base(obj)
{
try
{
GuardLevel = (int)obj["data"]["guard_info"]["guard_level"];
UserId = (long)obj["data"]["sender_uinfo"]["uid"];
UserName = (string)obj["data"]["sender_uinfo"]["base"]["name"];
GuardName = (string)obj["data"]["guard_info"]["role_name"];
Price = (int)obj["data"]["pay_info"]["price"];
Number = (int)obj["data"]["pay_info"]["num"];
Timestamp = (long)obj["data"]["guard_info"]["start_time"];
}
catch (Exception ex)
{
Log.Warn(nameof(GuardRenewEventArgs), "转换大航海信息发生错误,可能阿B修改了数据结构,请检查数据格式", ex);
}
//GiftId = obj["data"]["gift_id"].Value<string>();//舰长没有
}
}
}
4 changes: 4 additions & 0 deletions Core/LiveChat/LiveChatListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,10 @@ private void _parse(string jsonBody)
break;
//续费舰长
case "USER_TOAST_MSG":
MessageReceived(this, new GuardRenewEventArgs(obj));
break;
case "USER_TOAST_MSG_V2":
MessageReceived(this, new GuardRenewEventArgs(obj));
break;
//在房间内续费了舰长
case "NOTICE_MSG":
Expand Down
65 changes: 42 additions & 23 deletions Core/LiveChat/SendGiftEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,42 +8,61 @@

namespace Core.LiveChat
{
public class GuardBuyEventArgs : MessageEventArgs
public class SendGiftEventArgs : MessageEventArgs
{
/// <summary>
/// 舰长等级:1-总督 2-提督 3-舰长
/// </summary>
public int GuardLevel { get; set; }
public long UserId { get; set; }

public string GuardName { get; set; }
public string UserName { get; set; }

public int GuardLevel { get; set; }
public string GiftAction { get; set; }
/// <summary>
/// 礼物编号
/// </summary>
public int GiftId { get; set; }
/// <summary>
/// 礼物类型
/// </summary>
public int GiftType { get; set; }
/// <summary>
/// 花费:单位金瓜子
/// 礼物名称
/// </summary>
public int Price { get; set; }
public string GiftName { get; set; }
/// <summary>
/// 礼物价值
/// </summary>
public float GiftPrice { get; set; }

public int UserId { get; set; }
public int TotalCoin { get; set; }
/// <summary>
/// 礼物数量
/// </summary>
public int Amount { get; set; }

public string UserName { get; set; }
public bool IsGoldGift { get; set; }

//public string GiftId { get; set; }
public string CoinType { get; set; }

/// <summary>
/// 数量
/// </summary>
public int Number { get; set; }
public long Timestamp { get; set; }

internal GuardBuyEventArgs(JsonObject obj) : base(obj)
public string AvatarUrl { get; set; }

internal SendGiftEventArgs(JsonObject obj) : base(obj)
{
UserId = (long)obj["data"]["uid"];
UserName = (string)obj["data"]["uname"];
TotalCoin = (int)obj["data"]["total_coin"];
Amount = (int)obj["data"]["num"];
GiftName = (string)obj["data"]["giftName"];
GiftId = (int)obj["data"]["giftId"];
GiftType = (int)obj["data"]["giftType"];
GiftPrice = (float)obj["data"]["price"];
GuardLevel = (int)obj["data"]["guard_level"];
UserId = (int)obj["data"]["uid"];
UserName = (string)obj["data"]["username"];
GuardName = (string)obj["data"]["gift_name"];
Price = (int)obj["data"]["price"];
Number = (int)obj["data"]["num"];
Timestamp = (long)obj["data"]["start_time"];
//GiftId = obj["data"]["gift_id"].Value<string>();//舰长没有
GiftAction = (string)obj["data"]["action"];
CoinType = (string)obj["data"]["coin_type"];
IsGoldGift = (string)obj["data"]["coin_type"] == "gold";
Timestamp = (long)obj["data"]["timestamp"];
AvatarUrl = (string)obj["data"]["face"];
}
}
}
16 changes: 16 additions & 0 deletions Core/RuntimeObject/Download/Basics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,22 @@ public static void LiveChatListener_MessageReceived(object? sender, Core.LiveCha
});
break;
}
case GuardRenewEventArgs guardRenewEvent:
{

liveChatListener.DanmuMessage.GuardBuy.Add(new Danmu.GuardBuyInfo()
{
GuardLevel = guardRenewEvent.GuardLevel,
GuradName = guardRenewEvent.GuardName,
Number = guardRenewEvent.Number,
Price = guardRenewEvent.Price,
Time = liveChatListener.TimeStopwatch.ElapsedMilliseconds / 1000.00,
Timestamp = guardRenewEvent.Timestamp,
UserId = guardRenewEvent.UserId,
UserName = guardRenewEvent.UserName
});
break;
}
case SendGiftEventArgs sendGiftEventArgs:
{
liveChatListener.DanmuMessage.Gift.Add(new Danmu.GiftInfo()
Expand Down
5 changes: 5 additions & 0 deletions Desktop/Views/Windows/DanmaOnlyWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ private void LiveChatListener_MessageReceived(object? sender, Core.LiveChat.Mess
msg.Message = $"{GuardBuyEvent.UserName}:购买大航海[{(GuardBuyEvent.GuardLevel == 1 ? "总督" : GuardBuyEvent.GuardLevel == 2 ? "提督" : "舰长")}]一共[{GuardBuyEvent.Number}]个月";
break;
}
case GuardRenewEventArgs guardRenewEvent:
{
msg.Message = $"{guardRenewEvent.UserName}:购买大航海[{(guardRenewEvent.GuardLevel == 1 ? "总督" : guardRenewEvent.GuardLevel == 2 ? "提督" : "舰长")}]一共[{guardRenewEvent.Number}]个月";
break;
}
case SendGiftEventArgs sendGiftEventArgs:
{
msg.Message = $"{sendGiftEventArgs.UserName}:赠送[{sendGiftEventArgs.GiftName}]礼物[{sendGiftEventArgs.Amount}]个";
Expand Down

0 comments on commit fefe7b3

Please sign in to comment.