118 lines
4.8 KiB
C#
Executable File
118 lines
4.8 KiB
C#
Executable File
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
|
|
namespace ET
|
|
{
|
|
public class SendChatEvent : AEvent<EventType.SendChat>
|
|
{
|
|
public override async ETTask Run(EventType.SendChat args)
|
|
{
|
|
try
|
|
{
|
|
|
|
Unit sender = args.sender;
|
|
ChatType chatType = args.chatType;
|
|
string content = args.content;
|
|
switch (chatType)
|
|
{
|
|
case ChatType.NoneChat:
|
|
case ChatType.Private:
|
|
Log.Error($"chatType = {chatType} is invalid");
|
|
break;
|
|
case ChatType.Normal:
|
|
{
|
|
foreach (Unit unit in MapSceneComponent.Instance.GetMap(sender).GetAll())
|
|
{
|
|
if (unit.Id == sender.Id)
|
|
{
|
|
continue;
|
|
}
|
|
MessageHelper.SendActor(unit, new M2C_SendNormalChat
|
|
{
|
|
Id = sender.Id,
|
|
Type = chatType,
|
|
Content = content,
|
|
Name = (await UserComponent.Instance.Query(sender.Id)).NickName
|
|
});
|
|
}
|
|
}
|
|
break;
|
|
case ChatType.Team:
|
|
{
|
|
Team team = TeamComponent.Instance.Get(sender.TeamLeaderId);
|
|
foreach (Unit unit in team.GetUnits())
|
|
{
|
|
if (unit.Id == sender.Id)
|
|
{
|
|
continue;
|
|
}
|
|
MessageHelper.SendActor(unit, new M2C_SendNormalChat
|
|
{
|
|
Id = sender.Id,
|
|
Type = chatType,
|
|
Content = content,
|
|
Name = (await UserComponent.Instance.Query(sender.Id)).NickName
|
|
});
|
|
}
|
|
}
|
|
break;
|
|
case ChatType.World:
|
|
{
|
|
foreach (Unit unit in MapUnitComponent.Instance.GetAll())
|
|
{
|
|
if (unit.Id == sender.Id)
|
|
{
|
|
continue;
|
|
}
|
|
MessageHelper.SendActor(unit, new M2C_SendNormalChat
|
|
{
|
|
Id = sender.Id,
|
|
Type = chatType,
|
|
Content = content,
|
|
Name = (await UserComponent.Instance.Query(sender.Id)).NickName
|
|
});
|
|
}
|
|
}
|
|
break;
|
|
case ChatType.Family:
|
|
{
|
|
User user = await UserComponent.Instance.Query(sender.Id);
|
|
Family family =await FamilyComponent.Instance.Query(user.Family);
|
|
if (family == null) return;
|
|
foreach (long familyMemberId in family.GetAllId())
|
|
{
|
|
if (familyMemberId == sender.Id)
|
|
{
|
|
continue;
|
|
}
|
|
Unit unit = MapUnitComponent.Instance.Get(familyMemberId);
|
|
if (unit)
|
|
{
|
|
MessageHelper.SendActor(unit, new M2C_SendNormalChat
|
|
{
|
|
Id = sender.Id,
|
|
Type = chatType,
|
|
Content = content,
|
|
Name = user.NickName
|
|
});
|
|
}
|
|
}
|
|
}
|
|
break;
|
|
case ChatType.Camp:
|
|
{
|
|
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Log.Error(e);
|
|
}
|
|
await ETTask.CompletedTask;
|
|
}
|
|
}
|
|
}
|