84 lines
3.7 KiB
C#
84 lines
3.7 KiB
C#
using System;
|
|||
|
|
using System.Collections.Generic;
|
||
|
|
using System.Linq;
|
||
|
|
using CommonDomain;
|
||
|
|
using CommonDomain.BaseModel;
|
||
|
|
using CommonDomain.Enum;
|
||
|
|
using UserDomain.Entity;
|
||
|
|
|
||
|
|
namespace RedisService.Param
|
||
|
|
{
|
||
|
|
public static class RoomBotFactory
|
||
|
|
{
|
||
|
|
public static readonly int[] FixedBotSeats = Array.Empty<int>();
|
||
|
|
|
||
|
|
public static bool FixedBotSeatsEnabled => FixedBotSeats.Length > 0;
|
||
|
|
|
||
|
|
public static RedisGamePlayer CreateBot(int position, RoomConfig roomConfig, GameConfig gameConfig, IReadOnlyList<BotProfileEntity> botProfiles)
|
||
|
|
{
|
||
|
|
if (roomConfig?.CannonMultipleList == null || roomConfig.CannonMultipleList.Count == 0
|
||
|
|
|| botProfiles == null || botProfiles.Count == 0)
|
||
|
|
return null;
|
||
|
|
|
||
|
|
var profile = botProfiles[System.Random.Shared.Next(botProfiles.Count)];
|
||
|
|
var maxMultiple = roomConfig.CannonMultipleList.Max();
|
||
|
|
var gold = maxMultiple * System.Random.Shared.Next(100, 501);
|
||
|
|
var props = gameConfig?.PropConfig ?? new List<PropInfConfig>();
|
||
|
|
var cannons = props.Where(p => p.Type == ProductTypeEnum.炮台 && p.IsEnable && !p.Number.StartsWith("401")).ToList();
|
||
|
|
var wings = props.Where(p => p.Type == ProductTypeEnum.翅膀 && p.IsEnable && p.IsSale).ToList();
|
||
|
|
var warGods = props.Where(p => p.Type == ProductTypeEnum.战神 && p.IsEnable && p.IsSale).ToList();
|
||
|
|
|
||
|
|
var botId = Guid.NewGuid().ToString("N");
|
||
|
|
var botNumber = Common.Utils.RandomHelper.RandomNumbers(8);
|
||
|
|
return new RedisGamePlayer
|
||
|
|
{
|
||
|
|
UserId = botId,
|
||
|
|
UserNumber = botNumber,
|
||
|
|
UserName = profile.Name,
|
||
|
|
Avatar = profile.Avatar,
|
||
|
|
Level = System.Random.Shared.Next(1, 101),
|
||
|
|
IsBot = true,
|
||
|
|
Gold = gold,
|
||
|
|
Diamond = System.Random.Shared.Next(100, 5001),
|
||
|
|
Position = position,
|
||
|
|
CannonId = cannons.Count > 0 ? cannons[System.Random.Shared.Next(cannons.Count)].Number : string.Empty,
|
||
|
|
WingsId = wings.Count > 0 ? wings[System.Random.Shared.Next(wings.Count)].Number : string.Empty,
|
||
|
|
WarGodId = warGods.Count > 0 && System.Random.Shared.Next(5) == 0
|
||
|
|
? warGods[System.Random.Shared.Next(warGods.Count)].Number
|
||
|
|
: string.Empty,
|
||
|
|
CannonMultiple = roomConfig.CannonMultipleList[System.Random.Shared.Next(roomConfig.CannonMultipleList.Count)],
|
||
|
|
BeginCoin = gold,
|
||
|
|
BeginTime = new DateTimeOffset(DateTime.Now).ToUnixTimeSeconds(),
|
||
|
|
CId = string.Empty,
|
||
|
|
State = 0,
|
||
|
|
PlayerFactor = new PlayerFactor()
|
||
|
|
};
|
||
|
|
}
|
||
|
|
|
||
|
|
public static List<RedisGamePlayer> CreateFixedSeatBots(RedisGameRoom room, RoomConfig roomConfig, GameConfig gameConfig, IReadOnlyList<BotProfileEntity> botProfiles, IReadOnlyList<int> fixedSeats = null)
|
||
|
|
{
|
||
|
|
var result = new List<RedisGamePlayer>();
|
||
|
|
if (room == null)
|
||
|
|
return result;
|
||
|
|
|
||
|
|
fixedSeats ??= FixedBotSeats;
|
||
|
|
if (fixedSeats.Count == 0)
|
||
|
|
return result;
|
||
|
|
|
||
|
|
room.Players ??= new List<RedisGamePlayer>();
|
||
|
|
foreach (var seat in fixedSeats.Distinct())
|
||
|
|
{
|
||
|
|
if (seat < 0 || seat >= room.MaxPlayerCount)
|
||
|
|
continue;
|
||
|
|
if (room.Players.Any(p => p.Position == seat))
|
||
|
|
continue;
|
||
|
|
|
||
|
|
var bot = CreateBot(seat, roomConfig, gameConfig, botProfiles);
|
||
|
|
if (bot != null)
|
||
|
|
result.Add(bot);
|
||
|
|
}
|
||
|
|
return result;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|