增加修炼功能

This commit is contained in:
LN
2026-07-04 14:09:22 +08:00
147 changed files with 7790 additions and 693 deletions

View File

@@ -6,20 +6,25 @@ public interface IGameEquService
Task<game_equ> GetEquInfo(int equId);
Task<game_equ_suit> GetEuqSuitInfo(string suitCode);
#endregion
#region
Task<List<unit_user_equ>> GetUserEquData(string userId, int type, string equName, int PageIndex, int PageSize,
RefAsync<int> Total, bool isRemOn = false);
RefAsync<int> Total, bool isRemOn = false, bool isRemLock = false);
Task<List<unit_user_equ>> GetUserEquData(string userId, int equId);
Task<List<unit_user_equ>> GetUserEquData(string userId, string code, List<string> noUeId);
Task<unit_user_equ> GetUserEquInfo(string ueId);
Task<int> GetUserEquByEquIdCount(string userId, int equId);
Task<List<unit_user_equ>> GetUserEquByEquId(string userId, int equId);
Task<bool> AddUserEqu(string userId, int equId, int count, string remark);
Task<bool> AddUserEqu(unit_user_equ equData, string remark);
Task<unit_user_equ> AddUserEqu(string userId, int equId, bool rdAttr = false, string remark = "");
Task<bool> UpdateUserEquInfo(unit_user_equ equData, bool isAddLog = false, string code = "",
string remark = "");
Task<bool> DeductUserEqu(string userId, List<unit_user_equ> equData, string remark);
Task<bool> DeductUserEqu(string userId, int equId, int count, string remark);
@@ -27,13 +32,36 @@ public interface IGameEquService
bool isAddAttr = false);
Task<List<unit_user_equ>> GetUserOnEqu(string userId);
Task<UserAttrModel> GetUserEquAttrModel(string userId);
Task<bool> EquOnOrDown(unit_user_equ data, int state);
Task<List<UserEquSuit>> GetUserEquSuit(string userId);
Task<List<AttrItem>> GetUserEquSuitAttrInfo(string userId);
#endregion
#region
#region
Task<game_equ_awaken> GetEquAwakenInfo(string atId);
Task<game_equ_awaken> GetRandomOneAwakenByCode(string code);
Task<EquAwakenData> GetEquAwakenInfoByLev(string atId, int lev);
#endregion
#region /
Task<List<AttrItem>> GetRandomEquAttr(string equCode, int lev);
#endregion
#region
Task<game_equ_up> GetUserEquUpData(int lev);
#endregion
#region
Task<int> GetUserEquWeightSum(string userId);
Task<game_equ_make> GetMakeEquByGoodsId(int goodsId);
#endregion
}

View File

@@ -0,0 +1,26 @@
namespace Application.Domain;
public interface IGameFightService
{
#region
Task<List<string>> GetUserFight(string userId);
Task<bool> RemoveUserFight(string userId, string fightId);
#endregion
#region
Task<game_fight_data> GetFightInfo(string fightId);
Task<long> GetFightBlood(string keyId, long maxBlood);
Task SetFightBlood(string keyId, long blood);
Task AddFightHarm(string fightId, string userId, long harm);
Task<bool> AddFight(string fightId, string areaCode, string keyId, string mainId, string code,
string scene, string mapId,
string userId, long exp = 0, long copper = 0, long petExp = 0, string award = "", string pars = "");
Task<bool> SetFightWin(string fightId, string winUser);
#endregion
#region
#endregion
}

View File

@@ -29,7 +29,11 @@ public interface IGameGoodsService
#endregion
#region
Task<game_ship> GetShipInfo(int shipId);
#region
Task<string> CheckUseDrug(string userId, int goodsId, string drugConfig, string scene = "");
Task<bool> UseDrug(string userId, int goodsId, string drugConfig, string scene = "");
#endregion
}

View File

@@ -18,6 +18,7 @@ public interface IGameMapService
#region
Task<string> GetUserOnMapId(string userId);
Task<game_city_map> GetUserOnToMapInfo(string userId);
Task<unit_user_online> GetUserOnMap(string userId);
Task UpdateUserOnMap(string userId, string ip, string mapId);
Task<bool> UpdateUserOnMap(unit_user_online data, string mapId);

View File

@@ -0,0 +1,20 @@
namespace Application.Domain;
public interface IGameMonsterService
{
#region
Task<game_monster> GetMonsterInfo(string monsterId);
#endregion
#region
Task<List<game_monster_map>> GetMonsterDataByMap(string mapId);
Task<game_monster_map> GetMapMonsterInfo(string mmId);
Task<bool> CreateMonsterToMap(string userId, string mapId, string areaCode, string monsterId,
int count = 1, int time = 0, string par = "");
Task<unit_user_monster> GetCreateMonsterInfo(string umId);
Task<List<MapMonsterModel>> GetMapMonster(string userId, string mapId, string teamId);
#endregion
}

View File

@@ -0,0 +1,6 @@
namespace Application.Domain;
public interface IGameDicService
{
Task<game_dic> GetDicInfo(string code);
}

View File

@@ -43,4 +43,11 @@ public interface IMessageService
List<MsgEventBtn> btns = null, int days = 10);
#endregion
#region 广
Task<List<game_broadcast>> GetBroadcastData(int area);
Task<bool> SendBroadcast(string userId, string code, string msg);
#endregion
}

View File

@@ -4,9 +4,10 @@ public interface IUnitUserAttrService
{
#region
Task<UserAttrModel> GetUserAttrModel(string userId);
Task<UserAttrModel> GetUserAttrModel(string userId, string scene = "Default");
Task<unit_user_attr> GetUserAttr(string userId);
Task<int> GetUserLev(string userId);
#endregion
#region
@@ -29,6 +30,7 @@ public interface IUnitUserAttrService
Task<bool> UpdateUserMorale(string userId, int op, int count);
Task<bool> CheackRecoverMorale(string userId);
Task LockRecoverMorale(string userId);
#endregion
#region
@@ -43,6 +45,42 @@ public interface IUnitUserAttrService
Task<bool> UpdateOnLineTime(string userId, string code, int time);
#endregion
#region
Task<unit_user_drug> GetUserDrug(string userId);
Task<bool> UpdateUserDrug(unit_user_drug data);
#endregion
#region BUFF状态
Task<List<unit_user_state>> GetUserStateData(string userId, string scene = "Default");
Task<bool> AddUserState(string userId, string groupId, string name, string scene, string tips,
List<AttrItem> attr, int time, int count = 1);
#endregion
#region
Task<List<unit_user_stock>> GetUserStock(string userId, string code = "Default");
Task<bool> AddUserStock(string userId, string goodsId,string name, string type, string code, long sign,
string par = "",
int minute = 0);
Task<bool> UpdateUserStock(unit_user_stock data);
#endregion
#region
Task<List<unit_user_load>> GetUserLoadState(string userId);
Task<bool> AddUserLoadState(string userId, string name, string code);
Task<bool> RandomRemoveUserLoadState(string userId, int count);
Task RemoveUserLoadState(string userId);
#endregion
}

View File

@@ -19,7 +19,7 @@ public interface IUnitUserWeight
Task<bool> UpdateUserShipOnWeight(string userId, int op, int weight);
Task<bool> CheakUserShipWeight(string userId, int useWeight);
Task<bool> DeleteUserShip(string usId, string userId);
Task<bool> AddUserShip(string userId, string name, int goodsId, int speed, int weight);
Task<bool> AddUserShip(string userId, string name, int goodsId, int speed, int weight,int copper,long sale,string remark);
#endregion

View File

