117 lines
4.0 KiB
C#
117 lines
4.0 KiB
C#
using Assets.MyGame.Scripts.Net;
|
|
using Newtonsoft.Json;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
[Serializable]
|
|
public class WebSocketSendList
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
/// SignalR 消息类型,客户端调用服务器永远是 1
|
|
/// </summary>
|
|
public int type = 1;
|
|
|
|
/// <summary>
|
|
/// 调用 ID(字符串也可以)
|
|
/// 用来区分不同请求,可随便填
|
|
/// </summary>
|
|
public string invocationId;
|
|
|
|
/// <summary>
|
|
/// 要调用的服务器方法名,例如:JoinRoom、KillFish、Fire
|
|
/// </summary>
|
|
public string target;
|
|
|
|
/// <summary>
|
|
/// 参数数组(SignalR 要求必须是数组)
|
|
/// </summary>
|
|
public List<object> arguments;
|
|
public WebSocketSendList(string target, params object[] param)
|
|
{
|
|
|
|
invocationId = "1";
|
|
this.target = target;
|
|
arguments = param.ToList();
|
|
}
|
|
/// <summary>
|
|
/// 打中鱼
|
|
/// </summary>
|
|
/// <param name="roomId"></param>
|
|
/// <param name="userId"></param>
|
|
/// <param name="fishNumber">配置id</param>
|
|
/// <param name="fishId">唯一id</param>
|
|
public static void KillFish(string roomId, string userId, string fishNumber, string fishId,int paoBei)
|
|
{
|
|
var sendObj = new WebSocketSendList("KillFish", roomId, userId, fishNumber, fishId, paoBei, DateTimeOffset.UtcNow.ToUnixTimeSeconds());
|
|
WebSocketManager.Instance.Send(SocketType.game, JsonConvert.SerializeObject(sendObj));
|
|
}
|
|
/// <summary>
|
|
/// 发射子弹
|
|
/// </summary>
|
|
/// <param name="roomId"></param>
|
|
/// <param name="userId"></param>
|
|
/// <param name="gold">单价</param>
|
|
/// <param name="count">数量</param>
|
|
public static void ShootBullet(string roomId, string userId, int gold, int count)
|
|
{
|
|
var sendObj = new WebSocketSendList("ShootBullet", roomId, userId, gold, count);
|
|
WebSocketManager.Instance.Send(SocketType.game, JsonConvert.SerializeObject(sendObj));
|
|
}
|
|
/// <summary>
|
|
/// 链接登录界面ws
|
|
/// </summary>
|
|
/// <param name="userId"></param>
|
|
public static void Bind(string userId)
|
|
{
|
|
var sendObj = new WebSocketSendList("Bind", userId);
|
|
WebSocketManager.Instance.Send(SocketType.login, JsonConvert.SerializeObject(sendObj));
|
|
}
|
|
/// <summary>
|
|
/// 加入房间
|
|
/// </summary>
|
|
/// <param name="roomId"></param>
|
|
/// <param name="userId"></param>
|
|
/// <param name="level">房间等级</param>
|
|
public static void JoinRoom(string roomId, string userId, int level)
|
|
{
|
|
var sendObj = new WebSocketSendList("JoinRoom", roomId, userId, level);
|
|
WebSocketManager.Instance.Send(SocketType.game, JsonConvert.SerializeObject(sendObj));
|
|
}
|
|
/// <summary>
|
|
/// 使用道具
|
|
/// </summary>
|
|
/// <param name="roomId"></param>
|
|
/// <param name="userId"></param>
|
|
/// <param name="propNumber">道具id</param>
|
|
/// <param name="diamond">道具消耗</param>
|
|
public static void UseProp(string roomId, string userId, string propNumber, int diamond)
|
|
{
|
|
var sendObj = new WebSocketSendList("UseProp", roomId, userId, propNumber, diamond);
|
|
WebSocketManager.Instance.Send(SocketType.game, JsonConvert.SerializeObject(sendObj));
|
|
}
|
|
/// <summary>
|
|
/// 离开房间
|
|
/// </summary>
|
|
/// <param name="roomId"></param>
|
|
/// <param name="userId"></param>
|
|
public static void LeaveRoom(string roomId, string userId)
|
|
{
|
|
var sendObj = new WebSocketSendList("LeaveRoom", roomId, userId);
|
|
WebSocketManager.Instance.Send(SocketType.game, JsonConvert.SerializeObject(sendObj));
|
|
}
|
|
/// <summary>
|
|
/// 更改炮倍
|
|
/// </summary>
|
|
/// <param name="roomId"></param>
|
|
/// <param name="userId"></param>
|
|
/// <param name="multiple"></param>
|
|
public static void ChangeGunMultiple(string roomId, string userId,int multiple)
|
|
{
|
|
var sendObj = new WebSocketSendList("ChangeGunMultiple", roomId, userId, multiple);
|
|
WebSocketManager.Instance.Send(SocketType.game, JsonConvert.SerializeObject(sendObj));
|
|
}
|
|
}
|