This commit is contained in:
Putoo
2026-06-17 19:22:35 +08:00
parent 5cd6151b96
commit 3b0f1e37ee
40 changed files with 1856 additions and 55 deletions

View File

@@ -0,0 +1,13 @@
namespace Application.Domain.Entity;
public class game_broadcast
{
public string Id { get; set; }
public int area { get; set; }
public string code { get; set; }
public string userId { get; set; }
public string userNo { get; set; }
public string nick { get; set; }
public string msg { get; set; }
public long endTime { get; set; }
}

View File

@@ -0,0 +1,30 @@
namespace Application.Domain.Entity;
public class CheckTowerNeeds
{
private bool _result;
public bool result
{ get { return this._result; } set { this._result = value; } }
private System.Int32 _isDeal;
/// <summary>
/// 0不可交易1可交易
/// </summary>
public System.Int32 isDeal
{ get { return this._isDeal; } set { this._isDeal = value; } }
private System.Int32 _isGive;
/// <summary>
/// 0不可交易1可交易
/// </summary>
public System.Int32 isGive
{ get { return this._isGive; } set { this._isGive = value; } }
private List<TowerNeeds> _Needs;
public List<TowerNeeds> Needs
{ get { return this._Needs; } set { this._Needs = value; } }
}

View File

@@ -31,7 +31,6 @@ public class EquAwaken
/// <summary>
///
/// </summary>
[SqlSugar.SugarColumn(ColumnDataType = "varchar(max)", IsJson = true)]
public List<AttrItem> awaken
{ get { return this._awaken; } set { this._awaken = value; } }
}

View File

@@ -0,0 +1,36 @@
namespace Application.Domain.Entity;
public class EquAwakenData
{
private System.Int32 _lev;
/// <summary>
///
/// </summary>
public System.Int32 lev
{ get { return this._lev; } set { this._lev = value; } }
private System.Int32 _success;
/// <summary>
///
/// </summary>
public System.Int32 success
{ get { return this._success; } set { this._success = value; } }
private List<TowerNeed> _need;
/// <summary>
///
/// </summary>
public List<TowerNeed> need
{ get { return this._need; } set { this._need = value; } }
private List<AttrItem> _attr;
/// <summary>
///
/// </summary>
public List<AttrItem> attr
{ get { return this._attr; } set { this._attr = value; } }
}

View File

@@ -26,20 +26,20 @@ public class TowerNeed
public System.String parameter
{ get { return this._parameter; } set { this._parameter = value; } }
private System.Int32 _count;
private long _count;
/// <summary>
///
/// </summary>
public System.Int32 count
public long count
{ get { return this._count; } set { this._count = value; } }
private System.Int32 _retCount;
private long _retCount;
/// <summary>
///
/// </summary>
public System.Int32 retCount
public long retCount
{ get { return this._retCount; } set { this._retCount = value; } }
private System.Int32 _isOp;
@@ -57,4 +57,12 @@ public class TowerNeed
/// </summary>
public System.Int32 isAsk
{ get { return this._isAsk; } set { this._isAsk = value; } }
private long _onCount;
/// <summary>
///
/// </summary>
public long onCount
{ get { return this._onCount; } set { this._onCount = value; } }
}

View File