@@ -39,7 +39,7 @@ public class GameEquService(ISqlSugarClient DbClient, IRedisCache redis) : IGame
#region
public async Task<List<unit_user_equ>> GetUserEquData(string userId, int type, string equName, int PageIndex,
int PageSize, RefAsync<int> Total, bool isRemOn = false)
int PageSize, RefAsync<int> Total, bool isRemOn = false, bool isRemLock = false)
{
long onTime = TimeExtend.GetTimeStampSeconds;
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_equ>();
@@ -48,6 +48,7 @@ public class GameEquService(ISqlSugarClient DbClient, IRedisCache redis) : IGame
.WhereIF(type == 1, it => it.isOn == 1)
.WhereIF(type == 3, it => it.isAppr == 0)
.WhereIF(isRemOn, it => it.isOn == 0)
.WhereIF(isRemLock, it => it.isLock == 0)
.WhereIF(!string.IsNullOrEmpty(equName),
it => it.equName.Contains(equName) || it.unitEquName.Contains(equName))
.OrderByDescending(it => it.lev)
@@ -56,11 +57,18 @@ public class GameEquService(ISqlSugarClient DbClient, IRedisCache redis) : IGame
public async Task<List<unit_user_equ>> GetUserEquData(string userId, int equId)
{
long onTime = TimeExtend.GetTimeStampSeconds;
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_equ>();
return await db.Queryable<unit_user_equ>().Where(it => it.userId == userId && it.equId == equId).ToListAsync();
}
public async Task<List<unit_user_equ>> GetUserEquData(string userId, string code, List<string> noUeId)
{
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_equ>();
return await db.Queryable<unit_user_equ>().Where(it => it.userId == userId && it.code == code)
.WhereIF(noUeId.Count > 0, it => !noUeId.Contains(it.ueId))
.ToListAsync();
}
public async Task<unit_user_equ> GetUserEquInfo(string ueId)
{
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_equ>();
@@ -173,6 +181,115 @@ public class GameEquService(ISqlSugarClient DbClient, IRedisCache redis) : IGame
return result;
}
public async Task<bool> AddUserEqu(unit_user_equ equData, string remark)
{
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_equ>();
var result = await db.Insertable(equData).ExecuteCommandAsync() > 0;
if (result)
{
//添加日志
await AddEquLogs([equData], 1, remark, true);
//更新负重
int weightCount = Convert.ToInt32(equData.weight);
if (weightCount > 0)
{
var attrService = App.GetService<IUnitUserWeight>();
await attrService.UpdateUserWeight(equData.userId, 1, weightCount);
}
}
return result;
}
public async Task<unit_user_equ> AddUserEqu(string userId, int equId, bool rdAttr = false, string remark = "")
{
var equ = await GetEquInfo(equId);
if (equ == null)
{
return null;
}
unit_user_equ ue = new unit_user_equ();
string ueId = StringAssist.NewGuid;
ue.ueId = ueId;
ue.userId = userId;
ue.owerId = userId;
ue.equId = equ.equId;
ue.equName = equ.equName;
ue.unitEquName = equ.equName;
ue.img = equ.img;
ue.sign = "";
ue.isAppr = 1;
if (equ.isAppr == 0)
{
ue.minAtk = equ.minAtk;
ue.maxAtk = equ.maxAtk;
ue.Defense = Convert.ToInt32(equ.defense);
ue.Agility = Convert.ToInt32(equ.agility);
ue.Morale = Convert.ToInt32(equ.morale);
ue.Blood = Convert.ToInt32(equ.blood);
}
else
{
ue.minAtk = RandomAssist.GetFormatedNumeric((int)equ.minAtk, (int)equ.maxAtk);
ue.maxAtk = RandomAssist.GetFormatedNumeric((int)equ.minAtk, (int)equ.maxAtk);
string[] def = equ.defense.Split('-');
ue.Defense = RandomAssist.GetFormatedNumeric(Convert.ToInt32(def[0]), Convert.ToInt32(def[1]));
string[] agi = equ.agility.Split('-');
ue.Agility = RandomAssist.GetFormatedNumeric(Convert.ToInt32(agi[0]), Convert.ToInt32(agi[1]));
string[] mor = equ.morale.Split('-');
ue.Morale = RandomAssist.GetFormatedNumeric(Convert.ToInt32(mor[0]), Convert.ToInt32(mor[1]));
string[] blo = equ.blood.Split('-');
ue.Blood = RandomAssist.GetFormatedNumeric(Convert.ToInt32(blo[0]), Convert.ToInt32(blo[1]));
}
ue.code = equ.code;
ue.suitCode = equ.suitCode;
ue.lev = equ.lev;
ue.durability = equ.durability;
ue.maxdurability = equ.durability;
ue.isIntensify = equ.isIntensify;
ue.intensifyLev = 0;
ue.isLock = 0;
ue.holeCount = equ.holeCount;
ue.sex = equ.sex;
ue.weight = equ.weight;
ue.sysPrice = equ.sysPrice;
ue.qualityAttr = new List<AttrItem>();
if (rdAttr == false)
{
ue.quality = equ.quality;
ue.qualityName = GameTool.GetEquQualityName((int)ue.quality);
ue.EquAttr = equ.equAttr;
}
else
{
var randomAttr = await GetRandomEquAttr(equ.code, (int)equ.lev);
ue.quality = randomAttr.Count;
ue.qualityName = GameTool.GetEquQualityName((int)ue.quality);
ue.EquAttr = randomAttr;
}
ue.canEqualUp = equ.canEqualUp;
ue.isDeal = equ.isDeal;
ue.isGive = equ.isGive;
ue.opTime = 0;
ue.start = 0;
ue.EquMent = new EquMent();
ue.EquAwaken = new List<EquAwaken>();
ue.GemMent = new List<EquGem>();
ue.useEndTime = TimeExtend.GetTimeStampBySeconds(DateTime.Now.AddYears(20));
ue.isOn = 0;
if (await AddUserEqu(ue, remark))
{
return ue;
}
else
{
return null;
}
}
public async Task<bool> UpdateUserEquInfo(unit_user_equ equData, bool isAddLog = false, string code = "",
string remark = "")
{
@@ -184,6 +301,11 @@ public class GameEquService(ISqlSugarClient DbClient, IRedisCache redis) : IGame
{
await AddEquLog(equData, code, remark);
}
if (equData.isOn == 1)
{
await ClearUserOnEqu(equData.userId);
}
}
return result;
@@ -325,6 +447,52 @@ public class GameEquService(ISqlSugarClient DbClient, IRedisCache redis) : IGame
}
}
public async Task<UserAttrModel> GetUserEquAttrModel(string userId)
{
var key = string.Format(UserCache.BaseCacheKeys, "EquData", "UserOnEquAttr");
if (await redis.HExistsHashAsync(key, userId))
{
return await redis.GetHashAsync<UserAttrModel>(key, userId);
}
long endTime = TimeExtend.GetTimeStampSeconds;
UserAttrModel result = new UserAttrModel();
var myEqu = await GetUserOnEqu(userId);
foreach (var equ in myEqu)
{
if (equ.durability > 0 || equ.useEndTime > endTime)
{
UserAttrModel equTemp = new UserAttrModel();
var equAttr = EquTool.GetUserEquByIntensify(equ);
equTemp.minAtk = (int)equAttr.minAtk;
equTemp.maxAtk = (int)equAttr.maxAtk;
equTemp.defense = (int)equAttr.Defense;
equTemp.agility = (int)equAttr.Agility;
equTemp.upBlood = (int)equAttr.Blood;
equTemp.upMorale = (int)equAttr.Morale;
List<AttrItem> equAttrData = EquTool.GetUserEquAttrData(equ);
equTemp = GameAttrTool.GetRoleAttrTempMerge(equTemp, equAttrData);
result = GameAttrTool.GetRoleAttrTempMerge(result, equTemp);
}
}
await redis.AddHashAsync(key, userId, result);
return result;
}
private async Task ClearUserOnEqu(string userId)
{
var key = string.Format(UserCache.BaseCacheKeys, "EquData", "UserOnEqu");
await redis.DelHashAsync(key, userId);
key = string.Format(UserCache.BaseCacheKeys, "EquData", "UserOnEquAttr");
await redis.DelHashAsync(key, userId);
//清理套装缓存
key = string.Format(UserCache.BaseCacheKeys, "EquData:UserEquSuit", userId);
await redis.DelAsync(key);
key = string.Format(UserCache.BaseCacheKeys, "EquData:UserEquSuitAttr", userId);
await redis.DelAsync(key);
}
public async Task<bool> EquOnOrDown(unit_user_equ data, int state)
{
data.isOn = state;
@@ -334,21 +502,292 @@ public class GameEquService(ISqlSugarClient DbClient, IRedisCache redis) : IGame
var equInfo = await GetEquInfo((int)data.equId);
if (equInfo.useTime > 0)
{
data.useEndTime = TimeExtend.GetTimeStampBySeconds(DateTime.Now.AddDays((int)equInfo.useTime)) ;
data.useEndTime = TimeExtend.GetTimeStampBySeconds(DateTime.Now.AddDays((int)equInfo.useTime));
}
}
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_equ>();
bool result = await db.Updateable(data).ExecuteCommandAsync() > 0;
if (result)
{
await ClearUserOnEqu(data.userId);
}
return result;
}
/// <summary>
/// 获取个人套装
/// </summary>
/// <param name="userId"></param>
/// <returns></returns>
public async Task<List<UserEquSuit>> GetUserEquSuit(string userId)
{
List<UserEquSuit> result = new List<UserEquSuit>();
long time = TimeExtend.GetTimeStampSeconds;
var key = string.Format(UserCache.BaseCacheKeys, "EquData:UserEquSuit", userId);
if (await redis.ExistsAsync(key))
{
result = await redis.GetAsync<List<UserEquSuit>>(key);
}
else
{
List<string> opSuit = new List<string>();
var onEquData = await GetUserOnEqu(userId);
string[] onEqu = onEquData.Select(it => it.equId.ToString()).ToArray();
onEquData = onEquData.FindAll(it => it.useEndTime > time && it.durability > 0);
foreach (var item in onEquData)
{
if (item.suitCode != "0" && !string.IsNullOrEmpty(item.suitCode))
{
if (!opSuit.Contains(item.suitCode))
{
opSuit.Add(item.suitCode);
}
}
}
foreach (var suit in opSuit)
{
UserEquSuit temp = new UserEquSuit();
var suitInfo = await GetEuqSuitInfo(suit);
if (suitInfo != null)
{
temp.suitCode = suitInfo.suitCode;
temp.suitName = suitInfo.suitName;
temp.SuitAttr = new List<EquSuitAttr>();
foreach (var item in suitInfo.attr)
{
if (item.NeedType == nameof(EquEnum.SuitAttrNeedType.ON_EQU))
{
bool same = item.NeedData.All(item => onEqu.Contains(item));
if (same)
{
temp.SuitAttr.Add(item);
}
}
}
if (temp.SuitAttr.Count > 0) //存在满足条件得属性
{
result.Add(temp);
}
}
}
await redis.SetAsync(key, result, 300);
}
return result;
}
public async Task<List<AttrItem>> GetUserEquSuitAttrInfo(string userId)
{
List<AttrItem> result = new List<AttrItem>();
var key = string.Format(UserCache.BaseCacheKeys, "EquData:UserEquSuitAttr", userId);
if (await redis.ExistsAsync(key))
{
result = await redis.GetAsync<List<AttrItem>>(key);
}
else
{
var suitData = await GetUserEquSuit(userId);
foreach (var item in suitData)
{
foreach (var attr in item.SuitAttr)
{
result.AddRange(attr.AttrItem);
}
}
await redis.SetAsync(key, result, 300);
}
return result;
}
#endregion
#region
public async Task<game_equ_awaken> GetEquAwakenInfo(string atId)
{
string key = string.Format(BaseCache.BaseCacheKeys, "EquData", "AwakenData");
var data = await redis.GetHashAsync<game_equ_awaken>(key, atId);
if (data == null)
{
var db = DbClient.AsTenant().GetConnectionWithAttr<game_equ_awaken>();
data = await db.Queryable<game_equ_awaken>().Where(i => i.atId == atId).SingleAsync();
if (data != null)
{
await redis.AddHashAsync(key, atId, data);
}
}
return data;
}
public async Task<game_equ_awaken> GetRandomOneAwakenByCode(string code)
{
game_equ_awaken attr = new game_equ_awaken();
var db = DbClient.AsTenant().GetConnectionWithAttr<game_equ_awaken>();
var list = await db.Queryable<game_equ_awaken>().Where(i => i.position.Contains(code)).ToListAsync();
if (list.Count == 0)
{
return null;
}
List<object> data = new List<object>();
List<ushort> weights = new List<ushort>();
List<object> result = new List<object>();
Random rand = new Random();
foreach (var item in list)
{
data.Add(item);
weights.Add(ushort.Parse(item.random.ToString()));
}
RandomAssist random = new RandomAssist(1);
result = random.ControllerRandomExtract(rand, data, weights);
if (result.Count > 0)
{
attr = result[0] as game_equ_awaken;
return attr;
}
else
{
return null;
}
}
public async Task<EquAwakenData> GetEquAwakenInfoByLev(string atId, int lev)
{
var awakenInfo = await GetEquAwakenInfo(atId);
EquAwakenData awaken = new EquAwakenData();
foreach (var item in awakenInfo.levAttr)
{
if (item.lev == lev)
{
return item;
}
}
return null;
}
#endregion
#region /
private async Task<List<game_equ_attr>> GetEquAttrData(string erCode)
{
string key = string.Format(BaseCache.BaseCacheKeys, "EquData", "EquAttrData");
if (await redis.HExistsHashAsync(key, erCode))
{
return await redis.GetHashAsync<List<game_equ_attr>>(key, erCode);
}
var db = DbClient.AsTenant().GetConnectionWithAttr<game_equ_attr>();
var data = await db.Queryable<game_equ_attr>().Where(it => it.equCode == erCode).ToListAsync();
await redis.AddHashAsync(key, erCode, data);
return data;
}
public async Task<List<AttrItem>> GetRandomEquAttr(string equCode, int lev)
{
//计算出的数量
List<RandomDataBase> numData = new List<RandomDataBase>()
{
new RandomDataBase() { random = 100, data = 1 },
new RandomDataBase() { random = 90, data = 2 },
new RandomDataBase() { random = 80, data = 3 },
new RandomDataBase() { random = 50, data = 4 },
new RandomDataBase() { random = 30, data = 5 },
new RandomDataBase() { random = 15, data = 6 },
new RandomDataBase() { random = 5, data = 7 },
};
var numR = GameBus.GetRandomByWeight(numData);
int onNum = Convert.ToInt32(numR.data);
var attrData = await GetEquAttrData(equCode);
attrData = attrData.FindAll(it => it.minLev <= lev && it.maxLev >= lev);
//开始随机拿属性权重
List<object> data = new List<object>();
List<ushort> weights = new List<ushort>();
List<object> attrResult = new List<object>();
Random rand = new Random();
foreach (var item in attrData)
{
data.Add(item);
weights.Add(ushort.Parse(item.random.ToString()));
}
RandomAssist random = new RandomAssist(onNum);
attrResult = random.ControllerRandomExtract(rand, data, weights);
List<AttrItem> result = new List<AttrItem>();
if (attrResult.Count > 0)
{
foreach (var item in attrResult)
{
var onAttr = item as game_equ_attr;
AttrItem temp = new AttrItem();
temp.code = onAttr.code;
temp.compute = onAttr.compute;
if (onAttr.nt == "Number")
{
int onMin = Convert.ToInt32(onAttr.min_v);
int onMax = Convert.ToInt32(onAttr.max_v);
int onPar = RandomAssist.GetFormatedNumeric(onMin, onMax + 1);
temp.parameter = onPar;
string onTip = temp.parameter.ToString().TrimEnd('0').TrimEnd('.');
temp.tip = string.Format(onAttr.tips, onTip);
}
else
{
int onMin = Convert.ToInt32(onAttr.min_v * 100);
int onMax = Convert.ToInt32(onAttr.max_v * 100);
int onPar = RandomAssist.GetFormatedNumeric(onMin, onMax + 1);
temp.parameter = Math.Round(Convert.ToDecimal(onPar / 100.000M), 2);
string onTip = (temp.parameter * 100).ToString().TrimEnd('0').TrimEnd('.');
temp.tip = string.Format(onAttr.tips, onTip);
}
result.Add(temp);
}
}
return result;
}
#endregion
#region
public async Task<unit_user_equ> GetUserEquAttr(unit_user_equ equ)
{
return equ;
}
public async Task<game_equ_up> GetUserEquUpData(int lev)
{
string key = string.Format(BaseCache.BaseCacheKeys, "EquData", "EquUpData");
var data = await redis.GetHashAsync<game_equ_up>(key, lev.ToString());
if (data == null)
{
var db = DbClient.AsTenant().GetConnectionWithAttr<game_equ_up>();
data = await db.Queryable<game_equ_up>().Where(i => i.onLev <= lev && i.maxLev >= lev).FirstAsync();
if (data != null)
{
await redis.AddHashAsync(key, lev.ToString(), data);
}
}
return data;
}
#endregion
@@ -361,5 +800,43 @@ public class GameEquService(ISqlSugarClient DbClient, IRedisCache redis) : IGame
return data.Sum(it => (int)it.weight);
}
private async Task<List<game_equ_make>> GetEquMakeData(int goodsId)
{
string key = string.Format(BaseCache.BaseCacheKeys, "EquData", "EquUpData");
if (await redis.HExistsHashAsync(key, goodsId.ToString()))
{
return await redis.GetHashAsync<List<game_equ_make>>(key, goodsId.ToString());
}
var db = DbClient.AsTenant().GetConnectionWithAttr<game_equ_make>();
var data = await db.Queryable<game_equ_make>().Where(it => it.goodsId == goodsId).ToListAsync();
await redis.AddHashAsync(key, goodsId.ToString(), data);
return data;
}
public async Task<game_equ_make> GetMakeEquByGoodsId(int goodsId)
{
//构建随机数据
List<RandomDataBase> equBase = new List<RandomDataBase>();
var equData = await GetEquMakeData(goodsId);
foreach (var me in equData)
{
RandomDataBase temp = new RandomDataBase();
temp.random = (double)me.random;
temp.data = me;
equBase.Add(temp);
}
var makeEqu = GameBus.GetRandomByWeight(equBase);
if (makeEqu == null)
{
return null;
}
var onMakeEqu = makeEqu.data as game_equ_make;
return onMakeEqu;
}
#endregion
}

