This commit is contained in:
Putoo
2026-07-04 18:07:37 +08:00
parent ea32e7046e
commit fa00fc5d66
26 changed files with 871 additions and 69 deletions

View File

@@ -54,28 +54,6 @@ public class GameFightService(ISqlSugarClient DbClient, IRedisCache redis) : IGa
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)
{
@@ -91,6 +69,12 @@ public class GameFightService(ISqlSugarClient DbClient, IRedisCache redis) : IGa
await redis.AddHashAsync(key, userId, harm);
}
}
public async Task RemoveFightHarm(string fightId,string userId)
{
string key = string.Format(FightCache.FightCacheKeys, "FightData:Harm", fightId);
await redis.DelHashAsync(key, userId);
}
private async Task ClearFightInfoCache(string fightId, string keyId)

View File

@@ -204,4 +204,66 @@ public class GameMonsterService(ISqlSugarClient DbClient, IRedisCache redis) : I
}
#endregion
#region
public async Task<UserAttrModel> GetMonsterAttrModel(string keyId,string monsterId)
{
UserAttrModel temp = new UserAttrModel();
var monsterInfo = await GetMonsterInfo(monsterId);
if (monsterInfo != null)
{
temp.id = keyId;
temp.viceId = monsterId;
temp.name = monsterInfo.name;
temp.IsSystem = 1;
temp.isCopy = (int)monsterInfo.isCopy;
temp.sex = "Default";
temp.code = nameof(UserEnum.AttrCode.Monster);
temp.lev = (int)monsterInfo.lev;
temp.minAtk = (int)monsterInfo.minAtk;
temp.maxAtk = (int)monsterInfo.maxAtk;
temp.defense = (int)monsterInfo.defense;
temp.agility = (int)monsterInfo.agility;
temp.upBlood = (int)monsterInfo.blood;
temp.upMorale = 1;
temp.morale = 0;
temp = GameAttrTool.GetRoleAttrTempMerge(temp, monsterInfo.attr);
temp.score = 0;
//处理负面
var attrService = App.GetService<IUnitUserAttrService>();
var loadState = await attrService.GetUserLoadState(keyId);
temp = await GameAttrTool.CheckRoleLoadBuff(temp, loadState);
temp.blood = await GetMonsterBlood(keyId, temp.upBlood);
}
return temp;
}
private async Task<int> GetMonsterBlood(string keyId, int maxBlood)
{
int blood = maxBlood;
blood = blood < 0 ? 0 : blood;
string key = string.Format(FightCache.FightCacheKeys, "FightData:Blood", keyId);
if (await redis.ExistsAsync(key))
{
blood = await redis.GetAsync<int>(key);
blood = blood > maxBlood ? maxBlood : blood;
blood = blood < 0 ? 0 : blood;
}
else
{
await SetMonsterBlood(keyId, blood);
}
return blood;
}
public async Task SetMonsterBlood(string keyId, int blood)
{
string key = string.Format(FightCache.FightCacheKeys, "FightData:Blood", keyId);
await redis.SetAsync(key, blood, 43200);
}
#endregion
}

View File

@@ -778,6 +778,7 @@ public class UnitUserAttrService(ISqlSugarClient DbClient, IRedisCache redis) :
{
data.Remove(onData);
onData.count += 1;
onData.count = onData.count > 10 ? 10 : onData.count;
result = await redis.AddHashAsync(key, userId, data);
}

View File

@@ -21,9 +21,9 @@ public class UnitUserWeight(ISqlSugarClient DbClient, IRedisCache redis) : IUnit
{
int result = 100 + (int)data.maxWeight;
var attrService = App.GetService<IUnitUserAttrService>();
int myLev = await attrService.GetUserLev(data.userId);
result += myLev * GameConfig.UpLevAddWeight;
//其他属性加层
var userAttr = await attrService.GetUserAttrModel(data.userId);
result += userAttr.lev * GameConfig.UpLevAddWeight;
result += userAttr.weight;
return result;
}