181 lines
7.3 KiB
C#
Executable File
181 lines
7.3 KiB
C#
Executable File
using System;
|
|
using System.Collections.Generic;
|
|
using Cal.DataTable;
|
|
using ET.EventType;
|
|
using UnityEngine;
|
|
|
|
namespace ET
|
|
{
|
|
public class AfterEnterGameEvent:AEvent<AfterEnterGame>
|
|
{
|
|
public override async ETTask Run(AfterEnterGame args)
|
|
{
|
|
var unit = args.unit;
|
|
await ETTask.CompletedTask;
|
|
//同步玩家的信息
|
|
UnitCharacter unitCharacter =await CharacterHelper.GetUnitCharacter(unit);
|
|
MessageHelper.SendActor(unit, new M2C_SendUnitInfo { UnitCharacter = unitCharacter });
|
|
|
|
|
|
Team team = TeamComponent.Instance.Get(unit.TeamLeaderId);
|
|
PlayerData data = unit.GetComponent<PlayerData>();
|
|
|
|
if (unit.isAgainOnLine)
|
|
{
|
|
UnitScene unitScene = unit.GetComponent<UnitScene>();
|
|
if (team == null)
|
|
{
|
|
Log.Error($"team==null where {unit}");
|
|
}
|
|
else
|
|
if (team.TeamState == TeamState.Fight)
|
|
{
|
|
//!地图切换
|
|
await ChangeMap(unit, unitScene, false);
|
|
await TimerComponent.Instance.WaitAsync(1000);
|
|
TeamHelper.SendTeamMember(team);
|
|
//!战斗状态
|
|
CopyBattle battleBase = BattleMgrCompnent.Instance.GetBattle(unit);
|
|
battleBase.ReSendMonsterInfo(unit);
|
|
}
|
|
else
|
|
{
|
|
data.IsBattleIdle = false;
|
|
//!地图切换
|
|
await ChangeMap(unit, unitScene, true);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
MapScene map = unit.GetMapByUnitScene();
|
|
await map.Enter(unit);
|
|
|
|
if (team == null)
|
|
{
|
|
team = TeamComponent.Instance.CreateTeam(unit.Id);
|
|
}
|
|
team.ChangeState(TeamState.None);
|
|
await TimerComponent.Instance.WaitAsync(1000);
|
|
TeamHelper.SendTeamMember(team);
|
|
}
|
|
|
|
await TimerComponent.Instance.WaitAsync(1000);
|
|
|
|
CharacterHelper.SyncAttribute(unit);
|
|
|
|
|
|
//宠物
|
|
var pet = unit.GetComponent<Pet>();
|
|
Game.EventSystem.Change(pet);
|
|
|
|
//任务
|
|
UnitTask unitTask = unit.GetComponent<UnitTask>();
|
|
if (unitTask!=null &&
|
|
unitTask.RunningTaskList.Count==0 &&
|
|
unitTask.CompleteTaskIdList.Count==0&&
|
|
unitTask.FinishTaskIdList.Count==0
|
|
)
|
|
{
|
|
//!发送新任务
|
|
M2C_OpenTaskUI ret = new M2C_OpenTaskUI();
|
|
ret.TaskList.Add(new NPCTask() { Id = (int)TaskComponent.Instance.TaskBaseNpcIdDic[0][0].Id, TaskState = TaskState.TaskWaiting });
|
|
MessageHelper.SendActor(unit, ret);
|
|
}
|
|
|
|
//签到
|
|
bool isGetSininReward = ActiveComponent.instance.QuerySigninReward(unit, out var config);
|
|
int currConfigId = (int) config.Id;
|
|
var activeMessage = new M2C_SendActiveInfo() { isGetSininReward = isGetSininReward, signinCurrId = currConfigId,signinInMonthCount = data.signInCountInMonth};
|
|
activeMessage.gotSignInMonthList.AddRange(data.signInGetRewardCountInMonthList);
|
|
MessageHelper.SendActor(unit,activeMessage);
|
|
|
|
//boss
|
|
SendBossInfo(unit);
|
|
}
|
|
private void SendBossInfo(Unit unit)
|
|
{
|
|
Log.Debug($"【{ UserComponent.Instance.Get(unit.Id)?.NickName} ({ unit.Id})】发送Boss消息");
|
|
BossComponent boss = BossComponent.Instance;
|
|
using ListComponent<string> listComponent = ListComponent<string>.Create();
|
|
List<string> arr = listComponent.List;
|
|
foreach (KeyValuePair<int, BossComponent.BossState> item in boss.bossStateDic)
|
|
{
|
|
if (item.Value == BossComponent.BossState.Idle)
|
|
{
|
|
arr.Add($"[color=#00cc00]【{boss.GetBossBossName(item.Key)}】[/color]刷新了,大家赶紧去击杀吧,奖励多多!");
|
|
}
|
|
}
|
|
Chat.Instance.SendSystemCaht(unit, arr);
|
|
}
|
|
private async ETTask ChangeMap(Unit unit, UnitScene unitScene, bool initMap)
|
|
{
|
|
try
|
|
{
|
|
int mapId = unitScene.MapId;
|
|
UnitSceneType unitSceneType = MapHelper.GetMapType(mapId / 100);
|
|
if (unitSceneType == UnitSceneType.Boss)
|
|
{
|
|
int layer = unitScene.MapId % 100;
|
|
BossComponent.BossState state = BossComponent.Instance.GetState(layer);
|
|
if (state == BossComponent.BossState.Idle)
|
|
{
|
|
SendBossRefresh(unit, layer).Coroutine();
|
|
}
|
|
}
|
|
Sys_Scene targetSceneInfo = MapSceneComponent.Instance.GetMapInfo(mapId / 100);
|
|
Sys_Scene.PlayerPos position = targetSceneInfo.PlayerPosArr[0];
|
|
|
|
Team team = TeamComponent.Instance.Get(unit.TeamLeaderId);
|
|
if (team == null)
|
|
{
|
|
Log.Error(" team == null");
|
|
return;
|
|
}
|
|
|
|
unit.IsTransfer = true;
|
|
unitScene.enterTime = TimeHelper.ClientNow();
|
|
//!停止移动
|
|
unit.Stop();
|
|
await TimerComponent.Instance.WaitAsync(100);
|
|
|
|
unitScene.Position = new Vector2(position.PlayerPos_x, position.PlayerPos_y);
|
|
|
|
await unit.GetMapByUnitScene().Enter(unit,true);
|
|
|
|
//!发送切换地图
|
|
MessageHelper.SendActor(unit, new M2C_ChangeMap() { X = unitScene.Position.x, Y = unitScene.Position.y, MapId = unitScene.MapId });
|
|
await TimerComponent.Instance.WaitAsync(500);
|
|
if (initMap)
|
|
{
|
|
if (unitSceneType == UnitSceneType.MainStory || unitSceneType == UnitSceneType.Beach)
|
|
{
|
|
MainStoryMap.Instance.Init(unit, unitScene.MapId);
|
|
}
|
|
else if (unitSceneType == UnitSceneType.Trial)
|
|
{
|
|
TrialCopyMap.Instance.InitTrailCopyMap(unit, mapId);
|
|
}
|
|
else
|
|
{
|
|
await TimerComponent.Instance.WaitAsync(500);
|
|
StartupTransPoint(unit, unitScene.MapId);
|
|
}
|
|
}
|
|
void StartupTransPoint(Unit unit, int mapId)
|
|
{
|
|
MessageHelper.SendActor(unit, new M2C_StartupTransPoint() { MapId = mapId });
|
|
}
|
|
unit.IsTransfer = false;
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Log.Error(e);
|
|
}
|
|
}
|
|
private async ETVoid SendBossRefresh(Unit unit, int targetMapLayer)
|
|
{
|
|
await TimerComponent.Instance.WaitAsync(1000);
|
|
MessageHelper.SendActor(unit, new M2C_BossRefresh { BossId = BossComponent.Instance.GetBossId(targetMapLayer) });
|
|
}
|
|
}
|
|
} |