View File

@@ -0,0 +1,208 @@
namespace Application.Domain;
public class GameFightService(ISqlSugarClient DbClient, IRedisCache redis) : IGameFightService, ITransient
{
#region
public async Task<List<string>> GetUserFight(string userId)
{
string key = string.Format(FightCache.FightCacheKey, "UserFight");
if (await redis.HExistsHashAsync(key, userId))
{
return await redis.GetHashAsync<List<string>>(key, userId);
}
List<string> data = new List<string>();
await redis.AddHashAsync(key, userId, data);
return data;
}
private async Task<bool> AddUserFight(string userId, string fightId)
{
var data = await GetUserFight(userId);
data.Add(fightId);
string key = string.Format(FightCache.FightCacheKey, "UserFight");
bool result = await redis.AddHashAsync(key, userId, data);
return result;
}
public async Task<bool> RemoveUserFight(string userId, string fightId)
{
var data = await GetUserFight(userId);
data.Remove(fightId);
string key = string.Format(FightCache.FightCacheKey, "UserFight");
bool result = await redis.AddHashAsync(key, userId, data);
return result;
}
#endregion
#region
public async Task<game_fight_data> GetFightInfo(string fightId)
{
string key = string.Format(FightCache.FightCacheKeys, "FightData:Info", fightId);
if (await redis.ExistsAsync(key))
{
return await redis.GetAsync<game_fight_data>(key);
}
var db = DbClient.AsTenant().GetConnectionWithAttr<game_fight_data>();
game_fight_data data = await db.Queryable<game_fight_data>().Where(it => it.fightId == fightId).SingleAsync();
await redis.SetAsync(key, data, 3600);
return data;
}
public async Task<long> GetFightBlood(string keyId, long maxBlood)
{
long blood = maxBlood;
string key = string.Format(FightCache.FightCacheKeys, "FightData:Blood", keyId);
if (await redis.ExistsAsync(key))
{
blood = await redis.GetAsync<long>(key);
blood = blood > maxBlood ? maxBlood : blood;
}
else
{
await SetFightBlood(keyId, blood);
}
return blood;
}
public async Task SetFightBlood(string keyId, long blood)
{
string key = string.Format(FightCache.FightCacheKeys, "FightData:Blood", keyId);
await redis.SetAsync(key, blood, 43200);
}
public async Task AddFightHarm(string fightId,string userId, long harm)
{
string key = string.Format(FightCache.FightCacheKeys, "FightData:Harm", fightId);
if (await redis.HExistsHashAsync(key, userId))
{
long sum = await redis.GetHashAsync<long>(key, userId);
sum += harm;
await redis.AddHashAsync(key, userId, sum);
}
else
{
await redis.AddHashAsync(key, userId, harm);
}
}
private async Task ClearFightInfoCache(string fightId, string keyId)
{
string key1 = string.Format(FightCache.FightCacheKeys, "FightData:Info", fightId);
string key2 = string.Format(FightCache.FightCacheKeys, "FightData:Blood", keyId);
await redis.DelAsync(key1, key2);
}
public async Task<bool> AddFight(string fightId, string areaCode, string keyId, string mainId, string code,
string scene, string mapId,
string userId, long exp = 0, long copper = 0, long petExp = 0, string award = "", string pars = "")
{
long addTime = TimeExtend.GetTimeStampSeconds;
long endTime = addTime + 24 * 60 * 60;
List<game_fight_data> fights = new List<game_fight_data>();
game_fight_data data = new game_fight_data()
{
fightId = fightId,
areaCode = areaCode,
keyId = keyId,
mainId = mainId,
code = code,
scene = scene,
mapId = mapId,
userId = userId,
state = 0,
winUser = "",
exp = exp,
copper = copper,
petExp = petExp,
award = award,
pars = pars,
addTime = addTime,
okTime = 0,
endTime = endTime
};
fights.Add(data);
if (code == nameof(GameEnum.FightCode.PVP))
{
fights.Add(new game_fight_data()
{
fightId = StringAssist.NewGuid,
areaCode = areaCode,
keyId = keyId,
mainId = userId,
code = code,
scene = scene,
mapId = mapId,
userId = mainId,
state = 0,
winUser = "",
exp = exp,
copper = copper,
petExp = petExp,
award = award,
pars = pars,
addTime = addTime,
okTime = 0,
endTime = endTime
});
}
var db = DbClient.AsTenant().GetConnectionWithAttr<game_fight_data>();
bool result = await db.Insertable(fights).ExecuteCommandAsync() > 0;
if (result)
{
foreach (var item in fights)
{
await AddUserFight(item.userId, item.fightId);
}
}
return result;
}
public async Task<bool> SetFightWin(string fightId, string winUser)
{
bool result = false;
var data = await GetFightInfo(fightId);
if (data != null)
{
long okTime = TimeExtend.GetTimeStampSeconds;
data.state = 1;
data.winUser = winUser;
data.okTime = okTime;
var db = DbClient.AsTenant().GetConnectionWithAttr<game_fight_data>();
result = await db.Updateable<game_fight_data>().SetColumns(it => it.state == 1)
.SetColumns(it => it.winUser == winUser)
.SetColumns(it => it.okTime == okTime)
.Where(it => it.fightId == fightId).ExecuteCommandAsync() > 0;
}
if (result)
{
await ClearFightInfoCache(fightId, data.keyId);
//此处调用战斗结束相关
await HandleFight(data);
}
return result;
}
#endregion
#region
private async Task HandleFight(game_fight_data data)
{
}
#endregion
}

