111
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
global using Photon.Core;
|
||||
global using SqlSugar;
|
||||
global using Application.Domain.Entity;
|
||||
global using Photon.Core.Redis;
|
||||
global using Photon.Core.Redis;
|
||||
global using Photon.Core.Assist;
|
||||
@@ -0,0 +1,21 @@
|
||||
namespace Application.Domain;
|
||||
|
||||
public interface IGameMapService
|
||||
{
|
||||
#region 城市地图数据
|
||||
|
||||
Task<game_city> GetCityInfo(int cityId);
|
||||
Task<game_city_map> GetMapInfo(string mapId);
|
||||
Task<int> GetMapCityByMapId(string mapId);
|
||||
Task<List<game_city_npc>> GetMapNpc(string mapId);
|
||||
Task<game_city_npc> GetNpcInfo(int npcId);
|
||||
#endregion
|
||||
|
||||
#region 用户地图
|
||||
|
||||
Task<string> GetUserOnMapId(string userId);
|
||||
Task<unit_user_online> GetUserOnMap(string userId);
|
||||
Task UpdateUserOnMap(string userId, string ip, string mapId);
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -9,6 +9,7 @@ public interface IUnitUserService
|
||||
Task<unit_user> GetUserInfoByUserNo(string userNo);
|
||||
Task<unit_user> GetUserInfoByToken(string token);
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region 用户注册
|
||||
|
||||
@@ -0,0 +1,128 @@
|
||||
namespace Application.Domain;
|
||||
|
||||
public class GameMapService : IGameMapService, ITransient
|
||||
{
|
||||
private readonly ISqlSugarClient _dbClient;
|
||||
private readonly IRedisCache _redisClient;
|
||||
|
||||
public GameMapService(ISqlSugarClient dbClient, IRedisCache redisClient)
|
||||
{
|
||||
_dbClient = dbClient;
|
||||
_redisClient = redisClient;
|
||||
}
|
||||
|
||||
#region 城市地图数据
|
||||
|
||||
public async Task<game_city> GetCityInfo(int cityId)
|
||||
{
|
||||
string key = string.Format(BaseCache.BaseCacheKeys, "MapCityData", "CityData");
|
||||
var data = await _redisClient.GetHashAsync<game_city>(key, cityId.ToString());
|
||||
if (data == null)
|
||||
{
|
||||
var db = _dbClient.AsTenant().GetConnectionWithAttr<game_city>();
|
||||
data = await db.Queryable<game_city>().Where(it => it.cityId == cityId).SingleAsync();
|
||||
await _redisClient.AddHashAsync(key, cityId.ToString(), data);
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
public async Task<game_city_map> GetMapInfo(string mapId)
|
||||
{
|
||||
string key = string.Format(BaseCache.BaseCacheKeys, "MapCityData", "MapData");
|
||||
var data = await _redisClient.GetHashAsync<game_city_map>(key, mapId);
|
||||
if (data == null)
|
||||
{
|
||||
var db = _dbClient.AsTenant().GetConnectionWithAttr<game_city_map>();
|
||||
data = await db.Queryable<game_city_map>().Where(it => it.mapId == mapId).SingleAsync();
|
||||
await _redisClient.AddHashAsync(key, mapId, data);
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
public async Task<int> GetMapCityByMapId(string mapId)
|
||||
{
|
||||
var data = await GetMapInfo(mapId);
|
||||
if (data != null)
|
||||
{
|
||||
return (int)data.cityId;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<List<game_city_npc>> GetMapNpc(string mapId)
|
||||
{
|
||||
string key = string.Format(BaseCache.BaseCacheKeys, "MapCityData", "NpcData");
|
||||
var data = await _redisClient.GetHashAsync<List<game_city_npc>>(key, mapId);
|
||||
if (data == null)
|
||||
{
|
||||
var db = _dbClient.AsTenant().GetConnectionWithAttr<game_city_npc>();
|
||||
data = await db.Queryable<game_city_npc>().Where(it => it.mapId == mapId && it.status == 1).ToListAsync();
|
||||
await _redisClient.AddHashAsync(key, mapId, data);
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
public async Task<game_city_npc> GetNpcInfo(int npcId)
|
||||
{
|
||||
string key = string.Format(BaseCache.BaseCacheKeys, "MapCityData", "NpcInfo");
|
||||
var data = await _redisClient.GetHashAsync<game_city_npc>(key, npcId.ToString());
|
||||
if (data == null)
|
||||
{
|
||||
var db = _dbClient.AsTenant().GetConnectionWithAttr<game_city_npc>();
|
||||
data = await db.Queryable<game_city_npc>().Where(it => it.npcId == npcId).SingleAsync();
|
||||
await _redisClient.AddHashAsync(key, npcId.ToString(),data);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 用户地图
|
||||
|
||||
public async Task<string> GetUserOnMapId(string userId)
|
||||
{
|
||||
var data = await GetUserOnMap(userId);
|
||||
if (data == null)
|
||||
{
|
||||
return "16_27";
|
||||
}
|
||||
|
||||
return data.mapId;
|
||||
}
|
||||
|
||||
public async Task<unit_user_online> GetUserOnMap(string userId)
|
||||
{
|
||||
string key = string.Format(UserCache.BaseCacheKey, "UserOnline");
|
||||
if (await _redisClient.HExistsHashAsync(key, userId))
|
||||
{
|
||||
return await _redisClient.GetHashAsync<unit_user_online>(key, userId);
|
||||
}
|
||||
|
||||
var db = _dbClient.AsTenant().GetConnectionWithAttr<unit_user_online>();
|
||||
var data = await db.Queryable<unit_user_online>().Where(it => it.userId == userId).SingleAsync();
|
||||
await _redisClient.AddHashAsync(key, userId, data);
|
||||
return data;
|
||||
}
|
||||
|
||||
public async Task UpdateUserOnMap(string userId, string ip, string mapId)
|
||||
{
|
||||
unit_user_online onLine = new unit_user_online();
|
||||
onLine.userId = userId;
|
||||
onLine.mapId = mapId;
|
||||
onLine.ip = ip;
|
||||
onLine.upTime = TimeAssist.GetTimeStampNum;
|
||||
string key = string.Format(UserCache.BaseCacheKey, "UserOnline");
|
||||
if (await _redisClient.AddHashAsync(key, userId, onLine))
|
||||
{
|
||||
var db = _dbClient.AsTenant().GetConnectionWithAttr<unit_user_online>();
|
||||
await db.Updateable<unit_user_online>(onLine).ExecuteCommandAsync();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -14,11 +14,13 @@ public class UnitUserService : IUnitUserService, ITransient
|
||||
}
|
||||
|
||||
#region 用户信息
|
||||
|
||||
public async Task<List<unit_user>> GetUserDataByAccId(string accId)
|
||||
{
|
||||
var db = _dbClient.AsTenant().GetConnectionWithAttr<unit_user>();
|
||||
return await db.Queryable<unit_user>().Where(it => it.accId == accId).ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<unit_user> GetUserInfoByUserId(string userId)
|
||||
{
|
||||
string key = string.Format(UserCache.BaseCacheKeys, "UserInfo", "UserId");
|
||||
@@ -35,6 +37,7 @@ public class UnitUserService : IUnitUserService, ITransient
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
public async Task<unit_user> GetUserInfoByUserNo(string userNo)
|
||||
{
|
||||
string key = string.Format(UserCache.BaseCacheKeys, "UserInfo", "UserNo");
|
||||
@@ -68,6 +71,7 @@ public class UnitUserService : IUnitUserService, ITransient
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
private async Task ClearUserInfo(int type, string id)
|
||||
{
|
||||
unit_user result = new unit_user();
|
||||
@@ -81,17 +85,17 @@ public class UnitUserService : IUnitUserService, ITransient
|
||||
result = await GetUserInfoByToken(id);
|
||||
break;
|
||||
}
|
||||
await _redisClient.DelHashAsync(string.Format(UserCache.BaseCacheKeys, "UserInfo","UserId"), result.userId);
|
||||
await _redisClient.DelHashAsync(string.Format(UserCache.BaseCacheKeys, "UserInfo","UserNo"), result.userNo);
|
||||
await _redisClient.DelHashAsync(string.Format(UserCache.BaseCacheKeys, "UserInfo","Sid"), result.token);
|
||||
|
||||
await _redisClient.DelHashAsync(string.Format(UserCache.BaseCacheKeys, "UserInfo", "UserId"), result.userId);
|
||||
await _redisClient.DelHashAsync(string.Format(UserCache.BaseCacheKeys, "UserInfo", "UserNo"), result.userNo);
|
||||
await _redisClient.DelHashAsync(string.Format(UserCache.BaseCacheKeys, "UserInfo", "Sid"), result.token);
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region 用户注册
|
||||
|
||||
|
||||
|
||||
public async Task<unit_user> Register(int areaId, string accId)
|
||||
{
|
||||
unit_user result = new unit_user();
|
||||
@@ -114,7 +118,6 @@ public class UnitUserService : IUnitUserService, ITransient
|
||||
result.regOk = 0;
|
||||
result.isSystem = 0;
|
||||
result.addTime = DateTime.Now;
|
||||
result.upTime = DateTime.Now;
|
||||
bool isok = db.Insertable(result).ExecuteCommand() > 0;
|
||||
if (!isok)
|
||||
{
|
||||
@@ -131,6 +134,7 @@ public class UnitUserService : IUnitUserService, ITransient
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<bool> RegisterUserInfo(string userId, string nick, string sex)
|
||||
{
|
||||
var db = _dbClient.AsTenant().GetConnectionWithAttr<unit_user>();
|
||||
@@ -140,17 +144,74 @@ public class UnitUserService : IUnitUserService, ITransient
|
||||
.Where(it => it.userId == userId).ExecuteCommandAsync() > 0;
|
||||
if (result)
|
||||
{
|
||||
//注册配置信息
|
||||
await ClearUserInfo(0, userId);//清理个人信息表缓存
|
||||
|
||||
//注册账户
|
||||
unit_user_acc acc = new unit_user_acc();
|
||||
acc.userId = userId;
|
||||
acc.cowry = 0;
|
||||
acc.gold = 0;
|
||||
acc.teach = 0;
|
||||
acc.renown = 0;
|
||||
db.Insertable(acc).AddQueue();
|
||||
//注册游戏货币
|
||||
unit_user_copper copper = new unit_user_copper();
|
||||
copper.userId = userId;
|
||||
copper.copper = 0;
|
||||
db.Insertable(copper).AddQueue();
|
||||
|
||||
//注册个人基础属性
|
||||
unit_user_attr userAttr = GameTool.GetAttrData(1);
|
||||
userAttr.userId = userId;
|
||||
db.Insertable(userAttr).AddQueue();
|
||||
|
||||
//注册个人血量
|
||||
unit_user_blood blood = new unit_user_blood();
|
||||
blood.userId = userId;
|
||||
blood.blood = userAttr.upBlood;
|
||||
db.Insertable(blood).AddQueue();
|
||||
//注册士气
|
||||
unit_user_morale morale = new unit_user_morale();
|
||||
morale.userId = userId;
|
||||
morale.morale = userAttr.upMorale;
|
||||
db.Insertable(morale).AddQueue();
|
||||
|
||||
//注册等级经验
|
||||
unit_user_exp exp = new unit_user_exp();
|
||||
exp.userId = userId;
|
||||
exp.exp = 0;
|
||||
exp.upExp = GameTool.GetUserUpExp(1);
|
||||
db.Insertable(exp).AddQueue();
|
||||
|
||||
//注册负重
|
||||
unit_user_weight weight = new unit_user_weight();
|
||||
weight.userId = userId;
|
||||
weight.onWeight = 0;
|
||||
weight.maxWeight = 100;
|
||||
db.Insertable(weight).AddQueue();
|
||||
//注册活力
|
||||
unit_user_vigour vitality = new unit_user_vigour();
|
||||
vitality.userId = userId;
|
||||
vitality.vitality = 50;
|
||||
vitality.upVitality = 50;
|
||||
vitality.upTime = TimeAssist.GetDateTimeYMDString(0);
|
||||
db.Insertable(vitality).AddQueue();
|
||||
|
||||
//注册在线
|
||||
unit_user_online online = new unit_user_online();
|
||||
online.userId = userId;
|
||||
online.ip = "";
|
||||
online.mapId = "16_27";
|
||||
online.upTime = TimeAssist.GetTimeStampNum;
|
||||
db.Insertable(online).AddQueue();
|
||||
|
||||
await db.SaveQueuesAsync(false);
|
||||
|
||||
await ClearUserInfo(0, userId);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private async Task<int> GetUserNo()
|
||||
{
|
||||
int No = 0;
|
||||
|
||||
41
Service/Application.Domain/Tool/GameTool.cs
Normal file
41
Service/Application.Domain/Tool/GameTool.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
using Photon.Core.Assist;
|
||||
|
||||
namespace Application.Domain;
|
||||
|
||||
public class GameTool
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取等级基础属性
|
||||
/// </summary>
|
||||
/// <param name="lev"></param>
|
||||
/// <returns></returns>
|
||||
public static unit_user_attr GetAttrData(int lev)
|
||||
{
|
||||
unit_user_attr data = new unit_user_attr();
|
||||
data.lev = lev;
|
||||
data.minAtk = lev + 2;
|
||||
data.maxAtk = lev + Convert.ToInt32(lev * 0.05) + 4;
|
||||
data.defense = lev;
|
||||
data.agility = lev;
|
||||
data.upBlood = ((lev - 1) * 5) + 80;
|
||||
data.upMorale = 100 + (lev / 5) * 10;
|
||||
data.levUpdate = TimeAssist.GetTimeStampNum;
|
||||
return data;
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取等级升级经验
|
||||
/// </summary>
|
||||
/// <param name="lev"></param>
|
||||
/// <returns></returns>
|
||||
public static long GetUserUpExp(int lev)
|
||||
{
|
||||
long result = 50 * ((lev * lev * lev) + (5 * lev)) - 80;
|
||||
return result;
|
||||
}
|
||||
|
||||
public static bool AreaVerify( int area,string areas)
|
||||
{
|
||||
List<string> onArea = new List<string>() {"0",area.ToString() };
|
||||
return onArea.Any(it => areas.Contains(it));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user