R2G_AddUnitsToMapHandler.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. // 初始模板id
  12. int[] units = new int[] { 101, 111, 121, 131 };
  13. int templateId = RandomGenerator.RandomArray(units);
  14. // 房间是否存在
  15. Map map = scene.GetComponent<GameMapComponent>().GetMapByRoomId(request.RoomId);
  16. if (map == null)
  17. {
  18. Log.Debug($"未找到房间...");
  19. return;
  20. }
  21. string[] pos = map.GetCurXY().Split(";");
  22. Struct.MonsterUnit unit = new Struct.MonsterUnit();
  23. unit.id = templateId;
  24. unit.force = 1;
  25. unit.x = int.Parse(pos[0]);
  26. unit.y = int.Parse(pos[1]);
  27. unit.autoGuard = true;
  28. int objId = await map.AddUnits(unit, true);
  29. map.AddUnitObjId(request.OpenId, objId);
  30. map.AddUnitPlayer(request.OpenId, templateId);
  31. await ETTask.CompletedTask;
  32. }
  33. }
  34. }