using CSharpUtil;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
///
/// 玩家相关
///
internal class UserProxy : ProxyBase
{
public UserProxy() => this.opeCode = OpeCode.ope_user;
#region 数据接口
public const string UID_qq = "wqq";
public string userName;
public string pwd;
public Player player { get; set; }
///
/// 服务器和本地的时间差
///
private long serverTS = 0;
///
/// 服务器时间戳
///
///
public uint GetCurrentUnixTimeStamp()
{
TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
return Convert.ToUInt32(ts.TotalSeconds + serverTS);
}
///
/// 服务器时间
///
///
public static DateTime GetCurrentDateTime() => DateTime.Now.FromUnixStamp(UserProxy.Instance.GetCurrentUnixTimeStamp());
#endregion 数据接口
///
/// [6000]获取分区列表
///
/// 玩家Uid
/// 回调函数
public void GetZoneList(string uid, bool getRecommended, Action callback)
{
Post(CmdCode.cmd_user_getzonelist, uid, 1, new object[] { getRecommended },callback);
}
///
/// [6001] 玩家登录获取玩家信息
///
///
///
///
public void UserLogin(string uid, int zoneid, Action callback, Action onNewUser)
{
Post(CmdCode.cmd_user_loginuserinfo, uid, zoneid, new object[] { },
resp =>
{
if (null != resp.result["isNewUser"] && bool.Parse(resp.result["isNewUser"].ToString()))
{
onNewUser?.Invoke();
}
else
{
var p = new Player();
p.uid = uid;
p.zoneid = zoneid;
p.Initlize(resp.result);
UserProxy.Instance.player = p;
callback?.Invoke(resp.result);
SystemProxy.HearbeatBehavor.Instance.Start(); // 启动心跳机制
PollingManager.Instance.Register($"{Enum_PollingIDs.RefreshTili:G}", 60, () => { // 开启轮询,刷新体力
ActiveProxy.Instance.GetCurTili(null);
});
MessageCenter.Instance.Init();
MapTcpProxy.Instance.Login(); // 初始化地图数据(长连)
}
});
}
///
/// [6006]注册新角色
///
///
///
///
///
///
///
public void RegisterRole(string uid, int zoneid, string nickname, string sex, string img, Action callback, Action faild)
{
Post(CmdCode.cmd_user_registerNewRole, uid, zoneid, new object[] { nickname, sex, img },
resp =>
{
if (null == resp.result["用户已存在"])
{
var p = new Player();
p.uid = uid;
p.zoneid = zoneid;
p.Initlize(resp.result);
UserProxy.Instance.player = p;
callback?.Invoke(resp.result);
MessageCenter.Instance.Init();
MapTcpProxy.Instance.Login(); // 初始化地图数据
}
else
{
faild?.Invoke();
}
});
}
///
/// [6002]获取常量数据
///
///
///
public void DownLoadGameConfig(string versionts, Action callback)
{
Post(CmdCode.cmd_user_gameconstinfo, "", 0, new object[] { versionts },
resp =>
{
TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
serverTS = resp.ts - Convert.ToInt64(ts.TotalSeconds);
LogHelper.Log($"与服务器的时间差:{serverTS}s");
JObject obj = null;
string data = resp.result["data"]?.ToString() ?? "";
if (!string.IsNullOrEmpty(data))
{
obj = JObject.Parse(Base64Util.Decode(data, true));
using var sw = new StreamWriter(Const.ServerConfigFileName); // 更新本地缓存文件
sw.Write(data);
}
callback?.Invoke(obj);
});
}
///
/// 6015 收集玩家意见和bug
///
///
///
///
public void UserCtxBack(string ctx, string type, string phoneId, Action callback)
{
Post(CmdCode.cmd_user_ctxBack, new object[] { ctx, type, phoneId },
resp => callback?.Invoke());
}
///
/// 6016 拉取其他玩家的信息
///
///
///
///
public void UserOtherPlayerInfo(string other_UID, Action callback)
{
Post(CmdCode.cmd_user_other_info, new object[] { other_UID },
resp =>
{
Player p = new Player();
p.Initlize(resp.result);
callback?.Invoke(p);
});
}
///
/// 6016 删除角色
///
///
public void DeleteUserUId(Action callback)
{
Post(CmdCode.cmd_user_deleteUserUId, new object[] { },
resp =>
{
//Player p = new Player();
//p.Initlize(resp.result);
callback?.Invoke();
});
}
#region " 测试/送审 "
///
/// [6004] 测试-注册新玩家UID
///
///
///
///
///
///
///
public void testRegisterNewUID(string uid, string pwd, string mail, string phone, Action callback)
{
Post(CmdCode.cmd_user_testRegisterNewUID, uid, 1, new object[] { uid, pwd, mail, phone },
resp =>
{
bool result = false;
string msg = "失败";
bool bReturned = null != resp.result["ret"];
if (!bReturned)
{
msg = "未知的返回值"; // 失败原因1
}
if (resp.result["ret"].ToObject() != ErrCode.succeed)
{
msg = resp.result["msg"].ToObject(); // 失败原因2
}
else// 成功
{
result = true;
msg = "成功";
}
if (callback != null)
{
callback.Invoke(result, msg); // 回调
}
});
}
///
/// [6005]测试-验证账号密码
///
///
///
///
///
///
///
public void testUserLogin(string uid, string pwd, Action callback)
{
Post(CmdCode.cmd_user_testUserLogin, uid, 1, new object[] { uid, pwd },
resp =>
{
bool result = false;
string msg = "失败";
bool bReturned = null != resp.result["ret"];
if (!bReturned)
{
msg = "未知的返回值"; // 失败原因1
}
if (resp.result["ret"].ToObject() != ErrCode.succeed)
{
msg = resp.result["msg"].ToObject(); // 失败原因2
}
else// 成功
{
result = true;
msg = "成功";
}
if (callback != null)
{
callback.Invoke(result, msg); // 回调
}
});
}
#endregion
#region ' 新手引导 '
///
/// [6007] 新手引导的状态变更 2020.6.11
///
/// 引导步骤
///
public void UpdateNewbieGuideStep(int guideIndex, Action callback)
{
Post(CmdCode.cmd_user_completeNewbieGuide, new object[] { guideIndex }, resp =>
{
var p = UserProxy.Instance.player;
p.collectHero.InitData((JObject)resp.result["heros"], p);
p.NewbieGuideInfo.guideStep = guideIndex;
callback?.Invoke();
});
}
///
/// 查询当前引导步骤
///
///
public int GetNewbieGuideStep() => player.NewbieGuideInfo.guideStep;
#endregion
#region ' 玩家形象 '
///
/// [6010] 设置修改玩家昵称
///
///
public void SetUserNickName(string nick, Action callback)
{
Post(CmdCode.cmd_user_setNickName, new object[] { nick },
resp =>
{
player.baseInfo.name = nick;
player.baseInfo.cash -= Convert.ToInt32(GameConfigData.Ins.globalsettings.User_SetNickname_Cost);
callback?.Invoke(resp.result);
});
}
///
/// 6011 更改头像框
///
///
///
public void SetUserImageBorder(int headImageBorderId, Action callback)
{
Post(CmdCode.cmd_user_SetUserHeadImageBorder, new object[] { headImageBorderId },
resp =>
{
player.baseInfo.imgBorderId = headImageBorderId;
callback?.Invoke(resp.result);
});
}
///
/// 6012 更改形象
///
///
///
public void SetUserImage(string image, Action callback)
{
Post(CmdCode.cmd_user_SetUserImage, new object[] { image },
resp =>
{
player.baseInfo.img = image;
callback?.Invoke(resp.result);
});
}
///
/// 6013 更改头像框
///
///
public void SetUserHeadImage(string headImage, Action callback)
{
Post(CmdCode.cmd_user_changeUserHeadImage, new object[] { headImage },
resp =>
{
player.baseInfo.headImg = headImage;
callback?.Invoke(resp.result);
});
}
///
/// 6014 初始化火山引擎服务端数据
///
/// 应用名称(言灵世界)
/// 应用包名
/// 渠道
/// 应用版本号
/// 系统名称安卓/ios
/// 系统版本号
/// 设备型号
/// Ab测试,分组信息
/// 流量类型(wifi/2G/3G/4G/5G...)
public void InitVolcEngineData(string app_name, string app_package, string app_channel, string app_version, string os_name, string os_version, string device_model, string ab_version, string traffic_type)
{
Post(CmdCode.cmd_user_stat_initvolc, new object[] { app_name, app_package, app_channel, app_version, os_name, os_version, device_model, ab_version, traffic_type }, resp => { });
}
#endregion
#region 废弃
/// .
/// 6009 新手引导—— 结束引导
///
///
///
///
[Obsolete("暂未启用-wg 2020.6.11")]
public void SetGuideOver(Action callback)
{
Post(CmdCode.cmd_user_setNewbieGuideOver, new object[] { }, resp => callback?.Invoke(resp.result));
}
///
/// 完整观看(开篇)重要剧情奖励(2钻石)
///
public void SendImportantStoryViewFullReward() {
// 奖励2钻石
ItemProxy.Instance.AddItem(2, 2);
ItemProxy.Instance.UpdateItems();
}
///
/// [6008] 获取新手引导战斗奖励(卡牌)
///
///
///
///
[Obsolete("已过时-wg")]
public void GetGuideBattleReward(Action callback)
{
Post(CmdCode.cmd_user_getGuideBattleReward, new object[] { }, resp => callback?.Invoke(resp.result));
}
#endregion
#region 辅助内部类
///
/// 用户信息 界面详情
///
public class UIVO_UserInfo
{
private Player p = UserProxy.Instance.player;
public int Level => p.baseInfo.level;
public int Exp => p.baseInfo.xp;
public int Gold => p.baseInfo.gold;
public int Cash => p.baseInfo.cash;
public int CurMaxXp => p.baseInfo.maxXp;
public string headImg => p.baseInfo.headImg;
public string Name
{
get
{
if (p.baseInfo.name.Contains("No."))
{
return "新玩家";
}
else
{
return p.baseInfo.name;
}
}
}
public int FightPower => p.collectHero.GetTotalFightPower();
public Info_HeroTeamConfig Team => p.heroTeamConfig;
public string UID => p.uid;
public string ZoneName => p.zonename;
public string guildName => "未加入公会";
///
/// 改名消耗
///
public int ChangeNicknameCost => Convert.ToInt32(GameConfigData.Ins.globalsettings.User_SetNickname_Cost);
///
/// 选择头像界面
///
public class UI_SelectUserHeadImg
{
private Player p = UserProxy.Instance.player;
public List headList() =>
GameConfigData.Ins.item_yanling.Values.ToList().ConvertAll(y => new HeadImgInfo(y));
public class HeadImgInfo
{
private Player p = UserProxy.Instance.player;
private sm_item_yanling mo;
public HeadImgInfo(sm_item_yanling ylmo) => mo = ylmo;
///
/// 图标资源(头像)
///
public string icon => mo.GeneralData.icon;
///
/// 已解锁
///
public bool isUnlocked => p.collectYanling.items.Values.Count(yl => yl.nMo.typeId == mo.typeId) > 0;
public string name => mo.GeneralData.name;
public string desc => $"获得{name}解锁头像.";
}
}
///
/// 选择形像界面
///
public class UI_SelectUserImage
{
private Player p = UserProxy.Instance.player;
public List headList() =>
GameConfigData.Ins.item_yanling.Values.ToList().ConvertAll(y => new ImageInfo(y));
public class ImageInfo
{
private Player p = UserProxy.Instance.player;
private sm_item_yanling mo;
public ImageInfo(sm_item_yanling ylmo) => mo = ylmo;
///
/// 图标
///
public string icon => mo.GeneralData.icon;
///
/// 龙骨资源
///
public string img => mo.GeneralData.res;
///
/// 已解锁
///
public bool isUnlocked => p.collectYanling.items.Values.Count(yl => yl.nMo.typeId == mo.typeId) > 0;
public string name => mo.GeneralData.name;
public string desc => $"获得{name}解锁此形象.";
}
}
}
#endregion
}