增加修炼功能
This commit is contained in:
7
Service/Application.Domain/Cache/FightCache.cs
Normal file
7
Service/Application.Domain/Cache/FightCache.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace Application.Domain;
|
||||
|
||||
public class FightCache
|
||||
{
|
||||
public static string FightCacheKey = "GameFightCache:{0}";
|
||||
public static string FightCacheKeys = "GameFightCache:{0}:{1}";
|
||||
}
|
||||
@@ -17,4 +17,5 @@ public static class GameConfig
|
||||
public const int GameAutoDrugGoodsId = 10001;//急救箱物品ID
|
||||
public const int GameToMapNeedCopper = 5;//传送每海里费用
|
||||
public const int TeamCacheTime = 300;//队伍缓存时间
|
||||
public const int GameEquApprGoods = 10001;//鉴定装备道具
|
||||
}
|
||||
@@ -21,5 +21,11 @@ public static class EquEnum
|
||||
Ornaments = 3, //佩戴
|
||||
Fashion = 1, //时装
|
||||
Wing = 1, //羽翼
|
||||
Decorate = 5, //装饰
|
||||
}
|
||||
|
||||
public enum SuitAttrNeedType
|
||||
{
|
||||
ON_EQU
|
||||
}
|
||||
}
|
||||
7
Service/Application.Domain/Enum/FightEnum.cs
Normal file
7
Service/Application.Domain/Enum/FightEnum.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace Application.Domain;
|
||||
|
||||
public static class FightEnum
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
@@ -55,6 +55,89 @@ public static class GameEnum
|
||||
RetBlood,
|
||||
RetMorale,
|
||||
RetVigour,
|
||||
RetEqu,
|
||||
MapTo,
|
||||
Store,
|
||||
Make,
|
||||
}
|
||||
|
||||
public enum DicCode
|
||||
{
|
||||
Awaken,//觉醒配置
|
||||
Quality,//洗练配置
|
||||
}
|
||||
public enum ComputeType
|
||||
{
|
||||
Plus,//加法计算
|
||||
Ride,//乘法计算
|
||||
Reduce,//减法计算
|
||||
Except,//除法计算
|
||||
}
|
||||
public enum AttrCode
|
||||
{
|
||||
AddExp,//经验
|
||||
AddGold,//金币
|
||||
MinAtk,
|
||||
MaxAtk,
|
||||
Atk,//攻击
|
||||
Blood,//体力
|
||||
Defense,//防御
|
||||
Agility,//敏捷
|
||||
Morale,//士气
|
||||
Burst,//爆率
|
||||
InBlood,//吸血
|
||||
Crit,//暴击
|
||||
Dodge,//闪避
|
||||
NoHarm,//免伤
|
||||
Rebound,//反弹
|
||||
Punish,//制裁
|
||||
Slow,//迟缓
|
||||
Poison,//中毒
|
||||
PoisonLess,//抗毒攻
|
||||
Curse,//诅咒
|
||||
Weaken,//弱化
|
||||
Deadly,//致命
|
||||
DeadlyLess,//抗致命
|
||||
Depressed,//消沉 沮丧
|
||||
Breach,//突破
|
||||
Del_Fashion,//卸时装
|
||||
Atk_Next,//连击
|
||||
ReboundLess,//抗反弹
|
||||
Harm_Add,//额外伤害
|
||||
PalsyAtk,//麻痹
|
||||
PalsyAtkLess,//抗麻痹
|
||||
CurseLess,//抗诅咒
|
||||
WeakenLess,//抗弱化
|
||||
DepressedLess,//抗消沉
|
||||
BreachLess,//抗突破
|
||||
Luck,//幸运
|
||||
SlowLess,//抗迟缓
|
||||
Depth,//潜水深度
|
||||
Height,//升空高度
|
||||
Weight//负重
|
||||
}
|
||||
|
||||
public enum GameStockCode
|
||||
{
|
||||
Blood,
|
||||
Durability,
|
||||
|
||||
}
|
||||
public enum GameStockType
|
||||
{
|
||||
Number,//数值
|
||||
Time,//时间
|
||||
}
|
||||
|
||||
public enum FightCode
|
||||
{
|
||||
PVP,//人物对战
|
||||
PVE//NPC对战
|
||||
}
|
||||
public enum AreaCode
|
||||
{
|
||||
Own,//个人怪物
|
||||
Public,//公共怪物
|
||||
Team,//队伍怪物
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,19 @@ public static class GoodsEnum
|
||||
Card,//附魔卡片
|
||||
Mark,//圣痕
|
||||
Pack,//宝箱
|
||||
Practise,//修炼道具
|
||||
ChoicePack,//选择宝箱
|
||||
Weight,//负重
|
||||
Exp,//经验
|
||||
State,//状态物品
|
||||
Ship,//船只
|
||||
}
|
||||
|
||||
public enum DrugCls
|
||||
{
|
||||
Blood,//普通体力药品
|
||||
BloodStock,//体力储存药品
|
||||
Vigour,//活力
|
||||
Morale,//士气
|
||||
LoadBuff,//消除负面状态
|
||||
}
|
||||
}
|
||||
@@ -8,4 +8,12 @@ public static class MessageEnum
|
||||
Marry,//婚姻消息
|
||||
Trade,//交易通知
|
||||
}
|
||||
public enum BroadcastCode
|
||||
{
|
||||
Gift,
|
||||
System,
|
||||
Award,
|
||||
Remind,
|
||||
Promote
|
||||
}
|
||||
}
|
||||
11
Service/Application.Domain/Enum/MonsterEnum.cs
Normal file
11
Service/Application.Domain/Enum/MonsterEnum.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
namespace Application.Domain;
|
||||
|
||||
public static class MonsterEnum
|
||||
{
|
||||
public enum AwardCode
|
||||
{
|
||||
Default,
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -6,20 +6,25 @@ public interface IGameEquService
|
||||
|
||||
Task<game_equ> GetEquInfo(int equId);
|
||||
Task<game_equ_suit> GetEuqSuitInfo(string suitCode);
|
||||
|
||||
#endregion
|
||||
|
||||
#region 用户装备
|
||||
|
||||
Task<List<unit_user_equ>> GetUserEquData(string userId, int type, string equName, int PageIndex, int PageSize,
|
||||
RefAsync<int> Total, bool isRemOn = false);
|
||||
RefAsync<int> Total, bool isRemOn = false, bool isRemLock = false);
|
||||
|
||||
Task<List<unit_user_equ>> GetUserEquData(string userId, int equId);
|
||||
Task<List<unit_user_equ>> GetUserEquData(string userId, string code, List<string> noUeId);
|
||||
Task<unit_user_equ> GetUserEquInfo(string ueId);
|
||||
Task<int> GetUserEquByEquIdCount(string userId, int equId);
|
||||
Task<List<unit_user_equ>> GetUserEquByEquId(string userId, int equId);
|
||||
Task<bool> AddUserEqu(string userId, int equId, int count, string remark);
|
||||
|
||||
Task<bool> AddUserEqu(unit_user_equ equData, string remark);
|
||||
Task<unit_user_equ> AddUserEqu(string userId, int equId, bool rdAttr = false, string remark = "");
|
||||
Task<bool> UpdateUserEquInfo(unit_user_equ equData, bool isAddLog = false, string code = "",
|
||||
string remark = "");
|
||||
|
||||
Task<bool> DeductUserEqu(string userId, List<unit_user_equ> equData, string remark);
|
||||
Task<bool> DeductUserEqu(string userId, int equId, int count, string remark);
|
||||
|
||||
@@ -27,13 +32,36 @@ public interface IGameEquService
|
||||
bool isAddAttr = false);
|
||||
|
||||
Task<List<unit_user_equ>> GetUserOnEqu(string userId);
|
||||
Task<UserAttrModel> GetUserEquAttrModel(string userId);
|
||||
Task<bool> EquOnOrDown(unit_user_equ data, int state);
|
||||
Task<List<UserEquSuit>> GetUserEquSuit(string userId);
|
||||
Task<List<AttrItem>> GetUserEquSuitAttrInfo(string userId);
|
||||
#endregion
|
||||
|
||||
#region 辅助
|
||||
#region 觉醒相关
|
||||
|
||||
Task<game_equ_awaken> GetEquAwakenInfo(string atId);
|
||||
Task<game_equ_awaken> GetRandomOneAwakenByCode(string code);
|
||||
Task<EquAwakenData> GetEquAwakenInfoByLev(string atId, int lev);
|
||||
|
||||
#endregion
|
||||
|
||||
#region 洗练属性/词条
|
||||
|
||||
Task<List<AttrItem>> GetRandomEquAttr(string equCode, int lev);
|
||||
|
||||
#endregion
|
||||
|
||||
#region 强化相关
|
||||
|
||||
Task<game_equ_up> GetUserEquUpData(int lev);
|
||||
|
||||
#endregion
|
||||
|
||||
#region 辅助
|
||||
|
||||
Task<int> GetUserEquWeightSum(string userId);
|
||||
|
||||
Task<game_equ_make> GetMakeEquByGoodsId(int goodsId);
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
namespace Application.Domain;
|
||||
|
||||
public interface IGameFightService
|
||||
{
|
||||
#region 用户战斗索引
|
||||
|
||||
Task<List<string>> GetUserFight(string userId);
|
||||
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 = "");
|
||||
|
||||
Task<bool> SetFightWin(string fightId, string winUser);
|
||||
|
||||
|
||||
#endregion
|
||||
#region 战斗相关
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -29,7 +29,11 @@ public interface IGameGoodsService
|
||||
|
||||
#endregion
|
||||
|
||||
#region 船只
|
||||
Task<game_ship> GetShipInfo(int shipId);
|
||||
#region 药品
|
||||
|
||||
Task<string> CheckUseDrug(string userId, int goodsId, string drugConfig, string scene = "");
|
||||
Task<bool> UseDrug(string userId, int goodsId, string drugConfig, string scene = "");
|
||||
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
namespace Application.Domain;
|
||||
|
||||
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
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace Application.Domain;
|
||||
|
||||
public interface IGameDicService
|
||||
{
|
||||
Task<game_dic> GetDicInfo(string code);
|
||||
}
|
||||
@@ -43,4 +43,11 @@ public interface IMessageService
|
||||
List<MsgEventBtn> btns = null, int days = 10);
|
||||
|
||||
#endregion
|
||||
|
||||
#region 广播消息
|
||||
|
||||
Task<List<game_broadcast>> GetBroadcastData(int area);
|
||||
Task<bool> SendBroadcast(string userId, string code, string msg);
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -4,9 +4,10 @@ public interface IUnitUserAttrService
|
||||
{
|
||||
#region 个人属性
|
||||
|
||||
Task<UserAttrModel> GetUserAttrModel(string userId);
|
||||
Task<UserAttrModel> GetUserAttrModel(string userId, string scene = "Default");
|
||||
Task<unit_user_attr> GetUserAttr(string userId);
|
||||
Task<int> GetUserLev(string userId);
|
||||
|
||||
#endregion
|
||||
|
||||
#region 体力操作
|
||||
@@ -29,6 +30,7 @@ public interface IUnitUserAttrService
|
||||
Task<bool> UpdateUserMorale(string userId, int op, int count);
|
||||
Task<bool> CheackRecoverMorale(string userId);
|
||||
Task LockRecoverMorale(string userId);
|
||||
|
||||
#endregion
|
||||
|
||||
#region 活力
|
||||
@@ -43,6 +45,42 @@ public interface IUnitUserAttrService
|
||||
|
||||
Task<bool> UpdateOnLineTime(string userId, string code, int time);
|
||||
|
||||
#endregion
|
||||
|
||||
#region 药品栏
|
||||
|
||||
Task<unit_user_drug> GetUserDrug(string userId);
|
||||
Task<bool> UpdateUserDrug(unit_user_drug data);
|
||||
|
||||
#endregion
|
||||
|
||||
#region BUFF状态
|
||||
|
||||
Task<List<unit_user_state>> GetUserStateData(string userId, string scene = "Default");
|
||||
|
||||
Task<bool> AddUserState(string userId, string groupId, string name, string scene, string tips,
|
||||
List<AttrItem> attr, int time, int count = 1);
|
||||
|
||||
#endregion
|
||||
|
||||
#region 游戏资源储备
|
||||
|
||||
Task<List<unit_user_stock>> GetUserStock(string userId, string code = "Default");
|
||||
|
||||
Task<bool> AddUserStock(string userId, string goodsId,string name, string type, string code, long sign,
|
||||
string par = "",
|
||||
int minute = 0);
|
||||
|
||||
Task<bool> UpdateUserStock(unit_user_stock data);
|
||||
|
||||
#endregion
|
||||
|
||||
#region 负面状态
|
||||
|
||||
Task<List<unit_user_load>> GetUserLoadState(string userId);
|
||||
Task<bool> AddUserLoadState(string userId, string name, string code);
|
||||
Task<bool> RandomRemoveUserLoadState(string userId, int count);
|
||||
Task RemoveUserLoadState(string userId);
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -19,7 +19,7 @@ public interface IUnitUserWeight
|
||||
Task<bool> UpdateUserShipOnWeight(string userId, int op, int weight);
|
||||
Task<bool> CheakUserShipWeight(string userId, int useWeight);
|
||||
Task<bool> DeleteUserShip(string usId, string userId);
|
||||
Task<bool> AddUserShip(string userId, string name, int goodsId, int speed, int weight);
|
||||
Task<bool> AddUserShip(string userId, string name, int goodsId, int speed, int weight,int copper,long sale,string remark);
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -39,7 +39,7 @@ public class GameEquService(ISqlSugarClient DbClient, IRedisCache redis) : IGame
|
||||
#region 用户装备
|
||||
|
||||
public async Task<List<unit_user_equ>> GetUserEquData(string userId, int type, string equName, int PageIndex,
|
||||
int PageSize, RefAsync<int> Total, bool isRemOn = false)
|
||||
int PageSize, RefAsync<int> Total, bool isRemOn = false, bool isRemLock = false)
|
||||
{
|
||||
long onTime = TimeExtend.GetTimeStampSeconds;
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_equ>();
|
||||
@@ -48,6 +48,7 @@ public class GameEquService(ISqlSugarClient DbClient, IRedisCache redis) : IGame
|
||||
.WhereIF(type == 1, it => it.isOn == 1)
|
||||
.WhereIF(type == 3, it => it.isAppr == 0)
|
||||
.WhereIF(isRemOn, it => it.isOn == 0)
|
||||
.WhereIF(isRemLock, it => it.isLock == 0)
|
||||
.WhereIF(!string.IsNullOrEmpty(equName),
|
||||
it => it.equName.Contains(equName) || it.unitEquName.Contains(equName))
|
||||
.OrderByDescending(it => it.lev)
|
||||
@@ -56,11 +57,18 @@ public class GameEquService(ISqlSugarClient DbClient, IRedisCache redis) : IGame
|
||||
|
||||
public async Task<List<unit_user_equ>> GetUserEquData(string userId, int equId)
|
||||
{
|
||||
long onTime = TimeExtend.GetTimeStampSeconds;
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_equ>();
|
||||
return await db.Queryable<unit_user_equ>().Where(it => it.userId == userId && it.equId == equId).ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<List<unit_user_equ>> GetUserEquData(string userId, string code, List<string> noUeId)
|
||||
{
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_equ>();
|
||||
return await db.Queryable<unit_user_equ>().Where(it => it.userId == userId && it.code == code)
|
||||
.WhereIF(noUeId.Count > 0, it => !noUeId.Contains(it.ueId))
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<unit_user_equ> GetUserEquInfo(string ueId)
|
||||
{
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_equ>();
|
||||
@@ -173,6 +181,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 = "")
|
||||
{
|
||||
@@ -184,6 +301,11 @@ public class GameEquService(ISqlSugarClient DbClient, IRedisCache redis) : IGame
|
||||
{
|
||||
await AddEquLog(equData, code, remark);
|
||||
}
|
||||
|
||||
if (equData.isOn == 1)
|
||||
{
|
||||
await ClearUserOnEqu(equData.userId);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -325,6 +447,52 @@ public class GameEquService(ISqlSugarClient DbClient, IRedisCache redis) : IGame
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<UserAttrModel> GetUserEquAttrModel(string userId)
|
||||
{
|
||||
var key = string.Format(UserCache.BaseCacheKeys, "EquData", "UserOnEquAttr");
|
||||
if (await redis.HExistsHashAsync(key, userId))
|
||||
{
|
||||
return await redis.GetHashAsync<UserAttrModel>(key, userId);
|
||||
}
|
||||
|
||||
long endTime = TimeExtend.GetTimeStampSeconds;
|
||||
UserAttrModel result = new UserAttrModel();
|
||||
var myEqu = await GetUserOnEqu(userId);
|
||||
foreach (var equ in myEqu)
|
||||
{
|
||||
if (equ.durability > 0 || equ.useEndTime > endTime)
|
||||
{
|
||||
UserAttrModel equTemp = new UserAttrModel();
|
||||
var equAttr = EquTool.GetUserEquByIntensify(equ);
|
||||
equTemp.minAtk = (int)equAttr.minAtk;
|
||||
equTemp.maxAtk = (int)equAttr.maxAtk;
|
||||
equTemp.defense = (int)equAttr.Defense;
|
||||
equTemp.agility = (int)equAttr.Agility;
|
||||
equTemp.upBlood = (int)equAttr.Blood;
|
||||
equTemp.upMorale = (int)equAttr.Morale;
|
||||
List<AttrItem> equAttrData = EquTool.GetUserEquAttrData(equ);
|
||||
equTemp = GameAttrTool.GetRoleAttrTempMerge(equTemp, equAttrData);
|
||||
result = GameAttrTool.GetRoleAttrTempMerge(result, equTemp);
|
||||
}
|
||||
}
|
||||
|
||||
await redis.AddHashAsync(key, userId, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
private async Task ClearUserOnEqu(string userId)
|
||||
{
|
||||
var key = string.Format(UserCache.BaseCacheKeys, "EquData", "UserOnEqu");
|
||||
await redis.DelHashAsync(key, userId);
|
||||
key = string.Format(UserCache.BaseCacheKeys, "EquData", "UserOnEquAttr");
|
||||
await redis.DelHashAsync(key, userId);
|
||||
//清理套装缓存
|
||||
key = string.Format(UserCache.BaseCacheKeys, "EquData:UserEquSuit", userId);
|
||||
await redis.DelAsync(key);
|
||||
key = string.Format(UserCache.BaseCacheKeys, "EquData:UserEquSuitAttr", userId);
|
||||
await redis.DelAsync(key);
|
||||
}
|
||||
|
||||
public async Task<bool> EquOnOrDown(unit_user_equ data, int state)
|
||||
{
|
||||
data.isOn = state;
|
||||
@@ -334,21 +502,292 @@ public class GameEquService(ISqlSugarClient DbClient, IRedisCache redis) : IGame
|
||||
var equInfo = await GetEquInfo((int)data.equId);
|
||||
if (equInfo.useTime > 0)
|
||||
{
|
||||
data.useEndTime = TimeExtend.GetTimeStampBySeconds(DateTime.Now.AddDays((int)equInfo.useTime)) ;
|
||||
data.useEndTime = TimeExtend.GetTimeStampBySeconds(DateTime.Now.AddDays((int)equInfo.useTime));
|
||||
}
|
||||
}
|
||||
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_equ>();
|
||||
bool result = await db.Updateable(data).ExecuteCommandAsync() > 0;
|
||||
if (result)
|
||||
{
|
||||
await ClearUserOnEqu(data.userId);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取个人套装
|
||||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<List<UserEquSuit>> GetUserEquSuit(string userId)
|
||||
{
|
||||
List<UserEquSuit> result = new List<UserEquSuit>();
|
||||
long time = TimeExtend.GetTimeStampSeconds;
|
||||
var key = string.Format(UserCache.BaseCacheKeys, "EquData:UserEquSuit", userId);
|
||||
if (await redis.ExistsAsync(key))
|
||||
{
|
||||
result = await redis.GetAsync<List<UserEquSuit>>(key);
|
||||
}
|
||||
else
|
||||
{
|
||||
List<string> opSuit = new List<string>();
|
||||
var onEquData = await GetUserOnEqu(userId);
|
||||
string[] onEqu = onEquData.Select(it => it.equId.ToString()).ToArray();
|
||||
onEquData = onEquData.FindAll(it => it.useEndTime > time && it.durability > 0);
|
||||
foreach (var item in onEquData)
|
||||
{
|
||||
if (item.suitCode != "0" && !string.IsNullOrEmpty(item.suitCode))
|
||||
{
|
||||
if (!opSuit.Contains(item.suitCode))
|
||||
{
|
||||
opSuit.Add(item.suitCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var suit in opSuit)
|
||||
{
|
||||
UserEquSuit temp = new UserEquSuit();
|
||||
var suitInfo = await GetEuqSuitInfo(suit);
|
||||
if (suitInfo != null)
|
||||
{
|
||||
temp.suitCode = suitInfo.suitCode;
|
||||
temp.suitName = suitInfo.suitName;
|
||||
temp.SuitAttr = new List<EquSuitAttr>();
|
||||
foreach (var item in suitInfo.attr)
|
||||
{
|
||||
if (item.NeedType == nameof(EquEnum.SuitAttrNeedType.ON_EQU))
|
||||
{
|
||||
bool same = item.NeedData.All(item => onEqu.Contains(item));
|
||||
if (same)
|
||||
{
|
||||
temp.SuitAttr.Add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (temp.SuitAttr.Count > 0) //存在满足条件得属性
|
||||
{
|
||||
result.Add(temp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
await redis.SetAsync(key, result, 300);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<List<AttrItem>> GetUserEquSuitAttrInfo(string userId)
|
||||
{
|
||||
List<AttrItem> result = new List<AttrItem>();
|
||||
var key = string.Format(UserCache.BaseCacheKeys, "EquData:UserEquSuitAttr", userId);
|
||||
if (await redis.ExistsAsync(key))
|
||||
{
|
||||
result = await redis.GetAsync<List<AttrItem>>(key);
|
||||
}
|
||||
else
|
||||
{
|
||||
var suitData = await GetUserEquSuit(userId);
|
||||
foreach (var item in suitData)
|
||||
{
|
||||
foreach (var attr in item.SuitAttr)
|
||||
{
|
||||
result.AddRange(attr.AttrItem);
|
||||
}
|
||||
}
|
||||
await redis.SetAsync(key, result, 300);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 觉醒
|
||||
|
||||
public async Task<game_equ_awaken> GetEquAwakenInfo(string atId)
|
||||
{
|
||||
string key = string.Format(BaseCache.BaseCacheKeys, "EquData", "AwakenData");
|
||||
var data = await redis.GetHashAsync<game_equ_awaken>(key, atId);
|
||||
if (data == null)
|
||||
{
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<game_equ_awaken>();
|
||||
data = await db.Queryable<game_equ_awaken>().Where(i => i.atId == atId).SingleAsync();
|
||||
if (data != null)
|
||||
{
|
||||
await redis.AddHashAsync(key, atId, data);
|
||||
}
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
public async Task<game_equ_awaken> GetRandomOneAwakenByCode(string code)
|
||||
{
|
||||
game_equ_awaken attr = new game_equ_awaken();
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<game_equ_awaken>();
|
||||
var list = await db.Queryable<game_equ_awaken>().Where(i => i.position.Contains(code)).ToListAsync();
|
||||
if (list.Count == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
List<object> data = new List<object>();
|
||||
List<ushort> weights = new List<ushort>();
|
||||
List<object> result = new List<object>();
|
||||
Random rand = new Random();
|
||||
|
||||
foreach (var item in list)
|
||||
{
|
||||
data.Add(item);
|
||||
weights.Add(ushort.Parse(item.random.ToString()));
|
||||
}
|
||||
|
||||
RandomAssist random = new RandomAssist(1);
|
||||
|
||||
result = random.ControllerRandomExtract(rand, data, weights);
|
||||
if (result.Count > 0)
|
||||
{
|
||||
attr = result[0] as game_equ_awaken;
|
||||
return attr;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public async Task<EquAwakenData> GetEquAwakenInfoByLev(string atId, int lev)
|
||||
{
|
||||
var awakenInfo = await GetEquAwakenInfo(atId);
|
||||
EquAwakenData awaken = new EquAwakenData();
|
||||
foreach (var item in awakenInfo.levAttr)
|
||||
{
|
||||
if (item.lev == lev)
|
||||
{
|
||||
return item;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
#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<unit_user_equ> GetUserEquAttr(unit_user_equ equ)
|
||||
{
|
||||
return equ;
|
||||
}
|
||||
|
||||
public async Task<game_equ_up> GetUserEquUpData(int lev)
|
||||
{
|
||||
string key = string.Format(BaseCache.BaseCacheKeys, "EquData", "EquUpData");
|
||||
var data = await redis.GetHashAsync<game_equ_up>(key, lev.ToString());
|
||||
if (data == null)
|
||||
{
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<game_equ_up>();
|
||||
data = await db.Queryable<game_equ_up>().Where(i => i.onLev <= lev && i.maxLev >= lev).FirstAsync();
|
||||
if (data != null)
|
||||
{
|
||||
await redis.AddHashAsync(key, lev.ToString(), data);
|
||||
}
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -361,5 +800,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
|
||||
}
|
||||
@@ -0,0 +1,208 @@
|
||||
namespace Application.Domain;
|
||||
|
||||
public class GameFightService(ISqlSugarClient DbClient, IRedisCache redis) : IGameFightService, ITransient
|
||||
{
|
||||
#region 用户战斗索引
|
||||
|
||||
public async Task<List<string>> GetUserFight(string userId)
|
||||
{
|
||||
string key = string.Format(FightCache.FightCacheKey, "UserFight");
|
||||
if (await redis.HExistsHashAsync(key, userId))
|
||||
{
|
||||
return await redis.GetHashAsync<List<string>>(key, userId);
|
||||
}
|
||||
|
||||
List<string> data = new List<string>();
|
||||
await redis.AddHashAsync(key, userId, data);
|
||||
return data;
|
||||
}
|
||||
|
||||
private async Task<bool> AddUserFight(string userId, string fightId)
|
||||
{
|
||||
var data = await GetUserFight(userId);
|
||||
data.Add(fightId);
|
||||
string key = string.Format(FightCache.FightCacheKey, "UserFight");
|
||||
bool result = await redis.AddHashAsync(key, userId, data);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<bool> RemoveUserFight(string userId, string fightId)
|
||||
{
|
||||
var data = await GetUserFight(userId);
|
||||
data.Remove(fightId);
|
||||
string key = string.Format(FightCache.FightCacheKey, "UserFight");
|
||||
bool result = await redis.AddHashAsync(key, userId, data);
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 战斗信息
|
||||
|
||||
public async Task<game_fight_data> GetFightInfo(string fightId)
|
||||
{
|
||||
string key = string.Format(FightCache.FightCacheKeys, "FightData:Info", fightId);
|
||||
if (await redis.ExistsAsync(key))
|
||||
{
|
||||
return await redis.GetAsync<game_fight_data>(key);
|
||||
}
|
||||
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<game_fight_data>();
|
||||
game_fight_data data = await db.Queryable<game_fight_data>().Where(it => it.fightId == fightId).SingleAsync();
|
||||
await redis.SetAsync(key, data, 3600);
|
||||
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)
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private async Task ClearFightInfoCache(string fightId, string keyId)
|
||||
{
|
||||
string key1 = string.Format(FightCache.FightCacheKeys, "FightData:Info", fightId);
|
||||
string key2 = string.Format(FightCache.FightCacheKeys, "FightData:Blood", keyId);
|
||||
await redis.DelAsync(key1, key2);
|
||||
}
|
||||
|
||||
public async 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 = "")
|
||||
{
|
||||
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,
|
||||
areaCode = areaCode,
|
||||
keyId = keyId,
|
||||
mainId = mainId,
|
||||
code = code,
|
||||
scene = scene,
|
||||
mapId = mapId,
|
||||
userId = userId,
|
||||
state = 0,
|
||||
winUser = "",
|
||||
exp = exp,
|
||||
copper = copper,
|
||||
petExp = petExp,
|
||||
award = award,
|
||||
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(fights).ExecuteCommandAsync() > 0;
|
||||
if (result)
|
||||
{
|
||||
foreach (var item in fights)
|
||||
{
|
||||
await AddUserFight(item.userId, item.fightId);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<bool> SetFightWin(string fightId, string winUser)
|
||||
{
|
||||
bool result = false;
|
||||
var data = await GetFightInfo(fightId);
|
||||
if (data != null)
|
||||
{
|
||||
long okTime = TimeExtend.GetTimeStampSeconds;
|
||||
data.state = 1;
|
||||
data.winUser = winUser;
|
||||
data.okTime = okTime;
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<game_fight_data>();
|
||||
result = await db.Updateable<game_fight_data>().SetColumns(it => it.state == 1)
|
||||
.SetColumns(it => it.winUser == winUser)
|
||||
.SetColumns(it => it.okTime == okTime)
|
||||
.Where(it => it.fightId == fightId).ExecuteCommandAsync() > 0;
|
||||
}
|
||||
|
||||
if (result)
|
||||
{
|
||||
await ClearFightInfoCache(fightId, data.keyId);
|
||||
//此处调用战斗结束相关
|
||||
await HandleFight(data);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 战斗相关
|
||||
|
||||
private async Task HandleFight(game_fight_data data)
|
||||
{
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Reflection.Metadata;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Application.Domain;
|
||||
|
||||
@@ -68,6 +69,7 @@ public class GameGoodsService(ISqlSugarClient DbClient, IRedisCache redis) : IGa
|
||||
.OrderBy(it => it.count, OrderByType.Desc)
|
||||
.ToPageListAsync(page, limit, total);
|
||||
}
|
||||
|
||||
public async Task<List<unit_user_goods>> GetUserGoodsData(string userId, string code)
|
||||
{
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_goods>();
|
||||
@@ -163,8 +165,6 @@ public class GameGoodsService(ISqlSugarClient DbClient, IRedisCache redis) : IGa
|
||||
return await db.Insertable(bagLog).SplitTable().ExecuteCommandAsync() > 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region 辅助
|
||||
@@ -187,19 +187,142 @@ public class GameGoodsService(ISqlSugarClient DbClient, IRedisCache redis) : IGa
|
||||
|
||||
#endregion
|
||||
|
||||
#region 船只
|
||||
public async Task<game_ship> GetShipInfo(int shipId)
|
||||
#region 药品
|
||||
|
||||
private async Task<long> GetUserDrugLockTime(string userId, int goodsId)
|
||||
{
|
||||
string key = string.Format(BaseCache.BaseCacheKey, "ShipData");
|
||||
var data = await redis.GetHashAsync<game_ship>(key, shipId.ToString());
|
||||
if (data == null)
|
||||
long result = 0;
|
||||
string key = string.Format(UserCache.BaseCacheKey, "UserDrug", $"Lock:{userId}_{goodsId}");
|
||||
if (await redis.ExistsAsync(key))
|
||||
{
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<game_ship>();
|
||||
data = await db.Queryable<game_ship>().Where(it => it.shipId == shipId).SingleAsync();
|
||||
await redis.AddHashAsync(key, shipId.ToString(), data);
|
||||
long end = await redis.GetAsync<long>(key);
|
||||
result = end - TimeExtend.GetTimeStampSeconds;
|
||||
result = result < 0 ? 0 : result;
|
||||
}
|
||||
|
||||
return data;
|
||||
return result;
|
||||
}
|
||||
|
||||
private async Task AddUserDrugLockTime(string userId, int goodsId, int time)
|
||||
{
|
||||
if (time > 0)
|
||||
{
|
||||
long end = TimeExtend.GetTimeStampSeconds + time;
|
||||
string key = string.Format(UserCache.BaseCacheKey, "UserDrug", $"Lock:{userId}_{goodsId}");
|
||||
await redis.SetAsync(key, end, time);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task<int> GetUserDrugLockCount(string userId, int goodsId, string scene = "")
|
||||
{
|
||||
int result = 0;
|
||||
if (!string.IsNullOrEmpty(scene))
|
||||
{
|
||||
string key = string.Format(UserCache.BaseCacheKey, "UserDrug", $"Count:{scene}:{userId}_{goodsId}");
|
||||
if (await redis.ExistsAsync(key))
|
||||
{
|
||||
result = await redis.GetAsync<int>(key);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private async Task AddUserDrugLockCount(string userId, int goodsId, string scene = "")
|
||||
{
|
||||
if (!string.IsNullOrEmpty(scene))
|
||||
{
|
||||
var count = await GetUserDrugLockCount(userId, goodsId, scene);
|
||||
count += 1;
|
||||
string key = string.Format(UserCache.BaseCacheKey, "UserDrug", $"Count:{scene}:{userId}_{goodsId}");
|
||||
await redis.SetAsync(key, count, 43200);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public async Task<string> CheckUseDrug(string userId, int goodsId, string drugConfig, string scene = "")
|
||||
{
|
||||
string result = string.Empty;
|
||||
dynamic _drugConfig = JsonConvert.DeserializeObject<dynamic>(drugConfig);
|
||||
if (_drugConfig.cls == nameof(GoodsEnum.DrugCls.Blood))
|
||||
{
|
||||
//判断所定
|
||||
long lockTime = await GetUserDrugLockTime(userId, goodsId);
|
||||
if (lockTime > 0)
|
||||
{
|
||||
result = $"药品冷却中,{lockTime}秒后可使用!";
|
||||
}
|
||||
}
|
||||
else if (_drugConfig.cls == nameof(GoodsEnum.DrugCls.BloodStock))
|
||||
{
|
||||
if (_drugConfig.type == nameof(GameEnum.GameStockType.Number))
|
||||
{
|
||||
if (string.IsNullOrEmpty(scene))
|
||||
{
|
||||
var attrService = App.GetService<IUnitUserAttrService>();
|
||||
var userStock = await attrService.GetUserStock(userId);
|
||||
if (userStock.Count(it => it.goodsId == goodsId.ToString()) > 0)
|
||||
{
|
||||
result = "您已经使用过该药品啦!";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//要判断使用个数
|
||||
if (_drugConfig.use > 0)
|
||||
{
|
||||
var count = await GetUserDrugLockCount(userId, goodsId, scene);
|
||||
if (count >= _drugConfig.use)
|
||||
{
|
||||
result = $"当前最多可用{_drugConfig.use}个该物品!";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<bool> UseDrug(string userId, int goodsId, string drugConfig, string scene = "")
|
||||
{
|
||||
bool result = false;
|
||||
var attrService = App.GetService<IUnitUserAttrService>();
|
||||
dynamic _drugConfig = JsonConvert.DeserializeObject<dynamic>(drugConfig);
|
||||
if (_drugConfig.cls == nameof(GoodsEnum.DrugCls.Blood))
|
||||
{
|
||||
result = await attrService.UpdateUserBlood(userId, 1, Convert.ToInt32(_drugConfig.num), true);
|
||||
if (result)
|
||||
{
|
||||
await AddUserDrugLockTime(userId, goodsId, Convert.ToInt32(_drugConfig.time));
|
||||
}
|
||||
}
|
||||
else if (_drugConfig.cls == nameof(GoodsEnum.DrugCls.Morale))
|
||||
{
|
||||
result = await attrService.UpdateUserMorale(userId, 1, Convert.ToInt32(_drugConfig.num));
|
||||
}
|
||||
else if (_drugConfig.cls == nameof(GoodsEnum.DrugCls.Vigour))
|
||||
{
|
||||
result = await attrService.UpdateUserVigour(userId, 1, Convert.ToInt32(_drugConfig.num));
|
||||
}
|
||||
else if (_drugConfig.cls == nameof(GoodsEnum.DrugCls.LoadBuff))
|
||||
{
|
||||
result = await attrService.RandomRemoveUserLoadState(userId, Convert.ToInt32(_drugConfig.num));
|
||||
}
|
||||
else if (_drugConfig.cls == nameof(GoodsEnum.DrugCls.BloodStock))
|
||||
{
|
||||
result = await attrService.AddUserStock(userId, goodsId.ToString(), Convert.ToString(_drugConfig.name),Convert.ToString(_drugConfig.type),
|
||||
Convert.ToString(_drugConfig.code),
|
||||
Convert.ToInt64(_drugConfig.num), Convert.ToString(_drugConfig.par),
|
||||
Convert.ToInt32(_drugConfig.minute));
|
||||
if (result)
|
||||
{
|
||||
await AddUserDrugLockCount(userId, goodsId, scene);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -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");
|
||||
@@ -832,7 +838,7 @@ public class GameMapService(ISqlSugarClient DbClient, IRedisCache redis) : IGame
|
||||
if (!string.IsNullOrEmpty(offSet))
|
||||
{
|
||||
var offsetData = JsonConvert.DeserializeObject<TowerNeed>(offSet);
|
||||
var chekResult = await GameBus.CheakNeed(userId, offsetData, "");
|
||||
var chekResult = await GameBus.CheckNeed(userId, offsetData);
|
||||
if (chekResult.result)
|
||||
{
|
||||
if (offsetData.isOp == 0)
|
||||
@@ -858,7 +864,7 @@ public class GameMapService(ISqlSugarClient DbClient, IRedisCache redis) : IGame
|
||||
|
||||
public async Task<List<game_city_map_bus>> GetMapBus(string BusCode, int v, int l)
|
||||
{
|
||||
string key = string.Format(BaseCache.BaseCacheKeys, "CITY_MAP_BUS", BusCode);
|
||||
string key = string.Format(BaseCache.BaseCacheKeys, "CityMapBus", BusCode);
|
||||
var data = await redis.GetAsync<List<game_city_map_bus>>(key);
|
||||
if (data == null)
|
||||
{
|
||||
@@ -877,7 +883,7 @@ public class GameMapService(ISqlSugarClient DbClient, IRedisCache redis) : IGame
|
||||
|
||||
public async Task<game_city_map_bus> GetMapBusInfo(int busId)
|
||||
{
|
||||
string key = string.Format(BaseCache.BaseCacheKeys, "CITY_MAP_BUS", "BUS_INFO");
|
||||
string key = string.Format(BaseCache.BaseCacheKeys, "CityMapBus", "BUS_INFO");
|
||||
if (await redis.HExistsHashAsync(key, busId.ToString()))
|
||||
{
|
||||
return await redis.GetHashAsync<game_city_map_bus>(key, busId.ToString());
|
||||
@@ -925,6 +931,7 @@ public class GameMapService(ISqlSugarClient DbClient, IRedisCache redis) : IGame
|
||||
#endregion
|
||||
|
||||
#region 地图资源
|
||||
|
||||
public async Task<game_city_map_res> GetMapResInfo(string resId)
|
||||
{
|
||||
string key = string.Format(BaseCache.BaseCacheKeys, "CityData", "MapResInfo");
|
||||
@@ -938,6 +945,7 @@ public class GameMapService(ISqlSugarClient DbClient, IRedisCache redis) : IGame
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
public async Task<List<game_city_map_res>> GetMapRes(string mapId)
|
||||
{
|
||||
string key = string.Format(BaseCache.BaseCacheKeys, "CityData", "MapRes");
|
||||
|
||||
@@ -0,0 +1,207 @@
|
||||
using Microsoft.VisualBasic.CompilerServices;
|
||||
|
||||
namespace Application.Domain;
|
||||
|
||||
public class GameMonsterService(ISqlSugarClient DbClient, IRedisCache redis) : IGameMonsterService, ITransient
|
||||
{
|
||||
#region 基础资源库
|
||||
|
||||
public async Task<game_monster> GetMonsterInfo(string monsterId)
|
||||
{
|
||||
string key = string.Format(BaseCache.BaseCacheKeys, "MonsterData", "MonsterInfo");
|
||||
if (await redis.HExistsHashAsync(key, monsterId))
|
||||
{
|
||||
return await redis.GetHashAsync<game_monster>(key, monsterId);
|
||||
}
|
||||
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<game_monster>();
|
||||
var data = await db.Queryable<game_monster>().Where(it => it.monsterId == monsterId).SingleAsync();
|
||||
await redis.AddHashAsync(key, monsterId, data);
|
||||
return data;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 地图怪物
|
||||
|
||||
public async Task<List<game_monster_map>> GetMonsterDataByMap(string mapId)
|
||||
{
|
||||
string key = string.Format(BaseCache.BaseCacheKeys, "MonsterData", "MonsterOnMap");
|
||||
if (await redis.HExistsHashAsync(key, mapId))
|
||||
{
|
||||
return await redis.GetHashAsync<List<game_monster_map>>(key, mapId);
|
||||
}
|
||||
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<game_monster_map>();
|
||||
var data = await db.Queryable<game_monster_map>().Where(it => it.mapId == mapId).ToListAsync();
|
||||
await redis.AddHashAsync(key, mapId, data);
|
||||
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 = "")
|
||||
{
|
||||
bool result = false;
|
||||
var monsterInfo = await GetMonsterInfo(monsterId);
|
||||
if (monsterInfo != null)
|
||||
{
|
||||
time = time <= 0 ? 7 * 24 * 60 : time;
|
||||
long onTime = TimeExtend.GetTimeStampSeconds;
|
||||
long endTime = onTime + time * 60;
|
||||
List<unit_user_monster> data = new List<unit_user_monster>();
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
data.Add(new unit_user_monster()
|
||||
{
|
||||
umId = StringAssist.NewGuid,
|
||||
userId = userId,
|
||||
areaCode = areaCode,
|
||||
mapId = mapId,
|
||||
monsterId = monsterId,
|
||||
monsterName = monsterInfo.name,
|
||||
code = monsterInfo.code,
|
||||
par = par,
|
||||
addTime = onTime,
|
||||
endTime = endTime
|
||||
});
|
||||
}
|
||||
|
||||
if (data.Count > 0)
|
||||
{
|
||||
var createDb = DbClient.AsTenant().GetConnectionWithAttr<unit_user_monster>();
|
||||
await createDb.Insertable(data).ExecuteCommandAsync();
|
||||
}
|
||||
|
||||
result = true;
|
||||
}
|
||||
|
||||
if (result)
|
||||
{
|
||||
await ClearCreateMonster(mapId);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private async Task<List<unit_user_monster>> GetCreateMonsterByMapId(string mapId)
|
||||
{
|
||||
string key = string.Format(BaseCache.BaseCacheKeys, "MonsterData", "CreateMonsterOnMap");
|
||||
if (await redis.HExistsHashAsync(key, mapId))
|
||||
{
|
||||
return await redis.GetHashAsync<List<unit_user_monster>>(key, mapId);
|
||||
}
|
||||
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_monster>();
|
||||
var data = await db.Queryable<unit_user_monster>().Where(it => it.mapId == mapId).ToListAsync();
|
||||
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)
|
||||
{
|
||||
string key = string.Format(BaseCache.BaseCacheKeys, "MonsterData", "CreateMonsterOnMap");
|
||||
await redis.DelHashAsync(key, mapId);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
int random = 0; //此处需要判断用户状态中的几率
|
||||
int onTime = TimeAssist.GetHourNum;
|
||||
foreach (var item in mapMonster)
|
||||
{
|
||||
if (item.sTime < onTime && item.eTime > onTime)
|
||||
{
|
||||
if (RandomAssist.CheakRandom((int)item.chance + random))
|
||||
{
|
||||
for (int i = 0; i < item.addCount; i++)
|
||||
{
|
||||
MapMonsterModel temp = new MapMonsterModel()
|
||||
{
|
||||
monterId = item.mmId,
|
||||
name = item.monsterName,
|
||||
type = 0,
|
||||
sign = UserKeyTool.GetThickenDataByUserKey(userKey, "0", item.mmId)
|
||||
};
|
||||
result.Add(temp);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//此处追加个人生成怪物
|
||||
List<unit_user_monster> createData = new List<unit_user_monster>();
|
||||
var createMonster = await GetCreateMonsterByMapId(mapId);
|
||||
if (createMonster.Count > 0)
|
||||
{
|
||||
long onTime = TimeExtend.GetTimeStampSeconds;
|
||||
createMonster = createMonster.FindAll(it => it.endTime > onTime);
|
||||
|
||||
createData.AddRange(createMonster.FindAll(it =>
|
||||
it.userId == userId || it.areaCode == nameof(GameEnum.AreaCode.Public)));
|
||||
if (!string.IsNullOrEmpty(teamId) && teamId != "0")
|
||||
{
|
||||
var teamService = App.GetService<IGameTeamService>();
|
||||
var teamMember = await teamService.GetTeamMember(teamId);
|
||||
teamMember = teamMember.FindAll(it => it.userId != userId);
|
||||
var onCreate = createMonster.FindAll(it =>
|
||||
teamMember.Any(team =>
|
||||
team.userId == it.userId && it.areaCode == nameof(GameEnum.AreaCode.Team)));
|
||||
foreach (var item in onCreate)
|
||||
{
|
||||
if (createData.Any(it => it.umId == item.umId))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
createData.Add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (createData.Count > 0)
|
||||
{
|
||||
foreach (var item in createData)
|
||||
{
|
||||
MapMonsterModel temp = new MapMonsterModel()
|
||||
{
|
||||
monterId = item.umId,
|
||||
name = item.monsterName,
|
||||
type = 1,
|
||||
sign = UserKeyTool.GetThickenDataByUserKey(userKey, "1", item.umId)
|
||||
};
|
||||
result.Add(temp);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
namespace Application.Domain;
|
||||
|
||||
public class GameDicService(ISqlSugarClient DbClient, IRedisCache redis) : IGameDicService, ITransient
|
||||
{
|
||||
public async Task<game_dic> GetDicInfo(string code)
|
||||
{
|
||||
string key = string.Format(BaseCache.BaseCacheKey, "DicData");
|
||||
if (await redis.HExistsHashAsync(key, code))
|
||||
{
|
||||
return await redis.GetHashAsync<game_dic>(key, code);
|
||||
}
|
||||
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<game_dic>();
|
||||
var data = await db.Queryable<game_dic>().Where(it => it.code == code).SingleAsync();
|
||||
await redis.AddHashAsync(key, code, data);
|
||||
return data;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -33,6 +33,7 @@ public class GameTeamService(ISqlSugarClient DbClient, IRedisCache redis) : IGam
|
||||
await redis.AddHashAsync(key, userId, data);
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
public async Task<game_team> GetTeamInfo(string teamId)
|
||||
{
|
||||
|
||||
@@ -311,8 +311,9 @@ public class MessageService(ISqlSugarClient DbClient, IRedisCache redis) : IMess
|
||||
return await db.Queryable<unit_user_message_event>().Where(it => it.state == 0 && it.token == token).AnyAsync();
|
||||
}
|
||||
|
||||
public async Task<bool> SendEventMsg(string userId, string code, string name, string sign, string pars,string token,
|
||||
List<MsgEventBtn> btns=null, int days = 10)
|
||||
public async Task<bool> SendEventMsg(string userId, string code, string name, string sign, string pars,
|
||||
string token,
|
||||
List<MsgEventBtn> btns = null, int days = 10)
|
||||
{
|
||||
unit_user_message_event data = new unit_user_message_event();
|
||||
data.eventId = StringAssist.NewGuid;
|
||||
@@ -331,8 +332,9 @@ public class MessageService(ISqlSugarClient DbClient, IRedisCache redis) : IMess
|
||||
}
|
||||
else
|
||||
{
|
||||
data.btns = btns;
|
||||
data.btns = btns;
|
||||
}
|
||||
|
||||
data.addTime = DateTime.Now;
|
||||
data.endTime = TimeExtend.GetTimeStampBySeconds(DateTime.Now.AddDays(days));
|
||||
data.token = token;
|
||||
@@ -347,4 +349,54 @@ public class MessageService(ISqlSugarClient DbClient, IRedisCache redis) : IMess
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 广播消息
|
||||
|
||||
public async Task<List<game_broadcast>> GetBroadcastData(int area)
|
||||
{
|
||||
List<game_broadcast> data = new List<game_broadcast>();
|
||||
string key = string.Format(BaseCache.BaseCacheKey, "GameBroadcast");
|
||||
var result = await redis.GetHashAllAsync<game_broadcast>(key);
|
||||
if (result.Count > 0)
|
||||
{
|
||||
data = result.Values.ToList();
|
||||
}
|
||||
|
||||
long time = TimeExtend.GetTimeStampSeconds;
|
||||
data = data.FindAll(it => (it.area == area || it.area == 0) && it.endTime > time);
|
||||
data = data.OrderByDescending(it => it.endTime).Take(2).ToList();
|
||||
return data;
|
||||
}
|
||||
|
||||
public async Task<bool> SendBroadcast(string userId, string code, string msg)
|
||||
{
|
||||
game_broadcast add = new game_broadcast();
|
||||
add.Id = StringAssist.NewGuid;
|
||||
add.userId = userId;
|
||||
add.code = code;
|
||||
add.msg = msg;
|
||||
int area = 0;
|
||||
if (add.userId == "0")
|
||||
{
|
||||
add.area = 0;
|
||||
add.userNo = "0";
|
||||
add.nick = "海精灵";
|
||||
}
|
||||
else
|
||||
{
|
||||
var userService = App.GetService<IUnitUserService>();
|
||||
var userInfo = await userService.GetUserInfoByUserId(userId);
|
||||
add.area = (int)userInfo.areaId;
|
||||
add.userNo = userInfo.userNo;
|
||||
add.nick = userInfo.nick;
|
||||
area = add.area;
|
||||
}
|
||||
|
||||
add.endTime = TimeExtend.GetTimeStampSeconds + 300;
|
||||
string key = string.Format(BaseCache.BaseCacheKey, "GameBroadcast");
|
||||
bool result = await redis.AddHashAsync(key, add.Id, add);
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -4,7 +4,7 @@ public class UnitUserAttrService(ISqlSugarClient DbClient, IRedisCache redis) :
|
||||
{
|
||||
#region 个人属性
|
||||
|
||||
public async Task<UserAttrModel> GetUserAttrModel(string userId)
|
||||
public async Task<UserAttrModel> GetUserAttrModel(string userId, string scene = "Default")
|
||||
{
|
||||
UserAttrModel result = new UserAttrModel();
|
||||
result.id = userId;
|
||||
@@ -24,11 +24,150 @@ public class UnitUserAttrService(ISqlSugarClient DbClient, IRedisCache redis) :
|
||||
result.agility = (int)unitAttr.agility;
|
||||
result.upBlood = (int)unitAttr.upBlood;
|
||||
result.upMorale = (int)unitAttr.upMorale;
|
||||
var bloodInfo = await GetUserBlood(userId);
|
||||
result.blood = (int)bloodInfo.blood;
|
||||
var moraleInfo = await GetUserMorale(userId);
|
||||
result.morale = (int)moraleInfo.morale;
|
||||
|
||||
List<AttrItem> ExtendAttrData = new List<AttrItem>();
|
||||
|
||||
#region 构造基础加层体系
|
||||
|
||||
UserAttrModel temp = new UserAttrModel();
|
||||
temp.minAtk = (int)unitAttr.minAtk;
|
||||
temp.maxAtk = (int)unitAttr.maxAtk;
|
||||
temp.defense = (int)unitAttr.defense;
|
||||
temp.agility = (int)unitAttr.agility;
|
||||
temp.upBlood = (int)unitAttr.upBlood;
|
||||
temp.upMorale = (int)unitAttr.upMorale;
|
||||
|
||||
var equService = App.GetService<IGameEquService>();
|
||||
var equTemp = await equService.GetUserEquAttrModel(userId);
|
||||
temp = GameAttrTool.GetRoleAttrTempMerge(temp, equTemp);
|
||||
//套装加层
|
||||
var suitAttr = await equService.GetUserEquSuitAttrInfo(userId);
|
||||
ExtendAttrData.AddRange(suitAttr);
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region 参数
|
||||
|
||||
int minAtk = 0;
|
||||
int maxAtk = 0;
|
||||
int Agility = 0;
|
||||
int Defense = 0;
|
||||
int upBlood = 0;
|
||||
int upMorale = 0;
|
||||
|
||||
#endregion 参数
|
||||
|
||||
#region 队伍加层
|
||||
|
||||
var teamService = App.GetService<IGameTeamService>();
|
||||
var MyTeam = await teamService.GetUserTeamInfo(userId);
|
||||
if (MyTeam.state == 1)
|
||||
{
|
||||
int teamCount = MyTeam.user.Count(it => it.isOnline == 1);
|
||||
if (teamCount > 0)
|
||||
{
|
||||
decimal teamAdd = 0.05m * teamCount;
|
||||
teamAdd = teamAdd > 0.2m ? 0.2m : teamAdd;
|
||||
minAtk += Convert.ToInt32(temp.minAtk * teamAdd);
|
||||
maxAtk += Convert.ToInt32(temp.maxAtk * teamAdd);
|
||||
Defense += Convert.ToInt32(temp.defense * teamAdd);
|
||||
result.atkTips += $"(队+{Convert.ToInt32(teamAdd * 100)}%)";
|
||||
result.defTips += $"(队+{Convert.ToInt32(teamAdd * 100)}%)";
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region Buff加层
|
||||
|
||||
var MyState = await GetUserStateData(userId, scene);
|
||||
if (MyState.Count > 0)
|
||||
{
|
||||
foreach (var item in MyState)
|
||||
{
|
||||
minAtk += Convert.ToInt32(GameAttrTool.GetAttrItemValue(GameEnum.AttrCode.Atk.ToString(), item.attr,
|
||||
temp.minAtk));
|
||||
maxAtk += Convert.ToInt32(GameAttrTool.GetAttrItemValue(GameEnum.AttrCode.Atk.ToString(), item.attr,
|
||||
temp.maxAtk));
|
||||
Defense += Convert.ToInt32(GameAttrTool.GetAttrItemValue(GameEnum.AttrCode.Defense.ToString(),
|
||||
item.attr, temp.defense));
|
||||
Agility += Convert.ToInt32(GameAttrTool.GetAttrItemValue(GameEnum.AttrCode.Agility.ToString(),
|
||||
item.attr, temp.agility));
|
||||
upBlood += Convert.ToInt32(GameAttrTool.GetAttrItemValue(GameEnum.AttrCode.Blood.ToString(), item.attr,
|
||||
temp.upBlood));
|
||||
upMorale += Convert.ToInt32(GameAttrTool.GetAttrItemValue(GameEnum.AttrCode.Morale.ToString(),
|
||||
item.attr, temp.upMorale));
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 加层处理
|
||||
|
||||
var otTemp = GameAttrTool.GetRoleAttrTemp(temp, ExtendAttrData);
|
||||
result = GameAttrTool.GetRoleAttrTempMerge(result, otTemp); //加层其他
|
||||
result = GameAttrTool.GetRoleAttrTempMerge(result, temp); //加层其他
|
||||
|
||||
result.minAtk += minAtk;
|
||||
result.maxAtk += maxAtk;
|
||||
result.defense += Defense;
|
||||
result.agility += Agility;
|
||||
result.upBlood += upBlood;
|
||||
result.upMorale += upMorale;
|
||||
|
||||
#endregion
|
||||
|
||||
#region 数据效验
|
||||
|
||||
var userBlood = await GetUserBlood(userId);
|
||||
result.blood = (int)userBlood.blood;
|
||||
|
||||
//士气
|
||||
var userMorale = await GetUserMorale(userId);
|
||||
result.morale = (int)userMorale.morale;
|
||||
|
||||
//负面状态处理
|
||||
var loadState = await GetUserLoadState(userId);
|
||||
result = await GameAttrTool.CheckRoleLoadBuff(result, loadState);
|
||||
result = await ReviseUserRoleAttr(result);
|
||||
return result;
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private async Task<UserAttrModel> ReviseUserRoleAttr(UserAttrModel result)
|
||||
{
|
||||
//处理上限数据
|
||||
if (result.blood > result.upBlood)
|
||||
{
|
||||
result.blood = result.upBlood;
|
||||
await UpdateUserBlood(result.id, 2, result.blood, true);
|
||||
}
|
||||
|
||||
if (result.morale > result.upMorale)
|
||||
{
|
||||
result.morale = result.upMorale;
|
||||
await UpdateUserMorale(result.id, 2, Convert.ToInt32(result.morale));
|
||||
}
|
||||
|
||||
if (result.NoHarm > 0.8M) //免伤上限
|
||||
{
|
||||
result.NoHarm = 0.8M;
|
||||
}
|
||||
|
||||
if (result.Atk_Next > 0.3M) //连击上限
|
||||
{
|
||||
result.Atk_Next = 0.3M;
|
||||
}
|
||||
|
||||
//评分
|
||||
decimal _score = result.maxAtk + result.defense + result.agility + result.upBlood / 3.00M + result.upMorale;
|
||||
result.score = Math.Round(_score, 2);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -103,6 +242,11 @@ public class UnitUserAttrService(ISqlSugarClient DbClient, IRedisCache redis) :
|
||||
else if (op == 1)
|
||||
{
|
||||
data.blood += count;
|
||||
var myAttr = await GetUserAttrModel(userId);
|
||||
if (myAttr != null)
|
||||
{
|
||||
data.blood = data.blood > myAttr.upBlood ? myAttr.upBlood : data.blood;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -200,9 +344,6 @@ public class UnitUserAttrService(ISqlSugarClient DbClient, IRedisCache redis) :
|
||||
|
||||
if (result && IsUpUserAttr)
|
||||
{
|
||||
//增加负重
|
||||
var wightService = App.GetService<IUnitUserWeight>();
|
||||
await wightService.UpdateUserMaxWeight(userId, 1, GameConfig.UpLevAddWeight, 1, 0, "升级增加负重");
|
||||
await ClearUserAttrCache(userId);
|
||||
}
|
||||
|
||||
@@ -234,6 +375,8 @@ public class UnitUserAttrService(ISqlSugarClient DbClient, IRedisCache redis) :
|
||||
if (op == 1)
|
||||
{
|
||||
data.morale += count;
|
||||
var myAttr = await GetUserAttrModel(userId);
|
||||
data.morale = data.morale > myAttr.upMorale ? myAttr.upMorale : data.morale;
|
||||
}
|
||||
else if (op == 2)
|
||||
{
|
||||
@@ -260,10 +403,11 @@ public class UnitUserAttrService(ISqlSugarClient DbClient, IRedisCache redis) :
|
||||
string key = string.Format(UserCache.BaseCacheKeys, "Recover:Morale", userId);
|
||||
return await redis.ExistsAsync(key);
|
||||
}
|
||||
|
||||
public async Task LockRecoverMorale(string userId)
|
||||
{
|
||||
string key = string.Format(UserCache.BaseCacheKeys, "Recover:Morale", userId);
|
||||
await redis.SetAsync(key, DateTime.Now,TimeAssist.GetDateTimeYMD(1));
|
||||
await redis.SetAsync(key, DateTime.Now, TimeAssist.GetDateTimeYMD(1));
|
||||
}
|
||||
|
||||
#endregion 士气
|
||||
@@ -295,6 +439,13 @@ public class UnitUserAttrService(ISqlSugarClient DbClient, IRedisCache redis) :
|
||||
|
||||
public async Task<bool> UpdateUserVigour(string userId, int op, long count, string UpTime = "")
|
||||
{
|
||||
if (op == 1)
|
||||
{
|
||||
var userVigour = await GetUserVigourInfo(userId);
|
||||
long endVigour = (long)userVigour.upVitality - (long)userVigour.vitality;
|
||||
count = endVigour > count ? count : endVigour;
|
||||
}
|
||||
|
||||
bool result = false;
|
||||
try
|
||||
{
|
||||
@@ -337,7 +488,7 @@ public class UnitUserAttrService(ISqlSugarClient DbClient, IRedisCache redis) :
|
||||
|
||||
#endregion 活力
|
||||
|
||||
#region 在线时间
|
||||
#region 在线时间
|
||||
|
||||
public async Task<bool> UpdateOnLineTime(string userId, string code, int time)
|
||||
{
|
||||
@@ -350,6 +501,314 @@ public class UnitUserAttrService(ISqlSugarClient DbClient, IRedisCache redis) :
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 药品栏
|
||||
|
||||
public async Task<unit_user_drug> GetUserDrug(string userId)
|
||||
{
|
||||
string key = string.Format(UserCache.BaseCacheKeys, "UserTool", "DrugColumn");
|
||||
if (await redis.HExistsHashAsync(key, userId))
|
||||
{
|
||||
return await redis.GetHashAsync<unit_user_drug>(key, userId);
|
||||
}
|
||||
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_drug>();
|
||||
var data = await db.Queryable<unit_user_drug>().Where(it => it.userId == userId).SingleAsync();
|
||||
if (data == null)
|
||||
{
|
||||
data = new unit_user_drug();
|
||||
data.userId = userId;
|
||||
data.drug = new List<UserDrugModel>();
|
||||
await db.Insertable(data).ExecuteCommandAsync();
|
||||
}
|
||||
|
||||
await redis.AddHashAsync(key, userId, data);
|
||||
return data;
|
||||
}
|
||||
|
||||
public async Task<bool> UpdateUserDrug(unit_user_drug data)
|
||||
{
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_drug>();
|
||||
bool result = await db.Updateable<unit_user_drug>(data).ExecuteCommandAsync() > 0;
|
||||
if (result)
|
||||
{
|
||||
await ClearUserDrug(data.userId);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private async Task ClearUserDrug(string userId)
|
||||
{
|
||||
string key = string.Format(UserCache.BaseCacheKeys, "UserTool", "DrugColumn");
|
||||
await redis.DelHashAsync(key, userId);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region BUFF状态
|
||||
|
||||
private async Task<List<unit_user_state>> GetUserStateData(string userId)
|
||||
{
|
||||
string key = string.Format(UserCache.BaseCacheKeys, "AttrData", "State");
|
||||
var data = await redis.GetHashAsync<List<unit_user_state>>(key, userId);
|
||||
if (data == null)
|
||||
{
|
||||
long endTime = TimeExtend.GetTimeStampSeconds;
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_state>();
|
||||
data = await db.Queryable<unit_user_state>().Where(it => it.userId == userId && it.endTime > endTime)
|
||||
.ToListAsync();
|
||||
await redis.AddHashAsync(key, userId, data);
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
public async Task<List<unit_user_state>> GetUserStateData(string userId, string scene = "Default")
|
||||
{
|
||||
var data = await GetUserStateData(userId);
|
||||
if (scene == "ALL")
|
||||
{
|
||||
return data;
|
||||
}
|
||||
|
||||
data = data.FindAll(it => it.scene == "Default" || it.scene == scene);
|
||||
return data;
|
||||
}
|
||||
|
||||
public async Task<bool> AddUserState(string userId, string groupId, string name, string scene, string tips,
|
||||
List<AttrItem> attr, int time, int count = 1)
|
||||
{
|
||||
bool result = false;
|
||||
long onTime = TimeExtend.GetTimeStampSeconds;
|
||||
string usId = $"{userId}_{groupId}";
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_state>();
|
||||
var usData = await db.Queryable<unit_user_state>().Where(it => it.usId == usId).SingleAsync();
|
||||
if (usData == null)
|
||||
{
|
||||
usData = new unit_user_state();
|
||||
usData.usId = usId;
|
||||
usData.userId = userId;
|
||||
usData.goodsId = groupId;
|
||||
usData.name = name;
|
||||
usData.scene = scene;
|
||||
usData.tips = tips;
|
||||
usData.attr = attr;
|
||||
usData.addTime = onTime;
|
||||
usData.endTime = onTime + (time * 60 * count);
|
||||
result = await db.Insertable(usData).ExecuteCommandAsync() > 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (usData.endTime > onTime)
|
||||
{
|
||||
usData.endTime = usData.endTime + (time * 60 * count);
|
||||
}
|
||||
else
|
||||
{
|
||||
usData.addTime = onTime;
|
||||
usData.endTime = onTime + (time * 60 * count);
|
||||
}
|
||||
|
||||
result = await db.Updateable(usData).ExecuteCommandAsync() > 0;
|
||||
}
|
||||
|
||||
if (result)
|
||||
{
|
||||
await ClearUserState(userId);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private async Task ClearUserState(string userId)
|
||||
{
|
||||
string key = string.Format(UserCache.BaseCacheKeys, "AttrData", "State");
|
||||
await redis.DelHashAsync(key, userId);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 游戏资源储备
|
||||
|
||||
private async Task<List<unit_user_stock>> GetUserStock(string userId)
|
||||
{
|
||||
string key = string.Format(UserCache.BaseCacheKeys, "AttrData", "Stock");
|
||||
var data = await redis.GetHashAsync<List<unit_user_stock>>(key, userId);
|
||||
if (data == null)
|
||||
{
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_stock>();
|
||||
data = await db.Queryable<unit_user_stock>().Where(it => it.userId == userId).ToListAsync();
|
||||
await redis.AddHashAsync(key, userId, data);
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
public async Task<List<unit_user_stock>> GetUserStock(string userId, string code = "Default")
|
||||
{
|
||||
var data = await GetUserStock(userId);
|
||||
if (code != "Default")
|
||||
{
|
||||
data = data.FindAll(it => it.code == code);
|
||||
}
|
||||
|
||||
long endTime = TimeExtend.GetTimeStampSeconds;
|
||||
data = data.FindAll(it =>
|
||||
((it.type == "Number" && it.sign > 0) || it.type != "Number") && it.endTime > endTime);
|
||||
return data;
|
||||
}
|
||||
|
||||
public async Task<bool> AddUserStock(string userId, string goodsId, string name, string type, string code,
|
||||
long sign,
|
||||
string par = "",
|
||||
int minute = 0)
|
||||
{
|
||||
if (minute == 0)
|
||||
{
|
||||
minute = 525600;
|
||||
}
|
||||
|
||||
bool result = false;
|
||||
string usId = $"{userId}_{goodsId}";
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_stock>();
|
||||
var usInfo = await db.Queryable<unit_user_stock>().Where(it => it.usId == usId).SingleAsync();
|
||||
if (usInfo == null)
|
||||
{
|
||||
long endTime = TimeExtend.GetTimeStampSeconds + minute * 60;
|
||||
unit_user_stock stock = new unit_user_stock()
|
||||
{
|
||||
usId = usId,
|
||||
userId = userId,
|
||||
goodsId = goodsId,
|
||||
name = name,
|
||||
type = type,
|
||||
code = code,
|
||||
sign = sign,
|
||||
par = par,
|
||||
endTime = endTime
|
||||
};
|
||||
result = await db.Insertable(stock).ExecuteCommandAsync() > 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (usInfo.type == nameof(GameEnum.GameStockType.Number))
|
||||
{
|
||||
usInfo.sign += sign;
|
||||
usInfo.endTime = TimeExtend.GetTimeStampSeconds + minute * 60;
|
||||
}
|
||||
else if (usInfo.type == nameof(GameEnum.GameStockType.Time))
|
||||
{
|
||||
long onTime = TimeExtend.GetTimeStampSeconds;
|
||||
if (usInfo.endTime > onTime)
|
||||
{
|
||||
usInfo.endTime = usInfo.endTime + (minute * 60);
|
||||
}
|
||||
else
|
||||
{
|
||||
usInfo.endTime = TimeExtend.GetTimeStampSeconds + (minute * 60);
|
||||
}
|
||||
}
|
||||
|
||||
result = await db.Updateable(usInfo).ExecuteCommandAsync() > 0;
|
||||
}
|
||||
|
||||
if (result)
|
||||
{
|
||||
await ClearUserStockCache(userId);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private async Task ClearUserStockCache(string userId)
|
||||
{
|
||||
string key = string.Format(UserCache.BaseCacheKeys, "AttrData", "Stock");
|
||||
await redis.DelHashAsync(key, userId);
|
||||
}
|
||||
|
||||
public async Task<bool> UpdateUserStock(unit_user_stock data)
|
||||
{
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_stock>();
|
||||
var result = await db.Updateable(data).ExecuteCommandAsync() > 0;
|
||||
if (result)
|
||||
{
|
||||
await ClearUserAttrCache(data.userId);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 负面状态
|
||||
|
||||
public async Task<List<unit_user_load>> GetUserLoadState(string userId)
|
||||
{
|
||||
string key = string.Format(UserCache.BaseCacheKeys, "AttrData", "LoadState");
|
||||
if (await redis.HExistsHashAsync(key, userId))
|
||||
{
|
||||
return await redis.GetHashAsync<List<unit_user_load>>(key, userId);
|
||||
}
|
||||
|
||||
return new List<unit_user_load>();
|
||||
}
|
||||
|
||||
public async Task<bool> AddUserLoadState(string userId, string name, string code)
|
||||
{
|
||||
bool result = false;
|
||||
string key = string.Format(UserCache.BaseCacheKeys, "AttrData", "LoadState");
|
||||
var data = await GetUserLoadState(userId);
|
||||
var onData = data.Find(it => it.code == code);
|
||||
if (onData == null)
|
||||
{
|
||||
unit_user_load load = new unit_user_load()
|
||||
{
|
||||
id = $"{userId}_{code}",
|
||||
userId = userId,
|
||||
name = name,
|
||||
code = code,
|
||||
count = 1
|
||||
};
|
||||
data.Add(load);
|
||||
result = await redis.AddHashAsync(key, userId, data);
|
||||
}
|
||||
else
|
||||
{
|
||||
data.Remove(onData);
|
||||
onData.count += 1;
|
||||
result = await redis.AddHashAsync(key, userId, data);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<bool> RandomRemoveUserLoadState(string userId, int count)
|
||||
{
|
||||
var data = await GetUserLoadState(userId);
|
||||
int opCount = data.Count - count;
|
||||
opCount = opCount < 0 ? 0 : opCount;
|
||||
if (opCount > 0)
|
||||
{
|
||||
RandomAssist random = new RandomAssist(opCount);
|
||||
var result = random.RandomExtract(data);
|
||||
string key = string.Format(UserCache.BaseCacheKeys, "AttrData", "LoadState");
|
||||
await redis.AddHashAsync(key, userId, result);
|
||||
}
|
||||
else
|
||||
{
|
||||
await RemoveUserLoadState(userId);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public async Task RemoveUserLoadState(string userId)
|
||||
{
|
||||
string key = string.Format(UserCache.BaseCacheKeys, "AttrData", "LoadState");
|
||||
await redis.DelHashAsync(key, userId);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
@@ -268,9 +268,7 @@ public class UnitUserService(ISqlSugarClient DbClient, IRedisCache redis) : IUni
|
||||
|
||||
if (result)//注册各项后处理
|
||||
{
|
||||
//赠送初始负重
|
||||
var weightService = App.GetService<IUnitUserWeight>();
|
||||
await weightService.UpdateUserMaxWeight(userId, 1, 100, 1, 0, "初始负重");
|
||||
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
@@ -19,8 +19,12 @@ public class UnitUserWeight(ISqlSugarClient DbClient, IRedisCache redis) : IUnit
|
||||
|
||||
private async Task<int> GetUserMaxWeight(unit_user_weight data)
|
||||
{
|
||||
int result = (int)data.maxWeight;
|
||||
int result = 100 + (int)data.maxWeight;
|
||||
var attrService = App.GetService<IUnitUserAttrService>();
|
||||
int myLev = await attrService.GetUserLev(data.userId);
|
||||
result += myLev * GameConfig.UpLevAddWeight;
|
||||
//其他属性加层
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -41,7 +45,7 @@ public class UnitUserWeight(ISqlSugarClient DbClient, IRedisCache redis) : IUnit
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
public async Task<bool> UpdateUserWeight(string userId, int op, int weight)
|
||||
{
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_weight>();
|
||||
@@ -119,6 +123,7 @@ public class UnitUserWeight(ISqlSugarClient DbClient, IRedisCache redis) : IUnit
|
||||
}
|
||||
|
||||
#region 船只相关
|
||||
|
||||
public async Task<unit_user_ship> GetUserShipInfo(string usId)
|
||||
{
|
||||
string key = string.Format(UserCache.BaseCacheKeys, "UserShip", "Info");
|
||||
@@ -132,6 +137,7 @@ public class UnitUserWeight(ISqlSugarClient DbClient, IRedisCache redis) : IUnit
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
public async Task<List<unit_user_ship>> GetUserShip(string userId)
|
||||
{
|
||||
string key = string.Format(UserCache.BaseCacheKeys, "WeightData", "Ship");
|
||||
@@ -198,7 +204,7 @@ public class UnitUserWeight(ISqlSugarClient DbClient, IRedisCache redis) : IUnit
|
||||
return result;
|
||||
}
|
||||
|
||||
public async Task<bool> AddUserShip(string userId, string name, int goodsId, int speed, int weight)
|
||||
public async Task<bool> AddUserShip(string userId, string name, int goodsId, int speed, int weight,int copper,long sale,string remark)
|
||||
{
|
||||
unit_user_ship ship = new unit_user_ship();
|
||||
ship.usId = StringAssist.NewGuid;
|
||||
@@ -207,6 +213,9 @@ public class UnitUserWeight(ISqlSugarClient DbClient, IRedisCache redis) : IUnit
|
||||
ship.name = name;
|
||||
ship.speed = speed;
|
||||
ship.weight = weight;
|
||||
ship.copper = copper;
|
||||
ship.sale = sale;
|
||||
ship.remark = remark;
|
||||
var db = DbClient.AsTenant().GetConnectionWithAttr<unit_user_ship>();
|
||||
bool result = await db.Insertable(ship).ExecuteCommandAsync() > 0;
|
||||
if (result)
|
||||
|
||||
166
Service/Application.Domain/Tool/Base/EquTool.cs
Normal file
166
Service/Application.Domain/Tool/Base/EquTool.cs
Normal file
@@ -0,0 +1,166 @@
|
||||
namespace Application.Domain;
|
||||
|
||||
public class EquTool
|
||||
{
|
||||
public static unit_user_equ GetUserEquByIntensify(unit_user_equ equ)
|
||||
{
|
||||
//强化
|
||||
equ = GetIntensifyAttr(equ);
|
||||
List<AttrItem> AttrData = GetUserEquAttrData(equ);
|
||||
equ.minAtk += Convert.ToInt32(GameAttrTool.GetAttrItemValue(nameof(GameEnum.AttrCode.Atk), AttrData, (decimal)equ.minAtk));
|
||||
equ.minAtk +=
|
||||
Convert.ToInt32(GameAttrTool.GetAttrItemValue(nameof(GameEnum.AttrCode.MinAtk), AttrData, (decimal)equ.minAtk));
|
||||
equ.maxAtk += Convert.ToInt32(GameAttrTool.GetAttrItemValue(nameof(GameEnum.AttrCode.Atk), AttrData, (decimal)equ.maxAtk));
|
||||
equ.maxAtk +=
|
||||
Convert.ToInt32(GameAttrTool.GetAttrItemValue(nameof(GameEnum.AttrCode.MaxAtk), AttrData, (decimal)equ.minAtk));
|
||||
equ.Blood += Convert.ToInt32(GameAttrTool.GetAttrItemValue(nameof(GameEnum.AttrCode.Blood), AttrData, (decimal)equ.Blood));
|
||||
equ.Defense +=
|
||||
Convert.ToInt32(GameAttrTool.GetAttrItemValue(nameof(GameEnum.AttrCode.Defense), AttrData, (decimal)equ.Defense));
|
||||
equ.Agility +=
|
||||
Convert.ToInt32(GameAttrTool.GetAttrItemValue(nameof(GameEnum.AttrCode.Agility), AttrData, (decimal)equ.Agility));
|
||||
equ.Morale +=
|
||||
Convert.ToInt32(GameAttrTool.GetAttrItemValue(nameof(GameEnum.AttrCode.Morale), AttrData, (decimal)equ.Morale));
|
||||
return equ;
|
||||
}
|
||||
|
||||
private static unit_user_equ GetIntensifyAttr(unit_user_equ equ)
|
||||
{
|
||||
equ.minAtk = GetIntensifyAttrBase(equ.minAtk, equ.intensifyLev);
|
||||
equ.maxAtk = GetIntensifyAttrBase(equ.maxAtk, equ.intensifyLev);
|
||||
equ.Blood = GetIntensifyAttrBase(equ.Blood, equ.intensifyLev);
|
||||
equ.Defense = GetIntensifyAttrBase(equ.Defense, equ.intensifyLev);
|
||||
equ.Agility = GetIntensifyAttrBase(equ.Agility, equ.intensifyLev);
|
||||
|
||||
return equ;
|
||||
}
|
||||
|
||||
private static int GetIntensifyAttrBase(int? onV, int? lev)
|
||||
{
|
||||
if (onV < 1)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int onAttr = Convert.ToInt32(onV);
|
||||
int onLev = Convert.ToInt32(lev); //当前强化等级
|
||||
if (onLev < 1)
|
||||
{
|
||||
return onAttr;
|
||||
}
|
||||
|
||||
int result = onLev * 3;
|
||||
result = result > 57 ? 57 : result;
|
||||
|
||||
if (onLev > 19)
|
||||
{
|
||||
int addLev = onLev - 19;
|
||||
addLev = addLev > 10 ? 10 : addLev;
|
||||
result += addLev * 5;
|
||||
}
|
||||
|
||||
if (onLev > 29)
|
||||
{
|
||||
int addLev = onLev - 29;
|
||||
addLev = addLev > 10 ? 10 : addLev;
|
||||
result += addLev * 10;
|
||||
}
|
||||
|
||||
if (onLev > 39)
|
||||
{
|
||||
int addLev = onLev - 39;
|
||||
addLev = addLev > 10 ? 10 : addLev;
|
||||
result += addLev * 15;
|
||||
}
|
||||
|
||||
if (onLev > 49)
|
||||
{
|
||||
int addLev = onLev - 49;
|
||||
addLev = addLev > 10 ? 10 : addLev;
|
||||
result += addLev * 20;
|
||||
}
|
||||
|
||||
if (onLev > 59)
|
||||
{
|
||||
int addLev = onLev - 59;
|
||||
addLev = addLev > 10 ? 10 : addLev;
|
||||
result += addLev * 25;
|
||||
}
|
||||
|
||||
if (onLev > 69)
|
||||
{
|
||||
int addLev = onLev - 69;
|
||||
addLev = addLev > 10 ? 10 : addLev;
|
||||
int unitAdd = Convert.ToInt32(onAttr * 0.05);
|
||||
unitAdd = unitAdd < 30 ? 30 : unitAdd;
|
||||
result += addLev * unitAdd;
|
||||
}
|
||||
|
||||
if (onLev > 79)
|
||||
{
|
||||
int addLev = onLev - 79;
|
||||
addLev = addLev > 10 ? 10 : addLev;
|
||||
int unitAdd = Convert.ToInt32(onAttr * 0.1);
|
||||
unitAdd = unitAdd < 35 ? 35 : unitAdd;
|
||||
result += addLev * unitAdd;
|
||||
}
|
||||
|
||||
if (onLev > 89)
|
||||
{
|
||||
int addLev = onLev - 89;
|
||||
addLev = addLev > 10 ? 10 : addLev;
|
||||
int unitAdd = Convert.ToInt32(onAttr * 0.15);
|
||||
unitAdd = unitAdd < 40 ? 40 : unitAdd;
|
||||
result += addLev * unitAdd;
|
||||
}
|
||||
|
||||
if (onLev > 99)
|
||||
{
|
||||
int unitAdd = Convert.ToInt32(onAttr * 0.35);
|
||||
unitAdd = unitAdd < 100 ? 100 : unitAdd;
|
||||
result += unitAdd;
|
||||
}
|
||||
|
||||
return Convert.ToInt32(result + onAttr);
|
||||
}
|
||||
|
||||
public static List<AttrItem> GetUserEquAttrData(unit_user_equ equ)
|
||||
{
|
||||
List<AttrItem> AttrData = new List<AttrItem>();
|
||||
//装备本身特性
|
||||
AttrData.AddRange(equ.EquAttr);
|
||||
|
||||
//宝石
|
||||
if (equ.GemMent.Count > 0)
|
||||
{
|
||||
foreach (var item in equ.GemMent)
|
||||
{
|
||||
AttrData.AddRange(item.gemItem.GemAttr);
|
||||
}
|
||||
}
|
||||
|
||||
//附魔
|
||||
if (equ.EquMent != null)
|
||||
{
|
||||
if (equ.EquMent.EquAttr != null)
|
||||
{
|
||||
AttrData.AddRange(equ.EquMent.EquAttr);
|
||||
}
|
||||
}
|
||||
|
||||
//觉醒
|
||||
if (equ.EquAwaken != null)
|
||||
{
|
||||
foreach (var item in equ.EquAwaken)
|
||||
{
|
||||
if (item.awaken != null)
|
||||
{
|
||||
AttrData.AddRange(item.awaken);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return AttrData;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
239
Service/Application.Domain/Tool/Base/GameAttrTool.cs
Normal file
239
Service/Application.Domain/Tool/Base/GameAttrTool.cs
Normal file
@@ -0,0 +1,239 @@
|
||||
|
||||
namespace Application.Domain;
|
||||
|
||||
public class GameAttrTool
|
||||
{
|
||||
public static UserAttrModel GetRoleAttrTemp(UserAttrModel temp, List<AttrItem> attrData)
|
||||
{
|
||||
UserAttrModel result = new UserAttrModel();
|
||||
result.minAtk =
|
||||
Convert.ToInt32(GetAttrItemValue(GameEnum.AttrCode.Atk.ToString(), attrData, temp.minAtk));
|
||||
result.maxAtk =
|
||||
Convert.ToInt32(GetAttrItemValue(GameEnum.AttrCode.Atk.ToString(), attrData, temp.maxAtk));
|
||||
result.defense =
|
||||
Convert.ToInt32(GetAttrItemValue(GameEnum.AttrCode.Defense.ToString(), attrData, temp.defense));
|
||||
result.agility =
|
||||
Convert.ToInt32(GetAttrItemValue(GameEnum.AttrCode.Agility.ToString(), attrData, temp.agility));
|
||||
result.upBlood =
|
||||
Convert.ToInt32(GetAttrItemValue(GameEnum.AttrCode.Blood.ToString(), attrData, temp.upBlood));
|
||||
result.upMorale =
|
||||
Convert.ToInt32(GetAttrItemValue(GameEnum.AttrCode.Morale.ToString(), attrData, temp.upMorale));
|
||||
result.InBlood = GetAttrItemValue(GameEnum.AttrCode.InBlood.ToString(), attrData, temp.InBlood);
|
||||
result.Crit = GetAttrItemValue(GameEnum.AttrCode.Crit.ToString(), attrData, temp.Crit);
|
||||
result.NoHarm = GetAttrItemValue(GameEnum.AttrCode.NoHarm.ToString(), attrData, temp.NoHarm);
|
||||
result.Dodge = GetAttrItemValue(GameEnum.AttrCode.Dodge.ToString(), attrData, temp.Dodge);
|
||||
result.Rebound = GetAttrItemValue(GameEnum.AttrCode.Rebound.ToString(), attrData, temp.Rebound);
|
||||
result.ReboundLess =
|
||||
GetAttrItemValue(GameEnum.AttrCode.ReboundLess.ToString(), attrData, temp.ReboundLess);
|
||||
result.Punish = GetAttrItemValue(GameEnum.AttrCode.Punish.ToString(), attrData, temp.Punish);
|
||||
result.Slow = GetAttrItemValue(GameEnum.AttrCode.Slow.ToString(), attrData, temp.Slow);
|
||||
result.SlowLess = GetAttrItemValue(GameEnum.AttrCode.SlowLess.ToString(), attrData, temp.SlowLess);
|
||||
result.Poison = GetAttrItemValue(GameEnum.AttrCode.Poison.ToString(), attrData, temp.Poison);
|
||||
result.PoisonLess =
|
||||
GetAttrItemValue(GameEnum.AttrCode.PoisonLess.ToString(), attrData, temp.PoisonLess);
|
||||
result.Curse = GetAttrItemValue(GameEnum.AttrCode.Curse.ToString(), attrData, temp.Curse);
|
||||
result.CurseLess = GetAttrItemValue(GameEnum.AttrCode.CurseLess.ToString(), attrData, temp.CurseLess);
|
||||
result.Weaken = GetAttrItemValue(GameEnum.AttrCode.Weaken.ToString(), attrData, temp.Weaken);
|
||||
result.WeakenLess =
|
||||
GetAttrItemValue(GameEnum.AttrCode.WeakenLess.ToString(), attrData, temp.WeakenLess);
|
||||
result.Deadly = GetAttrItemValue(GameEnum.AttrCode.Deadly.ToString(), attrData, temp.Deadly);
|
||||
result.DeadlyLess =
|
||||
GetAttrItemValue(GameEnum.AttrCode.DeadlyLess.ToString(), attrData, temp.DeadlyLess);
|
||||
result.Depressed = GetAttrItemValue(GameEnum.AttrCode.Depressed.ToString(), attrData, temp.Depressed);
|
||||
result.DepressedLess =
|
||||
GetAttrItemValue(GameEnum.AttrCode.DepressedLess.ToString(), attrData, temp.DepressedLess);
|
||||
result.Breach = GetAttrItemValue(GameEnum.AttrCode.Breach.ToString(), attrData, temp.Breach);
|
||||
result.BreachLess =
|
||||
GetAttrItemValue(GameEnum.AttrCode.BreachLess.ToString(), attrData, temp.BreachLess);
|
||||
result.Del_Fashion =
|
||||
GetAttrItemValue(GameEnum.AttrCode.Del_Fashion.ToString(), attrData, temp.Del_Fashion);
|
||||
result.Atk_Next = GetAttrItemValue(GameEnum.AttrCode.Atk_Next.ToString(), attrData, temp.Atk_Next);
|
||||
result.Harm_Add = GetAttrItemValue(GameEnum.AttrCode.Harm_Add.ToString(), attrData, temp.Harm_Add);
|
||||
result.PalsyAtk = GetAttrItemValue(GameEnum.AttrCode.PalsyAtk.ToString(), attrData, temp.PalsyAtk);
|
||||
result.PalsyAtkLess =
|
||||
GetAttrItemValue(GameEnum.AttrCode.PalsyAtkLess.ToString(), attrData, temp.PalsyAtk);
|
||||
|
||||
result.addExp =
|
||||
GetAttrItemValue(nameof(GameEnum.AttrCode.AddExp), attrData, temp.addExp);
|
||||
result.addGold =
|
||||
GetAttrItemValue(nameof(GameEnum.AttrCode.AddGold), attrData, temp.addGold);
|
||||
result.burst =
|
||||
GetAttrItemValue(nameof(GameEnum.AttrCode.Burst), attrData, temp.burst);
|
||||
result.luck =
|
||||
GetAttrItemValue(nameof(GameEnum.AttrCode.Luck), attrData, temp.luck);
|
||||
result.weight = Convert.ToInt32(GetAttrItemValue(nameof(GameEnum.AttrCode.Weight), attrData, temp.weight));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static UserAttrModel GetRoleAttrTempMerge(UserAttrModel result, List<AttrItem> attrData)
|
||||
{
|
||||
result.minAtk +=
|
||||
Convert.ToInt32(GetAttrItemValue(GameEnum.AttrCode.Atk.ToString(), attrData, result.minAtk));
|
||||
result.maxAtk +=
|
||||
Convert.ToInt32(GetAttrItemValue(GameEnum.AttrCode.Atk.ToString(), attrData, result.maxAtk));
|
||||
result.defense +=
|
||||
Convert.ToInt32(GetAttrItemValue(GameEnum.AttrCode.Defense.ToString(), attrData, result.defense));
|
||||
result.agility +=
|
||||
Convert.ToInt32(GetAttrItemValue(GameEnum.AttrCode.Agility.ToString(), attrData, result.agility));
|
||||
result.upBlood +=
|
||||
Convert.ToInt32(GetAttrItemValue(GameEnum.AttrCode.Blood.ToString(), attrData, result.upBlood));
|
||||
result.upMorale +=
|
||||
Convert.ToInt32(GetAttrItemValue(GameEnum.AttrCode.Morale.ToString(), attrData, result.upMorale));
|
||||
result.InBlood += GetAttrItemValue(GameEnum.AttrCode.InBlood.ToString(), attrData, 0);
|
||||
result.Crit += GetAttrItemValue(GameEnum.AttrCode.Crit.ToString(), attrData, 0);
|
||||
result.NoHarm += GetAttrItemValue(GameEnum.AttrCode.NoHarm.ToString(), attrData, 0);
|
||||
result.Dodge += GetAttrItemValue(GameEnum.AttrCode.Dodge.ToString(), attrData, 0);
|
||||
result.Rebound += GetAttrItemValue(GameEnum.AttrCode.Rebound.ToString(), attrData, 0);
|
||||
result.ReboundLess += GetAttrItemValue(GameEnum.AttrCode.ReboundLess.ToString(), attrData, 0);
|
||||
result.Punish += GetAttrItemValue(GameEnum.AttrCode.Punish.ToString(), attrData, 0);
|
||||
result.Slow += GetAttrItemValue(GameEnum.AttrCode.Slow.ToString(), attrData, 0);
|
||||
result.SlowLess += GetAttrItemValue(GameEnum.AttrCode.SlowLess.ToString(), attrData, 0);
|
||||
result.Poison += GetAttrItemValue(GameEnum.AttrCode.Poison.ToString(), attrData, 0);
|
||||
result.PoisonLess += GetAttrItemValue(GameEnum.AttrCode.PoisonLess.ToString(), attrData, 0);
|
||||
result.Curse += GetAttrItemValue(GameEnum.AttrCode.Curse.ToString(), attrData, 0);
|
||||
result.CurseLess += GetAttrItemValue(GameEnum.AttrCode.CurseLess.ToString(), attrData, 0);
|
||||
result.Weaken += GetAttrItemValue(GameEnum.AttrCode.Weaken.ToString(), attrData, 0);
|
||||
result.WeakenLess += GetAttrItemValue(GameEnum.AttrCode.WeakenLess.ToString(), attrData, 0);
|
||||
result.Deadly += GetAttrItemValue(GameEnum.AttrCode.Deadly.ToString(), attrData, 0);
|
||||
result.DeadlyLess += GetAttrItemValue(GameEnum.AttrCode.DeadlyLess.ToString(), attrData, 0);
|
||||
result.Depressed += GetAttrItemValue(GameEnum.AttrCode.Depressed.ToString(), attrData, 0);
|
||||
result.DepressedLess += GetAttrItemValue(GameEnum.AttrCode.DepressedLess.ToString(), attrData, 0);
|
||||
result.Breach += GetAttrItemValue(GameEnum.AttrCode.Breach.ToString(), attrData, 0);
|
||||
result.BreachLess += GetAttrItemValue(GameEnum.AttrCode.BreachLess.ToString(), attrData, 0);
|
||||
result.Del_Fashion += GetAttrItemValue(GameEnum.AttrCode.Del_Fashion.ToString(), attrData, 0);
|
||||
result.Atk_Next += GetAttrItemValue(GameEnum.AttrCode.Atk_Next.ToString(), attrData, 0);
|
||||
result.Harm_Add += GetAttrItemValue(GameEnum.AttrCode.Harm_Add.ToString(), attrData, 0);
|
||||
result.PalsyAtk += GetAttrItemValue(GameEnum.AttrCode.PalsyAtk.ToString(), attrData, 0);
|
||||
result.PalsyAtkLess += GetAttrItemValue(GameEnum.AttrCode.PalsyAtkLess.ToString(), attrData, 0);
|
||||
|
||||
result.addExp += GetAttrItemValue(GameEnum.AttrCode.AddExp.ToString(), attrData, 0);
|
||||
result.addGold += GetAttrItemValue(GameEnum.AttrCode.AddGold.ToString(), attrData, 0);
|
||||
result.burst += GetAttrItemValue(GameEnum.AttrCode.Burst.ToString(), attrData, 0);
|
||||
result.luck += GetAttrItemValue(GameEnum.AttrCode.Luck.ToString(), attrData, 0);
|
||||
result.weight += Convert.ToInt32(GetAttrItemValue(GameEnum.AttrCode.Weight.ToString(), attrData, 0)) ;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static UserAttrModel GetRoleAttrTempMerge(UserAttrModel main, UserAttrModel vice)
|
||||
{
|
||||
main.minAtk += vice.minAtk;
|
||||
main.maxAtk += vice.maxAtk;
|
||||
main.defense += vice.defense;
|
||||
main.agility += vice.agility;
|
||||
main.upBlood += vice.upBlood;
|
||||
main.upMorale += vice.upMorale;
|
||||
main.InBlood += vice.InBlood;
|
||||
main.Crit += vice.Crit;
|
||||
main.NoHarm += vice.NoHarm;
|
||||
main.Dodge += vice.Dodge;
|
||||
main.Rebound += vice.Rebound;
|
||||
main.ReboundLess += vice.ReboundLess;
|
||||
main.Punish += vice.Punish;
|
||||
main.Slow += vice.Slow;
|
||||
main.Poison += vice.Poison;
|
||||
main.PoisonLess += vice.PoisonLess;
|
||||
main.Curse += vice.Curse;
|
||||
main.CurseLess += vice.CurseLess;
|
||||
main.Weaken += vice.Weaken;
|
||||
main.WeakenLess += vice.WeakenLess;
|
||||
main.Deadly += vice.Deadly;
|
||||
main.DeadlyLess += vice.DeadlyLess;
|
||||
main.Depressed += vice.Depressed;
|
||||
main.DepressedLess += vice.DepressedLess;
|
||||
main.Breach += vice.Breach;
|
||||
main.BreachLess += vice.BreachLess;
|
||||
main.Del_Fashion += vice.Del_Fashion;
|
||||
main.Atk_Next += vice.Atk_Next;
|
||||
main.Harm_Add += vice.Harm_Add;
|
||||
main.PalsyAtk += vice.PalsyAtk;
|
||||
main.PalsyAtkLess += vice.PalsyAtkLess;
|
||||
|
||||
main.addExp += vice.addExp;
|
||||
main.addGold += vice.addGold;
|
||||
main.burst += vice.burst;
|
||||
main.luck += vice.luck;
|
||||
main.weight += vice.weight;
|
||||
return main;
|
||||
}
|
||||
|
||||
public static decimal GetAttrItemValue(string attrCode, List<AttrItem> AttrData, decimal unit)
|
||||
{
|
||||
decimal result = 0.00M;
|
||||
foreach (var item in AttrData)
|
||||
{
|
||||
if (attrCode == item.code)
|
||||
{
|
||||
if (string.IsNullOrEmpty(item.compute))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (item.compute == nameof(GameEnum.ComputeType.Ride))
|
||||
{
|
||||
result += unit * Convert.ToDecimal(item.parameter);
|
||||
}
|
||||
else if (item.compute == nameof(GameEnum.ComputeType.Plus))
|
||||
{
|
||||
result += Convert.ToDecimal(item.parameter);
|
||||
}
|
||||
else if (item.compute == nameof(GameEnum.ComputeType.Reduce))
|
||||
{
|
||||
result = unit - Convert.ToDecimal(item.parameter);
|
||||
}
|
||||
else if (item.compute == nameof(GameEnum.ComputeType.Except))
|
||||
{
|
||||
result = unit / Convert.ToDecimal(item.parameter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static async Task<UserAttrModel> CheckRoleLoadBuff(UserAttrModel temp, List<unit_user_load> loadBuff)
|
||||
{
|
||||
foreach (var item in loadBuff)
|
||||
{
|
||||
if (item.code == nameof(GameEnum.AttrCode.Slow))
|
||||
{
|
||||
decimal radio = item.count * 0.05M;
|
||||
temp.agility = Convert.ToInt32(temp.agility * (1.0M - radio));
|
||||
}
|
||||
else if (item.code == nameof(GameEnum.AttrCode.Poison))
|
||||
{
|
||||
decimal radio = item.count * 0.08M;
|
||||
temp.upBlood = Convert.ToInt32(temp.upBlood * (1.0M - radio));
|
||||
}
|
||||
else if (item.code == nameof(GameEnum.AttrCode.Curse))
|
||||
{
|
||||
decimal radio = item.count * 0.08M;
|
||||
temp.minAtk = Convert.ToInt32(temp.minAtk * (1.0M - radio));
|
||||
temp.maxAtk = Convert.ToInt32(temp.maxAtk * (1.0M - radio));
|
||||
}
|
||||
else if (item.code == nameof(GameEnum.AttrCode.Weaken))
|
||||
{
|
||||
decimal radio = item.count * 0.02M;
|
||||
temp.Crit = temp.Crit - radio;
|
||||
}
|
||||
else if (item.code == nameof(GameEnum.AttrCode.Depressed))
|
||||
{
|
||||
decimal radio = item.count * 0.07M;
|
||||
temp.upMorale = Convert.ToInt32(temp.upMorale * (1.0M - radio));
|
||||
}
|
||||
else if (item.code == nameof(GameEnum.AttrCode.Breach))
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
namespace Application.Domain;
|
||||
|
||||
public class GameBus
|
||||
public static class GameBus
|
||||
{
|
||||
#region 物品资源操作
|
||||
|
||||
@@ -64,6 +64,11 @@ public class GameBus
|
||||
isok = await accService.UpdateUserAcc(userId, operate, nameof(AccEnum.AccType.teach), count,
|
||||
nameof(AccEnum.Name.其他), remark);
|
||||
}
|
||||
else if (goodsType.Equals(nameof(GameEnum.PropCode.map)))
|
||||
{
|
||||
var mapService = App.GetService<IGameMapService>();
|
||||
isok = await mapService.AddUserCityMap(userId, Convert.ToInt32(parameter));
|
||||
}
|
||||
|
||||
return isok;
|
||||
}
|
||||
@@ -96,20 +101,24 @@ public class GameBus
|
||||
|
||||
#region 验证
|
||||
|
||||
public static async Task<CheckTowerNeed> CheakNeed(string userId, TowerNeed item, string sid, int count = 1)
|
||||
public static async Task<CheckTowerNeed> CheckNeed(string userId, TowerNeed item, int count = 1)
|
||||
{
|
||||
CheckTowerNeed result = new CheckTowerNeed();
|
||||
result.Needs = new List<TowerNeed>();
|
||||
bool isok = true;
|
||||
int isDeal = 1;
|
||||
int isGive = 1;
|
||||
|
||||
item.isAsk = 1;
|
||||
if (item.code == nameof(GameEnum.PropCode.Equ))
|
||||
{
|
||||
var equService = App.GetService<IGameEquService>();
|
||||
int MyCount = await equService.GetUserEquByEquIdCount(userId, Convert.ToInt32(item.parameter));
|
||||
int neecCount = item.count * count;
|
||||
if (MyCount < neecCount)
|
||||
long needCount = item.count * count;
|
||||
item.count = needCount;
|
||||
item.onCount = MyCount;
|
||||
if (MyCount < needCount)
|
||||
{
|
||||
item.isAsk = 0;
|
||||
isok = false;
|
||||
}
|
||||
}
|
||||
@@ -132,29 +141,38 @@ public class GameBus
|
||||
}
|
||||
}
|
||||
|
||||
int needCount = item.count * count;
|
||||
long needCount = item.count * count;
|
||||
item.count = needCount;
|
||||
item.onCount = MyCount;
|
||||
if (MyCount < needCount)
|
||||
{
|
||||
isok = false;
|
||||
item.isAsk = 0;
|
||||
}
|
||||
}
|
||||
else if (item.code == nameof(GameEnum.PropCode.copper))
|
||||
{
|
||||
var accService = App.GetService<IUnitUserAccService>();
|
||||
var MyAcc = await accService.GetUserAccInfo(userId, nameof(AccEnum.AccType.copper));
|
||||
decimal needAcc = item.count * count;
|
||||
long needAcc = item.count * count;
|
||||
item.count = needAcc;
|
||||
item.onCount = MyAcc;
|
||||
if (MyAcc < needAcc)
|
||||
{
|
||||
isok = false;
|
||||
item.isAsk = 0;
|
||||
}
|
||||
}
|
||||
else if (item.code == nameof(GameEnum.PropCode.gold))
|
||||
{
|
||||
var accService = App.GetService<IUnitUserAccService>();
|
||||
var MyAcc = await accService.GetUserAccInfo(userId, nameof(AccEnum.AccType.gold));
|
||||
decimal needAcc = item.count * count;
|
||||
long needAcc = item.count * count;
|
||||
item.count = needAcc;
|
||||
item.onCount = MyAcc;
|
||||
if (MyAcc < needAcc)
|
||||
{
|
||||
item.isAsk = 0;
|
||||
isok = false;
|
||||
}
|
||||
}
|
||||
@@ -162,9 +180,12 @@ public class GameBus
|
||||
{
|
||||
var attrService = App.GetService<IUnitUserAttrService>();
|
||||
var MyAcc = await attrService.GetUserVigourInfo(userId);
|
||||
decimal neecAcc = item.count * count;
|
||||
if (MyAcc.vitality < neecAcc)
|
||||
long needAcc = item.count * count;
|
||||
item.count = needAcc;
|
||||
item.onCount = (long)MyAcc.vitality;
|
||||
if (MyAcc.vitality < needAcc)
|
||||
{
|
||||
item.isAsk = 0;
|
||||
isok = false;
|
||||
}
|
||||
}
|
||||
@@ -172,6 +193,8 @@ public class GameBus
|
||||
{
|
||||
var attrService = App.GetService<IUnitUserAttrService>();
|
||||
var MyLev = await attrService.GetUserLev(userId);
|
||||
item.count = item.count;
|
||||
item.onCount = MyLev;
|
||||
if (MyLev < item.count)
|
||||
{
|
||||
isok = false;
|
||||
@@ -181,18 +204,20 @@ public class GameBus
|
||||
result.result = isok;
|
||||
result.isDeal = isDeal;
|
||||
result.isGive = isGive;
|
||||
result.Needs.Add(item);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static async Task<CheckTowerNeed> CheakNeed(string userId, List<TowerNeed> needs, string sid, int count = 1)
|
||||
public static async Task<CheckTowerNeed> CheckNeed(string userId, List<TowerNeed> needs, int count = 1)
|
||||
{
|
||||
CheckTowerNeed result = new CheckTowerNeed();
|
||||
result.Needs = new List<TowerNeed>();
|
||||
bool isok = true;
|
||||
int isDeal = 1;
|
||||
int isGive = 1;
|
||||
foreach (var item in needs)
|
||||
{
|
||||
var cheakResult = await CheakNeed(userId, item, sid, count);
|
||||
var cheakResult = await CheckNeed(userId, item, count);
|
||||
if (isok)
|
||||
{
|
||||
isok = cheakResult.result;
|
||||
@@ -208,7 +233,117 @@ public class GameBus
|
||||
isGive = 0;
|
||||
}
|
||||
|
||||
item.isAsk = cheakResult.result ? 1 : 0;
|
||||
result.Needs.AddRange(cheakResult.Needs);
|
||||
}
|
||||
|
||||
result.result = isok;
|
||||
result.isDeal = isDeal;
|
||||
result.isGive = isGive;
|
||||
return result;
|
||||
}
|
||||
|
||||
public static async Task<CheckTowerNeeds> CheckNeeds(string userId, List<TowerNeeds> needs, int count = 1)
|
||||
{
|
||||
CheckTowerNeeds result = new CheckTowerNeeds();
|
||||
bool isok = true;
|
||||
int isDeal = 1;
|
||||
int isGive = 1;
|
||||
result.Needs = new List<TowerNeeds>();
|
||||
foreach (var item in needs)
|
||||
{
|
||||
item.isAsk = 1;
|
||||
if (item.code == nameof(GameEnum.PropCode.Equ))
|
||||
{
|
||||
var equService = App.GetService<IGameEquService>();
|
||||
int MyCount = await equService.GetUserEquByEquIdCount(userId, Convert.ToInt32(item.parameter));
|
||||
long needCount = item.count * count;
|
||||
item.count = needCount;
|
||||
item.onCount = MyCount;
|
||||
if (MyCount < needCount)
|
||||
{
|
||||
item.isAsk = 0;
|
||||
isok = false;
|
||||
}
|
||||
}
|
||||
else if (item.code == nameof(GameEnum.PropCode.Goods))
|
||||
{
|
||||
int MyCount = 0;
|
||||
var goodsService = App.GetService<IGameGoodsService>();
|
||||
var goodsInfo = await goodsService.GetUserGoodsInfo(userId, Convert.ToInt32(item.parameter));
|
||||
if (goodsInfo != null)
|
||||
{
|
||||
MyCount = (int)goodsInfo.count;
|
||||
if (goodsInfo.isDeal == 0)
|
||||
{
|
||||
isDeal = 0;
|
||||
}
|
||||
|
||||
if (goodsInfo.isGive == 0)
|
||||
{
|
||||
isGive = 0;
|
||||
}
|
||||
}
|
||||
|
||||
long needCount = item.count * count;
|
||||
item.count = needCount;
|
||||
item.onCount = MyCount;
|
||||
if (MyCount < needCount)
|
||||
{
|
||||
isok = false;
|
||||
item.isAsk = 0;
|
||||
}
|
||||
}
|
||||
else if (item.code == nameof(GameEnum.PropCode.copper))
|
||||
{
|
||||
var accService = App.GetService<IUnitUserAccService>();
|
||||
var MyAcc = await accService.GetUserAccInfo(userId, nameof(AccEnum.AccType.copper));
|
||||
long needAcc = item.count * count;
|
||||
item.count = needAcc;
|
||||
item.onCount = MyAcc;
|
||||
if (MyAcc < needAcc)
|
||||
{
|
||||
isok = false;
|
||||
item.isAsk = 0;
|
||||
}
|
||||
}
|
||||
else if (item.code == nameof(GameEnum.PropCode.gold))
|
||||
{
|
||||
var accService = App.GetService<IUnitUserAccService>();
|
||||
var MyAcc = await accService.GetUserAccInfo(userId, nameof(AccEnum.AccType.gold));
|
||||
long needAcc = item.count * count;
|
||||
item.count = needAcc;
|
||||
item.onCount = MyAcc;
|
||||
if (MyAcc < needAcc)
|
||||
{
|
||||
item.isAsk = 0;
|
||||
isok = false;
|
||||
}
|
||||
}
|
||||
else if (item.code == nameof(GameEnum.PropCode.vigour)) //活力
|
||||
{
|
||||
var attrService = App.GetService<IUnitUserAttrService>();
|
||||
var MyAcc = await attrService.GetUserVigourInfo(userId);
|
||||
long needAcc = item.count * count;
|
||||
item.count = needAcc;
|
||||
item.onCount = (long)MyAcc.vitality;
|
||||
if (MyAcc.vitality < needAcc)
|
||||
{
|
||||
item.isAsk = 0;
|
||||
isok = false;
|
||||
}
|
||||
}
|
||||
else if (item.code == nameof(GameEnum.PropCode.lev))
|
||||
{
|
||||
var attrService = App.GetService<IUnitUserAttrService>();
|
||||
var MyLev = await attrService.GetUserLev(userId);
|
||||
item.count = item.count;
|
||||
item.onCount = MyLev;
|
||||
if (MyLev < item.count)
|
||||
{
|
||||
isok = false;
|
||||
}
|
||||
}
|
||||
|
||||
result.Needs.Add(item);
|
||||
}
|
||||
|
||||
@@ -222,7 +357,30 @@ public class GameBus
|
||||
|
||||
#region 概率
|
||||
|
||||
public static List<TowerGet> GetRandomGoods(RandomModel random, int count = 1, int luck = 0)
|
||||
public static RandomDataBase GetRandomByWeight(List<RandomDataBase> data)
|
||||
{
|
||||
var _randomInstance = new Random();
|
||||
if (data.Count == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
double totalWeight = data.Sum(it => it.random);
|
||||
int rnd = _randomInstance.Next(Convert.ToInt32(totalWeight) + 1);
|
||||
double current = 0;
|
||||
foreach (var item in data)
|
||||
{
|
||||
current += item.random;
|
||||
if (rnd < current)
|
||||
{
|
||||
return item;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static List<TowerGet> GetRandomGoods(RandomModel random, int count = 1, decimal luck = 0)
|
||||
{
|
||||
List<TowerGet> result = new List<TowerGet>();
|
||||
for (int i = 0; i < count; i++)
|
||||
@@ -240,9 +398,9 @@ public class GameBus
|
||||
foreach (var item in timeAward)
|
||||
{
|
||||
var onAward = result.FindIndex(it => it.code == item.code && it.parameter == item.par);
|
||||
if(onAward>-1)
|
||||
if (onAward > -1)
|
||||
{
|
||||
result[onAward].count += item.count;
|
||||
result[onAward].count += RandomAssist.GetFormatedNumeric(item.minCount, item.maxCount);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -251,30 +409,31 @@ public class GameBus
|
||||
code = item.code,
|
||||
name = item.name,
|
||||
parameter = item.par,
|
||||
count = item.count
|
||||
count = RandomAssist.GetFormatedNumeric(item.minCount, item.maxCount)
|
||||
};
|
||||
result.Add(add);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private static List<RandomData> RandomHandleByWeight(RandomModel random, int luck = 0)
|
||||
private static List<RandomData> RandomHandleByWeight(RandomModel random, decimal luck = 0)
|
||||
{
|
||||
var _randomInstance = new Random();
|
||||
List<RandomData> result = new List<RandomData>();
|
||||
int empty = random.empty - luck;
|
||||
int empty = random.empty - Convert.ToInt32(luck * 100);
|
||||
if (_randomInstance.Next(0, 100) < empty)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
if (random.data.Count == 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
double totalWeight = random.data.Sum(it => it.chance);
|
||||
int rnd = _randomInstance.Next(Convert.ToInt32(totalWeight) + 1);
|
||||
double current = 0;
|
||||
@@ -290,29 +449,32 @@ public class GameBus
|
||||
|
||||
return result;
|
||||
}
|
||||
private static List<RandomData> RandomHandleByChance(RandomModel random, int luck = 0)
|
||||
|
||||
private static List<RandomData> RandomHandleByChance(RandomModel random, decimal luck = 0)
|
||||
{
|
||||
var _randomInstance = new Random();
|
||||
List<RandomData> result = new List<RandomData>();
|
||||
int empty = random.empty - luck;
|
||||
int empty = random.empty;
|
||||
if (_randomInstance.Next(0, 100) < empty)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
if (random.data.Count == 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
foreach (var item in random.data)
|
||||
{
|
||||
double rnd = _randomInstance.NextDouble();
|
||||
double okChance = item.chance / 100;
|
||||
double okChance = (item.chance / 100) * (1.0 + Convert.ToDouble(luck));
|
||||
if (rnd < okChance)
|
||||
{
|
||||
result.Add(item);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -138,7 +138,41 @@ public class GameTool
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
public static string GetEquQualityName(int count)
|
||||
{
|
||||
string result = "白";
|
||||
switch (count)
|
||||
{
|
||||
case 1:
|
||||
result = "红";
|
||||
break;
|
||||
case 2:
|
||||
result = "橙";
|
||||
break;
|
||||
case 3:
|
||||
result = "黄";
|
||||
break;
|
||||
case 4:
|
||||
result = "绿";
|
||||
break;
|
||||
case 5:
|
||||
result = "青";
|
||||
break;
|
||||
case 6:
|
||||
result = "粉";
|
||||
break;
|
||||
case 7:
|
||||
result = "紫";
|
||||
break;
|
||||
case 8:
|
||||
result = "金";
|
||||
break;
|
||||
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
#region 距离计算
|
||||
|
||||
/// <summary>
|
||||
|
||||
47
Service/Application.Domain/Tool/Base/UserKeyTool.cs
Normal file
47
Service/Application.Domain/Tool/Base/UserKeyTool.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
namespace Application.Domain;
|
||||
|
||||
public static class UserKeyTool
|
||||
{
|
||||
public static async Task<string> GetThickenData(string userId, params string[] data)
|
||||
{
|
||||
string key = await GetUserKey(userId);
|
||||
return GetThickenDataByUserKey(key, data);
|
||||
}
|
||||
|
||||
public static string GetThickenDataByUserKey(string key, params string[] data)
|
||||
{
|
||||
string _data = string.Join("", data);
|
||||
return EncryptAssist.Md5Encryption($"{key}_{_data}").ToLower();
|
||||
}
|
||||
|
||||
|
||||
public static async Task<bool> CheckUserThickenData(string userId, string sign, params string[] data)
|
||||
{
|
||||
string key = await GetUserKey(userId);
|
||||
string _sign = GetThickenDataByUserKey(key, data);
|
||||
await ResetUserKey(userId);
|
||||
return sign.ToLower() == _sign;
|
||||
}
|
||||
|
||||
public static async Task<string> GetUserKey(string userId)
|
||||
{
|
||||
var key = string.Format(UserCache.BaseCacheKey, "UserKey");
|
||||
var redis = App.GetService<IRedisCache>();
|
||||
if (await redis.HExistsHashAsync(key, userId))
|
||||
{
|
||||
return await redis.GetHashAsync<string>(key, userId);
|
||||
}
|
||||
|
||||
string data = StringAssist.RandomString(12);
|
||||
await redis.AddHashAsync(key, userId, data);
|
||||
return data;
|
||||
}
|
||||
|
||||
private static async Task ResetUserKey(string userId)
|
||||
{
|
||||
string data = StringAssist.RandomString(12);
|
||||
var key = string.Format(UserCache.BaseCacheKey, "UserKey");
|
||||
var redis = App.GetService<IRedisCache>();
|
||||
await redis.AddHashAsync(key, userId, data);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user