12121
This commit is contained in:
@@ -4,7 +4,8 @@ public static class UserEnum
|
||||
{
|
||||
public enum AttrCode
|
||||
{
|
||||
Person
|
||||
Person,
|
||||
Monster
|
||||
}
|
||||
|
||||
public enum ConfigCode
|
||||
|
||||
@@ -9,9 +9,8 @@ public interface IGameFightService
|
||||
#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 RemoveFightHarm(string fightId, string userId);
|
||||
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 = "");
|
||||
|
||||
@@ -16,5 +16,13 @@ public interface IGameMonsterService
|
||||
Task<unit_user_monster> GetCreateMonsterInfo(string umId);
|
||||
Task<List<MapMonsterModel>> GetMapMonster(string userId, string mapId, string teamId);
|
||||
|
||||
#endregion
|
||||
|
||||
#region 怪物模型
|
||||
|
||||
Task<UserAttrModel> GetMonsterAttrModel(string keyId, string monsterId);
|
||||
Task SetMonsterBlood(string keyId, int blood);
|
||||
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -227,11 +227,6 @@ public class GameAttrTool
|
||||
decimal radio = item.count * 0.04M;
|
||||
temp.defense = Convert.ToInt32(temp.defense * (1.0M - radio));
|
||||
}
|
||||
else if (item.code == nameof(GameEnum.AttrCode.PalsyAtk))
|
||||
{
|
||||
decimal radio = item.count * 0.1M;
|
||||
temp.Atk_Next -= radio;
|
||||
}
|
||||
}
|
||||
|
||||
return temp;
|
||||
|
||||
11
Service/Application.Domain/Tool/Base/UserStateTool.cs
Normal file
11
Service/Application.Domain/Tool/Base/UserStateTool.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
namespace Application.Domain;
|
||||
|
||||
public static class UserStateTool
|
||||
{
|
||||
public static async Task<bool> CheckUserFight(string userId)
|
||||
{
|
||||
var fightService = App.GetService<IGameFightService>();
|
||||
var myFight = await fightService.GetUserFight(userId);
|
||||
return myFight.Count > 0;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user