View File

@@ -1,4 +1,5 @@
using System.Reflection.Metadata;
using Newtonsoft.Json;
namespace Application.Domain;
@@ -68,6 +69,7 @@ public class GameGoodsService(ISqlSugarClient DbClient, IRedisCache redis) : IGa
.OrderBy(it => it.count, OrderByType.Desc)
.ToPageListAsync(page, limit, total);
}
public async Task<List<unit_user_goods>> GetUserGoodsData(string userId, string code)
{
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_goods>();
@@ -163,8 +165,6 @@ public class GameGoodsService(ISqlSugarClient DbClient, IRedisCache redis) : IGa
return await db.Insertable(bagLog).SplitTable().ExecuteCommandAsync() > 0;
}
#endregion
#region
@@ -187,19 +187,142 @@ public class GameGoodsService(ISqlSugarClient DbClient, IRedisCache redis) : IGa
#endregion
#region
public async Task<game_ship> GetShipInfo(int shipId)
#region
private async Task<long> GetUserDrugLockTime(string userId, int goodsId)
{
string key = string.Format(BaseCache.BaseCacheKey, "ShipData");
var data = await redis.GetHashAsync<game_ship>(key, shipId.ToString());
if (data == null)
long result = 0;
string key = string.Format(UserCache.BaseCacheKey, "UserDrug", $"Lock:{userId}_{goodsId}");
if (await redis.ExistsAsync(key))
{
var db = DbClient.AsTenant().GetConnectionWithAttr<game_ship>();
data = await db.Queryable<game_ship>().Where(it => it.shipId == shipId).SingleAsync();
await redis.AddHashAsync(key, shipId.ToString(), data);
long end = await redis.GetAsync<long>(key);
result = end - TimeExtend.GetTimeStampSeconds;
result = result < 0 ? 0 : result;
}
return data;
return result;
}
private async Task AddUserDrugLockTime(string userId, int goodsId, int time)
{
if (time > 0)
{
long end = TimeExtend.GetTimeStampSeconds + time;
string key = string.Format(UserCache.BaseCacheKey, "UserDrug", $"Lock:{userId}_{goodsId}");
await redis.SetAsync(key, end, time);
}
}
private async Task<int> GetUserDrugLockCount(string userId, int goodsId, string scene = "")
{
int result = 0;
if (!string.IsNullOrEmpty(scene))
{
string key = string.Format(UserCache.BaseCacheKey, "UserDrug", $"Count:{scene}:{userId}_{goodsId}");
if (await redis.ExistsAsync(key))
{
result = await redis.GetAsync<int>(key);
}
}
return result;
}
private async Task AddUserDrugLockCount(string userId, int goodsId, string scene = "")
{
if (!string.IsNullOrEmpty(scene))
{
var count = await GetUserDrugLockCount(userId, goodsId, scene);
count += 1;
string key = string.Format(UserCache.BaseCacheKey, "UserDrug", $"Count:{scene}:{userId}_{goodsId}");
await redis.SetAsync(key, count, 43200);
}
}
public async Task<string> CheckUseDrug(string userId, int goodsId, string drugConfig, string scene = "")
{
string result = string.Empty;
dynamic _drugConfig = JsonConvert.DeserializeObject<dynamic>(drugConfig);
if (_drugConfig.cls == nameof(GoodsEnum.DrugCls.Blood))
{
//判断所定
long lockTime = await GetUserDrugLockTime(userId, goodsId);
if (lockTime > 0)
{
result = $"药品冷却中,{lockTime}秒后可使用!";
}
}
else if (_drugConfig.cls == nameof(GoodsEnum.DrugCls.BloodStock))
{
if (_drugConfig.type == nameof(GameEnum.GameStockType.Number))
{
if (string.IsNullOrEmpty(scene))
{
var attrService = App.GetService<IUnitUserAttrService>();
var userStock = await attrService.GetUserStock(userId);
if (userStock.Count(it => it.goodsId == goodsId.ToString()) > 0)
{
result = "您已经使用过该药品啦!";
}
}
else
{
//要判断使用个数
if (_drugConfig.use > 0)
{
var count = await GetUserDrugLockCount(userId, goodsId, scene);
if (count >= _drugConfig.use)
{
result = $"当前最多可用{_drugConfig.use}个该物品!";
}
}
}
}
}
return result;
}
public async Task<bool> UseDrug(string userId, int goodsId, string drugConfig, string scene = "")
{
bool result = false;
var attrService = App.GetService<IUnitUserAttrService>();
dynamic _drugConfig = JsonConvert.DeserializeObject<dynamic>(drugConfig);
if (_drugConfig.cls == nameof(GoodsEnum.DrugCls.Blood))
{
result = await attrService.UpdateUserBlood(userId, 1, Convert.ToInt32(_drugConfig.num), true);
if (result)
{
await AddUserDrugLockTime(userId, goodsId, Convert.ToInt32(_drugConfig.time));
}
}
else if (_drugConfig.cls == nameof(GoodsEnum.DrugCls.Morale))
{
result = await attrService.UpdateUserMorale(userId, 1, Convert.ToInt32(_drugConfig.num));
}
else if (_drugConfig.cls == nameof(GoodsEnum.DrugCls.Vigour))
{
result = await attrService.UpdateUserVigour(userId, 1, Convert.ToInt32(_drugConfig.num));
}
else if (_drugConfig.cls == nameof(GoodsEnum.DrugCls.LoadBuff))
{
result = await attrService.RandomRemoveUserLoadState(userId, Convert.ToInt32(_drugConfig.num));
}
else if (_drugConfig.cls == nameof(GoodsEnum.DrugCls.BloodStock))
{
result = await attrService.AddUserStock(userId, goodsId.ToString(), Convert.ToString(_drugConfig.name),Convert.ToString(_drugConfig.type),
Convert.ToString(_drugConfig.code),
Convert.ToInt64(_drugConfig.num), Convert.ToString(_drugConfig.par),
Convert.ToInt32(_drugConfig.minute));
if (result)
{
await AddUserDrugLockCount(userId, goodsId, scene);
}
}
return result;
}
#endregion
}

