79 lines
2.4 KiB
C#
79 lines
2.4 KiB
C#
using System;
|
|||
|
|
using System.Collections.Generic;
|
||
|
|
using System.Linq;
|
||
|
|
using System.Text;
|
||
|
|
using System.Threading.Tasks;
|
||
|
|
using AutoMapper;
|
||
|
|
using CommonDomain;
|
||
|
|
using CommonDomain.Enum;
|
||
|
|
using MongoRepository;
|
||
|
|
using RedisService;
|
||
|
|
using RedisService.Param;
|
||
|
|
|
||
|
|
namespace UserService.GameConfigs
|
||
|
|
{
|
||
|
|
public class GameConfigService : IGameConfigService
|
||
|
|
{
|
||
|
|
private readonly IMongoBaseRepository<GameConfig> _mongo;
|
||
|
|
private readonly IMapper _mapper;
|
||
|
|
private IRedisService _redis;
|
||
|
|
|
||
|
|
public GameConfigService(IMongoBaseRepository<GameConfig> mongo, IMapper mapper, IRedisService redis)
|
||
|
|
{
|
||
|
|
_mongo = mongo;
|
||
|
|
_mapper = mapper;
|
||
|
|
_redis = redis;
|
||
|
|
}
|
||
|
|
|
||
|
|
public async Task<GameConfig> Get()
|
||
|
|
{
|
||
|
|
var gameConfig = _redis.GetGameConfig();
|
||
|
|
if (gameConfig == null)
|
||
|
|
{
|
||
|
|
gameConfig = await _mongo.FindOneAsync(c => true);
|
||
|
|
if (gameConfig != null)
|
||
|
|
_redis.SetGameConfig(gameConfig);
|
||
|
|
}
|
||
|
|
return gameConfig;
|
||
|
|
}
|
||
|
|
public async Task<(bool isok, string msg)> Update(GameConfig gameConfig)
|
||
|
|
{
|
||
|
|
bool isadd = false;
|
||
|
|
var model = await Get();
|
||
|
|
if (model == null)
|
||
|
|
{
|
||
|
|
isadd = true;
|
||
|
|
gameConfig.Id = Guid.NewGuid().ToString("N");
|
||
|
|
|
||
|
|
}
|
||
|
|
model = gameConfig;
|
||
|
|
|
||
|
|
_redis.SetGameConfig(gameConfig);
|
||
|
|
|
||
|
|
var killConfig = new FishingKillConfig
|
||
|
|
{
|
||
|
|
FishTypeConfigs = gameConfig.FishTypeConfigs?.Select(f => new FishTypeBriefConfig
|
||
|
|
{
|
||
|
|
FishNumber = f.FishNumber,
|
||
|
|
FishName = f.FishName,
|
||
|
|
FishType = f.FishType,
|
||
|
|
FishScore = f.FishScore,
|
||
|
|
KillWeight = f.KillWeight
|
||
|
|
}).ToList(),
|
||
|
|
KillConfig = gameConfig.KillConfig,
|
||
|
|
BossConfigs = gameConfig.BossConfigs,
|
||
|
|
BossDropConfig = gameConfig.BossDropConfig,
|
||
|
|
BattleOrderIsOpen = _redis.GetActivityConfig()?.BattleOrderConfig?.IsOpen ?? false
|
||
|
|
};
|
||
|
|
_redis.SetFishingKillConfig(killConfig);
|
||
|
|
|
||
|
|
if (isadd)
|
||
|
|
return await _mongo.InsertOneAsync(model);
|
||
|
|
else
|
||
|
|
return await _mongo.ReplaceOneAsync(model);
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
}
|
||
|
|
}
|