R2G_AddUnitsToMapHandler.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. namespace ET.Server
  2. {
  3. /// <summary>
  4. /// 抖音api http回调, 评论添加玩家
  5. /// </summary>
  6. [ActorMessageHandler(SceneType.Game)]
  7. public class R2G_AddUnitsToMapHandler: AMActorHandler<Scene, R2G_AddUnitsToMap>
  8. {
  9. protected override async ETTask Run(Scene scene, R2G_AddUnitsToMap request)
  10. {
  11. if (string.IsNullOrEmpty(request.OpenId))
  12. {
  13. Log.Debug($"未找到openId...");
  14. return;
  15. }
  16. // 房间是否存在
  17. Map map = scene.GetComponent<GameMapComponent>().GetMapByRoomId(request.RoomId);
  18. if (map == null)
  19. {
  20. Log.Debug($"未找到房间...");
  21. return;
  22. }
  23. // 初始模板id
  24. int[] units = new int[] { 101, 111, 121, 131 };
  25. int templateId = RandomGenerator.RandomArray(units);
  26. string[] pos = map.GetCurXY().Split(";");
  27. Struct.MonsterUnit unit = new Struct.MonsterUnit();
  28. unit.id = templateId;
  29. unit.force = 1;
  30. unit.x = int.Parse(pos[0]);
  31. unit.y = int.Parse(pos[1]);
  32. unit.autoGuard = true;
  33. int objId = await map.AddUnits(unit, true);
  34. map.AddUnitPlayer(request.OpenId, templateId, objId, 0);
  35. await ETTask.CompletedTask;
  36. }
  37. }
  38. }