115 lines
4.2 KiB
C#
115 lines
4.2 KiB
C#
|
using Cal.DataTable;
|
|||
|
using System;
|
|||
|
using System.Text;
|
|||
|
|
|||
|
namespace ET
|
|||
|
{
|
|||
|
[ActorMessageHandler]
|
|||
|
public class C2M_StartFamilyBossFightHandler : AMActorLocationRpcHandler<Unit, C2M_StartFamilyBossFight, M2C_StartFamilyBossFight>
|
|||
|
{
|
|||
|
|
|||
|
protected override async ETTask Run(Unit unit, C2M_StartFamilyBossFight request, M2C_StartFamilyBossFight response, Action reply)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
if (request.BossId == 0)
|
|||
|
return;
|
|||
|
if (!unit.IsTeamLeader)
|
|||
|
{
|
|||
|
response.Message = "您不是队长";
|
|||
|
reply();
|
|||
|
return;
|
|||
|
}
|
|||
|
var time = DateTime.UtcNow.Hour;
|
|||
|
if (time > 13 || time < 1)
|
|||
|
{
|
|||
|
response.Message = "Boss暂未开启,请在9:00 ~ 21:00攻打";
|
|||
|
reply();
|
|||
|
return;
|
|||
|
}
|
|||
|
Team team = TeamComponent.Instance.Get(unit.TeamLeaderId);
|
|||
|
if (team.TeamState == TeamState.Fight)
|
|||
|
{
|
|||
|
Log.Error($"*【{ UserComponent.Instance.Get(unit.Id)?.NickName} ({ unit.Id})】多次进行家族Boss战斗");
|
|||
|
response.Message = "多次进行战斗";
|
|||
|
reply();
|
|||
|
return;
|
|||
|
}
|
|||
|
var teamList = team.GetUnits();
|
|||
|
foreach (var u in teamList)
|
|||
|
{
|
|||
|
var data = u.GetComponent<PlayerData>();
|
|||
|
if (data == null)
|
|||
|
{
|
|||
|
Log.Error($"data == null where id = {u?.Id}");
|
|||
|
continue;
|
|||
|
}
|
|||
|
if (data.familyBossKeys <= 0)
|
|||
|
{
|
|||
|
response.Message = "您的或者队友的钥匙不够";
|
|||
|
reply();
|
|||
|
return;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
var user = await UserComponent.Instance.Query(unit.Id);
|
|||
|
if (string.IsNullOrEmpty(user.Family))
|
|||
|
{
|
|||
|
response.Message = "您没有家族!";
|
|||
|
reply();
|
|||
|
return;
|
|||
|
}
|
|||
|
foreach (var u in teamList)
|
|||
|
{
|
|||
|
var _user = await UserComponent.Instance.Query(unit.Id);
|
|||
|
if (!_user.Family.Equals(user.Family))
|
|||
|
{
|
|||
|
response.Message = "同一个家族才可组队战斗!";
|
|||
|
reply();
|
|||
|
return;
|
|||
|
}
|
|||
|
}
|
|||
|
var battle = BattleMgrCompnent.Instance.CreateBattle<FamilyBossBattle>(team);
|
|||
|
var familyBoss = await FamilyBossComponent.instance.Query(user.Family);
|
|||
|
if (familyBoss == null)
|
|||
|
{
|
|||
|
Log.Error($"familyBoss = null where name = {user.Family}");
|
|||
|
response.Message = "系统错误";
|
|||
|
reply();
|
|||
|
return;
|
|||
|
}
|
|||
|
if (request.BossId > familyBoss.lockedMaxId)
|
|||
|
{
|
|||
|
response.Message = "此Boss未解锁,请先击杀前一阶boss";
|
|||
|
reply();
|
|||
|
return;
|
|||
|
}
|
|||
|
if (familyBoss.GetBossHp(request.BossId) <= 0)
|
|||
|
{
|
|||
|
response.Message = "此Boss已被击杀";
|
|||
|
reply();
|
|||
|
return;
|
|||
|
}
|
|||
|
foreach (var u in teamList)
|
|||
|
{
|
|||
|
var data = u.GetComponent<PlayerData>();
|
|||
|
if (data == null)
|
|||
|
{
|
|||
|
Log.Error($"data == null where id = {u?.Id}");
|
|||
|
continue;
|
|||
|
}
|
|||
|
data.familyBossKeys--;
|
|||
|
UnitHelper.SaveComponenet(data).Coroutine();
|
|||
|
}
|
|||
|
battle.Init(request.BossId, familyBoss);
|
|||
|
|
|||
|
reply();
|
|||
|
await ETTask.CompletedTask;
|
|||
|
}
|
|||
|
catch (Exception e)
|
|||
|
{
|
|||
|
Log.Error(e);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|