/// <summary> /// Метод для получения интерфейса игрока в случае если огонь велся не с ручного оружия /// </summary> /// <param name="entityID"></param> /// <returns></returns> public IMyPlayer GetPlayer(long entityID) { try { IMyPlayer player = (IMyPlayer)null; IMyEntity entityById = MyAPIGateway.Entities.GetEntityById((long)entityID); switch (entityById) { case IMyCubeBlock _: MyCubeBlock myCubeBlock = entityById is MyCubeBlock ? entityById as MyCubeBlock : (MyCubeBlock)(entityById as MyFunctionalBlock); if (myCubeBlock.CubeGrid != null) { if (myCubeBlock.CubeGrid.HasMainCockpit() && myCubeBlock.CubeGrid.MainCockpit != null) { IMyShipController mainCockpit = myCubeBlock.CubeGrid.MainCockpit as IMyShipController; IMyControllerInfo controllerInfo = ((IMyControllableEntity)mainCockpit).ControllerInfo; if (controllerInfo != null && controllerInfo.ControllingIdentityId > 0L) { player = PlayerUtils.GetPlayer(((IMyControllableEntity)mainCockpit).ControllerInfo.ControllingIdentityId); } } if (player == null) { player = PlayerUtils.GetPlayer(PlayerUtils.GetOwner(myCubeBlock.CubeGrid)); } break; } break; case IMyCubeGrid _: player = PlayerUtils.GetPlayer(PlayerUtils.GetOwner(entityById as MyCubeGrid)); break; case IMyPlayer _: player = entityById as IMyPlayer; break; case IMyCharacter _: player = PlayerUtils.GetPlayer((entityById as MyCharacter).GetPlayerIdentityId()); break; case IMyHandheldGunObject <MyGunBase> _: player = PlayerUtils.GetPlayer((entityById as IMyHandheldGunObject <MyGunBase>).OwnerIdentityId); break; case IMyHandheldGunObject <MyToolBase> _: player = PlayerUtils.GetPlayer((entityById as IMyHandheldGunObject <MyToolBase>).OwnerIdentityId); break; default: ///если не удалось определить по какой причине умер игрок Log.Warn("Undetected kill type:"); Log.Warn("> Name: " + entityById.DisplayName); Log.Warn(string.Format("> Type: {0}", (object)((object)entityById).GetType())); break; } return(player); } catch (Exception e) { return(null); } }