@@ -0,0 +1,111 @@
namespace Application.Domain.Entity;
public class TowerNeeds
{
private System.Int32 _Id;
/// <summary>
///
/// </summary>
public System.Int32 Id
{
get { return this._Id; }
set { this._Id = value; }
}
private System.String _code;
/// <summary>
///
/// </summary>
public System.String code
{
get { return this._code; }
set { this._code = value; }
}
private System.String _name;
/// <summary>
///
/// </summary>
public System.String name
{
get { return this._name; }
set { this._name = value; }
}
private System.String _parameter;
/// <summary>
///
/// </summary>
public System.String parameter
{
get { return this._parameter; }
set { this._parameter = value; }
}
private long _count;
/// <summary>
///
/// </summary>
public long count
{
get { return this._count; }
set { this._count = value; }
}
private long _retCount;
/// <summary>
///
/// </summary>
public long retCount
{
get { return this._retCount; }
set { this._retCount = value; }
}
private System.Int32 _isOp;
/// <summary>
///
/// </summary>
public System.Int32 isOp
{
get { return this._isOp; }
set { this._isOp = value; }
}
private System.Int32 _isAsk;
/// <summary>
///
/// </summary>
public System.Int32 isAsk
{
get { return this._isAsk; }
set { this._isAsk = value; }
}
private long _onCount;
/// <summary>
///
/// </summary>
public long onCount
{
get { return this._onCount; }
set { this._onCount = value; }
}
private List<TowerNeed> _NeedItem;
public List<TowerNeed> NeedItem
{
get { return this._NeedItem; }
set { this._NeedItem = value; }
}
}

View File

@@ -0,0 +1,27 @@
using SqlSugar;
using System;
namespace Application.Domain.Entity
{
[Tenant("Kg.SeaTime.Resource")]
public class game_dic
{
/// <summary>
/// code
/// </summary>
[SugarColumn(Length = 50, IsNullable = true)]
public string? code { get; set; }
/// <summary>
/// sign
/// </summary>
[SugarColumn(IsNullable = true)]
public string? sign { get; set; }
/// <summary>
/// remark
/// </summary>
[SugarColumn(Length = 255, IsNullable = true)]
public string? remark { get; set; }
}
}

View File

@@ -0,0 +1,39 @@
using SqlSugar;
using System;
namespace Application.Domain.Entity
{
[Tenant("Kg.SeaTime.Resource")]
public class game_equ_awaken
{
/// <summary>
/// 特性表
/// </summary>
[SugarColumn(IsPrimaryKey = true, Length = 50)]
public string atId { get; set; }
/// <summary>
/// 特性名称
/// </summary>
[SugarColumn(Length = 50, IsNullable = true)]
public string? name { get; set; }
/// <summary>
/// levAttr
/// </summary>
[SugarColumn(IsNullable = true,IsJson = true)]
public List<EquAwakenData> levAttr { get; set; }
/// <summary>
/// 权重
/// </summary>
[SugarColumn(IsNullable = true)]
public int? random { get; set; }
/// <summary>
/// 可觉醒装备
/// </summary>
[SugarColumn(IsNullable = true)]
public string? position { get; set; }
}
}

View File

@@ -0,0 +1,39 @@
using SqlSugar;
using System;
namespace Application.Domain.Entity
{
[Tenant("Kg.SeaTime.Resource")]
public class game_equ_up
{
/// <summary>
/// euId
/// </summary>
[SugarColumn(IsPrimaryKey = true)]
public int euId { get; set; }
/// <summary>
/// onLev
/// </summary>
[SugarColumn(IsNullable = true)]
public int? onLev { get; set; }
/// <summary>
/// maxLev
/// </summary>
[SugarColumn(IsNullable = true)]
public int? maxLev { get; set; }
/// <summary>
/// okChance
/// </summary>
[SugarColumn(IsNullable = true)]
public int? okChance { get; set; }
/// <summary>
/// needData
/// </summary>
[SugarColumn(IsNullable = true,IsJson = true)]
public List<TowerNeeds> needData { get; set; }
}
}

View File

@@ -57,4 +57,9 @@ public static class GameEnum
RetVigour,
MapTo,
}
public enum DicCode
{
Awaken,//觉醒配置
}
}

View File

@@ -8,4 +8,12 @@ public static class MessageEnum
Marry,//婚姻消息
Trade,//交易通知
}
public enum BroadcastCode
{
Gift,
System,
Award,
Remind,
Promote
}
}

View File