View File

@@ -148,6 +148,12 @@ public class GameMapService(ISqlSugarClient DbClient, IRedisCache redis) : IGame
return data.mapId;
}
public async Task<game_city_map> GetUserOnToMapInfo(string userId)
{
var onMap = await GetUserOnMapId(userId);
return await GetMapInfo(onMap);
}
public async Task<unit_user_online> GetUserOnMap(string userId)
{
string key = string.Format(UserCache.BaseCacheKey, "UserOnline");
@@ -832,7 +838,7 @@ public class GameMapService(ISqlSugarClient DbClient, IRedisCache redis) : IGame
if (!string.IsNullOrEmpty(offSet))
{
var offsetData = JsonConvert.DeserializeObject<TowerNeed>(offSet);
var chekResult = await GameBus.CheakNeed(userId, offsetData, "");
var chekResult = await GameBus.CheckNeed(userId, offsetData);
if (chekResult.result)
{
if (offsetData.isOp == 0)
@@ -858,7 +864,7 @@ public class GameMapService(ISqlSugarClient DbClient, IRedisCache redis) : IGame
public async Task<List<game_city_map_bus>> GetMapBus(string BusCode, int v, int l)
{
string key = string.Format(BaseCache.BaseCacheKeys, "CITY_MAP_BUS", BusCode);
string key = string.Format(BaseCache.BaseCacheKeys, "CityMapBus", BusCode);
var data = await redis.GetAsync<List<game_city_map_bus>>(key);
if (data == null)
{
@@ -877,7 +883,7 @@ public class GameMapService(ISqlSugarClient DbClient, IRedisCache redis) : IGame
public async Task<game_city_map_bus> GetMapBusInfo(int busId)
{
string key = string.Format(BaseCache.BaseCacheKeys, "CITY_MAP_BUS", "BUS_INFO");
string key = string.Format(BaseCache.BaseCacheKeys, "CityMapBus", "BUS_INFO");
if (await redis.HExistsHashAsync(key, busId.ToString()))
{
return await redis.GetHashAsync<game_city_map_bus>(key, busId.ToString());
@@ -925,6 +931,7 @@ public class GameMapService(ISqlSugarClient DbClient, IRedisCache redis) : IGame
#endregion
#region
public async Task<game_city_map_res> GetMapResInfo(string resId)
{
string key = string.Format(BaseCache.BaseCacheKeys, "CityData", "MapResInfo");
@@ -938,6 +945,7 @@ public class GameMapService(ISqlSugarClient DbClient, IRedisCache redis) : IGame
return data;
}
public async Task<List<game_city_map_res>> GetMapRes(string mapId)
{
string key = string.Format(BaseCache.BaseCacheKeys, "CityData", "MapRes");

View File

@@ -0,0 +1,207 @@
using Microsoft.VisualBasic.CompilerServices;
namespace Application.Domain;
public class GameMonsterService(ISqlSugarClient DbClient, IRedisCache redis) : IGameMonsterService, ITransient
{
#region
public async Task<game_monster> GetMonsterInfo(string monsterId)
{
string key = string.Format(BaseCache.BaseCacheKeys, "MonsterData", "MonsterInfo");
if (await redis.HExistsHashAsync(key, monsterId))
{
return await redis.GetHashAsync<game_monster>(key, monsterId);
}
var db = DbClient.AsTenant().GetConnectionWithAttr<game_monster>();
var data = await db.Queryable<game_monster>().Where(it => it.monsterId == monsterId).SingleAsync();
await redis.AddHashAsync(key, monsterId, data);
return data;
}
#endregion
#region
public async Task<List<game_monster_map>> GetMonsterDataByMap(string mapId)
{
string key = string.Format(BaseCache.BaseCacheKeys, "MonsterData", "MonsterOnMap");
if (await redis.HExistsHashAsync(key, mapId))
{
return await redis.GetHashAsync<List<game_monster_map>>(key, mapId);
}
var db = DbClient.AsTenant().GetConnectionWithAttr<game_monster_map>();
var data = await db.Queryable<game_monster_map>().Where(it => it.mapId == mapId).ToListAsync();
await redis.AddHashAsync(key, mapId, data);
return data;
}
public async Task<game_monster_map> GetMapMonsterInfo(string mmId)
{
string key = string.Format(BaseCache.BaseCacheKeys, "MonsterData", "MapMonsterInfo");
if (await redis.HExistsHashAsync(key, mmId))
{
return await redis.GetHashAsync<game_monster_map>(key, mmId);
}
var db = DbClient.AsTenant().GetConnectionWithAttr<game_monster_map>();
var data = await db.Queryable<game_monster_map>().Where(it => it.mmId == mmId).SingleAsync();
await redis.AddHashAsync(key, mmId, data);
return data;
}
public async Task<bool> CreateMonsterToMap(string userId, string mapId, string areaCode, string monsterId,
int count = 1, int time = 0, string par = "")
{
bool result = false;
var monsterInfo = await GetMonsterInfo(monsterId);
if (monsterInfo != null)
{
time = time <= 0 ? 7 * 24 * 60 : time;
long onTime = TimeExtend.GetTimeStampSeconds;
long endTime = onTime + time * 60;
List<unit_user_monster> data = new List<unit_user_monster>();
for (int i = 0; i < count; i++)
{
data.Add(new unit_user_monster()
{
umId = StringAssist.NewGuid,
userId = userId,
areaCode = areaCode,
mapId = mapId,
monsterId = monsterId,
monsterName = monsterInfo.name,
code = monsterInfo.code,
par = par,
addTime = onTime,
endTime = endTime
});
}
if (data.Count > 0)
{
var createDb = DbClient.AsTenant().GetConnectionWithAttr<unit_user_monster>();
await createDb.Insertable(data).ExecuteCommandAsync();
}
result = true;
}
if (result)
{
await ClearCreateMonster(mapId);
}
return result;
}
private async Task<List<unit_user_monster>> GetCreateMonsterByMapId(string mapId)
{
string key = string.Format(BaseCache.BaseCacheKeys, "MonsterData", "CreateMonsterOnMap");
if (await redis.HExistsHashAsync(key, mapId))
{
return await redis.GetHashAsync<List<unit_user_monster>>(key, mapId);
}
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_monster>();
var data = await db.Queryable<unit_user_monster>().Where(it => it.mapId == mapId).ToListAsync();
await redis.AddHashAsync(key, mapId, data);
return data;
}
public async Task<unit_user_monster> GetCreateMonsterInfo(string umId)
{
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_monster>();
var data = await db.Queryable<unit_user_monster>().Where(it => it.umId == umId).SingleAsync();
return data;
}
private async Task ClearCreateMonster(string mapId)
{
string key = string.Format(BaseCache.BaseCacheKeys, "MonsterData", "CreateMonsterOnMap");
await redis.DelHashAsync(key, mapId);
}
public async Task<List<MapMonsterModel>> GetMapMonster(string userId, string mapId, string teamId)
{
string userKey = await UserKeyTool.GetUserKey(userId);
List<MapMonsterModel> result = new List<MapMonsterModel>();
var mapMonster = await GetMonsterDataByMap(mapId);
if (mapMonster.Count > 0)
{
int random = 0; //此处需要判断用户状态中的几率
int onTime = TimeAssist.GetHourNum;
foreach (var item in mapMonster)
{
if (item.sTime < onTime && item.eTime > onTime)
{
if (RandomAssist.CheakRandom((int)item.chance + random))
{
for (int i = 0; i < item.addCount; i++)
{
MapMonsterModel temp = new MapMonsterModel()
{
monterId = item.mmId,
name = item.monsterName,
type = 0,
sign = UserKeyTool.GetThickenDataByUserKey(userKey, "0", item.mmId)
};
result.Add(temp);
}
}
}
}
}
//此处追加个人生成怪物
List<unit_user_monster> createData = new List<unit_user_monster>();
var createMonster = await GetCreateMonsterByMapId(mapId);
if (createMonster.Count > 0)
{
long onTime = TimeExtend.GetTimeStampSeconds;
createMonster = createMonster.FindAll(it => it.endTime > onTime);
createData.AddRange(createMonster.FindAll(it =>
it.userId == userId || it.areaCode == nameof(GameEnum.AreaCode.Public)));
if (!string.IsNullOrEmpty(teamId) && teamId != "0")
{
var teamService = App.GetService<IGameTeamService>();
var teamMember = await teamService.GetTeamMember(teamId);
teamMember = teamMember.FindAll(it => it.userId != userId);
var onCreate = createMonster.FindAll(it =>
teamMember.Any(team =>
team.userId == it.userId && it.areaCode == nameof(GameEnum.AreaCode.Team)));
foreach (var item in onCreate)
{
if (createData.Any(it => it.umId == item.umId))
{
continue;
}
createData.Add(item);
}
}
}
if (createData.Count > 0)
{
foreach (var item in createData)
{
MapMonsterModel temp = new MapMonsterModel()
{
monterId = item.umId,
name = item.monsterName,
type = 1,
sign = UserKeyTool.GetThickenDataByUserKey(userKey, "1", item.umId)
};
result.Add(temp);
}
}
return result;
}
#endregion
}

View File

@@ -0,0 +1,19 @@
namespace Application.Domain;
public class GameDicService(ISqlSugarClient DbClient, IRedisCache redis) : IGameDicService, ITransient
{
public async Task<game_dic> GetDicInfo(string code)
{
string key = string.Format(BaseCache.BaseCacheKey, "DicData");
if (await redis.HExistsHashAsync(key, code))
{
return await redis.GetHashAsync<game_dic>(key, code);
}
var db = DbClient.AsTenant().GetConnectionWithAttr<game_dic>();
var data = await db.Queryable<game_dic>().Where(it => it.code == code).SingleAsync();
await redis.AddHashAsync(key, code, data);
return data;
}
}

View File

@@ -33,6 +33,7 @@ public class GameTeamService(ISqlSugarClient DbClient, IRedisCache redis) : IGam
await redis.AddHashAsync(key, userId, data);
return data;
}
public async Task<game_team> GetTeamInfo(string teamId)
{

View File

@@ -311,8 +311,9 @@ public class MessageService(ISqlSugarClient DbClient, IRedisCache redis) : IMess
return await db.Queryable<unit_user_message_event>().Where(it => it.state == 0 && it.token == token).AnyAsync();
}
public async Task<bool> SendEventMsg(string userId, string code, string name, string sign, string pars,string token,
List<MsgEventBtn> btns=null, int days = 10)
public async Task<bool> SendEventMsg(string userId, string code, string name, string sign, string pars,
string token,
List<MsgEventBtn> btns = null, int days = 10)
{
unit_user_message_event data = new unit_user_message_event();
data.eventId = StringAssist.NewGuid;
@@ -331,8 +332,9 @@ public class MessageService(ISqlSugarClient DbClient, IRedisCache redis) : IMess
}
else
{
data.btns = btns;
data.btns = btns;
}
data.addTime = DateTime.Now;
data.endTime = TimeExtend.GetTimeStampBySeconds(DateTime.Now.AddDays(days));
data.token = token;
@@ -347,4 +349,54 @@ public class MessageService(ISqlSugarClient DbClient, IRedisCache redis) : IMess
}
#endregion
#region 广
public async Task<List<game_broadcast>> GetBroadcastData(int area)
{
List<game_broadcast> data = new List<game_broadcast>();
string key = string.Format(BaseCache.BaseCacheKey, "GameBroadcast");
var result = await redis.GetHashAllAsync<game_broadcast>(key);
if (result.Count > 0)
{
data = result.Values.ToList();
}
long time = TimeExtend.GetTimeStampSeconds;
data = data.FindAll(it => (it.area == area || it.area == 0) && it.endTime > time);
data = data.OrderByDescending(it => it.endTime).Take(2).ToList();
return data;
}
public async Task<bool> SendBroadcast(string userId, string code, string msg)
{
game_broadcast add = new game_broadcast();
add.Id = StringAssist.NewGuid;
add.userId = userId;
add.code = code;
add.msg = msg;
int area = 0;
if (add.userId == "0")
{
add.area = 0;
add.userNo = "0";
add.nick = "海精灵";
}
else
{
var userService = App.GetService<IUnitUserService>();
var userInfo = await userService.GetUserInfoByUserId(userId);
add.area = (int)userInfo.areaId;
add.userNo = userInfo.userNo;
add.nick = userInfo.nick;
area = add.area;
}
add.endTime = TimeExtend.GetTimeStampSeconds + 300;
string key = string.Format(BaseCache.BaseCacheKey, "GameBroadcast");
bool result = await redis.AddHashAsync(key, add.Id, add);
return result;
}
#endregion
}

View File

@@ -4,7 +4,7 @@ public class UnitUserAttrService(ISqlSugarClient DbClient, IRedisCache redis) :
{
#region
public async Task<UserAttrModel> GetUserAttrModel(string userId)
public async Task<UserAttrModel> GetUserAttrModel(string userId, string scene = "Default")
{
UserAttrModel result = new UserAttrModel();
result.id = userId;
@@ -24,11 +24,150 @@ public class UnitUserAttrService(ISqlSugarClient DbClient, IRedisCache redis) :
result.agility = (int)unitAttr.agility;
result.upBlood = (int)unitAttr.upBlood;
result.upMorale = (int)unitAttr.upMorale;
var bloodInfo = await GetUserBlood(userId);
result.blood = (int)bloodInfo.blood;
var moraleInfo = await GetUserMorale(userId);
result.morale = (int)moraleInfo.morale;
List<AttrItem> ExtendAttrData = new List<AttrItem>();
#region
UserAttrModel temp = new UserAttrModel();
temp.minAtk = (int)unitAttr.minAtk;
temp.maxAtk = (int)unitAttr.maxAtk;
temp.defense = (int)unitAttr.defense;
temp.agility = (int)unitAttr.agility;
temp.upBlood = (int)unitAttr.upBlood;
temp.upMorale = (int)unitAttr.upMorale;
var equService = App.GetService<IGameEquService>();
var equTemp = await equService.GetUserEquAttrModel(userId);
temp = GameAttrTool.GetRoleAttrTempMerge(temp, equTemp);
//套装加层
var suitAttr = await equService.GetUserEquSuitAttrInfo(userId);
ExtendAttrData.AddRange(suitAttr);
#endregion
#region
int minAtk = 0;
int maxAtk = 0;
int Agility = 0;
int Defense = 0;
int upBlood = 0;
int upMorale = 0;
#endregion
#region
var teamService = App.GetService<IGameTeamService>();
var MyTeam = await teamService.GetUserTeamInfo(userId);
if (MyTeam.state == 1)
{
int teamCount = MyTeam.user.Count(it => it.isOnline == 1);
if (teamCount > 0)
{
decimal teamAdd = 0.05m * teamCount;
teamAdd = teamAdd > 0.2m ? 0.2m : teamAdd;
minAtk += Convert.ToInt32(temp.minAtk * teamAdd);
maxAtk += Convert.ToInt32(temp.maxAtk * teamAdd);
Defense += Convert.ToInt32(temp.defense * teamAdd);
result.atkTips += $"(队+{Convert.ToInt32(teamAdd * 100)}%)";
result.defTips += $"(队+{Convert.ToInt32(teamAdd * 100)}%)";
}
}
#endregion
#region Buff加层
var MyState = await GetUserStateData(userId, scene);
if (MyState.Count > 0)
{
foreach (var item in MyState)
{
minAtk += Convert.ToInt32(GameAttrTool.GetAttrItemValue(GameEnum.AttrCode.Atk.ToString(), item.attr,
temp.minAtk));
maxAtk += Convert.ToInt32(GameAttrTool.GetAttrItemValue(GameEnum.AttrCode.Atk.ToString(), item.attr,
temp.maxAtk));
Defense += Convert.ToInt32(GameAttrTool.GetAttrItemValue(GameEnum.AttrCode.Defense.ToString(),
item.attr, temp.defense));
Agility += Convert.ToInt32(GameAttrTool.GetAttrItemValue(GameEnum.AttrCode.Agility.ToString(),
item.attr, temp.agility));
upBlood += Convert.ToInt32(GameAttrTool.GetAttrItemValue(GameEnum.AttrCode.Blood.ToString(), item.attr,
temp.upBlood));
upMorale += Convert.ToInt32(GameAttrTool.GetAttrItemValue(GameEnum.AttrCode.Morale.ToString(),
item.attr, temp.upMorale));
}
}
#endregion
#region
var otTemp = GameAttrTool.GetRoleAttrTemp(temp, ExtendAttrData);
result = GameAttrTool.GetRoleAttrTempMerge(result, otTemp); //加层其他
result = GameAttrTool.GetRoleAttrTempMerge(result, temp); //加层其他
result.minAtk += minAtk;
result.maxAtk += maxAtk;
result.defense += Defense;
result.agility += Agility;
result.upBlood += upBlood;
result.upMorale += upMorale;
#endregion
#region
var userBlood = await GetUserBlood(userId);
result.blood = (int)userBlood.blood;
//士气
var userMorale = await GetUserMorale(userId);
result.morale = (int)userMorale.morale;
//负面状态处理
var loadState = await GetUserLoadState(userId);
result = await GameAttrTool.CheckRoleLoadBuff(result, loadState);
result = await ReviseUserRoleAttr(result);
return result;
#endregion
return result;
}
private async Task<UserAttrModel> ReviseUserRoleAttr(UserAttrModel result)
{
//处理上限数据
if (result.blood > result.upBlood)
{
result.blood = result.upBlood;
await UpdateUserBlood(result.id, 2, result.blood, true);
}
if (result.morale > result.upMorale)
{
result.morale = result.upMorale;
await UpdateUserMorale(result.id, 2, Convert.ToInt32(result.morale));
}
if (result.NoHarm > 0.8M) //免伤上限
{
result.NoHarm = 0.8M;
}
if (result.Atk_Next > 0.3M) //连击上限
{
result.Atk_Next = 0.3M;
}
//评分
decimal _score = result.maxAtk + result.defense + result.agility + result.upBlood / 3.00M + result.upMorale;
result.score = Math.Round(_score, 2);
return result;
}
@@ -103,6 +242,11 @@ public class UnitUserAttrService(ISqlSugarClient DbClient, IRedisCache redis) :
else if (op == 1)
{
data.blood += count;
var myAttr = await GetUserAttrModel(userId);
if (myAttr != null)
{
data.blood = data.blood > myAttr.upBlood ? myAttr.upBlood : data.blood;
}
}
}
@@ -200,9 +344,6 @@ public class UnitUserAttrService(ISqlSugarClient DbClient, IRedisCache redis) :
if (result && IsUpUserAttr)
{
//增加负重
var wightService = App.GetService<IUnitUserWeight>();
await wightService.UpdateUserMaxWeight(userId, 1, GameConfig.UpLevAddWeight, 1, 0, "升级增加负重");
await ClearUserAttrCache(userId);
}
@@ -234,6 +375,8 @@ public class UnitUserAttrService(ISqlSugarClient DbClient, IRedisCache redis) :
if (op == 1)
{
data.morale += count;
var myAttr = await GetUserAttrModel(userId);
data.morale = data.morale > myAttr.upMorale ? myAttr.upMorale : data.morale;
}
else if (op == 2)
{
@@ -260,10 +403,11 @@ public class UnitUserAttrService(ISqlSugarClient DbClient, IRedisCache redis) :
string key = string.Format(UserCache.BaseCacheKeys, "Recover:Morale", userId);
return await redis.ExistsAsync(key);
}
public async Task LockRecoverMorale(string userId)
{
string key = string.Format(UserCache.BaseCacheKeys, "Recover:Morale", userId);
await redis.SetAsync(key, DateTime.Now,TimeAssist.GetDateTimeYMD(1));
await redis.SetAsync(key, DateTime.Now, TimeAssist.GetDateTimeYMD(1));
}
#endregion
@@ -295,6 +439,13 @@ public class UnitUserAttrService(ISqlSugarClient DbClient, IRedisCache redis) :
public async Task<bool> UpdateUserVigour(string userId, int op, long count, string UpTime = "")
{
if (op == 1)
{
var userVigour = await GetUserVigourInfo(userId);
long endVigour = (long)userVigour.upVitality - (long)userVigour.vitality;
count = endVigour > count ? count : endVigour;
}
bool result = false;
try
{
@@ -337,7 +488,7 @@ public class UnitUserAttrService(ISqlSugarClient DbClient, IRedisCache redis) :
#endregion
#region 线
#region 线
public async Task<bool> UpdateOnLineTime(string userId, string code, int time)
{
@@ -350,6 +501,314 @@ public class UnitUserAttrService(ISqlSugarClient DbClient, IRedisCache redis) :
return result;
}
#endregion
#region
public async Task<unit_user_drug> GetUserDrug(string userId)
{
string key = string.Format(UserCache.BaseCacheKeys, "UserTool", "DrugColumn");
if (await redis.HExistsHashAsync(key, userId))
{
return await redis.GetHashAsync<unit_user_drug>(key, userId);
}
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_drug>();
var data = await db.Queryable<unit_user_drug>().Where(it => it.userId == userId).SingleAsync();
if (data == null)
{
data = new unit_user_drug();
data.userId = userId;
data.drug = new List<UserDrugModel>();
await db.Insertable(data).ExecuteCommandAsync();
}
await redis.AddHashAsync(key, userId, data);
return data;
}
public async Task<bool> UpdateUserDrug(unit_user_drug data)
{
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_drug>();
bool result = await db.Updateable<unit_user_drug>(data).ExecuteCommandAsync() > 0;
if (result)
{
await ClearUserDrug(data.userId);
}
return result;
}
private async Task ClearUserDrug(string userId)
{
string key = string.Format(UserCache.BaseCacheKeys, "UserTool", "DrugColumn");
await redis.DelHashAsync(key, userId);
}
#endregion
#region BUFF状态
private async Task<List<unit_user_state>> GetUserStateData(string userId)
{
string key = string.Format(UserCache.BaseCacheKeys, "AttrData", "State");
var data = await redis.GetHashAsync<List<unit_user_state>>(key, userId);
if (data == null)
{
long endTime = TimeExtend.GetTimeStampSeconds;
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_state>();
data = await db.Queryable<unit_user_state>().Where(it => it.userId == userId && it.endTime > endTime)
.ToListAsync();
await redis.AddHashAsync(key, userId, data);
}
return data;
}
public async Task<List<unit_user_state>> GetUserStateData(string userId, string scene = "Default")
{
var data = await GetUserStateData(userId);
if (scene == "ALL")
{
return data;
}
data = data.FindAll(it => it.scene == "Default" || it.scene == scene);
return data;
}
public async Task<bool> AddUserState(string userId, string groupId, string name, string scene, string tips,
List<AttrItem> attr, int time, int count = 1)
{
bool result = false;
long onTime = TimeExtend.GetTimeStampSeconds;
string usId = $"{userId}_{groupId}";
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_state>();
var usData = await db.Queryable<unit_user_state>().Where(it => it.usId == usId).SingleAsync();
if (usData == null)
{
usData = new unit_user_state();
usData.usId = usId;
usData.userId = userId;
usData.goodsId = groupId;
usData.name = name;
usData.scene = scene;
usData.tips = tips;
usData.attr = attr;
usData.addTime = onTime;
usData.endTime = onTime + (time * 60 * count);
result = await db.Insertable(usData).ExecuteCommandAsync() > 0;
}
else
{
if (usData.endTime > onTime)
{
usData.endTime = usData.endTime + (time * 60 * count);
}
else
{
usData.addTime = onTime;
usData.endTime = onTime + (time * 60 * count);
}
result = await db.Updateable(usData).ExecuteCommandAsync() > 0;
}
if (result)
{
await ClearUserState(userId);
}
return result;
}
private async Task ClearUserState(string userId)
{
string key = string.Format(UserCache.BaseCacheKeys, "AttrData", "State");
await redis.DelHashAsync(key, userId);
}
#endregion
#region
private async Task<List<unit_user_stock>> GetUserStock(string userId)
{
string key = string.Format(UserCache.BaseCacheKeys, "AttrData", "Stock");
var data = await redis.GetHashAsync<List<unit_user_stock>>(key, userId);
if (data == null)
{
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_stock>();
data = await db.Queryable<unit_user_stock>().Where(it => it.userId == userId).ToListAsync();
await redis.AddHashAsync(key, userId, data);
}
return data;
}
public async Task<List<unit_user_stock>> GetUserStock(string userId, string code = "Default")
{
var data = await GetUserStock(userId);
if (code != "Default")
{
data = data.FindAll(it => it.code == code);
}
long endTime = TimeExtend.GetTimeStampSeconds;
data = data.FindAll(it =>
((it.type == "Number" && it.sign > 0) || it.type != "Number") && it.endTime > endTime);
return data;
}
public async Task<bool> AddUserStock(string userId, string goodsId, string name, string type, string code,
long sign,
string par = "",
int minute = 0)
{
if (minute == 0)
{
minute = 525600;
}
bool result = false;
string usId = $"{userId}_{goodsId}";
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_stock>();
var usInfo = await db.Queryable<unit_user_stock>().Where(it => it.usId == usId).SingleAsync();
if (usInfo == null)
{
long endTime = TimeExtend.GetTimeStampSeconds + minute * 60;
unit_user_stock stock = new unit_user_stock()
{
usId = usId,
userId = userId,
goodsId = goodsId,
name = name,
type = type,
code = code,
sign = sign,
par = par,
endTime = endTime
};
result = await db.Insertable(stock).ExecuteCommandAsync() > 0;
}
else
{
if (usInfo.type == nameof(GameEnum.GameStockType.Number))
{
usInfo.sign += sign;
usInfo.endTime = TimeExtend.GetTimeStampSeconds + minute * 60;
}
else if (usInfo.type == nameof(GameEnum.GameStockType.Time))
{
long onTime = TimeExtend.GetTimeStampSeconds;
if (usInfo.endTime > onTime)
{
usInfo.endTime = usInfo.endTime + (minute * 60);
}
else
{
usInfo.endTime = TimeExtend.GetTimeStampSeconds + (minute * 60);
}
}
result = await db.Updateable(usInfo).ExecuteCommandAsync() > 0;
}
if (result)
{
await ClearUserStockCache(userId);
}
return result;
}
private async Task ClearUserStockCache(string userId)
{
string key = string.Format(UserCache.BaseCacheKeys, "AttrData", "Stock");
await redis.DelHashAsync(key, userId);
}
public async Task<bool> UpdateUserStock(unit_user_stock data)
{
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_stock>();
var result = await db.Updateable(data).ExecuteCommandAsync() > 0;
if (result)
{
await ClearUserAttrCache(data.userId);
}
return result;
}
#endregion
#region
public async Task<List<unit_user_load>> GetUserLoadState(string userId)
{
string key = string.Format(UserCache.BaseCacheKeys, "AttrData", "LoadState");
if (await redis.HExistsHashAsync(key, userId))
{
return await redis.GetHashAsync<List<unit_user_load>>(key, userId);
}
return new List<unit_user_load>();
}
public async Task<bool> AddUserLoadState(string userId, string name, string code)
{
bool result = false;
string key = string.Format(UserCache.BaseCacheKeys, "AttrData", "LoadState");
var data = await GetUserLoadState(userId);
var onData = data.Find(it => it.code == code);
if (onData == null)
{
unit_user_load load = new unit_user_load()
{
id = $"{userId}_{code}",
userId = userId,
name = name,
code = code,
count = 1
};
data.Add(load);
result = await redis.AddHashAsync(key, userId, data);
}
else
{
data.Remove(onData);
onData.count += 1;
result = await redis.AddHashAsync(key, userId, data);
}
return result;
}
public async Task<bool> RandomRemoveUserLoadState(string userId, int count)
{
var data = await GetUserLoadState(userId);
int opCount = data.Count - count;
opCount = opCount < 0 ? 0 : opCount;
if (opCount > 0)
{
RandomAssist random = new RandomAssist(opCount);
var result = random.RandomExtract(data);
string key = string.Format(UserCache.BaseCacheKeys, "AttrData", "LoadState");
await redis.AddHashAsync(key, userId, result);
}
else
{
await RemoveUserLoadState(userId);
}
return true;
}
public async Task RemoveUserLoadState(string userId)
{
string key = string.Format(UserCache.BaseCacheKeys, "AttrData", "LoadState");
await redis.DelHashAsync(key, userId);
}
#endregion
}

View File

@@ -268,9 +268,7 @@ public class UnitUserService(ISqlSugarClient DbClient, IRedisCache redis) : IUni
if (result)//注册各项后处理
{
//赠送初始负重
var weightService = App.GetService<IUnitUserWeight>();
await weightService.UpdateUserMaxWeight(userId, 1, 100, 1, 0, "初始负重");
}
return result;

View File

@@ -19,8 +19,12 @@ public class UnitUserWeight(ISqlSugarClient DbClient, IRedisCache redis) : IUnit
private async Task<int> GetUserMaxWeight(unit_user_weight data)
{
int result = (int)data.maxWeight;
int result = 100 + (int)data.maxWeight;
var attrService = App.GetService<IUnitUserAttrService>();
int myLev = await attrService.GetUserLev(data.userId);
result += myLev * GameConfig.UpLevAddWeight;
//其他属性加层
return result;
}
@@ -41,7 +45,7 @@ public class UnitUserWeight(ISqlSugarClient DbClient, IRedisCache redis) : IUnit
return result;
}
public async Task<bool> UpdateUserWeight(string userId, int op, int weight)
{
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_weight>();
@@ -119,6 +123,7 @@ public class UnitUserWeight(ISqlSugarClient DbClient, IRedisCache redis) : IUnit
}
#region
public async Task<unit_user_ship> GetUserShipInfo(string usId)
{
string key = string.Format(UserCache.BaseCacheKeys, "UserShip", "Info");
@@ -132,6 +137,7 @@ public class UnitUserWeight(ISqlSugarClient DbClient, IRedisCache redis) : IUnit
return data;
}
public async Task<List<unit_user_ship>> GetUserShip(string userId)
{
string key = string.Format(UserCache.BaseCacheKeys, "WeightData", "Ship");
@@ -198,7 +204,7 @@ public class UnitUserWeight(ISqlSugarClient DbClient, IRedisCache redis) : IUnit
return result;
}
public async Task<bool> AddUserShip(string userId, string name, int goodsId, int speed, int weight)
public async Task<bool> AddUserShip(string userId, string name, int goodsId, int speed, int weight,int copper,long sale,string remark)
{
unit_user_ship ship = new unit_user_ship();
ship.usId = StringAssist.NewGuid;
@@ -207,6 +213,9 @@ public class UnitUserWeight(ISqlSugarClient DbClient, IRedisCache redis) : IUnit
ship.name = name;
ship.speed = speed;
ship.weight = weight;
ship.copper = copper;
ship.sale = sale;
ship.remark = remark;
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_ship>();
bool result = await db.Insertable(ship).ExecuteCommandAsync() > 0;
if (result)