1212
This commit is contained in:
@@ -5,14 +5,13 @@ public interface IGameFightService
|
||||
#region 用户战斗索引
|
||||
|
||||
Task<List<string>> GetUserFight(string userId);
|
||||
Task<bool> AddUserFight(string userId, string fightId);
|
||||
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 = "");
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -2,13 +2,18 @@
|
||||
|
||||
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
|
||||
|
||||
@@ -17,7 +17,7 @@ public class GameFightService(ISqlSugarClient DbClient, IRedisCache redis) : IGa
|
||||
return data;
|
||||
}
|
||||
|
||||
public async Task<bool> AddUserFight(string userId, string fightId)
|
||||
private async Task<bool> AddUserFight(string userId, string fightId)
|
||||
{
|
||||
var data = await GetUserFight(userId);
|
||||
data.Add(fightId);
|
||||
@@ -61,16 +61,35 @@ public class GameFightService(ISqlSugarClient DbClient, IRedisCache redis) : IGa
|
||||
if (await redis.ExistsAsync(key))
|
||||
{
|
||||
blood = await redis.GetAsync<long>(key);
|
||||
blood = blood > maxBlood ? maxBlood : blood;
|
||||
}
|
||||
else
|
||||
{
|
||||
await SetFightBlood(keyId, blood);
|
||||
}
|
||||
|
||||
blood = blood > maxBlood ? maxBlood : 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, 3600);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -88,6 +107,8 @@ public class GameFightService(ISqlSugarClient DbClient, IRedisCache redis) : IGa
|
||||
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,
|
||||
@@ -104,17 +125,45 @@ public class GameFightService(ISqlSugarClient DbClient, IRedisCache redis) : IGa
|
||||
copper = copper,
|
||||
petExp = petExp,
|
||||
award = award,
|
||||
harm = 0,
|
||||
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(data).ExecuteCommandAsync() > 0;
|
||||
bool result = await db.Insertable(fights).ExecuteCommandAsync() > 0;
|
||||
if (result)
|
||||
{
|
||||
await AddUserFight(userId, fightId);
|
||||
foreach (var item in fights)
|
||||
{
|
||||
await AddUserFight(item.userId, item.fightId);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
@@ -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");
|
||||
|
||||
@@ -38,6 +38,20 @@ public class GameMonsterService(ISqlSugarClient DbClient, IRedisCache redis) : I
|
||||
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 = "")
|
||||
{
|
||||
@@ -96,6 +110,13 @@ public class GameMonsterService(ISqlSugarClient DbClient, IRedisCache redis) : I
|
||||
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)
|
||||
{
|
||||
@@ -105,6 +126,7 @@ public class GameMonsterService(ISqlSugarClient DbClient, IRedisCache redis) : I
|
||||
|
||||
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)
|
||||
@@ -123,7 +145,8 @@ public class GameMonsterService(ISqlSugarClient DbClient, IRedisCache redis) : I
|
||||
{
|
||||
monterId = item.mmId,
|
||||
name = item.monsterName,
|
||||
type = 0
|
||||
type = 0,
|
||||
sign = UserKeyTool.GetThickenDataByUserKey(userKey, "0", item.mmId)
|
||||
};
|
||||
result.Add(temp);
|
||||
}
|
||||
@@ -141,7 +164,7 @@ public class GameMonsterService(ISqlSugarClient DbClient, IRedisCache redis) : I
|
||||
createMonster = createMonster.FindAll(it => it.endTime > onTime);
|
||||
|
||||
createData.AddRange(createMonster.FindAll(it =>
|
||||
it.userId == userId || it.areaCode == nameof(MonsterEnum.AreaCode.Public)));
|
||||
it.userId == userId || it.areaCode == nameof(GameEnum.AreaCode.Public)));
|
||||
if (!string.IsNullOrEmpty(teamId) && teamId != "0")
|
||||
{
|
||||
var teamService = App.GetService<IGameTeamService>();
|
||||
@@ -149,7 +172,7 @@ public class GameMonsterService(ISqlSugarClient DbClient, IRedisCache redis) : I
|
||||
teamMember = teamMember.FindAll(it => it.userId != userId);
|
||||
var onCreate = createMonster.FindAll(it =>
|
||||
teamMember.Any(team =>
|
||||
team.userId == it.userId && it.areaCode == nameof(MonsterEnum.AreaCode.Team)));
|
||||
team.userId == it.userId && it.areaCode == nameof(GameEnum.AreaCode.Team)));
|
||||
foreach (var item in onCreate)
|
||||
{
|
||||
if (createData.Any(it => it.umId == item.umId))
|
||||
@@ -170,7 +193,8 @@ public class GameMonsterService(ISqlSugarClient DbClient, IRedisCache redis) : I
|
||||
{
|
||||
monterId = item.umId,
|
||||
name = item.monsterName,
|
||||
type = 1
|
||||
type = 1,
|
||||
sign = UserKeyTool.GetThickenDataByUserKey(userKey, "1", item.umId)
|
||||
};
|
||||
result.Add(temp);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user