@@ -6,7 +6,9 @@ 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,
@@ -21,6 +23,7 @@ public interface IGameEquService
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);
@@ -30,12 +33,25 @@ public interface IGameEquService
Task<List<unit_user_equ>> GetUserOnEqu(string userId);
Task<bool> EquOnOrDown(unit_user_equ data, int state);
Task<List<UserEquSuit>> GetUserEquSuit(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<game_equ_up> GetUserEquUpData(int lev);
#endregion
#region
Task<int> GetUserEquWeightSum(string userId);
#endregion
}

View File

@@ -0,0 +1,6 @@
namespace Application.Domain;
public interface IGameDicService
{
Task<game_dic> GetDicInfo(string code);
}

View File

@@ -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
}

View File

@@ -191,6 +191,11 @@ public class GameEquService(ISqlSugarClient DbClient, IRedisCache redis) : IGame
{
await AddEquLog(equData, code, remark);
}
if (equData.isOn == 1)
{
await ClearUserOnEqu(equData.userId);
}
}
return result;
@@ -429,6 +434,98 @@ public class GameEquService(ISqlSugarClient DbClient, IRedisCache redis) : IGame
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
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
#region

View File

@@ -832,7 +832,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 +858,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 +877,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 +925,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 +939,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");

View File

@@ -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;
}
}

View File

@@ -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
}

View File

@@ -1,6 +1,6 @@
namespace Application.Domain;
public class GameBus
public static class GameBus
{
#region
@@ -96,20 +96,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 +136,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 +175,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 +188,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 +199,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 +228,116 @@ 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);
}
@@ -240,7 +369,7 @@ 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;
}
@@ -256,7 +385,6 @@ public class GameBus
result.Add(add);
}
}
}
return result;
@@ -271,10 +399,12 @@ public class GameBus
{
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,6 +420,7 @@ public class GameBus
return result;
}
private static List<RandomData> RandomHandleByChance(RandomModel random, int luck = 0)
{
var _randomInstance = new Random();
@@ -299,11 +430,12 @@ public class GameBus
{
return result;
}
if (random.data.Count == 0)
{
return result;
}
foreach (var item in random.data)
{
double rnd = _randomInstance.NextDouble();
@@ -313,6 +445,7 @@ public class GameBus
result.Add(item);
}
}
return result;
}

View File

@@ -132,6 +132,7 @@ public class MapController : ControllerBase
#endregion
var broadcast = await _messageService.GetBroadcastData(area);
object ret = new
{
@@ -143,7 +144,8 @@ public class MapController : ControllerBase
nearUser,
noReadMsg = noReadMsg[3],
business,
mapRes
mapRes,
broadcast
};
return PoAction.Ok(ret);

View File

