您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 

56 行
1.1 KiB

  1. const sendObjToZone = async ({ obj, invokingObj, zoneName, toPos, toRelativePos }) => {
  2. const { serverId, instance: { physics, syncer: globalSyncer } } = obj;
  3. globalSyncer.flushForTarget(serverId);
  4. if (obj.zoneName === zoneName) {
  5. physics.removeObject(obj, obj.x, obj.y);
  6. if (toRelativePos) {
  7. toPos = {
  8. x: invokingObj.obj.x + toRelativePos.x,
  9. y: invokingObj.obj.y + toRelativePos.y
  10. };
  11. }
  12. obj.x = toPos.x;
  13. obj.y = toPos.y;
  14. physics.addObject(obj, obj.x, obj.y);
  15. globalSyncer.queue('onRespawn', {
  16. x: obj.x,
  17. y: obj.y
  18. }, [obj.serverId]);
  19. return;
  20. }
  21. obj.fireEvent('beforeRezone');
  22. obj.destroyed = true;
  23. await obj.auth.doSave();
  24. const simpleObj = obj.getSimple(true, false, true);
  25. if (toPos) {
  26. simpleObj.x = toPos.x;
  27. simpleObj.y = toPos.y;
  28. } else if (toRelativePos) {
  29. simpleObj.x = invokingObj.obj.x + toRelativePos.x;
  30. simpleObj.y = invokingObj.obj.y + toRelativePos.y;
  31. }
  32. process.send({
  33. method: 'rezone',
  34. id: obj.serverId,
  35. args: {
  36. obj: simpleObj,
  37. newZone: zoneName
  38. }
  39. });
  40. };
  41. module.exports = sendObjToZone;