121212
This commit is contained in:
@@ -180,6 +180,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 = "")
|
||||
{
|
||||
@@ -507,6 +616,93 @@ public class GameEquService(ISqlSugarClient DbClient, IRedisCache redis) : IGame
|
||||
|
||||
#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<game_equ_up> GetUserEquUpData(int lev)
|
||||
@@ -522,9 +718,9 @@ public class GameEquService(ISqlSugarClient DbClient, IRedisCache redis) : IGame
|
||||
await redis.AddHashAsync(key, lev.ToString(), data);
|
||||
}
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -537,5 +733,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
|
||||
}
|
||||
Reference in New Issue
Block a user