116 lines
3.8 KiB
C#
Executable File
116 lines
3.8 KiB
C#
Executable File
using Cal.DataTable;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
|
|
namespace ET
|
|
{
|
|
[ActorMessageHandler]
|
|
public class C2M_StartMainStoryAIHandler: AMActorLocationRpcHandler<Unit, C2M_StartMainStoryAI, M2C_StartMainStoryAI>
|
|
{
|
|
|
|
protected override async ETTask Run(Unit unit, C2M_StartMainStoryAI request, M2C_StartMainStoryAI response, Action reply)
|
|
{
|
|
try
|
|
{
|
|
if (!unit.IsTeamLeader)
|
|
{
|
|
response.Message = "您不是队长";
|
|
reply();
|
|
return;
|
|
}
|
|
|
|
if (unit.teamState != TeamState.None)
|
|
{
|
|
response.Message = "空闲状态才可以开始";
|
|
reply();
|
|
return;
|
|
}
|
|
AutoBattleAIType type = (AutoBattleAIType) request.Index;
|
|
string ret;
|
|
switch (type)
|
|
{
|
|
case AutoBattleAIType.MainStory:
|
|
ret = StartMainStory(unit);
|
|
break;
|
|
case AutoBattleAIType.StarSoul:
|
|
ret = StartStarSoul(unit);
|
|
break;
|
|
default:
|
|
throw new ArgumentOutOfRangeException();
|
|
}
|
|
|
|
if (ret != null)
|
|
{
|
|
response.Message = ret;
|
|
reply();
|
|
return;
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Log.Error(e);
|
|
}
|
|
|
|
reply();
|
|
await ETTask.CompletedTask;
|
|
}
|
|
|
|
private string StartStarSoul(Unit unit)
|
|
{
|
|
UnitScene unitScene = unit.GetComponent<UnitScene>();
|
|
var sceneType = MapHelper.GetMapType(unitScene.sceneId);
|
|
if (sceneType != UnitSceneType.StarSoulCopy)
|
|
{
|
|
return "地图错误";
|
|
}
|
|
|
|
int targetSceneId = unitScene.sceneId;
|
|
Team team = TeamComponent.Instance.Get(unit.TeamLeaderId);
|
|
|
|
var oldAI = MainStoryAIComponent.instance.GetAI(unit);
|
|
if (oldAI)
|
|
{
|
|
MainStoryAIComponent.instance.DestoryAI(oldAI);
|
|
}
|
|
|
|
MainStoryAI ai = MainStoryAIComponent.instance.CreateAI(team, unitScene.MapId,AutoBattleAIType.StarSoul);
|
|
return null;
|
|
}
|
|
|
|
private string StartMainStory(Unit unit)
|
|
{
|
|
UnitScene unitScene = unit.GetComponent<UnitScene>();
|
|
var sceneType = MapHelper.GetMapType(unitScene.sceneId);
|
|
if (sceneType != UnitSceneType.MainStory)
|
|
{
|
|
return "地图错误";
|
|
}
|
|
|
|
if (MainStoryMap.Instance.GetMainStoryData(unitScene.MapId) == null)
|
|
{
|
|
Log.Error($"{unit.Id.GetPlayerFormatName()} 开始挂机 地图错误:{unitScene.MapId}");
|
|
return "系统错误!";
|
|
}
|
|
|
|
int targetSceneId = unitScene.sceneId;
|
|
Team team = TeamComponent.Instance.Get(unit.TeamLeaderId);
|
|
LinkedList<Unit> teamList = team.GetUnits();
|
|
foreach (Unit u in teamList)
|
|
{
|
|
if (!u.GetComponent<PlayerData>().CanEnterMianStory(targetSceneId - 1))
|
|
{
|
|
return "队伍中至少有一人没通过这一章节!";
|
|
}
|
|
}
|
|
|
|
var oldAI = MainStoryAIComponent.instance.GetAI(unit);
|
|
if (oldAI)
|
|
{
|
|
MainStoryAIComponent.instance.DestoryAI(oldAI);
|
|
}
|
|
|
|
MainStoryAI ai = MainStoryAIComponent.instance.CreateAI(team, unitScene.MapId,AutoBattleAIType.MainStory);
|
|
return null;
|
|
}
|
|
}
|
|
} |