54 lines
1.9 KiB
C#
54 lines
1.9 KiB
C#
|
using System;
|
|||
|
using System.Net;
|
|||
|
|
|||
|
namespace ET
|
|||
|
{
|
|||
|
[ActorMessageHandler]
|
|||
|
public class C2M_GetMapCoinHandler : AMActorLocationRpcHandler<Unit, C2M_GetMapCoin, M2C_GetMapCoin>
|
|||
|
{
|
|||
|
|
|||
|
protected override async ETTask Run(Unit unit, C2M_GetMapCoin request, M2C_GetMapCoin response, Action reply)
|
|||
|
{
|
|||
|
|
|||
|
if (!unit.IsTeamLeader)
|
|||
|
{
|
|||
|
response.Message = "你不是队长!";
|
|||
|
reply();
|
|||
|
return;
|
|||
|
}
|
|||
|
UnitScene unitScene = unit.GetComponent<UnitScene>();
|
|||
|
if (!MapCoinComponent.instance.HasCoinMonster(unitScene.MapId))
|
|||
|
{
|
|||
|
response.Message = "金币怪消失";
|
|||
|
reply();
|
|||
|
return;
|
|||
|
}
|
|||
|
Team team = TeamComponent.Instance.Get(unit.TeamLeaderId);
|
|||
|
var list = team.GetUnits();
|
|||
|
bool hasCount = false;
|
|||
|
foreach (var u in list)
|
|||
|
{
|
|||
|
PlayerData data = u.GetComponent<PlayerData>();
|
|||
|
hasCount = hasCount || data.mapCoinCount > 0;
|
|||
|
}
|
|||
|
if (!hasCount)
|
|||
|
{
|
|||
|
response.Message = "没有次数了";
|
|||
|
reply();
|
|||
|
return;
|
|||
|
}
|
|||
|
MapCoinComponent.instance.RemoveMonster(unit.Id, unitScene.MapId);
|
|||
|
foreach (var u in list)
|
|||
|
{
|
|||
|
PlayerData data = u.GetComponent<PlayerData>();
|
|||
|
if (data.mapCoinCount <= 0) continue;
|
|||
|
data.mapCoinCount--;
|
|||
|
int count = RandomHelper.RandomArray_Len2(ConstDefine.MapCoinArr);
|
|||
|
CharacterHelper.AddMoney(u, CharacterHelper.MoneyType.Coin, count);
|
|||
|
MessageHelper.SendActor(u, new M2C_SendTip { Message = $"恭喜你获得{count}铜币" });
|
|||
|
}
|
|||
|
reply();
|
|||
|
await ETTask.CompletedTask;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|