@@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
namespace Application.Web.Controllers.Pub;
@@ -13,12 +14,17 @@ public class EquController : ControllerBase
private readonly IGameEquService _equService;
private readonly IUnitUserAttrService _attrService;
private readonly IUnitUserService _userService;
private readonly IGameDicService _dicService;
private readonly IMessageService _messageService;
public EquController(IGameEquService equService, IUnitUserAttrService attrService, IUnitUserService userService)
public EquController(IGameEquService equService, IUnitUserAttrService attrService, IUnitUserService userService,
IGameDicService dicService, IMessageService messageService)
{
_equService = equService;
_attrService = attrService;
_userService = userService;
_dicService = dicService;
_messageService = messageService;
}
/// <summary>
@@ -109,12 +115,6 @@ public class EquController : ControllerBase
return PoAction.Message("装备不存在!");
}
if (equInfo.isAppr == 0)
{
return PoAction.Message("装备未鉴定!");
}
equInfo.isLock = equInfo.isLock == 0 ? 1 : 0;
bool result = await _equService.UpdateUserEquInfo(equInfo);
@@ -341,4 +341,393 @@ public class EquController : ControllerBase
return PoAction.Ok(new { data, suit });
}
/// <summary>
/// 获取装备觉醒所需
/// </summary>
/// <param name="ue"></param>
/// <returns></returns>
[HttpGet]
public async Task<IPoAction> GetEquAwakenInfo(string ue)
{
string userId = StateHelper.userId;
var equData = await _equService.GetUserEquInfo(ue);
if (equData == null)
{
return PoAction.Message("装备不存在!");
}
if (equData.userId != userId)
{
return PoAction.Message("装备不存在!");
}
if (equData.isAppr == 0)
{
return PoAction.Message("装备未鉴定!");
}
if (equData.useEndTime < TimeExtend.GetTimeStampSeconds)
{
return PoAction.Message("装备已过期!");
}
CheckTowerNeed result = new CheckTowerNeed();
if (equData.EquAwaken.Count == 0)
{
var dicConfig = await _dicService.GetDicInfo(nameof(GameEnum.DicCode.Awaken));
List<TowerNeed> need = JsonConvert.DeserializeObject<List<TowerNeed>>(dicConfig.sign);
result = await GameBus.CheckNeed(userId, need);
}
else
{
var upAwaken =
await _equService.GetEquAwakenInfoByLev(equData.EquAwaken[0].atId, equData.EquAwaken[0].lev + 1);
if (upAwaken == null)
{
return PoAction.Message("觉醒已达到上限!");
}
result = await GameBus.CheckNeed(userId, upAwaken.need);
}
return PoAction.Ok(result);
}
/// <summary>
/// 觉醒装备
/// </summary>
/// <param name="ue"></param>
/// <param name="type">0重置1正常觉醒</param>
/// <returns></returns>
[HttpGet]
public async Task<IPoAction> HandleEquAwaken(string ue, int type)
{
string userId = StateHelper.userId;
var equData = await _equService.GetUserEquInfo(ue);
if (equData == null)
{
return PoAction.Message("装备不存在!");
}
if (equData.userId != userId)
{
return PoAction.Message("装备不存在!");
}
if (equData.isAppr == 0)
{
return PoAction.Message("装备未鉴定!");
}
if (equData.useEndTime < TimeExtend.GetTimeStampSeconds)
{
return PoAction.Message("装备已过期!");
}
EquAwakenData onAwaken = new EquAwakenData();
game_equ_awaken newAwaken = new game_equ_awaken();
CheckTowerNeed result = new CheckTowerNeed();
if (type == 0) //重置
{
newAwaken = await _equService.GetRandomOneAwakenByCode(equData.code);
if (newAwaken == null)
{
return PoAction.Message("该部件装备不可觉醒!");
}
onAwaken = newAwaken.levAttr.Find(it => it.lev == 1);
var dicConfig = await _dicService.GetDicInfo(nameof(GameEnum.DicCode.Awaken));
List<TowerNeed> need = JsonConvert.DeserializeObject<List<TowerNeed>>(dicConfig.sign);
result = await GameBus.CheckNeed(userId, need);
}
else
{
if (equData.EquAwaken.Count == 0)
{
newAwaken = await _equService.GetRandomOneAwakenByCode(equData.code);
if (newAwaken == null)
{
return PoAction.Message("该部件装备不可觉醒!");
}
onAwaken = newAwaken.levAttr.Find(it => it.lev == 1);
var dicConfig = await _dicService.GetDicInfo(nameof(GameEnum.DicCode.Awaken));
List<TowerNeed> need = JsonConvert.DeserializeObject<List<TowerNeed>>(dicConfig.sign);
result = await GameBus.CheckNeed(userId, need);
}
else
{
var upAwaken =
await _equService.GetEquAwakenInfoByLev(equData.EquAwaken[0].atId, equData.EquAwaken[0].lev + 1);
if (upAwaken == null)
{
return PoAction.Message("觉醒已达到上限!");
}
newAwaken = await _equService.GetEquAwakenInfo(equData.EquAwaken[0].atId);
onAwaken = upAwaken;
result = await GameBus.CheckNeed(userId, upAwaken.need);
}
}
if (result.result == false)
{
return PoAction.Message("不满足觉醒条件!");
}
if (await GameBus.UpdateBag(userId, 0, result.Needs, "觉醒装备"))
{
if (RandomAssist.CheakRandom(onAwaken.success))
{
EquAwaken awaken = new EquAwaken();
awaken.atId = newAwaken.atId;
awaken.name = newAwaken.name;
awaken.lev = onAwaken.lev;
awaken.awaken = onAwaken.attr;
equData.EquAwaken = [awaken];
if (await _equService.UpdateUserEquInfo(equData, true, "觉醒", "装备觉醒"))
{
string msg = $"[{equData.equName}]装备的特性【{awaken.name}】升至{awaken.lev}级!";
await _messageService.SendBroadcast(userId, nameof(MessageEnum.BroadcastCode.Promote), msg);
//此处为觉醒成功,返回相关数据
var nextAwaken =
await _equService.GetEquAwakenInfoByLev(equData.EquAwaken[0].atId,
equData.EquAwaken[0].lev + 1);
var nextResult = new CheckTowerNeed()
{
result = false,
Needs = new List<TowerNeed>()
};
if (nextAwaken != null)
{
nextResult = await GameBus.CheckNeed(userId, nextAwaken.need);
}
return PoAction.Ok(new { state = 1, awaken = equData.EquAwaken, result = nextResult }, "觉醒成功!");
}
else
{
return PoAction.Message("觉醒异常,请稍后尝试!");
}
}
else
{
//此处为觉醒成功,返回相关数据
var nextAwaken =
await _equService.GetEquAwakenInfoByLev(equData.EquAwaken[0].atId,
equData.EquAwaken[0].lev + 1);
var nextResult = new CheckTowerNeed()
{
result = false,
Needs = new List<TowerNeed>()
};
if (nextAwaken != null)
{
nextResult = await GameBus.CheckNeed(userId, nextAwaken.need);
}
return PoAction.Ok(new { state = 0, awaken = equData.EquAwaken, result = nextResult }, "觉醒失败!");
}
}
else
{
return PoAction.Message("觉醒异常,请稍后尝试!");
}
return PoAction.Ok(result);
}
/// <summary>
/// 获取强化信息
/// </summary>
/// <param name="ueId"></param>
/// <returns></returns>
[HttpGet]
public async Task<IPoAction> GetEquUpInfo(string ueId)
{
string userId = StateHelper.userId;
var equInfo = await _equService.GetUserEquInfo(ueId);
if (equInfo == null)
{
return PoAction.Message("装备不存在!");
}
if (equInfo.userId != userId)
{
return PoAction.Message("装备不存在!");
}
if (equInfo.isAppr == 0)
{
return PoAction.Message("装备未鉴定!");
}
long time = TimeExtend.GetTimeStampSeconds;
if (equInfo.useEndTime < time)
{
return PoAction.Message("装备已过期!");
}
if (equInfo.isIntensify == 0)
{
return PoAction.Message("装备不可强化!");
}
bool isMax = false;
int upLev = (int)equInfo.intensifyLev + 1;
var needs = await _equService.GetUserEquUpData(upLev);
if (needs == null)
{
isMax = true;
}
CheckTowerNeeds result = new CheckTowerNeeds();
result.result = false;
result.Needs = new List<TowerNeeds>();
if (!isMax)
{
result = await GameBus.CheckNeeds(userId, needs.needData);
}
return PoAction.Ok(new
{
equData = equInfo,
isMax,
result
});
}
/// <summary>
/// 强化装备
/// </summary>
/// <param name="parms"></param>
/// <returns></returns>
[HttpPost]
public async Task<IPoAction> HandleEquUp([FromBody] EquUpParms parms)
{
string ueId = parms.ueId;
string userId = StateHelper.userId;
var equInfo = await _equService.GetUserEquInfo(ueId);
if (equInfo == null)
{
return PoAction.Message("装备不存在!");
}
if (equInfo.userId != userId)
{
return PoAction.Message("装备不存在!");
}
if (equInfo.isAppr == 0)
{
return PoAction.Message("装备未鉴定!");
}
long time = TimeExtend.GetTimeStampSeconds;
if (equInfo.useEndTime < time)
{
return PoAction.Message("装备已过期!");
}
if (equInfo.isIntensify == 0)
{
return PoAction.Message("装备不可强化!");
}
int upLev = (int)equInfo.intensifyLev + 1;
var needs = await _equService.GetUserEquUpData(upLev);
if (needs == null)
{
return PoAction.Message("已达到最大强化等级!");
}
List<TowerNeeds> reqNeeds = JsonConvert.DeserializeObject<List<TowerNeeds>>(parms.needs);
//验证材料
foreach (var item in needs.needData)
{
var onNeed = reqNeeds.Find(it => it.Id == item.Id);
if (item.NeedItem.Any(it => it.code == onNeed.code && it.parameter == onNeed.parameter) == false &&
item.code != onNeed.code && item.parameter != onNeed.parameter)
{
return PoAction.Message("材料错误!");
}
}
var result = await GameBus.CheckNeeds(userId, reqNeeds);
if (result.result == false)
{
return PoAction.Message("材料不足!");
}
if (await GameBus.UpdateBag(userId, 0, reqNeeds, $"强化装备:{ueId}"))
{
CheckTowerNeeds nexResult = new CheckTowerNeeds();
nexResult.result = false;
nexResult.Needs = new List<TowerNeeds>();
bool isMax = false;
int state = 0;
int okNum = (int)needs.okChance;
if (RandomAssist.CheakRandom(okNum))
{
state = 1;
equInfo.intensifyLev = upLev;
equInfo.isDeal = result.isDeal;
equInfo.isGive = result.isGive;
if (await _equService.UpdateUserEquInfo(equInfo, true, "强化", "强化装备") == false)
{
return PoAction.Message("强化异常,请联系客服!");
}
var nextNeeds = await _equService.GetUserEquUpData((int)equInfo.intensifyLev + 1);
if (needs == null)
{
isMax = true;
}
else
{
var nexts = nextNeeds.euId == needs.euId ? reqNeeds : nextNeeds.needData;
nexResult = await GameBus.CheckNeeds(userId, nexts);
}
}
else //执行材料返还
{
List<TowerGet> retProp = new List<TowerGet>();
foreach (var item in reqNeeds)
{
if (item.retCount > 0 && item.isOp == 1)
{
TowerGet temp = new TowerGet()
{
code = item.code,
name = item.name,
parameter = item.parameter,
count = item.count
};
retProp.Add(temp);
}
}
if (retProp.Count > 0)
{
await GameBus.UpdateBag(userId, 1, retProp, "强化失败,返还");
}
nexResult = await GameBus.CheckNeeds(userId, reqNeeds);
}
return PoAction.Ok(new
{
state,
equData = equInfo,
isMax,
result = nexResult
});
}
else
{
return PoAction.Message("强化错误,请稍后尝试!");
}
}
}

View File

@@ -126,4 +126,18 @@ public class BagController : ControllerBase
return PoAction.Ok(new { data = new List<string>(), total = total.Value });
}
}
/// <summary>
/// 验证用户道具
/// </summary>
/// <param name="parms"></param>
/// <returns></returns>
[HttpPost]
public async Task<IPoAction> CheckUserProp([FromBody] CheckUserPropParms parms)
{
string userId = StateHelper.userId;
List<TowerNeeds> needs = JsonConvert.DeserializeObject<List<TowerNeeds>>(parms.needs);
var result = await GameBus.CheckNeeds(userId, needs, 1);
return PoAction.Ok(result);
}
}

View File

@@ -0,0 +1,7 @@
namespace Application.Web;
public class EquUpParms
{
public string ueId { get; set; }
public string needs { get; set; }
}

View File

@@ -0,0 +1,6 @@
namespace Application.Web;
public class CheckUserPropParms
{
public string needs { get; set; }
}